Slide 6.6: Semantic functions (cont.) Slide 7.1: A calculator language Home |
<
and >
enclosing a nonterminal are removed.
For example,
<N> ::= <N> <D> | <D>
is replaced by
N ::= N D | D
D[[0]] = 0
, and so on.
For clarity, we will generally continue to use the quotes, however.
E[[(2+3)*4]]
or, more precisely,
E[[ '(' '2' '+' '3' ')' '*' '4' ]]
The semantic value is calculated as follows:
E[[ '(' '2' '+' '3' ')' '*' '4' ]] = E[[ '(' '2' '+' '3' ')' ]] * E[[ '4' ]] = E[[ '2' '+' '3' ]] * N[[ '4' ]] = ( E[[ '2' ]] + E[[ '3' ]] ) * D[[ '4' ]] = ( N[[ '2' ]] + N[[ '3' ]] ) * 4 = ( D[[ '2' ]] + D[[ '3' ]] ) * 4 = ( 2 + 3 ) * 4 = 5 * 4 = 20Therefore, the expression "
(2+3)*4
" is a syntactic phrase that denotes the abstract object, namely the integer 20.