1. [ Chapter 10 ] An activation record for an ALGOL-like language typically contains the following entries:
local variables
parameters
dynamic link
static link
return address
Show the stack with all activation record instances, including variables, parameters, and static and dynamic chains, when execution reaches position 1 in the following skeletal program. (You may omit the return address value from your activation records.)
procedure MAIN is
X: Integer;
procedure A(P: in Integer) is
Y: Integer;
procedure B is
begin
... <----------------------- 1
end B;
procedure C(Q: in Integer) is
begin
...
B;
...
end C;
begin -- A
...
C(Y);
...
end A;
begin -- MAIN
...
A(X);
...
end MAIN;
2. [ Chapter 7 ] What is the result of evaluating the expression
6 * 5 - 4 - 3 * 2if we assume:
a) that multiplication (*) has lower precedence than subtraction (-), and that all operators are left-associative?
b) that multiplication (*) and subtraction (-) have the same precedence, and that all operators are right-associative?
c) that multiplication (*) has higher precedence than subtraction (-), and that all operators are left-associative?
3. [ Chapter 9 ] Consider the following program:
procedure main is
x, y: Integer;
procedure change (a, b: Integer) is
begin
a := a + b;
b := x;
Put(a); New_Line;
Put(b); New_Line;
Put(x); New_Line;
Put(y); New_Line;
end change;
begin -- main
x := 2;
y := 3;
change(x, y);
Put(x); New_Line;
Put(y); New_Line;
end main;
What output will be printed if we assume that variables x and
y are passed by
a) value
b) result
c) value-result
d) reference
e) name