CSE5317/4305 Project #4 (Type Checking)

Due Sunday April 12 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. This time, you may use Eclipse to develop your program (see project.html); this is not required.

Note that, if your previous projects (Project #1, #2, or #3) have errors, you can use the solution for these projects. For example, on Windows, you can use the following build.bat script:

del bin\edu\uta\pcat\*
set CLASSPATH=bin;System.jar;Solution.jar
exec scalac -d bin src\edu\uta\pcat\*.scala
So this script, will not compile your pcat.lex and pcat.cup files and will use the solution jar instead. Please do this only if you have errors in your pcat.lex or pcat.cup files.
Note: There is a newer Solution.jar that solves all problems related to using the solution. Please download the new Solution.jar in your pcat directory.

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:

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

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/26/15 by Leonidas Fegaras