GATE | GATE CS 2020 | Question 43

Consider the productions A → PQ and A → XY. Each of the five non-terminals A,P,Q,X, and Y has two attributes: s is a synthesized attribute, and i is an inherited attribute. Consider the following rules.

Rule 1: P.i=A.i+2, Q.i=P.i+A.i, and A.s=P.s+Q.s
Rule 2: X.i=A.i+Y.s and Y.i=X.s+A.i 

Which one of the following is TRUE ?
(A) Both Rule 1 and Rule 2 are L-attributed
(B) Only Rule 1 is L-attributed
(C) Only Rule 2 is L-attributed
(D) Neither Rule 1 nor Rule 2 is L-attributed

Answer: (B)

Explanation: According to L-attributed SDT:

  1. 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.
  2. Attributes in L-attributed SDTs are evaluated by depth-first and left-to-right parsing manner.
  3. Semantic actions are placed anywhere in RHS.


Rule 1: P.i=A.i+2, Q.i=P.i+A.i, and A.s=P.s+Q.s 

Rule 1 is L-attributed by definition.


Rule 2: X.i=A.i+Y.s and Y.i=X.s+A.i 

Rule 2 is not L-attributed because this expression (X. Rule 2: i = A.i + Y.s) fails to satisfy the definition of L-attributed.
It is failed for X.i =A.i +Y.s since X take value from its sibling which is present of its right, i.e., (A → XY).

Option (B) is correct.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.