Project 3: Semantic Analysis (type-checking)

Due 11:59pm Monday October 29th

Useful Links


Description

You will first complete semantic analysis for type-checking of Mojo as described in Chapter 5 of the text, by traversing the Abstract Syntax Tree (AST) generated by the parser from Project 2, and checking for various type compatibilities.

The code that you need to complete has been marked with TODO comments.

Resources

Before starting this project, familiarize yourself with Chapter 5 of the textbook. In addition to the lectures, this will give you a solid foundation for beginning your work.


Getting Started

Source code to get started with is available via svn on any of the lab machines using the command:
  svn co svn+ssh://sslab01.cs.purdue.edu/homes/cs352/svn/p3

You will now have a working copy of the project files in the directory p3. The p3 directory contains src and lib subdirectories. The src subdirectory contains source files for this project. The lib subdirectory contains any precompiled class files you will need to compile this project. (The files are actually configured as an Eclipse project, so you can also import the p3 directory as a new project in Eclipse at your convenience.)

All commands below will assume that you have first set your current directory to the p3/src subdirectory using the command:

  cd p3/src
to enter the src subdirectory.

All changes for this project will be done to the semantic analysis file mojo/Semant.java in the p3/src subdirectory. You can compile the project using the commands:

  javac */*.java
in the p3/src subdirectory.

You can run the type checking phase with the command:

  java mojo.Semant file
where file is a Mojo source code file. This will print out the types declared in the input program, and should also check for semantic errors in the input program.


Hints

In this project, you will be managing symbol tables to associate semantic values with the declared symbols of the input program. These are implemented by the mojo.Scope class.


Turnin

You should turn in your mojo/Semant.java file.
  cd p3/src/mojo
  turnin -ccs352 Semant.java


Grading

We will create a set of test cases, and then compare the output of your solution to our reference implementation. Grading test cases are intended to test separable functionality of your type checker.

There will be a reconciliation period after initial grading when you will be able to compare outputs of your parser with those of the reference implementation, and you may then offer simple fixes for the TAs to apply to your implementation to improve your grade. These fixes will be accepted only at the discretion of the TAs and the instructor — we will judge what "simple" means!

The reconciliation period is only intended for you to be able to fix simple problems that you may have mistakenly overlooked. Thus, you must make sure to test your implementation thoroughly.