Class DefinitionTable

java.lang.Object
  extended by DefinitionTable

public class DefinitionTable
extends Object

A simple table of definitions for a Context Free Grammar. This particular implementation is very expensive, and we'll see improved implementations in the latter part of the semester.


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

Constructor Detail

DefinitionTable

public DefinitionTable()
Constructs an empty symbol table.

Method Detail

contains

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

Parameters:
nonTerminal - 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 nonTerminal,
                Definition value)
Adds a string-value association to the table. Assumes that the nonTerminal is not null. If string has an associated value already, it is removed before adding the new association.

Parameters:
nonTerminal - a non-null string
value - a Definition associated with a string.

get

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

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

toString

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

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

main

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