ISRO Computer Science (CSE) 2026 - Question 74

All ISRO Computer Science (CSE) papers | ISRO Computer Science (CSE) 2026

Topic: Compiler Design / Parsing

The dangling-else grammar stmt -> if expr then stmt | if expr then stmt else stmt | other is

  • A. unambiguous
  • B. not context-free
  • C. ambiguous
  • D. regular

Answer: C. ambiguous

Explanation: The classic "dangling-else" grammar is inherently ambiguous. An input string like `if E1 then if E2 then S1 else S2` has two distinct, valid parse trees. The `else S2` can be incorrectly attached to the outer `if E1` or correctly attached to the inner `if E2`. Because a single string can generate more than one parse tree, the grammar is formally ambiguous.

| | All questions of ISRO Computer Science (CSE) 2026