Slide 6.4: Semantic functions
Slide 6.6: Denotational semantics of integer arithmetic expressions
Home

Semantic Functions (Cont.)


The semantic function from numbers to integers is based on the syntax
   N ::= N D | D
and is given by the following equations:
   N[[ND]]= 10 * N[[N]] + N[[D]]
   N[[D]] = D[[D]]
Here [[ND]] refers to the tree node and [[D]] to the node .

Applications of the Denotational Definition
The value of the numeral '65' can be found according to this definition:
   N[['65']] = 10 * N[['6']] + D[['5']]
     = 10 * D[['6']] + 5 = 10 * 6 + 5 = 60 + 5 = 65
Solely using the specification of the semantics of numerals, N[['008']] = N[['8']] can also be proved as follows:
   N[['008']] = 10*N[['00']]+D[['8']] 
     = 10*( 10*N[['0']]+D[['0']] )+8
     = 10*( 10*D[['0']]+0 )+8
     = 10*( 10*0+0 )+8 = 8
     = D[['8']] = N[['8']]
Although the syntactic expression '008' inside the brackets is written in linear form, it actually represents the abstract syntax tree that reflects its derivation
   <N>  <N> <D>  <N> <D> <D>  <D> <D> <D>
      '0' <D> <D>  '00' <D>  '008'