Lexical analysis

Question 1

The number of tokens in the following C statement is

printf("HELLO WORLD");
Cross

3

Tick

5

Cross

9

Cross

8



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 5 tokens in the above printf statement. Below are tokens in above program.

printf
(
"HELLO WORLD"
)
;
Question 2
In a compiler, keywords of a language are recognized during
Cross
parsing of the program
Cross
the code generation
Tick
the lexical analysis of the program
Cross
dataflow analysis


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?

Tick

Finite state automata

Cross

Deterministic pushdown automata

Cross

Non-Deterministic pushdown automata

Cross

Turing Machine



Question 3-Explanation: 

In lexical analysis finite automata is used to produce tokens in the form of identifiers, keywords and constants from the input program. In the process of pattern recognition, it used to search keywords by using string-matching algorithms. See https://www.geeksforgeeks.org/automata-theory-set-3/

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?
Cross
Only (I)
Cross
Only (II) and (III)
Cross
All (I), (II), and (III)
Tick
None of these


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?
Cross
Context-free grammar can be used to specify both lexical and syntax rules.
Tick
Type checking is done before parsing.
Cross
High-level language programs can be translated to different Intermediate Representations.
Cross
Arguments to a function can be passed using the program stack.


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?

Cross

T1T2T3

Cross

T1T1T3

Cross

T2T1T3

Tick

T3T3



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"

Tick

(1)

Cross

(2)

Cross

(3)

Cross

(4)



Question 8
The output of a lexical analyzer is
Cross
A parse tree
Cross
Intermediate code
Cross
Machine code
Tick
A stream of tokens


Question 8-Explanation: 
Lexical analysis produces a stream of tokens as output, which consists of identifier, keywords,separator,operator, and literals.
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 ?

Cross

Only I

Cross

Only II

Cross

Both I and II

Tick

Neither I nor II



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.
Tick
Only I
Cross
Only II
Cross
Both I and II
Cross
Neither I nor II


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.

  • Last Updated : 21 Jan, 2014

Share your thoughts in the comments
Similar Reads