Class SymbolTable

java.lang.Object
  extended by SymbolTable

public class SymbolTable
extends Object

A simple table of symbols for a postscript interpreter. This particular implementation is very expensive, and we'll see improved implementations in the latter part of the semester.


Constructor Summary
SymbolTable()
          Constructs an empty symbol table.
 
Method Summary
 void add(String symbol, Token value)
          Adds a string-value association to the table.
 boolean contains(String symbol)
          Checks for an entry associated with a particular string.
 Token get(String symbol)
          Gets a value associated with a string, from the symbol table.
static void main(String[] args)
          An example method that makes use of a symbol table.
 Token remove(String symbol)
          Removes a value associated with the a string.
 String toString()
          Returns a string representation of the symbol table.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SymbolTable

public SymbolTable()
Constructs an empty symbol table.

Method Detail

contains

public boolean contains(String symbol)
Checks for an entry associated with a particular string.

Parameters:
symbol - a string potentially associated with a value.
Returns:
true if (and only if) the symbol has an associated value in this table.

add

public void add(String symbol,
                Token value)
Adds a string-value association to the table. Assumes that the symbol is not null. If string has an associated value already, it is removed before adding the new association.

Parameters:
symbol - a non-null string
value - a Token associated with a string.

get

public Token get(String symbol)
Gets a value associated with a string, from the symbol table.

Parameters:
symbol - the string whose value is sought
Returns:
the Token associated with the string, or null, if none.

remove

public Token remove(String symbol)
Removes a value associated with the a string.

Parameters:
symbol - a string possibly keyed to a value in the symbol table.
Returns:
the token associated with the string

toString

public String toString()
Returns a string representation of the symbol table.

Overrides:
toString in class Object
Returns:
a string representation of the symbol table.

main

public static void main(String[] args)
An example method that makes use of a symbol table.