TokenIter.java
, use, or fix, your TokenIter code from P2.
TreeNode.java
,
Provided, don't change this code.
Tree.java
, use and extend the code provided in week 5 in InfixSum.jar.
ParseTreeExpr.java
, use and extend the code provided in InfixSum.jar.
ParseException.java
,
don't change this code.
Driver.java
,
don't change this code.
in, an example input file
, play with more inputs in this
or other input files.
inMin, another example input file
.
expr = term ( ("+" | "-") term )* term = factor ( ("*" | "/") factor )* factor = "-" factor | number | "(" expr ")"As discussed in class, this iterative, not left recursive, grammar can be directly transformed into a predictive parser, where every non-terminal becomes a method parsing that non-terminal.
You need to work on the following codes.
// if tree empty return null // else evaluate the tree by postorder traversal // and return its value public Integer postorderEval(){ Integer res = null; if(!isEmpty()){ res = postorderEval(root); } return res; }which evaluates the Expression Tree. It evaluates the operands, and then evaluates the operator. All nodes return an Integer value.
ResIn
contains the Dchriver output for
input file in.
ResInMin
contains the Driver output for
input file inMin.
Use the Checkin webserver to exercise and submit your code. Submit your P3.jar file containing TokenIter.java, Tree.java, and ParseTreeExpr.java**ONLY**.
Make sure you put ***java** files in your jar (not class files).