AUGUSTANA UNIVERSITY COLLEGE

CSC 370 -- Programming Languages

Sample Exam Question

Implementation of Block Structured Languages

Given the following Pascal-like program:

	
program A;

   var u : integer;

   procedure B (x : integer);

      var y : integer;

      procedure C (var w : integer);

         begin {C}
            D(w);
         end; {C}

      begin {B}
         D(x);
         C(y);
      end; {B}

   procedure D (var y : integer);

      var z : integer;

      begin {D}
         . . .
      end; {D}

   begin {A}
      u := 1;
      B(u)
   end. {A}

draw the stack and the activation records it contains after the call D(w). Fill in the static links, dynamic links, local variables, and parameter fields. Use arrows to represent the static and dynamic links. Put the names of the local variables in the local slots; for the contents, use some notation like address(uA) to represent the address of the variable u defined in the program A, or value(zD) to represent the value of the variable z defined in the procedure D. Include the stack and environment pointers (SP and EP).