CSE5317/4305 Project #4 (Type Checking)

Due on Thursday April 13 before midnight

Worth 20% 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.

Note that, if your previous projects (Project #1, #2, or #3) have errors, you can use the solution for these projects. To use the solution for the previous projects, edit pcat/src/main/scala/edu/uta/pcat/PCAT.scala and set the variable use_project_1_solution and use_project_2_and_3_solution to true. Please do this only if you have errors in your pcat.lex or pcat.cup files.

You will use the SymbolTable class. The bindings in the Symbol Table are instances of the class EnvDecl, which has the following case classes:

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

For this project, you need to modify the file TypeCheck.scala only. The typecheck methods typecheck e, which can be any expression, statement, declaration, etc. If it is an expression, it returns the type of the expression. The method typecheck uses the method:

def typeEquivalence ( tp1: Type, tp2: Type ): Boolean
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:

scala lib/pcat.jar 4 tests/hello.pcat
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:
scala pcat-solution.jar 4 tests/hello.pcat

After ensuring that your program compiles and executes correctly, cleanup your pcat directory using mvn clean Then, zip the pcat directory into the file pcat.zip. Then submit your file pcat.zip here:

Submit Project #4:

Last modified: 03/28/2017 by Leonidas Fegaras