The syntax for infix expressions is defined as follows:
expr = term ( "or" term )* term = factor ( "and" factor )* factor = "not" factor | "(" expr ")" | "true" | "false"As discussed in class, this iterative (not left recursive) grammar can be transformed directly into a predictive parser, where every non-terminal becomes a method parsing that non-terminal, and produces the TreeNode associated with the expression tree.
You need to work on the following codes.
TokenIter.java
, TreeNode.java
,
don't change this code, but you can run it.
Tree.java
, ParseTreeExpr.java
, ParseException.java
,
don't change this code.
ParseTreeDriver.java
, this is the main client code, taking input files and exercising your codes.
don't change this code. You need a proper TokenIter.java to make this code compile.
in
, // if tree empty return null // else evaluate the tree by postorder traversal // and return its value public Boolean postorderEval(){ Boolean res = null; if(!isEmpty()){ res = postorderEval(root); } return res; }which evaluates the (boolean expression) Tree. It evaluates the operands, and then evaluates the operator. All nodes return a Boolean value.
res
contains the ParseTreeDriver output for
input file in.
Use the Checkin webserver to exercise and submit your code. Submit your a P3.jar file containing TokenIter.java, Tree.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.