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