Class SymbolTable

java.lang.Object
com.github.tom65536.adelante.symboltable.SymbolTable

public class SymbolTable extends Object
Symbol table implementation.
  • Constructor Details

    • SymbolTable

      public SymbolTable()
      Initialize a new symbol table. The symbol table is initialized with no parent.
    • SymbolTable

      protected SymbolTable(SymbolTable aParent)
      Initialize a new symbol table.
      Parameters:
      aParent - the parent scope.
  • Method Details

    • setPacketName

      public void setPacketName(String aName)
      Set the current packet name.
      Parameters:
      aName - the new name.
    • getPacketName

      public String getPacketName()
      Get the current packet name. If the packet name is not set in the current scope this method recursively traverses the parent scopes.
      Returns:
      the current packet or file name.
    • lookup

      public List<SymbolTable.Entry> lookup(String id)
      Look up a symbol.
      Parameters:
      id - the normalized identifier to be looked up.
      Returns:
      a list of all matching definitions.
    • lookup

      public List<SymbolTable.Entry> lookup(Token token)
      Look up a token of an identifier.
      Parameters:
      token - the identifier token.
      Returns:
      a list of all matching definitions.
    • canAdd

      public boolean canAdd(Token token, DeclarationType kind)
      Report whether a symbol can be added to the current scope.
      Parameters:
      token - the defining token
      kind - the kind of declaration to be added
      Returns:
      true if the symbol can be added, false otherwise
    • add

      public void add(Token token, DeclarationType kind) throws IllegalArgumentException
      Add a symbol to the symbol table.
      Parameters:
      token - the defining token
      kind - the declaration kind
      Throws:
      IllegalArgumentException - if the symbol cannot be added.
    • getParent

      public SymbolTable getParent()
      Get the parent table.
      Returns:
      the parent table or null.
    • createChild

      public SymbolTable createChild()
      Create a new symbol table whose parent is this table.
      Returns:
      the created child parent table