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?
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? Correct Answer Only Rule 1 is L-attributed.
Concept:
A rule is said to be L- attributed if it used both synthesized and inherited attributes. But, in the inherited attribute, we can get attribute values from the parent or from the left siblings, but not the right sibling.
Rule 1 is L- attributed.
Rule 1: P.i = A.i + 2, Q.i = P.i + A.i, and A.s = P.s + Q.s
Explanation:
P.i = A.i + 2 ...{This is an inherited attribute, as child P is getting value from parent A}
Q.i = P.i + A.i ...{This is also inherited attribute and Q is getting value from parent P and left sibling A}
A.s = P.s + Q.s ...{This is synthesized attribute as Parent A is taking values from children P and Q}
Rule 2 is not L- attributed
Rule 2: X.i = A.i + Y.s and Y.i = X.s + A.i
Explanation:
X.i = A.i + Y.s ...{Child X is taking attribute value from parent A and right sibling Y}
Therefore, this violates the conditions of L- attributed definitions.