Slide 6.7: Denotational semantics of integer arithmetic expressions (cont.) Slide 7.2: The syntactic domains of the calculator language Home |
The following example develops the denotational semantics for the language of the simple three-function calculator.
A “program” on this calculator consists of a sequence of keystrokes generally alternating between operands and operators.
The syntax below gives those combinations that we call legal on the calculator.
For instance, “6 + 33 × 2 = ” produces the value 78 on the display of the calculator.
|
<program> ::= <expression sequence> <expression sequence> ::= <expression>| <expression> <expression sequence> <expression> ::= <term> | <expression> <operator> <term> | <expression> <answer> | <expression> <answer> +/- <term> ::= <numeral> | MR | Clear | <term> +/- <operator> ::= + | – | x <answer> ::= M+ | = <numeral> ::= <digit> | <numeral> <digit> <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
5 + + 6 =
and   88 × +/- 11 + MR MR
Clear
key occurs in several productions because a user is likely to press it at almost any time.
+/-
changes the sign of the displayed value.