java -jar ExprEval.jar --one-pass-eval input_file java -jar ExprEval.jar --two-pass-eval input_file java -jar ExprEval.jar --two-pass-mips input_file
The input_file will contain a single expression followed by a newline. The grammar for the input is as follows:
Expression ::=
Expression ("+" | "-" | "*" ) Expression
| < INTEGER_LITERAL >
| "(" Expression ")"
For this assignment, no error handling is necessary. In other words,
you can assume the input is correct.
For the option --one-pass-eval, the value of the expression should be printed to standard out.
For the option --two-pass-eval, you should generate an AST that is printed to an input_file.ast.dot file and the value of the expression should be computed by visiting the AST. As with the one pass evaluation, the value of the expression should be printed to standard out. We provide you with AST node implementations, an extensible visitor class that traverses all the nodes in the AST in depth-first order, and an example visitor that generates a dot specification of the AST.
When called with the --two-pass-mips option, the expression evaluator should generate an AST that is printed to a input_file.ast.dot file and it should generate a input_file.s file with a MIPS program that evaluates the expression. The MIPS program must be capable of being interpreted by the MARS interpreter.
MJExprStart/
Makefile
java-cup-11a.jar
java-cup-11a-runtime.jar
TestCases/
expr1.txt
expr1.txt.ast.dot
expr1.txt.s
java_cup/
...
src/
ExprEvalDriver.java
ExprEvalMainClass.txt
ast_visitors/
DotVisitor.java
ast/
analysis/
AnalysisAdapter.java
IAnalysis.java
DepthFirstAdapter.java
ReversedDepthFirstAdapter.java
node/
IExp.java
IntegerExp.java
Node.java
ISwitch.java
MinusExp.java
PlusExp.java
ISwitchable.java
MulExp.java
Token.java
mjparser/
TokenValue.java
The Makefile works for the reference compiler. You can see what .cup and .lex files you will need to create by looking at how the Makefile calls JLex and JavaCUP to generate the lexer and parsers. Remember to start from example .lex and .cup files that already work.
To pass line and position information from the lexer to the parser. You will need the following information in your .lex file:
package mjparser;
import java_cup.runtime.Symbol;
%%
%cup
%line
%char
%public
...
{number} {return new Symbol(sym.NUMBER, new TokenValue(yytext(), yyline, yychar));}
...
The above only shows how one token is specified. Use the example we did in recitation on February 13th to figure out the rest.
In the .cup file for the parser that generates an AST, you will need to generate AST nodes in the actions. Here is an example:
expr ::= NUMBER:n
{: RESULT = new IntegerExp(new Token(n.text,n.line,n.pos)); :}
The ast.analysis and ast.node packages will be covered in recitation on Friday. You can use them or organize your program differently. The ast_visitors.DotVisitor class is an example of using the ast.analysis package and can be used as follows:
java.io.PrintStream astout =
new java.io.PrintStream(
new java.io.FileOutputStream(filename + ".ast.dot"));
ast_root.apply(new DotVisitor(new PrintWriter(astout)));
System.out.println("Printing dot file to " + filename + ".ast.dot");
See example output in the TestCases/ subdirectory of MJExprStart.
To get your code to compile with Eclipse, you will need to put the java-cup-11a-runtime.jar in your build path.
Project --> Properties --> Java Build Path --> Libraries --> Add Library
svn log
svn info
svnlook tree REPOSITORY_PATH svnlook must be issued on a department machine
~cs453/bin/checkin PA3 PA3_groupname.tar