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.
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.
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.
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 >& out1The last command should not produce any output.  Make sure you satisy the Symbol table requirements too.  We'll test that separately.
% /homes/cs352/bin/p3 inputfile.java | /homes/cs352/bin/p4 >& out2
% diff -w out1 out2
Note: Late submissions will not be graded. Please see the course website for more info.
This has been adapted from Dr. Hosking and Dr. Brylow's previous course projects.