Start learning →

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)._
Practise this question with Quill — GATE CSE →

Keep practising Compiler Design

Browse all Compiler Design questions for GATE CSE, or explore more Computer Science topics.

Start a Compiler Design lesson →
Related questions