Question

Consider the productions A→PQA \to P Q and A→XYA \to X Y. Each of the five non-terminals A,P,Q,XA, P, Q, X, and YY has two attributes: ss is a synthesized attribute, and ii is an inherited attribute. Consider the following rules.

Rule 1: P.i=A.i+2,Q.i=P.i+A.i,A.s=P.s+Q.sP.i = A.i + 2,\quad Q.i = P.i + A.i,\quad A.s = P.s + Q.s
Rule 2: X.i=A.i+Y.s,Y.i=X.s+A.iX.i = A.i + Y.s,\quad Y.i = X.s + A.i

Which one of the following is TRUE?

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2020 answer key

Solution

Check attribute dependencies against the definition of L-attributed definition.

Definition of L-attributed syntax-directed definition (SDD):

  • In every production A→X1X2…XnA \to X_1 X_2 \dots X_n, each inherited attribute of XjX_j may depend only on:
    1. Inherited attributes of the parent AA.
    2. Any attributes of symbols to the left of XjX_j (i.e., X1,…,Xj−1X_1, \dots, X_{j-1}).
  • Synthesized attributes of AA may depend on any attributes of AA and its children.

Analysis of Rule 1:

  • P.i=A.i+2P.i = A.i + 2: Inherited attribute P.iP.i depends on parent's inherited attribute A.iA.i. (Valid)
  • Q.i=P.i+A.iQ.i = P.i + A.i: Inherited attribute Q.iQ.i depends on left sibling's attribute P.iP.i and parent's A.iA.i. (Valid)
  • A.s=P.s+Q.sA.s = P.s + Q.s: Synthesized attribute A.sA.s depends on children's synthesized attributes. (Valid)
  • Thus, Rule 1 is L-attributed.

Analysis of Rule 2:

  • Production A→XYA \to X Y.
  • X.i=A.i+Y.sX.i = A.i + Y.s: Inherited attribute X.iX.i of symbol XX depends on Y.sY.s, an attribute of symbol YY which appears to the right of XX.
  • Dependencies on right siblings are strictly prohibited in L-attributed grammars.
  • Thus, Rule 2 is NOT L-attributed.

Therefore, only Rule 1 is L-attributed.

Final answer

B

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2020 Computer Science and Information Technology (CS)
Question
43 of 65, printed as CS Q.33
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.