Skip to content
Official PYQ · 2025

GATE CS 2025 Set 2 Q12 — Syntax-directed Translation

Explain with AI

​​Given the following syntax directed translation rules:

  • Rule 1: R→AB{B.i=R.i−1;A.i=B.i;R.i=A.i+1;}R \rightarrow A B\{B . i=R . i-1 ; A . i=B . i ; R . i=A . i+1 ;\}
  • Rule 2: P→CD{P.i=C.i+D.i;D.i=C.i+2;}P \rightarrow C D\{P . i=C . i+D . i ; D . i=C . i+2 ;\}
  • Rule 3: Q→EF{Q.i=E.i+F.i;}Q \rightarrow E F\{Q . i=E . i+F . i ;\}
Which ONE is the CORRECT option among the following?
Choose one option
View worked solution

Answer: C

To determine the classification of each syntax-directed translation (SDT) rule, we use the definitions of SS-attributed and LL-attributed definitions:

  • SS-attributed SDD: Uses only synthesized attributes (attributes of the parent are computed from the attributes of its children).
  • LL-attributed SDD: Allows both synthesized and inherited attributes. However, an inherited attribute of a child on the right-hand side can only depend on the attributes of the parent or the siblings to its left.

Let's analyze each rule:

  1. Rule 1 (R→ABR \rightarrow A B): The action A.i = B.i defines the attribute of child AA using the attribute of child BB, which lies to its right. This violates the LL-attributed condition. Since it uses inherited attributes, it is also not SS-attributed. Thus, Rule 1 is neither SS-attributed nor LL-attributed.
  2. Rule 2 (P→CDP \rightarrow C D): The action D.i = C.i + 2 defines the inherited attribute of DD using its left sibling CC, which is allowed in LL-attributed. The action P.i = C.i + D.i defines the head's attribute using its children, which is also allowed. Since it defines an inherited attribute of a child (D.iD.i), it is not SS-attributed. Thus, Rule 2 is not SS-attributed and is LL-attributed.
  3. Rule 3 (Q→EFQ \rightarrow E F): The action Q.i = E.i + F.i only defines the attribute of the head QQ using the attributes of its children. This behaves purely as a synthesized attribute. Thus, Rule 3 is both SS-attributed and LL-attributed.

Hence, the correct option is C.

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

Published
Report a correction
Keep exploringMore Syntax-directed Translation questions