Questions: Lexical Error Handling and Reporting

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A scanner encounters an unterminated string literal: `"hello` at the end of a line with no closing quote. What is the most appropriate panic-mode recovery action?

AAbort scanning immediately and report a fatal error, since the file is now unusable
BEmit an error message, treat the partial string as an error token ending at the line boundary, and resume scanning on the next line
CSilently discard everything from the opening quote to end-of-file and continue
DInsert a closing quote after 'hello' and emit a valid string token without an error
Question 2 Multiple Choice

What is the primary goal of error recovery in a lexical analyzer, as opposed to simply halting on the first error?

ATo automatically correct all lexical errors so the parser sees no invalid input
BTo allow scanning to continue past the error so that later compiler phases can detect and report additional independent errors in a single pass
CTo guarantee that all subsequent tokens are syntactically valid
DTo reduce the number of error messages shown to the programmer
Question 3 True / False

A single lexical error in one part of a source file typically makes most tokens after it invalid and unusable by the parser.

TTrue
FFalse
Question 4 True / False

A high-quality lexical error message should include the source file name, line number, column position, and a description of what was encountered — so the programmer can locate and understand the problem without re-reading the whole file.

TTrue
FFalse
Question 5 Short Answer

Why is designing good lexical error messages considered a 'user interface problem' rather than just a technical correctness problem?

Think about your answer, then reveal below.