Skip to content

L-Attributed Grammar

Constrain inherited attributes to parent context and earlier siblings so parse-tree attributes can be evaluated left to right.

Version
v1 · 2026-10-03 · History
Domain-specific #
13369
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomains
Compiler Theory, Attribute Grammars → Computer Science & Software Engineering
Aliases
L-attributed definition, Left-attributed grammar

Core Idea

An L-attributed grammar, more precisely an L-attributed syntax-directed definition, restricts the dependencies of attributes on a parse tree. In a production A → X₁ … Xₙ, an inherited attribute of Xᵢ may use inherited attributes of A and attributes of siblings to the left of Xᵢ, but not values that will only be available from its right siblings. This permits depth-first left-to-right attribute evaluation.[1][2]

How would you explain it like I'm…

Only Peek Left

Imagine a row of kids passing notes down a line from left to right. Each kid can use notes from kids on their left, but never from kids on their right, because those kids haven't written anything yet. An L-Attributed Grammar is a rule like that for computers figuring out what a sentence means.

Left-to-Right Tree Walk

When a computer reads a program, it breaks it into a tree of parts and then works out facts about each part, like what type a number is. An L-Attributed Grammar is a rule that lets it do this in one trip: visit the parts from left to right, going down into each one. Before visiting a part, you can hand it information from its parent or from parts to its left. You can't hand it something that only a part to its right would figure out, since that part hasn't been visited yet. After visiting, the part can send results back up.

Left-Only Attribute Dependencies

An L-attributed grammar (more precisely, an L-attributed syntax-directed definition) is a set of rules for attaching meaning to the pieces of a parse tree so that everything can be computed in one depth-first, left-to-right walk. Values flowing down into a child are called inherited attributes; values flowing up are called synthesized attributes. For a child, an inherited attribute may depend only on its parent's inherited attributes and on attributes of siblings to its left. It can never need something from a right sibling, since that hasn't been computed yet. This restriction is about how meaning-values depend on each other, not about which strings the grammar accepts. An S-attributed definition, which uses only synthesized attributes, is a special case that automatically satisfies it.

 

An L-attributed grammar—more precisely an L-attributed syntax-directed definition—is an attribute-grammar discipline guaranteeing that all attributes can be evaluated by a depth-first, left-to-right traversal of the parse tree. For a production A → X₁ X₂ … Xₙ, an inherited attribute of Xᵢ may depend only on inherited attributes of A and on inherited or synthesized attributes of X₁ … Xᵢ₋₁. It may not depend on a right sibling, whose values aren't yet available at that point in the traversal. Synthesized attributes are computed from already-visited children and passed upward. This pattern lets you pass context into a child before visiting it and receive a result afterward. S-attributed definitions, with only synthesized attributes, are a special case. The property concerns semantic dependencies, not the recognized language, and it does not by itself make a grammar suitable for predictive parsing or guarantee its actions embed in every parser implementation.

Scope of Application

Compilers use the discipline to propagate types, environments, and other semantic values through syntax trees. A declaration list can receive a type computed from an earlier Type node; an expression tail can receive a value computed from a left sibling. S-attributed definitions, which have no inherited attributes, are a special case.[1][2]

Clarity

The property classifies attribute equations, not the strings recognized by a grammar or the suitability of its syntax for LL parsing. An acyclic attribute grammar may still need a later sibling's value before an earlier child can be visited, so it can fail the L test despite being evaluable in some other order.[2]

Manages Complexity

The left-to-right restriction gives a local evaluation schedule: compute a child's inherited inputs from parent context and completed left siblings, visit that child, then pass its synthesized outputs onward. It avoids a general dependency solver for definitions that satisfy the restriction. Bottom-up parser implementations may nevertheless need marker rules or other refactoring to expose inherited values at the right time.[1]

Abstract Reasoning

For each inherited attribute of Xᵢ, inspect every value its equation reads. If all come from inherited A attributes or earlier siblings, the local restriction passes. If one comes from a right sibling, a single depth-first left-to-right visit cannot provide it as written. Rewriting the equation or changing the evaluation method becomes necessary.[2]

Knowledge Transfer

The exact test transfers among attributed parse-tree applications such as type propagation and expression evaluation. It presupposes a context-free grammar's ordered productions and parse-tree children; those alone do not supply the added semantic dependency rule. Its broader analogy is “use only values already available in the chosen order,” but without grammar productions and inherited/synthesized attributes the named abstraction is not literally present.

Relationships to Other Abstractions

Local relationship map for L-Attributed GrammarParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.L-Attributed GrammarDOMAINDomain-specific abstraction: Context-Free Grammar — presupposesContext-FreeGrammarDOMAINDomain-specific abstraction: ECLR-Attributed Grammar — is a kind ofECLR-AttributedGrammarDOMAINDomain-specific abstraction: LR-Attributed Grammar — is a kind ofLR-AttributedGrammarDOMAIN

Current abstraction L-Attributed Grammar Domain-specific

Parents (1) — outgoing typed relations

  • L-Attributed Grammar presupposes Context-Free Grammar Domain-specific

    L-attributed equations require ordered context-free productions and their parse-tree children.

Children (2) — abstractions linked here by typed relations

  • ECLR-Attributed Grammar Domain-specific is a kind of L-Attributed Grammar

    ECLR's formal definition requires L-attributedness and adds statewise equal, unique expressions for a partition of inherited attributes.

  • LR-Attributed Grammar Domain-specific is a kind of L-Attributed Grammar

    LR-attribution retains L-attributed dependencies and adds LR parser-directed evaluability.

Hierarchy paths (2) — routes to 2 parentless roots

Neighborhood in Abstraction Space

L-Attributed Grammar sits in a sparse region of the domain-specific corpus (62nd percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Program Scope & Nesting Disciplines (10 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

References

[1] Stony Brook University CSE 504, “Syntax-Directed Definitions”, especially slides 4–7 and 19–22. registry ↩a ↩b ↩c

[2] East Carolina University, “Synthesized and inherited attributes,” §11.4. registry ↩a ↩b ↩c ↩d