0
44kviews
Explain S-Attributed & L-Attributed In Detail

Subject: system programming and compiler construction

Topic: Syntax Directed Translation

Difficulty: Low

1 Answer
4
2.9kviews

S-attributed SDT If an SDT uses only synthesized attributes, it is called as S-attributed SDT. These attributes are evaluated using S-attributed SDTs that have their semantic actions written after the production (right hand side).

enter image description here

S-attributed SDT As depicted above, attributes in S-attributed SDTs are evaluated in bottom-up parsing, as the values of the parent nodes depend upon the values of the child nodes.

L-attributed SDT This form of SDT uses both synthesized and inherited attributes with restriction of not taking values from right siblings.

In L-attributed SDTs, a non-terminal can get values from its parent, child, and sibling nodes. As in the 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.

enter image description here

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

L-attributed SDT We may conclude that if a definition is S-attributed, then it is also L-attributed as L-attributed definition encloses S-attributed definitions.

Please log in to add an answer.