Due: Monday, 21 June 2009 (midnight)
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.
<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 FTTFTthe correct output is:
false false false false true true true false
Read the input until EOF (there is no sentenial value).
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.
|
Course=cse2010 Project=asgn10 |