1

Lexical analysis

Question 1
The number of tokens in the following C statement is (GATE 2000)
printf("i = %d, &i = %x", i, &i);
A
3
B
26
C
10
D
21
Misc    Lexical analysis    
Discuss it


Question 1 Explanation: 
In a C source program, the basic element recognized by the compiler is the “token.” A token is source-program text that the compiler does not break down into component elements. There are 6 types of C tokens : identifiers, keywords, constants, operators, string literals and other separators. There are total 10 tokens in the above printf statement. Below are tokens in above program.
printf
(
"i = %d, &i = %x"
, 
i
,
&
i
)
;
Question 2
In a compiler, keywords of a language are recognized during
A
parsing of the program
B
the code generation
C
the lexical analysis of the program
D
dataflow analysis
GATE CS 2011    Lexical analysis    
Discuss it


Question 2 Explanation: 
Lexical analysis is the process of converting a sequence of characters into a sequence of tokens. A token can be a keyword.
Question 3
The lexical analysis for a modern computer 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
GATE CS 2011    Lexical analysis    
Discuss it


There are 3 questions to complete.
1

Company Wise Coding Practice    Topic Wise Coding Practice