java -jar PA7_groupname.jar --two-pass-mips input_fileWhen called with the --two-pass-mips option, the program should generate a MIPS program in the input_file.s file. The generated MIPS program must be capable of being interpreted by the MARS interpreter.
Extra Credit: You can earn up to 10 extra credit points for this assignment by implementing interpretation for all of MiniJava (except for inheritance). Indicate in your README file if your group implemented MiniJava interpretation. To evaluate your extra credit, we will use the option --two-pass-interpret to perform an interpretation of program execution. The interpretation should be implemented as a visitor that traverses the AST.
The input file to your compiler will contain a legal MiniJava/Java program including inline comments and C-like comments. For example, the following program is possible PA7 input:
class ArrayAssign {
public static void main(String[] a){
System.out.println(new MyClass().testing());
}
}
/* here is a multi-line C comment
goodbye */
class MyClass {
int [] y; // member variable
public int testing() {
int [] x; // local variable
y = new int [80];
x = new int [10];
x[0] = 7;
x[3] = 77;
y[75] = 42;
return x[0] + y[x[3]-2];
}
}
We will NOT be giving you a reference compiler for this assignment.
Use javac and java to compare your results. Your type errors will not
be identical, but you should be catching the same first error that javac
catches.
If you are concerned about matching the output of the reference compiler
for type errors, then send example test cases to the mailing list and we will
send the output back to the whole list.
For this assignment, you need to maintain the semantic analysis from the previous assignments and additionally catch the following errors:
[LINENUM,POSNUM] Class CLASSNAME does not exist
// anywhere an id token should be a class name
[LINENUM,POSNUM] Array reference to non-array type
// array expressions and array assignments
[LINENUM,POSNUM] Invalid index expression type for array reference
[LINENUM,POSNUM] Operator length called on non-array type
[LINENUM,POSNUM] Invalid expression type assigned into array
// array assignments
[LINENUM,POSNUM] Receiver of method call must be a class type
[LINENUM,POSNUM] Method METHODNAME does not exist in class type CLASSNAME
[LINENUM,POSNUM] Invalid operand type for new array operator
The above errors are all considered inappropriate type usage errors and therefore it is only necessary to report the first error.
As always you should start this assignment right away. We recommend the following progression:
LINE_COMMENT="//"{NOT_EOL}*{EOL}
C_COMMENT="/*"{NOT_STAR}*("*"({NOT_STAR_OR_SLASH}{NOT_STAR}*)?)*"*/"
NOT_EOL=[^\r\n]
NOT_STAR=[^*]
NOT_STAR_OR_SLASH=[^*/]
{LINE_COMMENT} { /* ignore comments */ yychar = 0; yy_buffer_start = yy_buffer_index-1; /* reset for EOL */ }
{C_COMMENT} { /* ignore comments */ }
For expressions,
use the following precedence, which is listed from lowest to highest
with operators and tokens listed on the same line having equal precedence:
You will probably run into some shift/reduce parser issues for the full MiniJava grammar. The AmbiguousGrammarExamples.tar example that we went over in class covers how to generate debug information for solving shift/reduce errors.
As in previous assignments, all of the AST nodes needed have been provided in MJFuncStart/src/ast/nodes. Also, the ast/analysis package has been updated.
Here are some routines you might want to implement for class STEs:
int allocMember(int size) - Given the size of a member variable,
allocates space for the member variable in the class layout and
returns the member variable's offset.
int getNumVariables() - Returns the number of member variables that
a class contains. Useful when computing the size of a class
instance. Note that in MiniJava, all member variables are of
size 4 bytes.
While building the symbol table for PA7, the new features needed are the following:
[LINENUM,POSNUM] Class CLASSNAME does not exist
// anywhere an id token should be a class name
[LINENUM,POSNUM] Array reference to non-array type
// array expressions and array assignments
[LINENUM,POSNUM] Invalid index expression type for array reference
// index expressions must be of type integer
[LINENUM,POSNUM] Operator length called on non-array type
[LINENUM,POSNUM] Invalid expression type assigned into array
// array assignments
[LINENUM,POSNUM] Receiver of method call must be a class type
[LINENUM,POSNUM] Method METHODNAME does not exist in class type CLASSNAME
[LINENUM,POSNUM] Invalid operand type for new array operator
// Errors from previous assignment that are still relevant
[LINENUM,POSNUM] Invalid type returned from method METHODNAME
// any method declaration
[LINENUM,POSNUM] Method METHODNAME requires exactly NUM arguments
[LINENUM,POSNUM] Invalid argument type for method METHODNAME
// any call to a method (note that println is a method)
[LINENUM,POSNUM] Undeclared variable VARNAME
// anywhere an id token could be a variable name
[LINENUM,POSNUM] Invalid expression type assigned to variable VARNAME
// assignment statements
[LINENUM,POSNUM] Invalid left operand type for operator OP
[LINENUM,POSNUM] Invalid right operand type for operator OP
[LINENUM,POSNUM] Invalid operand type for operator !
[LINENUM,POSNUM] Invalid condition type for if statement
[LINENUM,POSNUM] Invalid condition type for while statement
where LINENUM is the line number for the symbol, POSNUM is the position number for the symbol, OP is a specific binary operator, CLASSNAME is a specific class name, METHODNAME is the unmangled method name, and VARNAME is a specific variable name.
To enable easier testing and grading, do not change the phrasing of the error messages.
Method calls in the MiniJava grammar include an expression on the left-hand-side of the ".", which is called the receiver. The receiver is a reference/pointer to an object instance on which a method is invoked; it "receives" the method call. The receiver is what is passed in as the implicit "this" parameter.
When at a method call (CallExp), it is necessary to know the class type for the receiver in order to lookup the method name. Keep in mind that all of the methods in MiniJava are public and therefore can be called from within other classes. This means that you will have to look up the class symbol table entry for the method being called in order to look up the method symbol table entry. In the type checking visitor, you are already maintaining a mapping of expression nodes to their type. Therefore, determining the type of the receiver is simply a matter of looking up the type for the receiver expression while you are in the call expression AST node. You will also need this information in other AST visitors, so you will need to maintain a mapping of expressions to types either in the symbol table or for each visitor.
The TestCases directory includes some test cases.
Start working through the phases as outlined above.
svn log
svn info
svnlook tree REPOSITORY_PATH svnlook must be issued on a department machine
~cs453/bin/checkin PA7 PA7_groupname.jar