Semantic information is stored in attributes associated with terminal and nonterminal symbols of the grammar.
Attributes allow the transfer of information from anywhere in the abstract syntax tree to anywhere else, in a controlled and formal way.
In simple applications, such as evaluation of arithmetic expressions, attribute grammar may be used to describe the entire task to be performed besides parsing in straightforward way; in complicated systems, for instance, when constructing a language translation tool, such as a compiler, it may be used to validate semantic checks associated with a grammar, representing the rules of a language not explicitly imparted by the syntax definition.
It may be also used by parsers or compilers to translate the syntax tree directly into code for some specific machine, or into some intermediate language.
Attribute grammars were invented by Donald Knuth and Peter Wegner.
Some embryonic ideas trace back[3] to the work of Edgar T. "Ned" Irons,[4] the author of IMP.
The following is a simple context-free grammar which can describe a language made up of multiplication and addition of integers.
Inherited attributes are convenient for expressing the dependence of a programming language construct on the context in which it appears.