Posted: April 4, 2006
Due: Before class on April 11, 2006
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
Given the recursive call back to
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 *)
Last updated on April 4, 2006 by gopalan@cs.umn.edu