Computer Science 5641
Compiler Design
Homework Assignment 4 (20 points)
Due November 21, 2002

  1. [5] Do exercise 6.3 from the textbook.
  2. [5] Construct a program using C or C++ syntax that has different output assuming parameters are passed by (1) value, (2) reference or (3) value-result.
  3. [5] At the points labeled (A) through (E) show the symbol table structure that would exist in analyzing this program using (1) a symbol table using a list of hashtables and (2) a symbol table using a hashtable of lists.

    Assume the most closely nesting scope rule for resolving uses and that each function introduces one new scope for both its parameters and local variables.

    int X;
    double Y;
    int F (char X, int Z) {
      char Y;
      /* (A) */
        double X, Y;
        int W;
        /* (B) */
      char W;
      /* (C) */
    /* (D) */
    double G (int Z) {
      char X;
      /* (E) */
  4. [5] Many languages allow functions to be passed as parameters. Using C++'s mechanism for passing functions as parameters, discuss how having these types would be dealt with in a symbol table and during type checking.