Name: Email:
Exercise 1: Consider the following procedure swap2.
procedure swap2 (x, y : integer); procedure f() : integer; var z : integer; begin (* f *) z := x; x := y; return z; end; y := f(); end;
Describe the effect of the procedure call swap2(i, A[i]) under each of the following parameter passing methods:
Exercise 2: Consider the following program and describe the effect of running the program with both lexical scoping and dynamic scoping.
program main; var x : integer; procedure sub1; begin writeln ('x=', x) end; procedure sub2; var x : integer; begin x := 10; sub1; end; begin x:= 5; sub2; end.
Exercise 3: Describe the stack contents (the activation records) for the following program at the point where f(1) is called.
program activations; function pred (m: integer) : integer; begin pred := m-l; end; function f (n: integer): integer; begin if n = 0 then f := 1 else f := n * f (pred(n)) end; begin f(3); end.
Exercise 4: Write and compile the "hello world" program on your favorite C++ compiler. Submit the source code here.
Exercise 5: Modify the stack program that we described in class to implement a first-in/first out buffer, based on the following invariants:
last revised: September 21, 1996