dspl
Class SymbolTable

java.lang.Object
  extended by dspl.SymbolTable
All Implemented Interfaces:
ParserTokensTokenTypes

public class SymbolTable
extends java.lang.Object
implements ParserTokensTokenTypes

SymbolTable serves as a storage for all variables.
SymbolTable internally uses a HashMap to map identifiers to their corresponding Variable

Author:
David

Field Summary
private  int nextFloatConstIDInt
           
private  int nextStringIDInt
          When strings are added to the symbol table, their identifier is set as "stringLabel#" where # is this number, must be unique, so we increment it on each call
private  java.util.HashMap symbolHashMap
          HashMap used to map identifiers to Variable-typed objects for the Variable represented by the provided identifier
 
Fields inherited from interface dspl.frontend.ParserTokensTokenTypes
ASSIGN, COMMA, COMMENT, DECLS, DIGITS, DIV, DOT, EOF, EQ, GE, GT, ID, LBRACE, LBRACK, LE, LITERAL_byte, LITERAL_byte_array, LITERAL_ccall, LITERAL_complex, LITERAL_complex_array, LITERAL_else, LITERAL_float, LITERAL_float_array, LITERAL_for, LITERAL_if, LITERAL_int, LITERAL_int_array, LITERAL_string, LITERAL_ubyte, LITERAL_ubyte_array, LITERAL_uint, LITERAL_uint_array, LITERAL_while, LPAREN, LT, MINUS, MUL, NE, NEGATE, NEWLINE, NULL_TREE_LOOKAHEAD, NUM, PLUS, PROGRAM, RBRACE, RBRACK, REAL, RPAREN, SEMI, STRING, TILDE, WS
 
Constructor Summary
SymbolTable()
          Constructor for SymbolTable
 
Method Summary
 Variable addStringVariable(java.lang.String identifier)
           
 void addVariable(Variable v)
          Adds the provided Variable to the Symbol table
 void constructTable(antlr.collections.AST tree)
          Takes the AST that represents the program being compiled and adds all of the variables found to the Symbol table
 java.util.ArrayList getAllVariables()
           
 java.lang.String getNextFloatConstID()
          Provides unique label for each string added to the symbol table
private  java.lang.String getNextStringID()
          Provides unique label for each string added to the symbol table
 Variable getVariable(java.lang.String identifier)
          Returns the Variable corresponding to the identifier provided
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

symbolHashMap

private java.util.HashMap symbolHashMap
HashMap used to map identifiers to Variable-typed objects for the Variable represented by the provided identifier


nextStringIDInt

private int nextStringIDInt
When strings are added to the symbol table, their identifier is set as "stringLabel#" where # is this number, must be unique, so we increment it on each call


nextFloatConstIDInt

private int nextFloatConstIDInt
Constructor Detail

SymbolTable

public SymbolTable()
Constructor for SymbolTable

Method Detail

getNextStringID

private java.lang.String getNextStringID()
Provides unique label for each string added to the symbol table

Returns:

getNextFloatConstID

public java.lang.String getNextFloatConstID()
Provides unique label for each string added to the symbol table

Returns:

constructTable

public void constructTable(antlr.collections.AST tree)
                    throws SymbolicException
Takes the AST that represents the program being compiled and adds all of the variables found to the Symbol table

Parameters:
tree -
Throws:
SymbolicException

addVariable

public void addVariable(Variable v)
                 throws SymbolicException
Adds the provided Variable to the Symbol table

Note: The same symbol cannot be added to the symbol table multiple times

Parameters:
v -
Throws:
SymbolicException

getVariable

public Variable getVariable(java.lang.String identifier)
                     throws SymbolicException
Returns the Variable corresponding to the identifier provided

Parameters:
the - identifier of the desired variable
Returns:
variable corresponding to the provided identifier if in SymbolTable, else returns null
Throws:
SymbolicException

addStringVariable

public Variable addStringVariable(java.lang.String identifier)
                           throws SymbolicException
Throws:
SymbolicException

getAllVariables

public java.util.ArrayList getAllVariables()