Question
Create a Symbol Table Class in Java based on the following requirements: The symbol table is a fixed index list (once a row of data
Create a Symbol Table Class in Java based on the following requirements:
The symbol table is a fixed index list (once a row of data has been added, its index must not change during the run of the program) consisting of an indexed list of entries, with each entry (a single row of data) containing: a name field (String type); a kind field (to hold a label, variable, or constant indicator, represented by a char, l, v, or c); a data_type field specifying the data as an integer, float, or string (represented by a char, i, f, or s); and a set of 3 value fields (integerValue, floatValue, stringValue) to hold one of these: an integer, double, or String, as specified by the data_type field. (Later, it will be clear why labels will always store their data in the integerValue field, while variables and constants may use any one of the integerValue, floatValue, stringValue storage areas based on their data_type field). The interface to the SymbolTable must implement the following methods (in addition to a constructor, as shown):
SymbolTable(int maxSize)
Initializes the SymbolTable to hold maxSize rows of data.
int AddSymbol(String symbol, char kind, int value) int AddSymbol(String symbol, char kind, double value) int AddSymbol(String symbol, char kind, String value)
Three overloaded methods to add symbol with given kind and value to the end of the symbol table, automatically setting the correct data_type, and returns the index where the symbol was located. If the symbol is already in the table according to a non-case-sensitive comparison [Total matches total as well as ToTaL]with all the existing strings in the table, no change or verification is made, and this just returns the row index where the symbol was found.
These methods only FAIL, and return -1, when the table already contains maxSize rows, and adding a new row would exceed this size limit.
int LookupSymbol(String symbol)
Returns the index where symbol is found, or -1s if not in the table. Uses a non- case-sensitive comparison.
String GetSymbol(int index) char GetKind(int index) char GetDataType(int index) String GetString(int index) int GetInteger(int index) double GetFloat(int index)
Return the various values currently stored at index.
UpdateSymbol(int index, char kind, int value) UpdateSymbol(int index, char kind, double value) UpdateSymbol(int index, char kind, String value)
Overloaded methods, these set appropriate fields at the slot indicated by index.
PrintSymbolTable(String filename)
Prints to a plain text file all the data in only the occupied rows of the symbol table. Must be in neat tabular format, 1 text line per row, selectively showing only the the value field (stringValue, integerValue, or floatValue) which is active for that row based on the dataType for that row.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started