Home › GATE CSE › computerscience › Compiler Design › The SCANNER (or LEXER) is the FIRST phase of a c…
The SCANNER (or LEXER) is the FIRST phase of a compiler. Its job is to
Aexecute the source code
Boptimise the program
Cproduce machine code directly
Dproduce a token stream
Answer & 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)._
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