GATE CS 2025 Set 2 | Question 22

Compiler Design › Parser · MCQ · 1 mark · Answer: C

  1. Question 22Compiler Designmcq1 mark
    Given the following syntax directed translation rules:
    Rule 1: R -> A B  { B.i = R.i - 1;  A.i = B.i;  R.i = A.i + 1; }
    Rule 2: P -> C D  { P.i = C.i + D.i;  D.i = C.i + 2; }
    Rule 3: Q -> E F  { Q.i = E.i + F.i; }
    Which ONE is the CORRECT option among the following?
    • A.
      Rule 1 is S-attributed and L-attributed; Rule 2 is S-attributed and not L-attributed; Rule 3 is neither S-attributed nor L-attributed
    • B.
      Rule 1 is neither S-attributed nor L-attributed; Rule 2 is S-attributed and L-attributed; Rule 3 is S-attributed and L-attributed
    • C.
      Rule 1 is neither S-attributed nor L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed
      ✓
    • D.
      Rule 1 is S-attributed and not L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed

    Answer: C

    Solution

    Answer: (C) An SDT is S-attributed if every attribute is synthesized; it is L-attributed if each inherited attribute of a symbol depends only on its parent or on symbols to its left. - Rule 1: it computes inherited attributes (), so not S-attributed. Worse, makes (left symbol) depend on (to its right) → violates L-attributed. So Rule 1 is neither. - Rule 2: is an inherited attribute (so not S-attributed), but it depends on , which is to 's left → L-attributed. - Rule 3: assigns only the synthesized attribute of the head from its children → S-attributed (hence also L-attributed). This matches option (C).

More GATE PYQ on Parser

All GATE CS Compiler Design PYQ →

Attempt GATE CS 2025 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →