CS 352 Fall 2020
Compiler Project 2.3
Posted on October 10, Due November 3rd 2020, 11:59pm
1. Introduction
Project 2.3 is the last part of Project 2. To review the overview of the entire Project 2, please read the handout for Project 2.1, which also specifies the overall requirement and the distribution of the grade points across different parts of Project 2.
2. Scope and Tasks
A Yacc/Bison script is to be written to perform the following tasks on input programs that fall into the
entire scope of Project 2.
• Build the abstract syntax tree (AST).
• Traverse the AST to type check and to interpret the input program. (We have discussed the main technique to perform the traversals in the lectures.)
• Students should go over MiniJava+ grammar to make sure they implement all program constructs and data structures defined by the grammar. The following enumerates the most important new features:
o The input program, besides having a main class, may have zero or more additional classes. There are no limits on the number of fields and methods declared inside a class.
o Extension of classes.
o Instantiation of classes and accesses to class fields. o Method invocation and return.
o The standard library method Integer.parseInt should now be implemented, using atoi() standard library function in C, for example. You can assume that the argument passed to this method is a properly written unsigned integer.
o The command line argument argv[] should be implemented, using corresponding access in C. Note the difference between the indices to the argument array when the command is invoked (see submission instruction for more details).
• To substantially simplify the symbol table implementation for program interpretation, we make the following important restrictions:
o The test cases will contain no recursive calls.
o A class has no more than one instance. These restrictions permit program interpretation to use the same symbol table as the type checker, with additional fields created in such symbol tables to store data values computed at run time. We may introduce recursive calls and arbitrary instances of a class in Project 3 when machine code is generated.
o NOTE: arrays and strings are special cases and they may be constructed multiple times. Furthermore, if a class is extended, then both the superclass and the extended class can be constructed, each having its own single instance.
For this milestone, approximately half of the test cases will contain a variety of type rule violations, and the rest are assumed to have none. If type rule violations are found, each violation is to be reported, following the format specified in the specification for Project 2.1. Note that a test case may contain multiple type rule violations. All should be reported, with the caveat specified in Project 2.2 concerning undefined types. If and only if no type rule violations are found, the program is interpreted.
All restrictions, assumptions, and exclusions listed in Project 2.2 handout still hold, with the understanding, however, the scope of the language defined in MiniJava+ grammar is now fully implemented. See lecture slides for other exclusions that may be omitted project handouts.
3. Submission instruction
Requirements concerning the contents of the submitted directory and makefile can be found in the handout for Project 2.1. It is important to review those requirements again. Some of these requirements are reiterated or customized for this project as shown below.
1) No offline submission (such as email) is accepted.
2) Use the following command on CS lab machines that run any Linux OS, e.g. the XINU machines (i.e., xinu01.cs ~ xinu20.cs) to submit your homework.
turnin –c cs352 –p p2_3 [your working directory]
Prior to executing the turnin command, it is very important that you remove all files in the submitted folder except the make file, the yacc program (.y), the lex program (.l), and the .h and .c files you write for the project. If you implement in C++, similar care must be taken.
(Your home directories are directly accessible to you on all CS lab machines.)
3) You are free to write your own Make file, as long as the following requirements are met.
The grader will run your Makefile by executing the command “make interpret” to produce the executable program named interpret. Hence, it is important that your Makefile produces such an executable when invoked.
4) Your program MUST compile and run without any error on CS lab’s Linux machines. Please do a final test of this before submission, especially if you do your project on other computers.
5) Your code will be tested for grading by the following command;
> ./interpret program_name
Where “program_name” is the file name containing the input program and
NOTE: Deviation from the above requirement will get a 10 point of penalty. (For example, if your code receives 90 points, the final score on the Blackboard for this assignment will be 80 points.)