All mock tests are FREE till 31 December — register to save your progress
Unit 8 · Theory of Computation and Compilers Paper 2 CS · June 2024 (Cancelled Exam)

The grammar
stmt → if expr then stmt else stmt | if expr then stmt
suffers from:

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: A. Ambiguity

Explanation

This is the dangling-else grammar: 'if E then if E then S else S' has two parse trees, so the grammar is ambiguous (it also needs left factoring for LL parsing).

More Theory of Computation and Compilers questions