Computer Science 5641
Compiler Design
Homework Assignment 4 (20 points)
Due December 3, 2009

  1. The grammar below defines lists of lists of literals. A list type can be declared as a "list of" type and a list literal is made as a set of expressions between parentheses separated by commas. Write syntax directed translation rules to type the expressions in this grammar and check that types match (e.g., a list must be of one type).
  2. Exercise 6.5.1, page 398
  3. What is printed by the program below for (a) call by value, (b) calue by reference and (c) call by value-result. Assume that an argument that includes an operator has a temporary variable created to holds it value:
            void p (x, y, z) {
                print(x,y,z);
                y = y + 1;
                z = z + x;
                print(x,y,z);
            }
            print(a,b);
            a = 2;
            b = 3;
            p(a + b, a, a);
            print(a,b);
      
  4. Languages that use dynamic scoping cannot be typed at compile time. Explain why with an example.