CSSE 4 SE424 Semantics
Worksheet 2
- Using the binary numeral semantics in Figure 4.1 to determine the meaning of the following derivation trees:
- [ | 0011 | ]
- [ | 000 | ]
- [ | 111 | ]
- Using Figure 4.3 simplify these calculator programs to their meanings in Nat*
- [ | ON 1 + (IF LASTANSWER, 4, 1) TOTAL LASTANSWER TOTAL 5*2 TOTAL OFF | ]
- [ | ON 5 TOTAL 5 TOTAL 10 TOTAL OFF | ]
- [ | ON LASTANSWER TOTAL OFF | ]
- Augment the calculator so that it can compare 2 values for equality: add an = button to it and augment the BNF rule for expression to read:
E ::= … | E1 = E2
- Write the semantic equation for E [ | E1 = E2 | ]
- What changes must be made to the other parts of the denotational definition to accommodate the new construct? Make those changes.
- Alter the calculator semantics so that the memory cell argument to S and E becomes a memory stack; i.e. use Nat* in place of Nat as an argumant domain to S and E.
- Adjust the semantics so that the last answer is pushed onto the memory stack and the LASTANSWER button access the top value on the stack
- Augment the syntax of the calculator language so that the user can explicitly pop values of the memory stack