S Attributed and L Attributed SDTs in Syntax Directed Translation (original) (raw)

Last Updated : 24 Apr, 2026

In Syntax-Directed Translation (SDT), semantic actions are attached to grammar productions to pass semantic information (attributes) between nodes of the parse tree during parsing. These actions perform tasks such as type checking, intermediate code generation, symbol table management, and other semantic processing. Based on the way attributes are evaluated and passed in the parse tree, SDTs are classified into S-Attributed SDT and L-Attributed SDT.

Importance of SDTs

S-attributed SDT

An S-attributed SDT ****(Synthesized Attributed SDT)** is one of the Syntax-Directed Translation schemes in which all attributes are synthesized. Typically, these values are generated at the leaf nodes and then propagated upward to the root of the parse tree during evaluation.

Key Features:

Example:

Let us consider a production role such that.

E → E1 + T

Hence, the synthesized attribute E.val can be calculated as:

E.val = E1.val + T.val

L-attributed SDT

An **L-Attributed SDT (Left-Attributed SDT) allows both synthesized attributes and inherited attributes.
Inherited attributes obtain their values from the parent or left sibling nodes, while synthesized attributes are computed from the child nodes, similar to S-attributed SDTs. Inherited attributes can only depend on the parent and symbols to the left of the current symbol in a production rule.

Key Features:

Example:

Consider a production rule.

S → A B

Now, the inherited attribute A.inh can be calculated as.

A.inh = f(S.inh)

likewise, B can also have synthesized attributes based on A :

B.inh = g(A.synth)