...
Due: 11:59pm Monday, Nov 16, 2020
200 points
Overview
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
andfalse
; - a symbol
S
representing a boolean variable; (make-Not X)
whereX
is aboolExp
;(make-And X Y) where =X
andY
areboolExps
;(make-Or X Y) where =X
andY
areboolExps
;(make-Implies X Y) where {{X
andY
areboolExps
; or(make-If X Y Z)
whereX
,Y
, andZ
areboolExps
.
Notes:
The
or
operator must be written as
...
\|
...
in
...
Racket instead of
|
because|
is a metasymbol with a special meaning in Racket.
In essence,
boolSimp.rkt
is a solution to Homework 5. The Java code in the fileParser.java
assumes the input in written in Racket notation, but with the following abbreviations to shorten the length of formulas:Abbreviation Original Symbol T true F false ! Not & And | Or > Implies ? If
...
- The Java abstract syntax classes include a separate composite hierarchy (called
...
-
ifExp
inboolSimp.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 described in the preceding program description. If you are still learning Java mechanics, you are encouraged to write an interpreter solution first and perhaps translate it (if you can) later to visitor form. A perfect interpreter visitor solution will only be penalized 15% versus 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 Parser.java and InterpParser.java contain references to these visitor class names and method names, respectively
Support Code
Here are the links for the files:
- boolsimpboolSimp.ss is rkt is the reference Scheme Racket program.BoolSimp
- boolSimp.djjava is a stub program for a visitor solution.
- BoolSimpTestboolSimpTest.java\ is a stub test file for a visitor solution.
- Parser.java is a parser file for a visitor solution.
- interpBoolSimp.dj is a stub program for an interpreter solution.
- InterpBoolSimpTestinterpBoolSimpTest.java is a stub test file for an interpreter solution.
- InterpParser.java is a parser file for an interpreter solution.
...