146 Chapter 3 Describing Syntax and Semantics
The only error we consider in expressions is a variable having an unde-
fined value. Obviously, other errors can occur, but most of them are machine-
dependent. Let Z be the set of integers, and let error be the error value. Then
Z h {error} is the semantic domain for the denotational specification for our
expressions.
The mapping function for a given expression E and state s follows. To
distinguish between mathematical function definitions and the assignment
statements of programming languages, we use the symbol = to define
mathematical functions. The implication symbol, =>, used in this definition
connects the form of an operand with its associated case (or switch) con-
struct. Dot notation is used to refer to the child nodes of a node. For exam-
ple, <binary_expr>.<left_expr> refers to the left child node of <binary_expr>.
Me(<expr>, s) Δ= case <expr> of
<dec_num>=>Mdec(<dec_num>, s)
<var> =>if VARMAP(<var>, s) == undef
then error
else VARMAP(<var>, s)
<binary_expr> =>
if(Me(<binary_expr>.<left_expr>,s) == undef OR
Me(<binary_expr>.<right_expr>, s) == undef)
then error
else if (<binary_expr>.<operator> == '+')
then Me(<binary_expr>.<left_expr>, s) +
Me(<binary_expr>.<right_expr>, s)
else Me(<binary_expr>.<left_expr>, s) *
Me(<binary_expr>.<right_expr>, s)
3.5.2.4 Assignment Statements
An assignment statement is an expression evaluation plus the setting of the
target variable to the expression’s value. In this case, the meaning function maps
a state to a state. This function can be described with the following:
Ma(x = E, s) Δ= if Me(E, s) == error
then error
else s = {<i 1 , v 1 >, <i 2 , v 2 >,... , <in, vn>}, where
for j = 1, 2,... , n
if ij == x
then vj = Me(E, s)
else vj = VARMAP(ij, s)
Note that the comparison in the third last line above, ij == x, is of names, not
values.