Semantic Actions Phase 1
The first phase of the semantic action part of the project is due Wednesday,
April 23.
The semantic actions are the biggest part of the compiler, in part because
this is where all the pieces you have developed finally start working together.
If you are using C++ before starting this phase, please consult Compiler
File Organization in C++, which provides the overall structure of the files
in your compiler.
Once your file structure is set up correctly, do the following in this order:
- Set up the semantic action class, including the declarations for the Execute
method and the semantic stack. For the time being you do not need to set up
the Quadruple array--leave it to a later phase.
- Add the following private data members to the class and initialize them
as indicated. All of these are boolean variables:
- INSERT/SEARCH = INSERT { flags insertion/search mode in symbol table }
- GLOBAL/LOCAL = GLOBAL { flags global vs. local environment }
- ARRAY/SIMPLE = SIMPLE { flags array vs. simple variable }
Do not concern yourself with any of the other variables and methods described
in the semantic
action routines for now.
- Implement and test the Execute
method, which simply consults the action number passed to it and calls the
appropriate semantic action routine. In this phase you will implement only
the following actions: 1, 2, 3, 4, 6, 7, 13. Therefore, you need only provide
a switch statement that calls these routines (and of course does something
meaningful if passed any other action number).
- Implement and test the semantic
actions listed below, in this order:
- Actions 1, 2, and 6
- Actions 4, 7, and 13 (these involve pushing an item on the semantic
stack)
- Action 3
Action 3 is the most involved. Before you start on action 3, make sure
the others work, your semantic stack behaves as it should etc.
- Implement a "semantic stack dump" routine that prints the stack
contents.
A sample header file for C++ is here.
A sample skeleton file for Java is here.