Practice free →
HomeGATE CSEcomputerscienceCompiler Design › PANIC MODE error recovery in a parser works by

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)._
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions