RPN Calculator
IStack - this remembers a stack.
- this is a stack of tokens
23 + 45
push 2 then the 3 button.
display will show 23
hit the ENTER button
23 goes on the stack (push)
display clear
push 4 button then 5
display shows 45
hit +:
23 is popped
23 + 45 is evaluated
68 goes on the stack.
2*3 + 5 []
push 2
ENTER [2]
push 3
* [6]
push 5
+ [11]
Binary Tree:
made of trees
each tree has a left child and a right child
(4 + 5)** 2 + 7*3
+
/ \
(4 + 5)**2 7*3
Parse Tree:
+
/ \
** *
/ \ / \
+ 2 7 3
/ \
4 5
Types of tokens: operators
numbers
token: atoms of meaning
push 4
push ENTER [4]
push 5
push + [9]
push 2
** [81]
push 7
ENTER [7 81]
push 3
* [21 81]
push + [102]
push ** [81]
FUNCTIONS: they are unary operators
- unary sign-changing operator
5 - 3
+
/ \
5 -
|
3
Pretty face:
---------------------------------------------------
|RPN Calculator |
---------------------------------------------------
| DISPLAY |
---------------------------------------------------
| 7 | 8 | 9 | OP Buttons Scientific Calculator |
| 4 | 5 | 6 | Functions |
| 1 | 2 | 3 | |
| . | 0 | E | |
---------------------------------------------------
| stack shows here |
---------------------------------------------------
buttons:
NumberButton -
OpButtons - BinaryOperator
FunctionButtons - UnaryOperator
ENTER
Display:
acted upon by the buttons
Should teh display be thought of as the top of the stack or
just as a buffer?
Appearance?