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