TokenIter.java
, use, or fix, your TokenIter code from P2
TreeNode.java
,
don't change this code.
Tree.java
, use and complete the code provided in week 5.
ParseExpr.java
, use, or fix, the code you worked in recitation 6.
ParseTreeExpr.java
, use and complete the code provided in week 5.
ParseException.java
,
don't change this code.
ParseDriver.java
,
don't change this code.
ParseTreeDriver.java
,
don't change this code.
in, an example input file
, play with more inputs in this
or other input files.
expr = term ( ("+" | "-") term )* term = 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.
pResDB
contains the ParseDriver output for
input file in, when in debug mode.
pRes
contains the ParseDriver output for
input file in, when not in debug mode.
ptResDB
contains the ParseTreeDriver output for
input file in, when in debug mode.
pRes
contains the ParseTreeDriver output for
input file in, when not in debug mode.
Use the Checkin webserver to exercise and submit your code. Submit your a P3.jar file containing TokenIter.java, Tree.java, ParseExpr.java, and ParseTreeExpr.java**ONLY**.
Make sure you put ***java** files in your jar (not class files). The TAs can help you creating a proper jar file.