Skip to content
Official PYQ · 2020

GATE CS 2020 Q33 — Syntax-directed Translation

Explain with AI

Consider the productions A→PQA \rightarrow PQ and A→XYA \rightarrow XY. Each of the five non-terminals A,P,Q,X,A, 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,1: P . i = A.i + 2, \: Q.i = P. i + A.i, and A.s=P.s+Q.sA.s = P.s +Q. s
  • Rule 2:X.i=A.i+Y.s2: X.i = A.i + Y.s and Y.i=X.s+A.iY. i = X. s +A .i

Which one of the following is TRUE?

Choose one option
View worked solution

Answer: B

To determine whether the rules are LL-attributed, let us recall the definition of an LL-attributed Syntax-Directed Definition (SDD):

For a production X→Y1Y2…YnX \rightarrow Y_1 Y_2 \dots Y_n, an inherited attribute of a symbol YkY_k on the right-hand side can only depend on:

  1. Inherited attributes of the head non-terminal XX.
  2. Any attributes (synthesized or inherited) of the symbols Y1,Y2,…,Yk−1Y_1, Y_2, \dots, Y_{k-1} that lie to the left of YkY_k.

Synthesized attributes of the head XX can depend on any attributes of the children on the right-hand side.


Analysis of Rule 1: A→PQA \rightarrow PQ

  • P.i=A.i+2P.i = A.i + 2: The inherited attribute P.iP.i depends on A.iA.i (inherited attribute of the head AA). This is valid.
  • Q.i=P.i+A.iQ.i = P.i + A.i: The inherited attribute Q.iQ.i depends on P.iP.i (attribute of PP, which is to the left of QQ) and A.iA.i (inherited attribute of the head AA). This is valid.
  • A.s=P.s+Q.sA.s = P.s + Q.s: The synthesized attribute of the head AA depends on the attributes of its children. This is valid.

Since all dependencies satisfy the conditions, Rule 1 is LL-attributed.


Analysis of Rule 2: A→XYA \rightarrow XY

  • X.i=A.i+Y.sX.i = A.i + Y.s: The inherited attribute X.iX.i depends on Y.sY.s (synthesized attribute of YY). Since YY lies to the right of XX, this dependency on a right sibling is invalid for an LL-attributed definition.

Thus, Rule 2 is not LL-attributed.


Therefore, only Rule 1 is LL-attributed. The correct option is B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Syntax-directed Translation questions