fi.hu.cs.titokone
Class SymbolTable

java.lang.Object
  extended byfi.hu.cs.titokone.SymbolTable

public class SymbolTable
extends java.lang.Object

This class represents the symbol table of a TTK-91 program. It contains symbols with defined values. It also contains DEF-definitions, which are like symbols except the value is String. Symbols and DEFs are in separated maps.


Field Summary
private  java.util.HashMap definitions
          This field contains the SymbolTable's definitions.
private  java.util.HashMap symbols
          This field contains the SymbolTable's symbols.
 
Constructor Summary
SymbolTable()
           
 
Method Summary
 void addDefinition(java.lang.String key, java.lang.String value)
          This method adds a new definition.
 void addSymbol(java.lang.String symbolName, int symbolValue)
          This method adds a new symbol to the symbol table.
 java.lang.String[] getAllDefinitions()
          This method returns a string array that contains all the currently made definitions.
 java.lang.String[] getAllSymbols()
          This method returns a string array that contains all the currently defined symbols.
 java.lang.String getDefinition(java.lang.String key)
          This function returns the string value that corresponds to a given definition.
 int getSymbol(java.lang.String symbolName)
          This function returns the integer value that corresponds to a given symbol.
 java.util.HashMap toHashMap()
          This method returns the symbol table as a hashmap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

symbols

private java.util.HashMap symbols
This field contains the SymbolTable's symbols.


definitions

private java.util.HashMap definitions
This field contains the SymbolTable's definitions.

Constructor Detail

SymbolTable

public SymbolTable()
Method Detail

getSymbol

public int getSymbol(java.lang.String symbolName)
              throws InvalidSymbolException
This function returns the integer value that corresponds to a given symbol.

Parameters:
symbolName - Name of the symbol.
Returns:
Integer value that corresponds to the symbol.
Throws:
InvalidSymbolException - If there is no such symbol in the SymbolTable.

getAllSymbols

public java.lang.String[] getAllSymbols()
This method returns a string array that contains all the currently defined symbols. (Not pre-defined value symbols which are not used in the application this symbol table is related to.)

Returns:
An Array that contains all the defined symbols.

addSymbol

public void addSymbol(java.lang.String symbolName,
                      int symbolValue)
This method adds a new symbol to the symbol table. If the symbol was already defined this changes its value.

Parameters:
symbolName - Name of the symbol.
symbolValue - Integer value of the symbol.

addDefinition

public void addDefinition(java.lang.String key,
                          java.lang.String value)
This method adds a new definition. A definition is much like a symbol, only the value is a string instead of an integer, and the usage differs.

Parameters:
key - The name of the definition.
value - The value to be attached to the name.

getDefinition

public java.lang.String getDefinition(java.lang.String key)
                               throws InvalidDefinitionException
This function returns the string value that corresponds to a given definition.

Parameters:
key - Name of the definition.
Returns:
String that corresponds to the definition.
Throws:
InvalidDefinitionException - If there is no such definition in the SymbolTable.

getAllDefinitions

public java.lang.String[] getAllDefinitions()
This method returns a string array that contains all the currently made definitions.

Returns:
An Array that contains all the definition keys with values to them.

toHashMap

public java.util.HashMap toHashMap()
This method returns the symbol table as a hashmap. The hashmap returned is a copy, not a reference.

Returns:
A HashMap containing the symbol table, with the symbol names as key Strings and the integer values as Integer objects.