Class SymTable

java.lang.Object
edu.iu.jrsalata.SymTable

public class SymTable extends Object
The SymTable class provides a static symbol table, block table, and macro table that can be used across other classes. It includes methods to add, retrieve, and check symbols, blocks, and macros, as well as to clear the tables. The symbol and block tables are organized by control sections.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The maximum length allowed for labels and other constants For SIC/XE, that length is 6
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addBlock(String symbol, String block, String controlSection)
    Adds a block to the block table for a given control section.
    static void
    Adds a macro to the macro table.
    static void
    addSymbol(String symbol, HexNum location, String block, String controlSection)
    Adds a symbol to the symbol table with the specified location, block, and control section.
    static void
    Clears all entries from the symbol table, block table, and macro table.
    static boolean
    containsBlock(String symbol, String controlSection)
    Checks if the block table contains the specified symbol within the given control section.
    static boolean
    containsSymbol(String symbol, String controlSection)
    Checks if the specified symbol exists in the symbol table for the given control section.
    static String
    getBlock(String symbol, String controlSection)
    Retrieves the block associated with the given symbol and control section.
    static Set<String>
    getKeys(String controlSection)
    Retrieves the set of keys from the symbol table for the specified control section.
    Retrieves a macro from the macro table by its name.
    static Set<String>
    Retrieves the set of keys from the macro table.
    static HexNum
    getSymbol(String symbol, String controlSection)
    Retrieves the HexNum associated with the given symbol in the specified control section.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_LEN

      public static final int MAX_LEN
      The maximum length allowed for labels and other constants For SIC/XE, that length is 6
      See Also:
  • Method Details

    • addSymbol

      public static void addSymbol(String symbol, HexNum location, String block, String controlSection)
      Adds a symbol to the symbol table with the specified location, block, and control section. If the control section does not exist, it will be created.
      Parameters:
      symbol - the symbol to be added
      location - the location of the symbol as a HexNum
      block - the program block associated with the symbol
      controlSection - the control section to which the symbol belongs
    • addBlock

      public static void addBlock(String symbol, String block, String controlSection)
      Adds a block to the block table for a given control section. If the control section does not exist, it will be created.
      Parameters:
      symbol - the symbol to be added to the block table
      block - the block associated with the symbol
      controlSection - the control section where the block will be added
    • addMacro

      public static void addMacro(String name, MacroProcessorInterface processor)
      Adds a macro to the macro table.
      Parameters:
      name - the name of the macro to be added
      processor - the macro processor interface associated with the macro
    • getMacro

      public static MacroProcessorInterface getMacro(String name)
      Retrieves a macro from the macro table by its name.
      Parameters:
      name - the name of the macro to retrieve
      Returns:
      the macro associated with the given name, or null if no such macro exists
    • getMacroKeys

      public static Set<String> getMacroKeys()
      Retrieves the set of keys from the macro table.
      Returns:
      a Set containing all the keys in the macro table.
    • getSymbol

      public static HexNum getSymbol(String symbol, String controlSection)
      Retrieves the HexNum associated with the given symbol in the specified control section. If the control section does not exist, it will be created.
      Parameters:
      symbol - the symbol to look up
      controlSection - the control section where the symbol is defined
      Returns:
      the hexadecimal number associated with the symbol, or null if the symbol is not found
    • getKeys

      public static Set<String> getKeys(String controlSection)
      Retrieves the set of keys from the symbol table for the specified control section. If the control section does not exist, it will be created.
      Parameters:
      controlSection - the control section whose keys are to be retrieved
      Returns:
      a set of keys from the symbol table for the specified control section
    • getBlock

      public static String getBlock(String symbol, String controlSection)
      Retrieves the block associated with the given symbol and control section. If the control section does not exist, it will be created.
      Parameters:
      symbol - the symbol whose block is to be retrieved
      controlSection - the control section in which to look for the symbol
      Returns:
      the block associated with the given symbol and control section
    • containsSymbol

      public static boolean containsSymbol(String symbol, String controlSection)
      Checks if the specified symbol exists in the symbol table for the given control section.
      Parameters:
      symbol - the symbol to check for existence
      controlSection - the control section in which to check for the symbol
      Returns:
      true if the symbol exists in the specified control section, false otherwise
    • containsBlock

      public static boolean containsBlock(String symbol, String controlSection)
      Checks if the block table contains the specified symbol within the given control section.
      Parameters:
      symbol - the symbol to check for in the block table
      controlSection - the control section in which to check for the symbol
      Returns:
      true if the block table contains the symbol within the specified control section, false otherwise
    • clear

      public static void clear()
      Clears all entries from the symbol table, block table, and macro table. This method ensures that the tables are created if they do not already exist before attempting to clear them.