Slide 7.2: The syntactic domains of the calculator language
Slide 7.4: The semantic domains of the calculator language (cont.)
Home

The Semantic Domains of the Calculator


To define the semantics of the calculator, we use a state that maintains four registers or values to capture its internal working:
  1. An internal accumulator maintains a running total value reflecting the operations that have been carried out so far.

  2. An operator flag indicates the pending operation that will be executed when another operand is made available.

  3. The current display portrays the latest numeral that has been entered, the memory value that has been recalled using MR, or the total computed so far whenever the = or M+ key has been pressed.

  4. The memory of the calculator contains a value, initially zero.
Keystroke Accumulator Operator Flag Display Memory
  0 nop 0 0
12 0 nop 12 0
+ 12 plus 12 0
5 12 plus 5 0
+/- 12 plus -5 0
= 12 nop 7 0
× 7 times 7 0
2 7 times 2 0
M+ 7 nop 14 14
123 7 nop 123 14
M+ 7 nop 123 137
MR 7 nop 137 137
+/- 7 nop -137 137
-137 minus -137 137
25 -137 minus 25 137
= -137 nop -162 137
+ -162 plus -162 137
MR -162 plus 137 137
= -162 nop -25 137
A sample of expression calculation is as follows:

12 + 5 +/- = × 2 M+ 123 M+ MR +/- – 25 = + MR =


To Divide use / Symbol