Symbol Tables vs. Symbol Table OrganizationTopIntroductionUnderstanding Block Structure

Understanding Block Structure

  1. First, recall the rules of nested block structure.
  2. A very helpful way to understand such scope rules is to recognize that the nesting is just an alternate way to represent a tree structure:
  3. For example, consider the interpretation of identifier references in the program whose skeleton is shown in Figure *.
    public class NestingExample {   
    
    int x; int y;
    class One {
    Two y; int z;

    class In1 {
    One y;
    }

    void m1() { int y; y = 1; x = y; }
    }

    class Two {
    Three x;
    void m2() x.m3();
    }

    class Three {
    Two x; One y;

    class In3 extends One {
    void mIn3() {
    y.m2();
    m1();
    }
    }

    void m3() { /* ... */ }
    }
    }

    A class definition skeleton illustrating nested declarations
     

    Tree of scopes corresponding to Figure *
     

  4. Within each node of this tree, we have written the names of the identifiers declared within the scope that corresponds to the tree node.
  5. If an identifier is referenced within a given scope in the program, the correct definition can be found by sequentially searching the scopes on the path in this tree from the node for the scope to the root of the tree.
  6. Note the interesting contents of the scope for the class In3. Because this class extends the class One. It includes new bindings for the names y, z, m1, and In1. These names are not redeclared. Rather, new bindings to existing declarations are created and added to the scope.

Computer Science 434
Department of Computer Science
Williams College

Symbol Tables vs. Symbol Table OrganizationTopIntroductionUnderstanding Block Structure