GATE / CS ARCHIVE

GATE CSE 2011 / QUESTION 1

Compiler keyword recognition

Compiler Design · Lexical Analysis · Full GATE CSE 2011 paper

GATE 2011, Q1 1 mark · MCQ
Report issue

Lexical Analysis

Question 1, GATE 2011: In a compiler, during which phase are language keywords recognized?

(A) Parsing the program
(B) Code generation
(C) Lexical analysis
(D) Dataflow analysis
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Lexical analysis groups source characters into tokens and recognizes reserved keywords, often by distinguishing them from identifier tokens using a keyword table. This precedes parsing, so C.

A scanner first isolates a lexeme such as 'while'. It then returns the reserved token WHILE rather than an ordinary identifier token. A parser consumes that token to determine grammatical structure. Code generation emits target instructions after the program has been analyzed, while dataflow analysis studies facts such as reaching definitions. These later tasks cannot be the first point at which the keyword token is recognized.

Original paper, page 2 · Answer key