In this assignment, you will:
permitted to work in groups of 2 in this assignment.
two programs (that are examples of the Interpreter Pattern, which is
the composite pattern on steriods). Both programs are HP
Calculator interpreters; these interpreters took expressions in Polish
(prefix) notation as input. The first interpreter, Kalc, emulates
the HP35. The second interpreter, KalcPP,
translates input in Polish notation to normal (infix) notation.
getting both programs to work correctly, you are to create a framework
from these programs. One plugin will provides the
functionality of Kalc. Another provides the functionality ot
It is likely that you may not have used
a Polish (prefix) calculator before. Any questions about the semantics
of a calculation
(e.g., what order do you place values on a stack) will be resolved by
using the HP-35 calculator emulator below (just click on the image to
pull up the calculator itself):
I: Install and complete both Kalc and KalcPP
the code for Kalc and KalcPP. Install them
in separate Netbeans or Eclipse Projects.
kalc> 4 5 2 + *
4 5 2 + * = 28
kalc> 1 2 3 * +
1 2 3 * + = 7
kalcPP> 4 5 2 + *
4 5 2 + * = ( 4 * ( 5 + 2 ) )
kalcPP> 4 5 2 * +
4 5 2 * + = ( 4 + ( 5 * 2 ) )
Both programs are incomplete. You
need to provide execute methods for the operations %
(power), ++ (increment), and -- (decrement). These changes
are indicated below
/ non-negative integer postfix calculator
// grammar.b : simple calculator
// Simple tokens specified in simple format
// Regular expression tokens specified in JavaCC format
<INTEGER: ["0"-"9"] (["0"-"9"])* >
Exp : Action [Exp] :: Expr
Action : INTEGER :: Push
| ADD :: Add
| SUB :: Sub
| DIV :: Div
| MUL :: Mul
| MOD :: Mod // computes x%y (as in Java)
| POW :: Pow // computes x^y (raises x to the power y)
| INC :: Inc // computes x++ (increments value on the top of the stack)
| DEC :: Dec // computes x (decrements the value on the top of the stack)
In short, I created a parser from the
grammar and have generated all the classes that you'll
need. Please note in the above grammar that
the name of the class that is instantiated for a production is after
the double colon (::). So if there is a divide operation in
an expression that you enter, you
will see an instance of the Div class in a parse tree. It is
this naming convention that you should keep in mind as you proceed.
Your tasks are to:
in execute methods in classes Mod,
Pow, Inc, and Dec.
a regression test
(similar to, but more general than, this input file) to ensure that each program produces the
if you have any questions on the order in which arguments are to be
entered, consult the HP-35 simulator at the top of this web
pagre. Any discrepancies between what I have written above
and the HP simulator, go with the simulator.
2: Create the KalcFramework and KalcPlugin and KalcPPPlugin
now, you will have noticed that both Kalc and KalcPP are *really*
similar programs. Your next and last task if to move all of
the commonalities into a package called KalcFramework,
performing the usual tasks (that I indicated in the class notes) for
separating out framework code from plugin code. You will
create two plugins, KalcPlugin
and KalcPPPlugin to represent the extensions of
that correspond to the Kalc
Your tasks are to:
KalcFramework as a separate Java Package (or Jar). To do
this, you'll have to pull classes of the original applications apart,
build and use abstract factories, etc.
a project Kalc1, which imports KalcFramework, and implements the Kalc
extension of this framework. This extension is in package
another project KalcPP1, which imports KalcFramework, and
impolements a KalcPP extension of this framework. This
extension is in package KalcPPPlugin.
that your framework refactorings work by showin that your regression
tests from Part 1 still work on Kalc1 and KalcPP1.
- zip files for each completed Kalc and KalcPP project
- the script file(s) of your regression test
files for each project KalcFramework, Kalc1 and KalcPP1
projects (which contain the Kalc and KalcPP plugins)
critical part of any design is clarity and
understandability. Hence, you will be graded on the
of your project and its ability to work correctly. Sloppy
documentation, or anything that makes grading or understanding your
program difficult will cost you points! Beware, some of these
"beauty" points are subjective.
bash script to run the regression script file(s) for each program and to run each program (e.g,
run regression test for first program and then re-run the program so
that the Grader can type in expressions of his own, then run the next
- A README
file that explains
- what you
have done (beyond what was asked of you).
- how to
invoke your bash script
else I (the grader) needs to know.
late assignments/submissions will be accepted.