Class SymbolTable


  • public class SymbolTable
    extends java.lang.Object
    A table of symbols for a postscript interpreter. Uses java.util.HashMap for a simple, efficient implementation. We'll learn about the Map ADT and hashing soon.
    • Constructor Summary

      Constructors 
      Constructor Description
      SymbolTable()
      Constructs empty symbol table
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.String symbol, Token value)
      Add a string and associated token to the table
      boolean contains​(java.lang.String symbol)
      Check if a string is present in the table
      Token get​(java.lang.String symbol)
      Retrieve the token associated with a string from the table
      Token remove​(java.lang.String symbol)
      Remove a string and the associated token from the table
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • SymbolTable

        public SymbolTable()
        Constructs empty symbol table
    • Method Detail

      • contains

        public boolean contains​(java.lang.String symbol)
        Check if a string is present in the table
        Parameters:
        symbol - String to check for in the table
        Returns:
        true if symbol is in the table
      • add

        public void add​(java.lang.String symbol,
                        Token value)
        Add a string and associated token to the table
        Parameters:
        symbol - String to add to the table
        value - Token to associate with symbol Note: if symbol is already in the table, its associated Token will be replaced with value
      • get

        public Token get​(java.lang.String symbol)
        Retrieve the token associated with a string from the table
        Parameters:
        symbol - String to retrieve from the table
        Returns:
        returns Token associated with symbol
      • remove

        public Token remove​(java.lang.String symbol)
        Remove a string and the associated token from the table
        Parameters:
        symbol - String to remove from the table
        Returns:
        Token associated with symbol (or null if symbol is not present in the table)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        returns printable version of symbol table. Use with ptable.