Slide 7.6: The semantic functions of the calculator language (cont.)
Slide 8.1: Operational semantics
Home

A Sample Calculation


As an example of an evaluation according to the definition, consider the series of keystrokes “2 + 3 =”. The meaning of the sequence is given by
   meaning[[2 + 3 =]] = d
      where perform[[2 + 3 =]](0, nop, 0, 0) = (a, op, d, m)
The evaluation proceeds as follows:
   perform[[2 + 3 =]](0, nop, 0, 0)

= evaluate[[2 + 3 =]](0, nop, 0, 0)

= ( calculate[[=]] º evaluate[[2 + 3]] )(0, nop, 0, 0)

= ( calculate[[=]] º evaluate[[3]] º compute[[+]]
º evaluate[[2]] )(0, nop, 0, 0)
= calculate[[=]]( evaluate[[3]]( compute[[+]]( evaluate[[2]](0, nop, 0, 0) ) ) )
= calculate[[=]]( evaluate[[3]]( compute[[+]](0, nop, 2, 0) ) ),
since value[[2]] = 2
= calculate[[=]]( evaluate[[3]](2, plus, 2, 0) ),
since nop(0, 2) = 2
= calculate[[=]](2, plus, 3, 0), since value[[3]] = 3

= (2, nop, 5, 0), since plus(2, 3) = 5.
Therefore meaning[[2 + 3 =]] = 5.

Real calculators have two conditions that produce errors when evaluating integer arithmetic: arithmetic overflow and division by zero. Our calculator has no division so that we can avoid handling the problem of division by zero as a means of reducing the complexity of the example. Furthermore, we assume unlimited integers so that overflow is not a problem.

To Divide use / Symbol