[UMN logo]

CSCI 5106: Programming Languages
Spring 2006, University of Minnesota
Homework 6


Posted: April 4, 2006
Due: Before class on April 11, 2006


Problem 1.

Problem 5.1 in the book.


Problem 2.

Note: You should read Sections 5.5, 5.6 and 5.7 in the book carefully before doing this problem and the next one.

The pseudocode below uses a Pascal-style presentation to depict a set of nested procedures with nonlocal variables. In case you are unfamiliar with this style of presenting procedure declarations, here is how to read it. Following the procedure header is a collection of variable and nested procedure declarations and eventually the body of the procedure enclosed between a begin and an end; comments in this code that are signified by being enclosed between (* and *) help you identify the body of each procedure. The variables and procedures declared in a given procedure are visible in the rest of the procedure, including the procedures nested within it unless they are occluded by other declarations in that context.

Assuming lexical scoping, for each assignment statement in the pseudocode describe the actions that occur every time it is executed. Be explicit about the procedure call and return sequences and the use and maintenance of the control and access links. For the latter, be sure to discuss the way in which these links are used in identifying the location of the cell corresponding to a variable, the way in which the stack space is freed up and the way in which the right values for control and access links are computed when a new activation record is created. Indicate also what information the compiler must generate with regard to variable occurrences to support these actions and also any global pointers into the stack that should be maintained for this purpose by the runtime system. Be sure to check the actions that you describe are correct even when control reaches the relevant assignment statement through the call to procedure P from within R.

Given the recursive call back to P from within R, you may wonder if the given program ever terminates. This is a little orthogonal to the main point of the problem but, nevertheless, here is an explanation. The ellipsis in the code (i.e. the portions indicated by ...) could contain conditional statements that govern when the assignment statements specifically indicated get executed.

  program M;
    var x;

    procedure P;
      var w, y, z;

      procedure Q;
        var x;

        procedure R;

        begin (* R *) ... 
                      z := P; 
                      ... 
        end; (* R *)

      begin (* Q *) ... 
                    y := R; 
                    ... 
      end; (* Q *)

    begin (* P *) ... 
                  x := Q; 
                  w := Q; 
                  ... 
    end; (* P *)

  begin (* main prog *)  
     ... P; ... 
  end. (* main prog *)


Problem 3.

Redo the previous problem using a display instead of access links.


Last updated on April 4, 2006 by gopalan@cs.umn.edu