CSE 2010: Asgn #10, Well-formed formula

Due: Monday, 21 June 2009 (midnight)

The Task

Design a tree for WFF consisting of propositions, (binary) implications, and (unary) negations. Propositions are represented by a lower-case letter (a-z).

These are examples of WFF in postfix notation:

pqC
q
rN
abCN
abNC       (a => (not b))
xyzCC      (x => (y => z))

The DNode class from the chapter 6 is a good starting place. The BTNode class of code fragment 7.15 is possible, but more complicated than necessary for this project.

Evaluating the expression in the form of a tree is easy, but it may take some thinking to come up with an algorithm to construct a tree from a postfix expression. This is accomplished most easily with a stack.

Input/Output

Each line of the input consists of space-separated words of the following format:
<WFF>  <asgn1>  <asgn2>  <asgn3> ... <asgnn>
(0 ≤ n ≤ 100) WFF is a wff in postfix notation as described above. Each assignment is a list of T's and F's. The first T or F will be the value of the proposition a, the second T or F will be the value of the proposition b, and so on. You may assume that the list is long enough to define a value for all of the propositions that occur in WFFF. (The list may be longer.)

For each line of input print one line of output. For each assignment print the word 'true' if the WFF is true under the assignment and print the word 'false' if it is not.

For the following three lines of input:

abCN FFTTT FTT FTTT
pqC FFFFFFFFFFFFFFFTFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
abCeCN FFFFF FTTTF FTTFT 
the correct output is:
false false false
false true
true true false

Read the input until EOF (there is no sentenial value).

Helpful Stuff

Turning it in

Turn in the Java source code for the program using the submission server. The file name should be Eval.java and the project is asgn10. Be sure your name is in comments at the beginning of your program as required in the standard header for this class. For your convenience, here is a submission form for this assignment.

File 1
Control code:
Course=cse2010
Project=asgn10
(If you turn-in multiple files, use the general submissions page.)


Ryan Stansifer <ryan@cs.fit.edu>
Last modified: Sun Jun 21 13:57:49 EDT 2009