L-attributed grammar

{{More citations|date=July 2020}}

L-attributed grammars are a special type of attribute grammars.{{cite journal |last1=Knuth |first1=Donald E. |authorlink1=Donald Knuth |date=June 1968 |title=Semantics of context-free languages |journal=Mathematical Systems Theory |volume=2 |issue=2 |pages=127–145 |citeseerx=10.1.1.455.1434 |doi=10.1007/BF01692511 |issn=0025-5661 |s2cid=5182310 |id={{QID|56672530}}}} They allow the attributes to be evaluated in one depth-first left-to-right traversal of the abstract syntax tree. As a result, attribute evaluation in L-attributed grammars can be incorporated conveniently in top-down parsing.

A syntax-directed definition is L-attributed if each inherited attribute of X_j on the right side of A \rightarrow X_1, X_2, \dots, X_n depends only on

  1. the attributes of the symbols X_1, X_2, \dots, X_{j-1}
  2. the inherited attributes of A (but not its synthesized attributes)

Every S-attributed syntax-directed definition is also L-attributed.

Implementing L-attributed definitions in Bottom-Up parsers requires rewriting L-attributed definitions into translation schemes.

Many programming languages are L-attributed. Special types of compilers, the narrow compilers, are based on some form of L-attributed grammar. These are a strict superset of S-attributed grammars. Used for code synthesis.

Either "inherited attributes" or "synthesized attributes" associated with the occurrence of symbol X_1,X_2, \dots, X_n.

References

{{reflist}}

{{DEFAULTSORT:L-Attributed Grammar}}

Category:Formal languages

Category:Compiler construction