Semantics I, Continuing with the Symbol Table
Posted Thursday, March 27
Due at the beginning of your next lab period
Objectives
The objectives of this assignment are
-
determination of the level you desire to achieve
-
inclusion of semantic actions in your parser to construct the symbol table
-
incorporation of a special method to print all symbol tables currently in existence on demand
To Do
-
Decide with your group which level you hope to achieve. It is possible
to plan for level A even at this point and still back off to level
B or C. You just need to make sure the features for handling the earlier
levels are covered.
-
Build the semantic records and include the necessary semantic action calls
in your parser (and the corresponding semantic action methods routines
in your symbol table ADT) for inserting identifiers into the symbol table upon declaration
(this should actually be complete already from last time).
-
Build the semantic records and include the necessary semantic action calls
in your parser (and the corresponding semantic action methods in your symbol
table ADT) for determining whether identifiers encountered in the parse have
been declared before use. That is, every time you parse an identifier that is not in a
declaration construct, you should include a semantic action call to your symbol table ADT to see if
that identifier has been declared in scope or not.
-
Ensure that your compiler outputs proper error messages if variables have
not been declared before use or are declared multiple times. Note that at this time you can
still continue parsing (your parser does not need to quit if a variable is undeclared).
-
Update your symbol table module with a public method for printing the symbol table. You should
be able to call this method from any location in your parser to print the symbol table. This
will help you (and us) see whether the table is being properly constructed. Be sure to show
the stacks structure of the tables. In this
case, each new symbol table in the stack structure should be labeled with
the name of the program, procedure, or function that it corresponds to.
Notes
Level A, B, and C compilers all need to be able to parse all mPascal
programs, including those with procedures, functions, and parameters.
Only level A compilers will be required to translate mPascal programs that include procedures,
functions, and parameters.
Therefore, if you are certain that you are going for level A, you should program for complete symbol
table functionality. If you are a little behind, or you are certain that you are targeting
only level B or C, you should get the symbol table functioning at least for programs with no
procedures or functions. As you get this done, we suggest that you include symbol table
functionality for procedures, functions, and parameters. In fact, for all of you, we recommend
(as usual) a phased-in approach, as outlined next.
Remember that it is always best to construct and test your project in
stages. For example, you should be sure that your symbol table is being constructed and
utilized properly when parsing programs that have no procedures and functions. Then add the
functionality for dealing with the new scope required by a procedures and functions that have no
parameters. Then do the same for
procedures and functions that have parameters. That way, you have something working before going on to the next stage.
To Turn In
Follow the TA's instructions on turning in this milestone.