HP Calculator Framework

In this assignment, you will:

• Complete 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.
• Once 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 KalcPP.
You are permitted to work in groups of 2 in this assignment.

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):

Part I: Install and complete both Kalc and KalcPP

• Here's the code for Kalc and KalcPP.  Install them in separate Netbeans or Eclipse Projects.
• You will need a jar file jakarta.jar for both programs.

• Both programs should work immediately if you limit yourself to the operations { +, -, *, / }.  When you run either program, you will be prompted for command-line input.  Provide 2 lines: the first line contains a Polish expression to evaluate and the second line contains only a period ("."), which tells the parser (that is part of both programs) to evaluate the expression.  Below are some examples:
`kalc Started...kalc> 4 5 2 + * > .4 5 2 + * = 28kalc> 1 2 3 * + > .1 2 3 * + = 7kalc> .`

`kalcPP Started...kalcPP> 4 5 2 + * > .`
`4 5 2 + * = ( 4 * ( 5 + 2 ) )`
`kalcPP> 4 5 2 * + > .4 5 2 * + = ( 4 + ( 5 * 2 ) )kalcPP> .`
• Both programs are incomplete. You need to provide execute methods for the operations  % (modulo), ^ (power), ++ (increment), and -- (decrement).  These changes are indicated below

`/ non-negative integer postfix calculator// grammar.b : simple calculator// Simple tokens specified in simple format"+" ADD"-" SUB"*" MUL"/" DIV"%" MOD"^" POW"++" INC"--" DEC// Regular expression tokens specified in JavaCC formatTOKEN :{<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 above 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.

• Fill in execute methods in classes Mod, Pow, Inc, and Dec.
• Create a regression test (similar to, but more general than, this input file) to ensure that each program produces the correct output.

Note: 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.

Part 2: Create the KalcFramework and KalcPlugin and KalcPPPlugin

By 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 the KalcFramework that correspond to the Kalc and KalcPP programs.

• Create 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.
• Create a project Kalc1, which imports KalcFramework, and implements the Kalc extension of this framework.  This extension is in package KalcPlugin.
• Create another project KalcPP1, which  imports KalcFramework, and impolements a KalcPP extension of this framework.  This extension is in package KalcPPPlugin.
• Verify that your framework refactorings work by showin that your regression tests from Part 1 still work on Kalc1 and KalcPP1.

What to Submit

From Part 1:
• zip files for each completed Kalc and KalcPP project
• the script file(s) of your regression test
From Part 2:
• zip files for each project KalcFramework,  Kalc1 and KalcPP1 projects (which contain the Kalc and KalcPP plugins)
And:
• A 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 program etc.)

• A README file that explains
• what you have done (beyond what was asked of you).
• how to invoke your bash script
• anything else I (the grader) needs to know.
A critical part of any design is clarity and understandability.   Hence, you will be graded on the clarity of your project and its ability to work correctly.  Sloppy code, documentation, or anything that makes grading or understanding your program difficult will cost you points!  Beware, some of these "beauty" points are subjective.

No late assignments/submissions will be accepted.