GATE / CS ARCHIVE

GATE CSE 2011 / QUESTION 19

Automaton model for lexical analysis

Compiler Design · Lexical Analysis · Full GATE CSE 2011 paper

GATE 2011, Q19 1 mark · MCQ
Report issue

Lexical Analysis

Question 19, GATE 2011: Which machine model has the necessary and sufficient power for conventional lexical analysis of a modern language such as Java?

(A) Finite-state automaton
(B) Deterministic pushdown automaton
(C) Nondeterministic pushdown automaton
(D) Turing machine
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Conventional token categories such as identifiers, keywords and numeric literals are specified by regular patterns. Finite-state automata suffice to recognize them; pushdown or Turing power is unnecessary for this lexical task. Hence A, distinguished from parsing nested syntax.

A lexical analyzer needs only a finite summary of a token prefix: for example, whether it has begun an identifier, is inside a number, or has just seen an exponent sign. A regular expression for a token can be converted to an NFA and then a DFA. Nested grammatical structure, such as matching arbitrary levels of parentheses, is handled later by parsing. Stronger machines could perform lexical recognition too, but their extra power is not necessary.

Original paper, page 5 · Answer key