Computer Science 433
Programming Languages
Fall 2012, The College of Saint Rose
1. What are the values printed out in the following program if static scoping is used? What are the values printed out in the same program if dynamic scoping is used? The program is in a Pascal-like syntax. Ask if you are unsure about what any line of code is intended to do. (6 points)
program main; var x : integer; procedure sub0; begin {sub0} static int x := 3; x := x + 1 end; {sub0} procedure sub1; begin {sub1} writeln('x = ', x) end; {sub1} procedure sub2; begin {sub2} var x : integer; x := 12; sub1; end; {sub2} begin {main} x := 8; sub0; sub2; end. {main}
2. Compute the address of the [5][2] element in a 10 ×10 2-dimensional array of integers (4 bytes each) called IntArray where the initial address for the array starts at 00004400 for the following languages:
a. C++ (2 points)
b. Fortran (2 points)
3. Sebesta Programming Exercise 5, p. 241. You need to do only 2 of the 3 languages listed. (4 points)
4. Sebesta Programming Exercise 6, p. 241. Here, you need to do this for 1 of the 3 languages listed. (3 points)
5. Sebesta Programming Exercise 7, p. 241. (8 points)