Jump to content

L-attributed grammar

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Tom.Reding (talk | contribs) at 22:01, 29 June 2016 (top: Rem stub tags (class = non-stub & non-list) using AWB). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

L-attributed grammars are a special type of attribute grammars. 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 Xj on the right side of

A → X1 X2 … Xn

depends only on

1.the attributes of the symbols X1, X2, …, Xj-1

2.the inherited attributes of A

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 X1,X2-----Xn