retagged by
9,065 views
18 votes
18 votes

Consider the productions $A \rightarrow PQ$ and $A \rightarrow  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?

  1. Both Rule $1$ and Rule $2$ are $L$-attributed.
  2. Only Rule $1$ is $L$-attributed.
  3. Only Rule $2$ is $L$-attributed.
  4. Neither Rule $1$ nor Rule $2$ is $L$-attributed.
retagged by

2 Answers

Best answer
21 votes
21 votes

Answer : B.

In L-attributed definitions,

  1.  A parent can take its attribute values from any child (which is $S-$attributed and Every $S-$attributed is also $L-$Attributed).
  2.  A child can take its attribute values from the parent as well as from any left sibling but not from any right sibling.

Based on these properties, only Rule-1 is $L-$attributed.
Rule-2 is failed for the production $A \to XY,$ and defintion $X.i =A.i +Y.s$ since $X$ take value from its sibling $Y,$ which is present in its right in the production. 

edited by
2 votes
2 votes
L-attributed definition:  it can synthesized or inherited type.

Synthesized: An attribute can take values from its children.

Inherited: an attribute can take values from its siblings.
But, the condition is inherited attribute can take values only from the parent or left sibling. Strictly not from right sibling

In Rule1: all are following conditions of L-attributed grammer.

In Rule2:  X.i = A.i + Y.s   ( given production is A-->XY )

An attriubte is taking values from its right sibling. Therefore not L-attributed.

Therefore Ans : (B)
Answer:

Related questions

19 votes
19 votes
2 answers
2
Arjun asked Feb 12, 2020
12,345 views
Consider the following grammar.$S \rightarrow aSB \mid d$$B \rightarrow b$The number of reduction steps taken by a bottom-up parser while accepting the string $aaadbbb$ ...
9 votes
9 votes
3 answers
4
Arjun asked Feb 12, 2020
5,734 views
If $P = 3$, $R = 27$, $T = 243$, then $Q + S =$ ________$40$$80$$90$$110$