L-attribute definition

L-Attribute class of Syntax Directed Definition (SDD) is called L-Attributed definitions.

The idea behind this class is that, between the attributes associated with a production body, dependency-graph edges can go from left to right, but not from right to left hence L-attribute.

L-Attribute 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 SDD. As a result, attribute evaluation in L-attributed grammars can be incorporated conveniently in top-down parsing.

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.

In L-attributed SDTs, a non-terminal can get values from its parent, child, and sibling nodes.

Example:

Let following production

S –>ABC

  • S can take values from A, B, and C (synthesized).
  • A can take values from S only.
  • B can take values from S and A.
  • C can get values from S, A, and B.
  • No non-terminal can get values from the sibling to its right.

Attributes in L-attributed SDTs are evaluated by depth-first and left-to-right parsing manner.