March 20

Symbol Tables and Symbol Table Update Actions


Objectives

The objectives of this laboratory are

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.

 

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.