1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
A language's grammar rules define its syntax. Its semantics are defined
through semantic values that can be associated with terminal and nonterminal
symbols, and generally by the actions taken when nonterminals or parts of
production rules have been recognized.
For example, the calculator performs real-life calculations because the value
associated with each expression is its computed numeric value; it correcly
performs addition because the action for an expression like `x + y' is to add
those numbers and to return their sum.
Two ways of defining semantics have already been discussed:
itemization(
it() link(using a single data type for all semantic
values)(STYPE);
it() Semantic values representing link(several alternative data
types)(UNION).
)
A third way for defining semantic values is discussed next (cf. section
ref(POLYMORPHIC)). em(Shorthand notations) that can be used in action blocks
are described next (cf. section tt(ACTIONS)). Finally, Action blocks usually
appear at the end of production rules. But in fact they can be defined
anywhere in production rules. Refer to this section's final subsection
(section ref(MIDACTIONS)) for the characteristics of such em(mid-rule action
blocks).
|