CS 200, Fall 2015
P3: Parsing infix Boolean expressions, building and evaluating expression trees

Due and late dates and times

Overview

The object of this assignment is to parse infix Boolean expressions, convert them to expression trees, and evaluate these expression trees. Use ( OR FIX ) your TokenIter from P2. Use the InfixSum code that parses arithmetic infix expressions, made available in week 6, as an example. Debug mode will no longer be enforced, or tested.

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.

Tree

Your Tree code needs a proper implementation of the postorderEval(TreeNode node) method , that is called by:
    // 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.

TokenIter

Use, or fix, your TokenIter code from P2.

ParseTreeExpr

Extend the code provided in week 6. Be aware that that code only dealt with sums. Here you need to deal with "not", "and" and "or" internal nodes, and "true" and "false" leaves.

Testing and submitting your code

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.