GATE CS 2025 Set 2 | Question 51

Compiler Design › Parser · MSQ · 2 marks · Answer: C, D

  1. Question 51Compiler Designmsq2 marks
    Consider grammars and :
    G1: S -> if E then S | if E then S else S | a
        E -> b
    G2: S -> if E then S | M
        M -> if E then M else S | c
        E -> b
    Which of the following option(s) is/are CORRECT?
    • A.
      is not LL(1) and is LL(1).
    • B.
      is LL(1) and is not LL(1).
    • C.
      and are not LL(1).
      ✓
    • D.
      and are ambiguous.
      ✓

    Answer: C, D

    Solution

    Answer: (C) and (D) (C) Neither grammar is LL(1). In the two -productions both begin with if, giving a FIRST/FIRST conflict. In both and also begin with if, so FIRSTFIRST — again not LL(1). (D) Both grammars exhibit the dangling-else construct and admit more than one parse tree for such inputs (per the official key), so both are ambiguous.

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 →