Description
For this assignment you are to write a module that will maintain a symbol table for your compiler. Use the linked implementation of a hash table. The unit should provide the following operations (named as given in assignment):
- insert(lex,token,depth) – insert the lexeme, token and depth into a record in the symbol table.
- lookup(lex) – lookup uses the lexeme to find the entry and returns a pointer to that entry.
- deleteDepth(depth) – delete is passed the depth and deletes all records that are in the table at that depth.
- writeTable(depth) – include a procedure that will write out all variables (lexeme only) that are in the table at a specified depth. [this will be useful for debugging your compiler]
- hash(lexeme) – (private)passed a lexeme and return the location for that lexeme. (this should be an internal routine only, do not list in the interface section).
The module should automatically initialize the table to empty and the table itself should be a variable declared in the module.
Store the following information for each record type in the symbol table:
- VARIABLE type of variable (use an enumerated data type), offset (use an integer variable) and size (use an integer variable).
- CONSTANT appropriate fields to store either a real or integer value.
- FUNCTION size of local variables (this is the total required for all locals), number of parameters, type of each parameter, and return type.
You must use a union in C/C++ to store the information, for each item in the table the fields token, lexeme, depth and next will be needed. Python, Java, and C# programmers will need to use appropriate object oriented techniques to store the correct object type for each of the three record types.