An attribute grammar is a formal way to define attributes for the productions of a formal grammar, associating these attributes to values. The evaluation occurs in the nodes of the abstract syntax tree, when the language is processed by some parser or compiler.
The attributes are divided into two groups: synthesized attributes and inherited attributes. The synthesized attributes are the result of the attribute evaluation rules, and may also use the values of the inherited attributes. The inherited attributes are passed down from parent nodes.
In some approaches, synthesized attributes are used to pass semantic information up the parse tree, while inherited attributes help pass semantic information down and across it. For instance, when constructing a language translation tool, such as a compiler, it may be used to assign semantic values to syntax constructions. Also, it is possible to validate semantic checks associated with a grammar, representing the rules of a language not explicitly imparted by the syntax definition.
Attribute grammars can also be used to translate the syntax tree directly into code for some specific machine, or into some intermediate language.
One strength of attribute grammars is that they can transport information from anywhere in the abstract syntax tree to anywhere else, in a controlled and formal way.
Read more about Attribute Grammar: Example, Synthesized Attributes, Inherited Attributes, Special Types of Attribute Grammars
Famous quotes containing the words attribute and/or grammar:
“Both the Moral Majority, who are recycling medieval language to explain AIDS, and those ultra-leftists who attribute AIDS to some sort of conspiracy, have a clearly political analysis of the epidemic. But even if one attributes its cause to a microorganism rather than the wrath of God, or the workings of the CIA, it is clear that the way in which AIDS has been perceived, conceptualized, imagined, researched and financed makes this the most political of diseases.”
—Dennis Altman (b. 1943)
“Literary gentlemen, editors, and critics think that they know how to write, because they have studied grammar and rhetoric; but they are egregiously mistaken. The art of composition is as simple as the discharge of a bullet from a rifle, and its masterpieces imply an infinitely greater force behind them.”
—Henry David Thoreau (18171862)