Slide 6.5: Semantic functions (cont.) Slide 6.7: Denotational semantics of integer arithmetic expressions (cont.) Home |
E: Expression N: Number D: Digit
E ::= E1 '+' E2 | E1 '–' E2 | E1 '*' E2 | '(' E ')' | N N ::= N D | D D ::= '0' | '1' | ... | '9'
v: Integer = { ..., -2, -1, 0, 1, 2, ...}
+: Integer
× Integer
→ Integer
–: Integer
× Integer
→ Integer
*: Integer
× Integer
→ Integer
E: Expression → Integer E[[E1 '+' E2]] = E[[E1]] + E[[E2]] E[[E1 '–' E2]] = E[[E1]] – E[[E2]] E[[E1 '*' E2]] = E[[E1]] * E[[E2]] E[['(' E ')']] = E[[E]] E[[N]] = N[[N]] N: Number → Integer N[[ND]] = 10 * N[[N]] + N[[D]] N[[D]] = D[[D]] D: Digit → Integer D[['0']] = 0, D[['1']] = 1, ..., D[['9']] = 9