Skip to content
Related Articles
Open in App
Not now

Related Articles

S – attributed and L – attributed SDTs in Syntax directed translation

Improve Article
Save Article
Like Article
  • Difficulty Level : Easy
  • Last Updated : 16 Feb, 2023
Improve Article
Save Article
Like Article

Before coming up to S-attributed and L-attributed SDTs, here is a brief intro to Synthesized or Inherited attributes Types of attributes – Attributes may be of two types – Synthesized or Inherited.

  1. Synthesized attributes – A Synthesized attribute is an attribute of the non-terminal on the left-hand side of a production. Synthesized attributes represent information that is being passed up the parse tree. The attribute can take value only from its children (Variables in the RHS of the production). For e.g. let’s say A -> BC is a production of a grammar, and A’s attribute is dependent on B’s attributes or C’s attributes then it will be synthesized attribute.
  2. Inherited attributes – An attribute of a nonterminal on the right-hand side of a production is called an inherited attribute. The attribute can take value either from its parent or from its siblings (variables in the LHS or RHS of the production). For example, let’s say A -> BC is a production of a grammar and B’s attribute is dependent on A’s attributes or C’s attributes then it will be inherited attribute.

Now, let’s discuss about S-attributed and L-attributed SDT.

  1. S-attributed SDT :
    • If an SDT uses only synthesized attributes, it is called as S-attributed SDT.
    • S-attributed SDTs are evaluated in bottom-up parsing, as the values of the parent nodes depend upon the values of the child nodes.
    • Semantic actions are placed in rightmost place of RHS.
  2. L-attributed SDT:
    • If an SDT uses both synthesized attributes and inherited attributes with a restriction that inherited attribute can inherit values from left siblings only, it is called as L-attributed SDT.
    • Attributes in L-attributed SDTs are evaluated by depth-first and left-to-right parsing manner.
    • Semantic actions are placed anywhere in RHS.
My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!