Show/Draw the stack with all activation record instances, including static and dynamic chains, when execution reaches position ("Draw stack at this point") indicated in the following skeletal program. Assume Bigsub is at level 1.
procedure Bigsub is MySum : Float; procedure A is X : Integer; procedure B(Sum : Float) is Y, Z : Float; begin -- of B . . . C(Z) . . . end; -- of B begin -- of A . . . B(X); . . . end; -- of A procedure C(Plums : Float) is begin -- of C . . . Draw stack at this point end; -- of C L : Float; begin - - of Bigsub . . . A; . . . end; -- of Bigsub
To draw the stack at the indicated position in the skeletal program, we need to trace the activation records including static and dynamic chains. Let's start by identifying the activation records and their relationships.
At the position where we are asked to draw the stack, the procedure C is being called from procedure B. The activation records at this point will consist of the records for procedures B, A, and Bigsub. Let's identify the relevant details for each activation record and then draw the stack:
Bigsub Activation Record:
A Activation Record:
B Activation Record:
Now, let's draw the stack at this point:
----------------------------- | B Activation Record | |---------------------------| | Parameters: Sum | | Local Variables: Y, Z | | Static Chain: A (Level 2)| | Dynamic Chain: Bigsub | ----------------------------- | A Activation Record | |---------------------------| | Local Variables: X | | Static Chain: Bigsub | | Dynamic Chain: Bigsub | ----------------------------- | Bigsub Activation Record | |---------------------------| | Local Variables: MySum | -----------------------------
This represents the stack at the indicated point in the program, including the activation records for procedures B, A, and Bigsub, with their respective static and dynamic chains and local variables/parameters.