Lab 6
Symbol Tables and Symbol Table Update Actions
Objectives
The objectives of this laboratory are
- to prepare you for the inclusion of semantic actions in your parse table for the construction of a symbol table.
Special Notes
You are to begin thinking about the next step in constructing a compiler, which in this case is the inclusion of a symbol table and a determination about where enough information is known during a parse to actually insert information about identifiers into the symbol table. You will not be graded for whether you actually come up with correct answers. We are more interested in seeing you come up with reasonable ideas.
To Do - The Symbol Table
1. Examine the following program (this is not exactly in micro Pascal form):
program lab1; var apple, candy: integer; y: float; zebra, xyz: integer; procedure mixit(a, b: integer; var x: float); var pony: integer; function fred(var q: float) returns integer; begin --fred -- Point 1
fred := q + 1; end; -- fred function mary(x: integer) returns integer; begin --mary -- Point 2 mary := x - 1; end; -- mary --Point 3
begin --mixit pony := a + b; end; --mixit begin --lab1 -- Point 4 write(zebra) end. --lab1
1 Draw an illustration of the symbol table structure at points 1, 2, 3, and 4 (see the comments in the program). Use the single symbol table per scope approach.
2. Bring up your parser and the context free grammar for μPascal on our resources page.
- Find the methods in your parser that refer to variable, parameter, function, and procedure declarations and correlate these with the rules in the grammar
- For each of the relevant grammar rules, mark the positions in the rule where enough information would be known from the parse to that point to
- create a symbol table for a new scope (mark with #create).
- insert the name of the identifier (variable names, parameter names, procedure name, or function name) and their attributes into the symbol table (mark with #insert).
- destroy a symbol table for a scope mark with #destroy.
- For each type of identifier (variable name, parameter name, procedure name, and function name) list the attributes that the identifier should have associated with it (according to the definition of μPascal).
3. Work with your team on a design for a symbol table ADT. Remember that for your project there must be different symbol tables for each different scope in a program (follow the ideas presented in the lectures). What public methods will your ADT have? What data structure will you use inside the ADT for holding the symbol table values?
To Turn In
Put your names and group number on your work as usual. Turn it in to the Lab 7 dropbox.