Attribute Grammars as a framework for semantic processing
Attribute Grammars as a framework for semantic processing
Semantic processing routines often return values that summarize
the properties of the sub-phrases to which they were applied.
For example, your function to process expressions should
return the type descriptor of the expression.
It can be useful to think of the values returned by such semantic
processing routines as labels that get affixed to the nodes of
the parse tree or abstract syntax tree as it is processed.
These "labels" are often referred to as "attributes".
Those interested in building formal systems for specifying
the details of semantic processing often base their schemes
on the notion of such attribute values.
A grammar for the souce language or an abstract
grammar for abstract syntax trees is annotated
with rules that associate attribute values with
the terminals and non-terminals of the grammar.
Synthesized attributes are those whose values
are determined by a node's subtrees (a phrase's
substructure). The type of an expression
might be an example.
Inherited attributes are those whose values
are determined by the context of a phrase
(the current scope's nesting level, the entire symbol table (in
a purely applicative compiler) ).