int var = 10;
procedure set_var(int val):
var = val;
int var = 2;
Suppose the procedure main() uses static (lexical) scoping. What will it print, and why?
Suppose the procedure main() uses dynamic scoping. What will it print, and why?
This problem uses the following procedure. This procedure uses static (lexi-cal) scoping.
procedure proc1(int i):
b = a + 1;
procedure recursion(int k):
b = b – 1;
if (b > 1):
recursion(k * b);
a = k;
b = b + i;
a = 1;
What does this procedure print? (Give the output of procedure main().)
Rewrite the procedure main() where each variable (argument vari-ables, declared variables, procedure names) is renamed by their (level, o set) pairs.
How does procedure proc1 nd variable a in instruction b = a + 1;? Show the RISC instructions corresponding to the high-level instruc-tion b = a + 1; in this procedure. You should use the same ILOC instruction format as used in class.
Show the stack frames at the beginning of procedure proc1. Label each frame with its procedures name, and make sure you include the
local variables and their values. Show all access links and control links between the stack frames, and the frame pointer (FP), by drawing arrows. You should use the frame layout in the gure below.
Figure 1: Figure for the frame layout