TopDeclaration Descriptor ContentsSemantic Processing Subphase Ordering

Semantic Processing Subphase Ordering

  1. The fact that Woolite supports arbitrarily deep nesting of class definitions and allows forward references to declarations (except in extends clauses) makes it necessary to make several partial sub-passes over the syntax tree and to think very carefully about what processing to perform during each pass.
  2. For example, consider the simple program shown in Figure *. Even though this program only includes three declarations at the top level, it is enough to show that several "obvious" strategies for processing the declarations won't work.
    class Program {
          Forward x;
          
          class Forward {
                int counter;
             
                void relay() {
                      x.action();
                 }
                 
                 void action() {
                     counter = counter + 1;
                 }
                 
                 void init() {
                     counter = 0;
                 }
                 
                 int get() {
                     return counter;
                  }
             }
             
             int main() {
                 x = new Forward;
                 x.relay();
                 return x.get();
             }
     }
     
    Coping with forward references
     

  3. In addition to these (relatively simple) issues raised by forward references, the ability to invoke a method on an object leads to a form of vertical forward reference through which it appears to become necessary to process inner scopes before outer scopes.
  4. To deal with this, your semantic processing phase will make two passes over the syntax tree.

Computer Science 434
Department of Computer Science
Williams College

TopDeclaration Descriptor ContentsSemantic Processing Subphase Ordering