package a1;
import java.util.InputMismatchException;
/**
Test program for the Interpreter class
*/
public class A1
{
/**
Prints true or false, depending
on the value of a given boolean expression. If the expression
is ill-formed, an error message is printed.
@param p an interpreter that uses that grammar of the
Interpreter class
@param expr the expresssion, represented as a string of tokens
separated by whitespace characters as recognized by the
Character.isWhitespace predicate.
*/
public static void test(Interpreter p, String expr) {
try {
boolean result = p.evaluateShowingTraversal(expr);
System.out.println("result: " + result); }
catch(InputMismatchException e) {
System.out.println(e.getMessage()); }
try {
boolean result = p.evaluate(expr);
System.out.println("result: " + result); }
catch(InputMismatchException e) {
System.out.println(e.getMessage()); } }
/**
The main test program
@param args is ignored
*/
public static void main(String args[]) {
Interpreter p = new Interpreter();
test(p, "true ");
test(p, "~ ~ ~ true ");
test(p, "( true ^ true )");
test(p, "( true ^ false )");
test(p, "( T v T )");
test(p, "~ ( F v T )");
test(p, "( false ^ ~ T )");
test(p, "~ ( F ^ ~ true )");
test(p, "( T ^ ~ ( T ^ F ) )");
test(p, "~ ( ~ ( T ^ F ) ^ T )");
test(p, "( F v ~ ( T v F ) )");
test(p, "~ ( ~ ( T v F ) v F )");
test(p, "( ( T ^ ( T ^ T ) ) ^ ( T ^ ( T ^ ( T ^ F ) ) ) )");
test(p, "( ( ( T ^ T ) ^ T ) v ( ( T ^ ( T ^ F ) ) ^ T ) )");
test(p, "( true XOR false )");
test(p, "( true ^ 1 )");
test(p, "~ ( true )");
test(p, "( ( T ^ F ^ T ) )");
test(p, "( ( T ^ F ) )");
test(p, "( T ^ ~ ( T ^ F ) ) )");
test(p, "( T ^ ~ ( T ^ F )");
test(p, "( T ^ ~ ( T ^ ");
test(p, "( T ^ ~ ( T ");
}
}