Question:The lexical analysis for a modern language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?

A: Finite state automata
B: Deterministic pushdown automata
C: Non-deterministic pushdown automata
D: Turing machine

Ans: A
Solution:

Arrays
Articles
Bit Magic
C/C++ Puzzles
GFacts
Linked Lists
MCQ
Misc
Output
Strings
Trees

Automata Theory | Set 3
July 2, 2012

Following questions have been asked in GATE CS 2011 exam.

1) The lexical analysis for a modern language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?
(A) Finite state automata
(B) Deterministic pushdown automata
(C) Non-deterministic pushdown automata
(D) Turing machine

Answer (A)
Lexical analysis is the first step in compilation. In lexical analysis, program is divided into tokens. Lexical analyzers are typically based on finite state automata. Tokens can typically be expressed as different regular expressions:
An identifier is given by [a-zA-Z][a-zA-Z0-9]*
The keyword if is given by if.
Integers are given by [+-]?[0-9]+.