Computer Science 5641
Compiler Design
Project Part 4 - Symbol Table and Type Checking (90 points)
Due December 2, 2002 (4pm)


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. Your code should also show any coercions that occur. For example, if the input were:

int a = 1;
int b = a;
int c( int a , int b ) {
  float c;
  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);
int c(3) ( int a(4) , int b(5) ) {
  float c(6);
  c(6) = ( (float) 1 );
  a(4) = ( b(5) * 2 );
int main(7) ( ) {
  c(3) ( 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.

Extra Credit

Line numbers in errors (5 points) - make the error messages more readable by including line numbers and character locations for errors.

Overloading (10 points) - allow overloading of function names. Resolve calls by looking for a close match where a match must have the same number of variables, and where multiple functions may match due to coercions the best match is the one with the smallest number of coercions (if two matches have the same number of coercions this is an ambiguity error).