Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Due: 11:59pm Monday, Nov 16, 2020

200 points


Write a Java program  that reduces boolean expressions (represented in the input and output streams in Racket-like notation) to simplified form. For the purposes of this assignment, boolean expressions are Racket expressions constructed from:


  • a boolean constant true and false ;
  • a symbol S representing a boolean variable;
  • (make-Not X) where X is a boolExp ;
  • (make-And X Y) where =X and Y are boolExps;
  • (make-Or X Y) where =X and Y are boolExps;
  • (make-Implies X Y) where {{X and Y are boolExps; or
  • (make-If X Y Z) where X, Y, and Z are boolExps.


  1. The or operator must be written as



  1. \|



  1. in


  1. Racket instead of | because | is a metasymbol with a special meaning in Racket


  2. In essence, boolSimp.rkt is a solution to Homework 5.   The Java code in the file assumes the input in written in Racket notation, but with the following abbreviations to shorten the length of formulas:

    AbbreviationOriginal Symbol


  1. The Java abstract syntax classes include a separate composite hierarchy (called


  1. ifExp in boolSimp.rkt ). This representation includes only three concrete variant classes, making it much easier to write the visitors that perform normalization, evaluation, and convert-To-Bool.

Hints on Writing Your Java Code

The visitor pattern is a straightforward but notationally cumbersome alternative to the interpreter pattern. You can mechanically translate interpreter pattern code to visitor pattern code. (Perhaps IDEs like Eclipse should support such transformations.) The interpreter solution to this assignment is a bit easier to write than the visitor solution. If you are still learning Java mechanics, you are encouraged to write an interpreter solution first and perhaps translate it later to visitor form. A perfect interpreter visitor solution will not be penalized relative to a perfect visitor solutionbe given 10 extra points over a perfect interpreter solutionu. If you submit an interpreter solution, your program must conform to class signatures given in the interpreter pattern support code below (just as a visitor solution must conform to the class signatures given in the visitor pattern code below).

The interpreter version of the support code replaces the ConvertToIf, Normalize, HeadNormalize, Evaluate, and Print visitors by methods named convertToIf, normalize, headNormalize, eval, and print.  The classes and contain references to the these visitor class names and method names, respectively, in the API for the help functions assumed by our test code.


Support Code

Here are the links for the files: