Lexical analysis


12
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
C 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


Question 4
Consider the following statements: (I) The output of a lexical analyzer is groups of characters. (II) Total number of tokens in printf("i=%d, &i=%x", i, &i); are 11. (III) Symbol table can be implementation by using array and hash table but not tree. Which of the following statement(s) is/are correct?
A
Only (I)
B
Only (II) and (III)
C
All (I), (II), and (III)
D
None of these
Lexical analysis    GATE CS Mock 2018 | Set 2    
Discuss it


Question 4 Explanation: 
(I) The output of a lexical analyzer is tokens. (II) Total number of tokens in printf("i=%d, &i=%x", i, &i); are 10. (III) Symbol table can be implementation by using array, hash table, tree and linked lists. So, option (D) is correct.
Question 5
Which one of the following statements is FALSE?
A
Context-free grammar can be used to specify both lexical and syntax rules.
B
Type checking is done before parsing.
C
High-level language programs can be translated to different Intermediate Representations.
D
Arguments to a function can be passed using the program stack.
Lexical analysis    Parsing and Syntax directed translation    GATE CS 2018    
Discuss it


Question 5 Explanation: 
Type checking is done at semantic analysis phase and parsing is done at syntax analysis phase. And we know Syntax analysis phase comes before semantic analysis. So Option (B) is False. All other options seems Correct.
Question 6
A lexical analyzer uses the following patterns to recognize three tokens T1, T2, and T3 over the alphabet {a,b,c}. T1: a?(b∣c)*a T2: b?(a∣c)*b T3: c?(b∣a)*c Note that ‘x?’ means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the token that matches the longest possible prefix. If the string bbaacabc is processes by the analyzer, which one of the following is the sequence of tokens it outputs?
A
T1T2T3
B
T1T1T3
C
T2T1T3
D
T3T3
Lexical analysis    GATE CS 2018    
Discuss it


Question 6 Explanation: 
0 or 1 occurrence of the symbol x.   T1 : (b+c)* a + a(b+c)* a T2 : (a+c)* b + b(a+c)* b T3 : (b+a)* c + c(b+a)* c Given String : bbaacabc Longest matching prefix is " bbaac " (Which can be generated by T3) The remaining part (after Prefix) "abc" (Can be generated by T3) So, the answer is T3T3
Question 7
Match the description of several parts of a classic optimizing compiler in List - I, with the names of those parts in List - II: Capture11
A
(1)
B
(2)
C
(3)
D
(4)
Lexical analysis    Parsing and Syntax directed translation    Code Generation and Optimization    UGC-NET CS 2017 Nov - II    
Discuss it


Question 7 Explanation: 
Parser is a part of compiler and responsible for syntax recognition. Scanner (or tokenization) used by lexical analyzer. In Semantic analysis consistency and definition of syntax is checked. An optimizer is used improve the IR program. So option (A) is correct.
Question 8
The output of a lexical analyzer is
A
A parse tree
B
Intermediate code
C
Machine code
D
A stream of tokens
Lexical analysis    ISRO CS 2017 - May    
Discuss it


Question 8 Explanation: 
Question 9
Consider the following statements related to compiler construction : I. Lexical Analysis is specified by context-free grammars and implemented by pushdown automata. II. Syntax Analysis is specified by regular expressions and implemented by finite-state machine. Which of the above statement(s) is/are correct ?
A
Only I
B
Only II
C
Both I and II
D
Neither I nor II
Lexical analysis    Parsing and Syntax directed translation    UGC NET CS 2017 Jan - II    
Discuss it


Question 9 Explanation: 
Both statements are wrong for detailed information on lexical analysis and syntax analysis Refer:Compiler Design | Introduction to Syntax Analysis and Compiler Design | Lexical Analysis option (D) is correct.
Question 10
Which of the following statement(s) regarding a linker software is/are true ? I A function of a linker is to combine several object modules into a single load module. II A function of a linker is to replace absolute references in an object module by symbolic references to locations in other modules.
A
Only I
B
Only II
C
Both I and II
D
Neither I nor II
Lexical analysis    Parsing and Syntax directed translation    UGC NET CS 2017 Jan - II    
Discuss it


Question 10 Explanation: 
A linker is computer software that combine two or more file generated by compiler into a single executable file. Option I is correct but II option doesn't resemble linker. For more information on linker Refer:How Linkers Resolve Global Symbols Defined at Multiple Places? Option (A) is correct.
There are 15 questions to complete.
12


My Personal Notes arrow_drop_up