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.

Solution:

According to the question, we have to just check whether Rule 1 and Rule 2 are L-attributed or not.

In L-attributed:

  • A parent is allowed to take its attribute values from its child. This is known as s-attributed and every s-attributed is L-attributed.
  • A child is allowed to take its attribute values from its parents and left siblings.

Note: A child is not allowed to take its attribute values from the right siblings. If so, then it will be inherited attribute but not L-attributed.

Now, Rule 1 satisfies this property but Rule 2 does not satisfy.