Home › GATE CSE › computerscience › Compiler Design › When the scanner encounters an INVALID character…
When the scanner encounters an INVALID character (e.g. '@' in a language that doesn't use it), it typically
Aignores it silently
Breports an error and keeps scanning
Chalts the entire compilation
Dtreats it as an identifier
Answer & Solution
Correct answer: B. reports an error and keeps scanning
1. Good practice: report the error with line number AND a helpful message, then CONTINUE scanning the rest of the file.
2. Continuation allows the compiler to find MULTIPLE errors in one pass, which is what programmers want.
3. The compiler tracks an error flag so that, despite continuing to scan/parse, it knows not to proceed to code generation.
4. Silent ignoring (option A) hides bugs. Halting after one error (option C) is annoying. Treating as identifier (option D) leads to confusing downstream errors.
_Source: Bob Nystrom, "Crafting Interpreters", Ch 4.5 (Error handling in scanner) + Ch 6.3 cross-ref._
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 whenWhich of these is a BOTTOM-UP (LR) parser feature?An LL(1) grammar requires that, given the leftmost non-terminal and ONE token of lookaheadLL parsers (recursive descent) parse from thePANIC MODE error recovery in a parser works by