Question:medium

The output of a lexical analyzer is which one of the following?

Show Hint

Lexical analysis converts characters into tokens, while syntax analysis converts tokens into a parse structure.
Updated On: Jul 6, 2026
  • A parse tree
  • Intermediate code
  • Machine code
  • A stream of tokens
Show Solution

The Correct Option is D

Approach Solution - 1

Think of the lexical analyzer as the phase that turns raw text into meaningful "words". It scans character by character and groups them into the smallest meaningful units of the language, keywords, identifiers, numbers, operators, and so on.
It doesn't understand grammar (that's the parser's job, which builds a parse tree from these units), and it definitely doesn't produce intermediate or machine code, those come from much later phases.
What it hands off is simply a sequence of these classified units, one after another, which is what "a stream of tokens" means.
So the correct answer is a stream of tokens.
Was this answer helpful?
0
Show Solution

Approach Solution -2

We can also answer this by placing each option at its correct position in the standard compiler pipeline (lexical analysis, syntax analysis, semantic analysis, intermediate code generation, optimization, code generation) and checking which one sits immediately after lexical analysis:

  1. Parse tree: Produced by syntax analysis, the phase directly consuming the lexical analyzer's output, not produced by lexical analysis itself.
  2. Intermediate code: Produced much later, by the intermediate code generation phase, after the program's meaning has already been captured.
  3. Machine code: Produced at the very end of the pipeline, by the code generator, the last phase before the executable is emitted.
  4. Stream of tokens: This is the output that sits directly at the boundary between lexical analysis and syntax analysis, it's what the lexical analyzer builds from raw characters and passes forward.

Only one of these outputs actually belongs to the first phase of the pipeline; the rest belong to phases that come after it and rely on its output.

Therefore, the correct answer is A stream of tokens.

Was this answer helpful?
0