Week 10, Oct 28 and 30
About that "given enough eyeballs, all bugs are shallow" thing ....
Wednesday
Discussion of how to explain what a calculator does
expression evaluation: ~/271/expressions (code should be in pld.cs.luc.edu/courses/271/spr18/demos/expressionsij.zip)
java expr_eval (traced version is expr_exp)
java expr_assign
Notes: pld.cs.luc.edu/courses/271/spr18/mnotes/recursion.html#exprtrees
Demo of command-line expressions
With a calculator interface, things are a little different. Generally, the '(' key clears the display and starts a new subexpression. Operator keys might display the current operator on the screen. The ')' key acts like the '=' key for the current expression, displaying the results so far. galculator takes this approach.
To put it another way, there are these states:
In ENTER_NUMBER state, additional digits pressed go into the display.
We go into OPERATOR state when an operator key is pressed. We save and clear the display, and save the operator. If a digit is pressed in OPERATOR state, we go into ENTER_NUMBER state again.
We go into EQUALS state when the "=" key is pressed. We retrieve the last stored operator and apply it to the previously saved display and the current display. The display is updated to show the result.
The other alternative is to display the entire expression on the display line. qalculate does this.