Control stack
. Flow of control in program corresponds to depth first traversal of activation tree
. Use a stack called control stack to keep track of live procedure activations
. Push the node when activation begins and pop the node when activation ends
. When the node n is at the top of the stack the stack contains the nodes along the path from n to the root
The flow of control in a program corresponds to a depth first traversal of the activation tree that starts at the root, visits a node before its children, and recursively visits children at each node in a left to right fashion. A stack called control stack is used to keep track of live procedure activations. The idea is to push the node for an activation onto the control stack as the activation begins and to pop the node when the activation ends. Then the contents of the control stack are related to paths to the root of the activation tree. When node n is at the top of the control stack, the stack contains the nodes along the path from n to the root.
If in the previous example, we consider the activation tree when the control reaches q(2,3), then at this point the control stack will contain the following nodes:
s, q(1,9), q(1,3), q(2,3)
following the path to the root.
|