Add support for classes to your compiler for the T programming language. However, you do not need to implement methods (or constructors or destructors) for this phase. Methods (and constructors and destructors) will be added in Phase 4.
Therefore, you are responsible for implementing class declarations, including fields and the specification of the superclass. You should also implement class instance creation, but you do not need to call a constructor. Simply ensure that all fields are given the correct default value. Also implement field access.
And you should implement the assignment of reference types, testing of equality of reference types, casting of reference types, accesses to fields, and the null literal.
First, you should fix all bugs in your compiler with respect to Phases 1 and 2. Testing (and grading) your Phase 3 submission will depend on the Phase 1 and Phase 2 functionality. The test files used for grading Phase 2 will be available in ~cs712/public/tests/phase2/grading after the final date to submit Phase 2 has passed.
You will need to upgrade your scanner to add support for the keywords required by class declaration and class instance creation. Also add tokens for the field access operator and the null literal.
You will need to upgrade your parser to add the necessary productions and build AST nodes for class declarations, class instance creation expressions, field access expressions, cast expressions and null literals. See the file ~cs712/public/phase3.y for the productions of the T grammar that you need to add for this phase.
You will need to upgrade your semantic analysis routines to properly handle classes, including the pre-defined class Object. Be sure to detect the necessary semantic errors and issue appropriate messages to stderr. Note that, now that we have more than just int type, we can test semantic errors involving some of the operators implemented in Phase 1, such as adding an int to a reference to a class instance. And, note that, as well as handling class instance creation, field access and cast, you need to upgrade previously implemented operators that can take class instance operands (assignment and equality).
Finally, you will need to upgrade your code generator to generate code for classes. Note that this will include tracking the types of class instances at run time. Be sure to consider detecting run-time errors involving cast expressions, null references and class instance creation. See the file ~cs712/public/phase3.intel for the code generation patterns for this phase.
Your compiler should maintain all the behavior mandated by the Phase 1 specification, regarding command-line switches, AST dump format, Makefile goals, README file, etc.
Add a new command-line flag "-classes" that will dump all class types to stderr. For each class, show the class name, the super class name and the list of fields, indicating the name and type of each field. The exact format of this display can vary but please make yours easily understandable. This dump should include the pre-defined class Object.
There are a few T test programs for this phase in the directory ~cs712/public/tests/phase3.
As in earlier phases, archive all your files in a tar file called "src.tar". This tar file should un-tar into a single directory called "src", which should contain the Makefile, the README file, the "RTS.c" file and all the source files. All submitted files should be placed directly in the top-level of this directory. (That is, please do not use subdirectories.) You should submit your tar archive from agate.cs.unh.edu using my "submit" script. Please note: the tar file you submit should not be compressed. But, please, do not include any executable or object files in the tar file.
To turn in this assignment, type:
~cs712/bin/submit phase3 src.tar
Submissions can be checked by typing (also on agate.cs.unh.edu):
~cs712/bin/scheck phase3
Points will be assigned for this assignment in the following manner:
The assignment is due on Sunday April 7. There is a grace period to 8am on Monday April 8 when no late penalty will be assigned. Submissions between 8am April 8 and 8am April 9 will have a late penalty of 15 points. Submissions between 8am April 9 and 8am April 10 will have a late penalty of 30 points. No program may be turned in after 8am on Wednesday April 10.
Remember: you are expected to do your own work on this assignment.
Comments and questions should be directed to hatcher@unh.edu