Package edu.iu.jrsalata
Class SymTable
java.lang.Object
edu.iu.jrsalata.SymTable
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
Modifier and TypeFieldDescriptionstatic final int
The maximum length allowed for labels and other constants For SIC/XE, that length is 6 -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Adds a block to the block table for a given control section.static void
addMacro
(String name, MacroProcessorInterface processor) Adds a macro to the macro table.static void
Adds a symbol to the symbol table with the specified location, block, and control section.static void
clear()
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
Retrieves the block associated with the given symbol and control section.Retrieves the set of keys from the symbol table for the specified control section.static MacroProcessorInterface
Retrieves a macro from the macro table by its name.Retrieves the set of keys from the macro table.static HexNum
Retrieves the HexNum associated with the given symbol in the specified control section.
-
Field Details
-
MAX_LEN
public static final int MAX_LENThe maximum length allowed for labels and other constants For SIC/XE, that length is 6- See Also:
-
-
Method Details
-
addSymbol
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 addedlocation
- the location of the symbol as a HexNumblock
- the program block associated with the symbolcontrolSection
- the control section to which the symbol belongs
-
addBlock
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 tableblock
- the block associated with the symbolcontrolSection
- the control section where the block will be added
-
addMacro
Adds a macro to the macro table.- Parameters:
name
- the name of the macro to be addedprocessor
- the macro processor interface associated with the macro
-
getMacro
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
Retrieves the set of keys from the macro table.- Returns:
- a Set containing all the keys in the macro table.
-
getSymbol
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 upcontrolSection
- 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
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
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 retrievedcontrolSection
- the control section in which to look for the symbol- Returns:
- the block associated with the given symbol and control section
-
containsSymbol
Checks if the specified symbol exists in the symbol table for the given control section.- Parameters:
symbol
- the symbol to check for existencecontrolSection
- the control section in which to check for the symbol- Returns:
- true if the symbol exists in the specified control section, false otherwise
-
containsBlock
Checks if the block table contains the specified symbol within the given control section.- Parameters:
symbol
- the symbol to check for in the block tablecontrolSection
- 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.
-