Exercise 13      Name                                    Points __/35

Document last modified: 

  1. Compute wp for the following:
    1. (1)                 y := x + 13;            {y > 3} 
       
    2. (1)                 x := x - y + 2;         {x > 4}
       
    3. (2)                 y := x + 7;             
                           x := y - 5;               {x < 4}
       
    4. (2) 
           if (x<5) then
                                y := y + 7        
           else               y := y - 8           {y > 5}
       
    5. (2)
           if (x<5) then
                                y := x + 7         
           else               y := y - 8           {y > 5}
       
    6. (2) 
           if (x<5) then
                                 y := x + 7 - y    
           else                y := y - 8          {y > 5}
       
    7. (3)
           if (x<5) then
                        x := y + 3                    
                        y := x - 4                  
           else          
                        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] );
 }