Process T declarations, including both main-block variables and classes.
You should use flex to build a scanner to recognize the tokens required for declarations. As well as allowing the scanner to be integrated with the rest of your compiler, you should also build the scanner in a manner that allows it to be used as a stand-alone program, where it will read a T program from stdin and will write the tokens to stdout, one token to a line (like was done by the Simp scanner). When running integrated with the full compiler, the scanner should still read from stdin.
You should use bison to build a parser to recognize declarations. The T specification includes a yacc input for the whole language. Your parser should build an AST for the whole program. You may assume that the statement block for method bodies, constructor bodies, destructor bodies and the main-block body will always be an empty block. The compiler may stop at the first parse error.
Your compiler should have a command-line option ("-before") that allows the user to dump the AST before semantic analysis is done. The AST should be dumped in prefix form, one AST node per line (like was done by the Simp compiler). The dump should be printed to stderr. Print a blank line to stderr before starting the dump.
The semantic analysis required by this phase is implemented by two traversals of the AST. One traversal of the AST should be performed simply to obtain the list of classes defined by the program. A second traversal should then be performed to process all the declarations in the program. Main-block declarations should be placed in a data structure that is searchable by variable name. Classes should be placed in a second data structure that is searchable by class name. (The efficiency of these data structures is not important for grading purposes.) Place the pre-defined class Object in the second data structure at compiler start-up time.
Represent types with an appropriate set of objects in your compiler. You should have an abstract class Type and derived types for Integer, Class and Array.
Add another command-line option ("-classes") that will dump all class types to stderr. For each class, show the class name, the super class name, the list of fields and the list of methods. Indicate the name and type of each field. Indicate the name, the return type and the list of parameters for each method. Include the non-default destructors and constructors, but do not include the inherited methods. List the parameters in order and indicate the name and type of each one. The exact format of the dump of the classes can vary but please make yours easily understandable. This dump should include the pre-defined class Object. Print a blank line to stderr before starting the dump.
Add yet another command-line option ("-main") that will dump all main-block variables to stderr. For each variable show its name and type. Print a blank line to stderr before starting the dump.
You should try to identify all semantic errors in the input. When an error is found, report it with the appropriate line number and an appropriate error message. (Sometimes because of how flex and bison work, your line number may unavoidably be off by one. This is okay.) Error messages should be written to stderr. Try to avoid a cascade of error messages caused by a single error.
Write a Makefile called "Makefile" for building both the stand-alone scanner and the whole compiler. The Make goal for the stand-alone scanner should be "lexdbg", and this should be the executable name for the stand-alone scanner. The Make goal for the whole compiler should be "tc" and this should be the executable name for the whole compiler. You should also have a Makefile goal called "clean" which will remove all files that can be re-created (object files, executable files, flex output and bison output).
Provide a README file (called "README") that explains the current state of your compiler. Describe how well your compiler fulfills the requirements of this assignment.
The three required command-line options ("-before", "-classes" and "-main") can be given in any order if more than one is supplied.
Archive all your files in a tar file called "phase1.tar". This tar file should un-tar into a single directory called "phase1", which should contain the Makefile, the README 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 phase1 phase1.tar
Submissions can be checked by typing (also on agate.cs.unh.edu):
~cs712/bin/scheck phase1
Please read this specification carefully and try to follow it exactly. I will use scripts to test your compiler and therefore it is important that you follow my directions for the file names, command-line options, Makefile goals, tar file name, etc. (Points may be deducted if you do not follow the directions.)
To obtain 60% of the points for this assignment, you should support main-block declarations. You should also support class definitions that do not contain methods. You do not not need to detect any semantic errors. You do not need to support array types.
To obtain 70% of the points for this assignment, you should first complete the 60% requirements. And then add support for method declarations for methods without parameters. You do not not need to detect any semantic errors. You do not need to support array types.
To obtain 80% of the points for this assignment, you should first complete the 70% requirements. And then add support for method parameter declarations. You do not not need to detect any semantic errors. You do not need to support array types.
To obtain 90% of the points for this assignment, you should first complete the 80% requirements. And then add support for detecting semantic errors.
To obtain 100% of the points for this assignment, you should first complete the 90% requirements. And then add support for array types, including detecting semantic errors concerning array types.
Note: You must approach this assignment by first completing the 60% level, then the 70% level, then the 80% level, then the 90% level, and finally the 100% level. First, I believe this will most likely lead to the greatest success for the most of you. You need to get a piece of the assignment working and then add to it as much as you can until you run out of time (or energy). ( Do not try to sit down and do the whole assignment at once! ) Second, this is how I will grade it. For example, my tests for the 80% level will assume you have the 70% level done.
To receive full credit for the assignment, you must turn in your files prior to 8am on Monday February 23. Late submissions will be accepted at a penalty of 2 points for one day late, 5 points for two days late, 10 points for three days late, 20 points for four days late, and 40 points for five days late. No program may be turned in more than 5 days late.
Remember: you are expected to do your own work on this assignment.
Comments and questions should be directed to hatcher@unh.edu