Augustana logo

COMPUTING SCIENCE 370 -- Programming Languages


Exercise Set 2 -- Implementation of Block Structured Languages



Due Date: Friday, Nov. 19, at the start of the lab session (12:50 p.m.)

Objectives

Exercises

  1. Given the following Pascal-like program:

       
    program A;
    
       var u : integer;
    
       procedure B (x : integer);
    
          var v : integer;
    
          begin {B}
             v := 2 * x;
          end; {B}
    
       procedure C (var y : integer);
    
          var w : integer;
    
          procedure D (var z : integer);
    
             begin {D}
                z := y + 2;
    
                { DRAW STATE OF SYSTEM AT THIS POINT }
                . . .
             end; {D}
    
          begin {C}
             B( y ); 
             D( w );
          end; {C}
    
       begin {A}
          u := 1;
          C( u )
       end. {A}
    

    draw the stack and the activation records it contains after the execution of the first line of procedure D. Fill in the static links, dynamic links, local variables, and parameter fields. Include space in the activation record for storing the instruction pointer (IP). Use arrows to represent the static and dynamic links. Put the names of the formal parameters and local variables in their corresponding slots in the activation records, and indicate the contents of these fields using actual values (for value fields) or by drawing arrows to the corresponding actual parameters (for reference parameters). Include the stack and environment pointers (SP and EP).

  2. Do the same exercise but using a display instead of static links. Be sure you also show the storage locations for previous values that were stored in the display, which would be needed to restore the display on the return from a subroutine.

Notes


Copyright © 2004 Jonathan Mohr