Lab 8 - Completing the Symbol Table
Objectives
The objectives of this laboratory are
- to give students opportunity to tune their LL(1) tables to a correct LL(1) table. This table was constructed from first principles and from running the updated microPascal grammer through an LL(1) table generating tool. The output of that program can be found here. Since it is difficult to read, it has been hand transcribed to the correct LL(1) table. The hand trascription may have typos in it. If you find any, let me know.
- to update the microPascal grammar with a missing rule
- to give you time to work as a group on your compiler in order to complete the symbol table.
To Do - Make Decisions
As a group, it is time for you to settle carefully on the decision as to which level (A, B, or C) you wish to strive for with your compiler. Neither level B nor C require the translation of procedures and functions. However, your compiler should still be able to parse any mPascal program. Thus, you will need to be able to construct a symbol table with scopes. We have had you work on the multi-scope symbol table this past week so that you will all understand how it works. One thing to remember in making your choice is that the higher the level you strive for, the more practice you will get with the concepts we cover in the lecture, which will make your learning of the concepts that much easier (e.g., for quizzes).
To Do - Work on your Compiler
Continue to work on your symbol table. Your next assignment will require that you include code that will print your symbol table on demand. You will be able to put this call into your code at any point for help in debugging as well as to demonstrate that your symbol table works. Whenever the new print_symbol_table method of the Symbol_Table object or package is called, the entire stack of symbol tables for each scope must be printed and labeled with the name of its scope (name of the procedure, function, or program of that scope). The assignment will require other things as well, posted with the milestone.
Special Notes
Today's lab will be dedicated primarily to your team's progress. You will be given time to work together on your projects. The main issue at this point is completion of the symbol table. Recall the previous lab. There are some special issues you will need to consider:
- You must have the nesting level represented in each scope's symbol table.
- You should label the symbol table with the name of the scope (main program, procedure, or function) so that when you print the stack of symbol tables you can also print the name of each scope to help in debugging.
- Each new scope representing a procedure or function will need to have a label associated with it in the symbol table so that a call can be generated to that procedure or function at translation time. So, you will need to build a label generator method that returns to you the next label (or a class with a getLabel method that always returns the next label in numeric order, beginning with L1.
- Activation records will be built at run time to be placed on the stack for each call to a procedure or function. The activation record must have room for each parameter and variable. The offsets must be tweaked from the way we have been doing them in class to leave room for the old display register value (which must be restored once the procedure or function has been executed) and, in the case of a function, space must also be reserved for the function return value. Consider that when the function returns when executed, this value must be left on top of the stack as described in the lecture. Try to arrange the offsets in your symbol table so that space for the return value is the first space in the activation record (which can then be left as the stack top when the function returns).
To Turn In
There is nothing to turn in today.