Project 4: Semantic Analysis

Due date: 2003 Oct 27th(Wednesday), 12:00 Noon

Project 4 Errata list.

Description

In this project, you need to do semantic analysis for type-checking as described in Chapter 5 of the text. Basically, you will read in and traverse the Abstract Syntax Tree (that was generated by the parser in Project 3), and check for various type compatibilities.

This project is to be completed in pairs.

Directions

Resources

If you have questions please ask either Dr. Brylow or a TA, or post a message to the class news group at purdue.class.cs352.


Hints

The symbol table will have  functions to put an object for an associated symbol( put(Symbol, Object) ) and get the Object stored for a particular symbol( get(Symbol) ). In addition, it will have methods to begin a new scope ( beginScope( ) ) and end the scope( endScope( ) ). Endscope will basically delete all the entries added after the beginScope( ), so that the information for those entries is not retained after the scope has ended. You will neeed to use two symbol tables: classEnv (used to store all the information of various classes, including their fields and functions), and varEnv (used to store information of various variables with the function declarations).

You may want to create various classes for each type. Each of these classes will have coerceTo( ) method to check if two types are compatible. For example, if you have two objects X and Y, and you want to check if these two objects are compatible, then you have to invoke either X.coerceTo(Y) or Y.coerceTo(X), which will return true or false.

Error Messages

All the possible error messages can be found here. You must generate the same error messages and also the same number of error messages for the particular testcase as the solution program provided(though the messages may differ with respect to number of spaces), else you will receive zero points for the test case. You cannot come later and claim any partial credit claiming that the meaning of the error message is same, or that there is a spelling mistake, etc. There won't be any change in policy regarding this. Also you must match the other standard output generated regarding the types exactly.

Errors must be printed on StdErr. So while using diff to compare the outputs, use the following commands:


% /homes/cs352/bin/p3 inputfile.java | java Semant.Main >& out1

% /homes/cs352/bin/p3 inputfile.java | /homes/cs352/bin/p4 >& out2

% diff -w out1 out2
The last command should not produce any output.  Make sure you satisy the Symbol table requirements too.  We'll test that separately.

Turnin

Note: Late submissions will not be graded. Please see the course website for more info.

Useful Links


Credits

This has been adapted from Dr. Hosking and Dr. Brylow's previous course projects.


Rev 1.01 2004 Oct 04 23:33 MM]