java -jar PA4_groupname.jar --two-pass-interpret input_file java -jar PA4_groupname.jar --two-pass-mips input_file
For the option --two-pass-interpret, your program should generate an AST that is printed to an input_file.ast.dot file and the program should be interpreted by visiting the AST.
When called with the --two-pass-mips option, the program should generate an AST that is printed to a input_file.ast.dot file, and it should generate an input_file.s file with a MIPS program that executes the program in the input file. The generated MIPS program must be capable of being interpreted by the MARS interpreter.
The input_file will contain one or more statements with the assignment of constant expressions to variables and println statements. For example, the input_file might include the following list of statements:
{
a = 4 * 5 + 3 - (6+3);
System.out.println(a*2);
System.out.println(10-9-8);
b = 42;
}
The output from the interpreter and the mips program when run should be
as follows:
28
-7
Note that we will be treating the list of statements as a block of statements
in a similar fashion to how MiniJava uses statement blocks.
The test cases from PA3 can be converted into equivalent programs with assignments and println statements by wrapping the single expression from a PA3 input file into a println statement. For example,
4 + 5 - 9
would become
System.out.println( 4 + 5 - 9 );
For this assignment, no error handling is necessary. In other words,
you can assume the input is correct.
MJExprAssignStart
|-- TestCases
| |-- assign1.txt
| |-- assign1.txt.two-pass-interpret.out
| |-- assign1.txt.two-pass-mips.out
| |-- assign2.txt.two-pass-interpret.out
| |-- assign2.txt.two-pass-mips.out
| |-- expr1.txt
| |-- expr1.txt.two-pass-interpret.out
| |-- expr1.txt.two-pass-mips.out
| |-- expr2.txt
| `-- regress.csh
`-- src
|-- ast
| |-- analysis
| | |-- AnalysisAdapter.java
| | |-- DepthFirstAdapter.java
| | |-- IAnalysis.java
| | `-- ReversedDepthFirstAdapter.java
| `-- node
| |-- AssignStatement.java
| |-- BlockStatement.java
| |-- IExp.java
| |-- IStatement.java
| |-- ISwitch.java
| |-- ISwitchable.java
| |-- IdExp.java
| |-- IntegerExp.java
| |-- MinusExp.java
| |-- MulExp.java
| |-- Node.java
| |-- PlusExp.java
| |-- PrintStatement.java
| `-- Token.java
`-- mjparser
|-- JLex.jar
|-- ParseException.java
`-- TokenValue.java
As for PA3, we have given you all of the needed AST nodes and the DepthFirstAdapter class that is capable of visiting all the AST nodes including the new nodes PrintStatement, etc.
The TestCases directory includes some test cases and an example regression script.
Suggested steps for adding assignment statements and print statements to your expression evaluator:
parser code {:
public void unrecovered_syntax_error(Symbol cur_token) {
report_fatal_error("Fatal syntax error", cur_token);
}
public void report_fatal_error(String message, Object info) {
report_error(message, info);
done_parsing();
Symbol token = (Symbol)info;
mjparser.TokenValue tok = (mjparser.TokenValue)token.value;
throw new mjparser.ParseException("Fatal parsing error",
tok.line, tok.pos);
}
public void report_error(String message, Object info) {
Symbol token = (Symbol)info;
mjparser.TokenValue tok = (mjparser.TokenValue)token.value;
System.err.println("[" + tok.line + "," + tok.pos + "] "
+ message + " at " + tok.toString() );
}
:}
Also put the following in the .lex file:
%eofval{
return new Symbol(sym.EOF, new TokenValue("EOF", yyline, yychar));
%eofval}
and make sure all of the tokens result in a TokenValue being constructed.
svn log
svn info
svnlook tree REPOSITORY_PATH svnlook must be issued on a department machine
~cs453/bin/checkin PA4 PA4_groupname.jar