Given CFG
, Attribute grammar is
and
are synthesized and inherited attributes
of
resp.
are ``rules'' for each
.
- Can only define inherited attributes of right-hand side symbols
and synthesized attributes of left-hand side symbol:
- Given a tree
over the context-free grammar, assume all nodes have
a unique name.
- Instantiate
wherever
occurs in the tree,
replacing
with the name of the corresponding node.
- Solve resulting equations simultaneously.
- Terminals are ``types'':
- Nonterminals are ``phyla'':
- Productions are ``constructors'':
- Attributes have declared types and defaults.
Inherited attributes must be so declared:
- Rules are ``pattern matches'':
The expression
may use attribute values, constants etc.
John Tang Boyland
2004-09-30