March 20
Symbol Tables and Symbol Table Update Actions
Objectives
The objectives of this laboratory are
- to have you demonstrate your parsers.
- to prepare you for the inclusion of semantic actions in your parse table for the
construction of a symbol table.
Preparation
Be sure your project executable file has its permissions set to be executable by
the world.
Special Notes
The symbol table portion of this laboratory exercise is a look ahead. You aren't expected to know all of the
right answers. Instead, you are to think 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 - Program Test
You will need to follow your TA's instructions on how to swap programs for
testing. Use the test files you developed for your program to test the
other group's program. On your lab sheet, give the group number and a
description of whether the executable actually executed, and what you observed
in your testing of it.
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;
-- Point 1
procedure mixit(a, b: integer; var x: float);
var pony, apple, y: integer;
begin --mixit
pony := a + b
-- Point 2
end; --mixit
begin --lab1
-- Point 3
write(zebra);
end. --lab1
1a. Give a picture of the symbol table structure at points 1, 2, and 3 (see the comments in the
program). Use the single symbol table per scope approach.
1b. Repeat exercise 1a, but use the single symbol table approach as shown in
lecture last Friday. Use a hash table with 11 elements (0-10).
Assume that your hash function makes the following assignments.
apple 4, candy 7, y 0, zebra 7, xyz 10 mixit 8, a 3, b 1, x 9, pony 7.
2. Repeat exercise 1a for the following program.
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
3. Bring up the grammar for mPascal found on the class resources page.
- On the context free grammar page, print the sections that refer to variable,
parameter, function, and procedure declarations.
- For each of the relevant grammar rules, mark the positions in the rules where enough
information would be known from the parse to that point to insert the name of the
identifier (variable names, parameter names, procedure name, or function name) and their
attributes into the symbol table.
Call the action #insert for now.
- For each type of identifier (variable name, parameter name, procedure name, and function name) list
the attributes that the name should have associated with it (according to the definition
of mPascal).
4.
Work 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)
To Turn In
Put your names and group number on your work as usual. Turn in the results
of your comparison of your LL(1) table with the one generated by the tool.
Also, turn in the pages with your modified grammar rules and your plan for implementing a
symbol table ADT.