edu.gac.max.mcs388.s2003.compiler_support
Class ScopedIdentifier

java.lang.Object
  |
  +--edu.gac.max.mcs388.s2003.compiler_support.ScopedIdentifier

public class ScopedIdentifier
extends java.lang.Object

The ScopedIdentifier class represents the programming language concept of an identifier, i.e., a name that can have declarations associated with it.


Method Summary
 void declare(edu.gac.max.mcs388.s2003.compiler_support.Declaration decl)
          declare associates some piece of information (the Declaration) with a ScopedIdentifier in the current scope.
static void enterScope()
          The static enterScope method serves notice that a new scope is being entered, nested inside the current scope.
static void exitScope()
          The static exitScope method serves notice that the current scope is being exited, returning to the outer scope it was nested inside.
static edu.gac.max.mcs388.s2003.compiler_support.ScopedIdentifier get(java.lang.String nm)
          The static get method provides the only way to obtain a ScopedIdentifier, since there is no public constructor.
 edu.gac.max.mcs388.s2003.compiler_support.Declaration getDeclaration()
          getDeclaration returns the Declaration that is currently in effect.
 java.lang.String toString()
          toString returns the String that was passed to the get method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

get

public static edu.gac.max.mcs388.s2003.compiler_support.ScopedIdentifier get(java.lang.String nm)
The static get method provides the only way to obtain a ScopedIdentifier, since there is no public constructor. The same ScopedIdentifier object will consistently be returned every time get is passed an equal String; this is the point of get. The String becomes the ScopedIdentifier's name.


toString

public java.lang.String toString()
toString returns the String that was passed to the get method

Overrides:
toString in class java.lang.Object

declare

public void declare(edu.gac.max.mcs388.s2003.compiler_support.Declaration decl)
             throws edu.gac.max.mcs388.s2003.compiler_support.RedeclarationException
declare associates some piece of information (the Declaration) with a ScopedIdentifier in the current scope.

Throws:
edu.gac.max.mcs388.s2003.compiler_support.RedeclarationException - If the ScopedIdentifier already has been declared in this exact scope (not counting surrounding scopes)

getDeclaration

public edu.gac.max.mcs388.s2003.compiler_support.Declaration getDeclaration()
getDeclaration returns the Declaration that is currently in effect. This is the one that was declared in the innermost scope that has not yet been exited


enterScope

public static void enterScope()
The static enterScope method serves notice that a new scope is being entered, nested inside the current scope. Thus all identifiers are once again eligible for declaration without it being an illegal redeclaration. This also delimits how many declarations are to be undone when the scope is exited.


exitScope

public static void exitScope()
The static exitScope method serves notice that the current scope is being exited, returning to the outer scope it was nested inside. This does two things. First of all, all declarations done within the scope being exited is forgotten, i.e., will no longer be returned by getDeclaration. Second, each of the forgotten Declaration objects has its leavingScope method invoked as a form of "callback", so that any additional operation can be done that the particular form of Declaration needs, e.g., deallocating a register.