Exercise 13      Name                                    Points __/35

Document last modified: 

  1. Compute wp for the following:
    1. (1) {x > -10} y := x + 13;              {y > 3} 
       
    2. (1) {y < x - 2} x := x - y + 2;         {x > 4}
       
    3. (2) {x < 2} y := x + 7;                  {y < 9}
           {y < 9} x := y - 5;                   {x < 4}
       
    4. (2) {y > 13}
           if (x<5) then
                  {y > -2} y := y + 7          {y > 5}
           else {y > 13} y := y - 8           {y > 5}
       
    5. (2) {y > 13 && x > -2}
           if (x<5) then
                  {x > -2} y := x + 7          {y > 5}
           else {y > 13} y := y - 8           {y > 5}
       
    6. (2) {y > 13 && x > y-2}
           if (x<5) then
                  {x > y-2} y := x + 7 - y    {y > 5}
           else {y > 13}  y := y - 8          {y > 5}
       
    7. (3) {y > 13 }
           if (x<5) then
           {y > 6}  x := y + 3                  {x > 9}  
           {x > 9}  y := x - 4                   {y > 5}
           else          
           {y > 13} y := y - 8                  {y > 5}
  1. (10) Scoping
  1. Give the static scoping diagram.

  2. What is the result with static scoping?

  3. Give the dynamic scoping diagram.

  4. What is the result with dynamic scope?

int z = 2;

int add ( int f(int), int z) {  return f ( z ); }

int p(int x) { return x+z; }

void main() { cout << add( p, 3); }

 

 

 

3. (12 pts) What is the output of the following for:

  1. x is passed by value and y is passed by value;
  2. x is passed by value and y is passed by name;
  3. x is passed by name and y is passed by value; and
  4. x is passed by name and y is passed by name?
#include <iostream.h>

int I = 0;
int A[3] = { 7, 11, 13 };

void P(int x, int y) {
        y = 1;
        cout << x << "\t";
        I = 2;
        cout << x << "\t";
        I = 2;
        cout << x << "\t";
        cout << y << "\n";
}

void main() {
        P( A[I],  I );
        P( I     , A[I] );
 }
a.
7       7       7       1
2       2       2       1

b.
7       7       7       2
2       2       2       1

c.
7       13    13      1
2        2       2      1

d.
11      13    13     2
2          2      2     1