TopIntermediate RepresentationsBlock Structure and Symbol Table Organization

Block Structure and Symbol Table Organization

  1. First, recall the rules of nested block structure.
  2. For example, consider the interpretation of identifier references in the program whose skeleton is shown in Figure *. The tree of scopes corresponding to this program text is shown in Figure *.

    class Program {
    int W;
    int X;
    class A {
    int W;
    int Y;
    int Z;
    void B() { int X ; . . . }
    void C() { int X; int Y ; . . . }
    . . .
    } // end of A
    void D() { int Z ; . . . }
    }

    A class definition skeleton illustrating nested declarations
     

    Tree of scopes corresponding to Figure *
     

  3. The organization of many compiler symbol tables is fairly complex as a result of the need to support the scope rules associated with block structure. The standard approach to explaining symbol table organization, however, adds additional complexity by failing to properly distinguish the role of the scanner in building the symbol table from that of the semantic analysis routines in completing it.

  4. Many compiler texts describe the symbol table as a dictionary, typically implemented using a hash table or a search tree.

  5. In the "symbol table is a hash table" view of a compiler, detecting undeclared and multiply declared identifiers becomes a task split between the scanner, parser and symbol table routines.

  6. A cleaner separation of function can be arranged. Only one search function is needed: The errors that would have been raised by find and enter can instead be recognized during semantic analysis.
  7. The basic idea is to let the syntactic analyzer simply process all references to an identifier by mapping them to a pointer to the symbol table entry for the identifier. The semantic analysis phase then distinguishes declarations from uses by either putting information into or taking information out of the symbol table entry.

Computer Science 434
Department of Computer Science
Williams College

TopIntermediate RepresentationsBlock Structure and Symbol Table Organization