Skip to main content

GATE CSE 2025Compiler Design › Syntax-Directed Translation & Intermediate CodeVerified

GATE CSE 2025 PYQ: ​​Given the following syntax directed translation rules: Rule 1: R → A B { B . i = R . i − 1 ; A . i = B . i…

​​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?
  1. A
    Rule 1 is SS-attributed and LL-attributed; Rule 2 is SS-attributed and not LL-attributed; Rule 3 is neither SS-attributed nor LL-attributed.
  2. B
    Rule 1 is neither SS-attributed not LL-attributed; Rule 2 is SS-attributed and LL-attributed; Rule 3 is SS-attributed and LL-attributed.
  3. C
    Rule 1 is neither SS-attributed nor LL-attributed; Rule 2 is not SS-attributed and is LL-attributed; Rule 3 is SS-attributed and LL-attributed.
    Correct answer
  4. D
    Rule 1 is SS-attributed and not LL-attributed; Rule 2 is not SS-attributed and is LL-attributed; Rule 3 is SS-attributed and LL-attributed.

Answer

(C) Rule 1 1 1 is neither S S S -attributed nor L L L -attributed; Rule 2 2 2 is not S S S -attributed and is L L L -attributed; Rule 3 3 3 is S S S -attributed and L L L -attributed.

Approach

Classify each semantic rule by checking whether it uses only synthesized attributes or whether any inherited attribute depends only on the parent/left siblings. An attribute defined using child attributes is synthesized; one defined from the parent or a sibling is inherited. S-attributed requires all attributes to be synthesized. L-attributed allows inherited attributes only if they depend on parent inherited attributes or attributes of left siblings, never right siblings.

Rule 1 violates L-attributedness because A.i uses right sibling B.i, and it also has inherited attributes, so it is neither S- nor L-attributed. Rule 2 has inherited D.i from left sibling C, making it L-attributed but not S-attributed. Rule 3 computes only synthesized attributes, making it both S- and L-attributed. Therefore option C is correct.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.