Computer Science 5641
Compiler Design
Project Part 4 - Symbol Table and Type Checking (50 points)
Due Thursday, December 2, 2004


In this part of the project you will build a symbol table to connect uses with declarations using the rules described below and then you will build a type checker for the resulting annotated AST. In doing this you should make use of the parser and AST you implemented in part 3 of the project.

Name Rules

For the purposes of building your symbol table, you should apply the following rules:

Type Checking

Once you have resolved all of the uses in a language you should type check the resulting AST according to the following rules:

Execution Order

Symbol table checking should only occur if no parser errors are detected. The symbol table check should report any multiple use and undeclared variable errors with the names of the variables. Type checking should only occur if no parse or symbol table errors were detected. The type checker should report errors as appropriate based on the above rules.


If errors are detected error messages should be printed. In no errors are detected an annotated version of the code should be printed out. During symbol table processing each function and variable declaration should be given a unique number (give each declaration the next number in the sequence starting with 1). When printing out the code each declared name and use should be followed by the number associated with than name. Names of fields within a structure should also be numbered and that number printed out when they are used. Your code should also show any coercions that occur. For example, if the input were:

int a = 1;
int b = a;
struct S { 
  double x;
  int y;
int c( int a , int b ) {
  S s1;
  float c;
  s1.x = a + b;
  c = 1;
  a = ( b * 2 );
int main( ) {
  c( 2 , 1 );
  return 0;

The output should look something like this:

int a(1) = 1;
int b(2) = a(1);
struct S(3) {
  double x(3.1);
  int y(3.2);
int c(4) ( int a(5) , int b(6) ) {
  S(3) s1(7);
  float c(8);
  ( s1(7) . x(1) ) = ( (float) (a(5) + b(5) ) );
  c(8) = ( (float) 1 );
  a(5) = ( b(6) * 2 );
int main(9) ( ) {
  c(4) ( 2 , 1 );
  return 0;

What To Turn In

Turn in documented versions of all of your code (including test code). Also document your test cases and show results from your code on each test file. You will likely need to construct many test files in order to fully exercise your code. You should also write a team report on this part of the project and in addition submit a short individual report from each member of the team.