CSE5317/4305 Project #4 (Type Checking)

Due Tuesday March 27 before midnight

Worth 18% of your project grade

For this project, you are asked to implement the type checking program for PCAT. You will work in the same directory pcat you used in project #3.

You will use the SymbolTable class given in System.jar. The bindings in the Symbol Table, when printed with the method toString(), should follow the following syntax:

The values of level, offset, label, min_offset should be set to 0 now, but they will be set to their proper values in the next project.

For this project, you need to modify the file TypeCheck.gen only. The typecheck function typechecks e, which can be any expression, statement, declaration, etc. If it is an expression, it returns the type of the expression (otherwise it returns the AST type NoTyp()). The method typecheck uses the function:

static boolean type_equivalence ( Tree tp1, Tree tp2 )
to test whether the types tp1 and tp2 are equal (recall that PCAT supports name equivalence only).

Note that, in contrast to the PCAT manual, you should not allow mixed-typed operations (eg, adding an integer to a float). Also the for-loop introduces a new declaration: the for-variable that has an integer type. The scope of the variable is the body of the for-loop. The variable can only be used within the body. So ignore the PCAT manual that says that the for-variable must be declared before the for-loop.

You need to run your parser against all tests/*.pcat files. For example:

run 4 hello
The output consists of the tracing of the type checker. To test for type errors, you need to change the test files a little bit (by changing a variable name, adding an extra argument to a call, etc), so you can get type errors. You also need to compare your output with that of the solution:
solution 4 hello

After ensuring that your program compiles and executes correctly, cleanup your pcat directory using clean Then, if you are using Linux/MacOS, archive your pcat directory using tar cfz pcat.tgz pcat. If you are using Windows, zip the pcat directory into the file pcat.zip. Then submit your file (pcat.tgz or pcat.zip) here:

Submit Project #4:

Last modified: 03/08/12 by Leonidas Fegaras