The SCANNER (or LEXER) is the FIRST phase of a compiler. Its job is to
- execute the source code
- optimise the program
- produce machine code directly
- produce a token stream
Show answer and solution
Correct answer: D. produce a token stream
1. The scanner reads the source code as a sequence of CHARACTERS.
2. It groups those characters into meaningful chunks called TOKENS — the 'words' and 'punctuation' of the programming language.
3. Output: a stream of tokens (each with a type, lexeme, literal, line number).
4. Subsequent phases (parser, semantic analyser, code generator) work on this token stream instead of raw text.
5. Options A, C, D describe later phases (interpreter, code gen, optimiser).
_Source: Bob Nystrom, "Crafting Interpreters", Ch 4 (Scanning, intro)._