Homework 2
Basic Semantics

Due on Thursday March 3 before midnight


This homework must be done individually. No copying is permitted.

  1. (25 points) Show the stack of bindings for each variable x, y, and z (as illustrated in the class slides) at the three points indicated by the comments in the following program using static scope. What does the program print?
    int x, y, z;
    void print (void) {
     printf("%d %d %d\n",x,y,z);
    void q (void) {
     x = y+10;
    void p (void) {
     int x;
     x = y+1;
     z = x+2;
     /* point 2 */
     /* point 3 */
    main() {
     x = 1
     y = 2;
     z = 3;
     /* point 1 */

  2. (25 points) Repeat the previous problem for dynamic scope. (That is, show the stacks of bindings at the three points and print the result.)

  3. (40 points) Problem 5.26 in the textbook (p185).

  4. (10 points) Problem 5.27 in the textbook (p185).

What to Submit

Use the form below to submit your homework. We do not accept email or hardcopy submissions. Acceptable file formats for your submitted file are: plain text, Microsoft Word document (.doc), PDF (.pdf), and postscript (.ps). Don't forget to put your name and student ID on your homework. You may submit your file as many times as you like, but only the most recently submitted file will be retained and evaluated.

Submit Homework #2:

Last modified: 02/24/11 by Leonidas Fegaras