![]() |
VOOZH | about |
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.
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.
Let us consider a production role such that.
E → E1 + THence, the synthesized attribute E.val can be calculated as:
E.val = E1.val + T.valAn 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.
Consider a production rule.
S → A BNow, 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)