Class SymbolTable


  • public class SymbolTable
    extends Object
    The symbol table handling declared identifies.
    Version:
    0.1
    Author:
    Michael Bouschen
    • Field Detail

      • actualScope

        protected int actualScope
        The actual scope level.
      • nestings

        protected Stack nestings
        Stack of old definitions.
      • symbols

        protected Hashtable symbols
        The table of declared identifier (symbols).
    • Constructor Detail

      • SymbolTable

        public SymbolTable()
    • Method Detail

      • enterScope

        public void enterScope()
        Opens a new scope. Prepare everything to handle old definitions when a identifier declaration is hidden.
      • leaveScope

        public void leaveScope()
        Closes the actual scope. Hidden definitions are reinstalled.
      • getActualScope

        public int getActualScope()
        Returns the level of the actual scope.
        Returns:
        actual scope level.
      • declare

        public Definition declare​(String ident,
                                  Definition def)
        Add identifier to the actual scope. If the identifier was already declared in the actual scope the symbol table is NOT changed and the old definition is returned. Otherwise a possible definition of a lower level scope is saved in the actual nesting and the new definition is stored in the symbol table. This allows to reinstall the old definition when the sctaul scope is closed.
        Parameters:
        ident - identifier to be declared
        def - new definition of identifier
        Returns:
        the old definition if the identifier was already declared in the actual scope; null otherwise
      • isDeclared

        public boolean isDeclared​(String ident)
        Checks whether the specified identifier is declared.
        Parameters:
        ident - the name of identifier to be tested
        Returns:
        true if the identifier is declared; false otherwise.
      • getDefinition

        public Definition getDefinition​(String ident)
        Checks the symbol table for the actual definition of the specified identifier. If the identifier is declared the definition is returned, otherwise null.
        Parameters:
        ident - the name of identifier
        Returns:
        the actual definition of ident is declared; null otherise.
      • forgetNesting

        protected void forgetNesting​(Nesting nesting)
        Internal method to reinstall the old definitions. The method is called when a scope is closed. For all identifier that were declared in the closed scope their former definition (that was hidden) is reinstalled.
        Parameters:
        nesting - list of hidden definitions