In a compiler, keywords of a language are recognized during

20112025

In a compiler, keywords of a language are recognized during

  1. A.

    parsing of the program

  2. B.

    the code generation

  3. C.

    the lexical analysis of the program

  4. D.

    dataflow analysis

Attempted by 381 students.

Show answer & explanation

Correct answer: C

Correct answer: the lexical analysis of the program.

Explanation: The lexical analyzer (lexer or scanner) reads the raw source characters, groups them into lexemes, and classifies those lexemes into tokens. Keywords are recognized here by matching lexemes against the language's reserved-word list or token patterns, so the parser receives tokens that indicate reserved words rather than plain identifiers.

  • Lexer role: convert character streams into a stream of tokens (identifiers, keywords, literals, operators, etc.).

  • Parser role: consume the token stream to build syntactic structure (parse tree or AST); it relies on tokens produced by the lexer.

  • Later phases (semantic analysis, dataflow analysis, code generation) operate on the parsed/IR form and do not perform initial keyword recognition.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir