com.adamcornett.cminus
Class SymbolTable

java.lang.Object
  extended by com.adamcornett.cminus.SymbolTable

public class SymbolTable
extends Object

A table for storing symbols

Author:
Adam Cornett

Field Summary
private  Map<TokenLocation,Symbol> symbolsByLoc
          A map keyed of the definition location of a symbol.
private  Map<String,Symbol> symbolsByName
          A map keyed off the name of a symbol
 
Constructor Summary
SymbolTable()
           
 
Method Summary
 void add(Symbol symbol)
          Add a symbol to this table.
 Symbol get(String s)
          Lookup a symbol by name
 Symbol get(TokenLocation location)
          Look up a symbol by its definition location
 int size()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

symbolsByLoc

private final Map<TokenLocation,Symbol> symbolsByLoc
A map keyed of the definition location of a symbol.


symbolsByName

private final Map<String,Symbol> symbolsByName
A map keyed off the name of a symbol

Constructor Detail

SymbolTable

public SymbolTable()
Method Detail

add

public void add(Symbol symbol)
Add a symbol to this table.

Parameters:
symbol - The symbol to be added

get

public Symbol get(String s)
Lookup a symbol by name

Parameters:
s - The name of the symbol
Returns:
The symbol object if it is found, or NULL if it is not found

get

public Symbol get(TokenLocation location)
Look up a symbol by its definition location

Parameters:
location - The location where a token was defined.
Returns:
The symbol object, or NULL if it is not found.

toString

public String toString()
Overrides:
toString in class Object

size

public int size()