PANIC MODE error recovery in a parser works by
Ahalting the parser immediately
Basking the user to re-enter input
Cguessing what the programmer meant
Dskip tokens until a synchronisation point
Answer & Solution
Correct answer: D. skip tokens until a synchronisation point
1. PANIC MODE: when a syntax error is detected, the parser DISCARDS tokens (consumes without acting) until it finds a SAFE state to resume parsing.
2. SAFE STATES (synchronisation points) are typically statement boundaries: tokens like `;`, `}`, or the start of a new statement (`if`, `for`, `class`, `return`).
3. The parser RESETS its state to expect a fresh statement and CONTINUES from there.
4. This allows the compiler to report MULTIPLE errors in one pass, not just the first.
5. Trade-off: may report SPURIOUS errors (a cascade from one real error) but is generally more useful than halting at the first error.
6. Other options describe non-panic strategies (none used in practice).
_Source: Bob Nystrom, "Crafting Interpreters", Ch 6.3 (Panic mode synchronisation)._
Keep practising Compiler Design
Browse all Compiler Design questions for GATE CSE, or explore more Computer Science topics.
Related questions
The FOLLOW(A) set in LL parsing isThe FIRST(α) set of a string α in LL parsing isAfter the parser produces an AST, the next compiler phase is typicallyA SHIFT/REDUCE CONFLICT in an LR parser occurs whenLL parsers (recursive descent) parse from theWhat is a SYNTAX ERROR?How does a parser typically encode OPERATOR PRECEDENCE in the grammar?An AMBIGUOUS grammar is one where