250+ TOP MCQs on Lexical Analyser and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Lexical Analyser”.

1. The process of forming tokens from an input stream of characters is called __________
a) Liberalisation
b) Characterisation
c) Tokenization
d) None of the mentioned

Answer: c
Clarification: The process of forming tokens from an input stream of characters is called tokenization.

2. When expression sum=3+2 is tokenized then what is the token category of 3?
a) Identifier
b) Assignment operator
c) Integer Literal
d) Addition Operator

Answer: c
Clarification:
Lexeme
Token category

Sum	"Identifier"
=	"Assignment operator"
3	"Integer literal"
+	"Addition operator"
2	"Integer literal"
;	"End of statement".

3. Which grammar defines Lexical Syntax?
a) Regular Grammar
b) Syntactic Grammar
c) Context free Grammar
d) Lexical Grammar

Answer: d
Clarification: The specification of a programming language often includes a set of rules, the lexical grammar, which defines the lexical syntax.

4. Two Important lexical categories are __________
a) White Space
b) Comments
c) None of the mentioned
d) White Space & Comments

Answer: d
Clarification: Two important common lexical categories are white space and comments.

5. It has encoded within it information on the possible sequences of characters that can be contained within any of the tokens it handles. The mentioned function is performed by?
a) Scanner
b) Parser
c) Syntactic Analyser
d) All of the mentioned

Answer: a
Clarification: The first stage, the scanner, is FSM. It has encoded information on the possible sequences of characters that can be contained within any of the tokens it handles.

6. What goes over the characters of the lexeme to produce value?
a) Scanner
b) Parser
c) Evaluator
d) Lexical generator

Answer: a
Clarification: In order to construct a token, the lexical analyzer needs a second stage, the evaluator, which goes over the characters of the lexeme to produce a value.

7. Lexers are often generated by a lexer generator, same as parser generators.
a) True
b) False

Answer: a
Clarification: Lexers are often generated by a lexer generator same as parser.

8. Which one is a lexer Generator?
a) ANTLR
b) DRASTAR
c) FLEX
d) All of the mentioned

Answer: d
Clarification: ANTLR – Can generate lexical analyzers and parsers.
DFASTAR – Generates DFA matrix table-driven lexers in C++.
Flex – variant of the “lex” (C/C++).
Ragel – A state machine and lexer generator with output in C, C++, C#, Objective-C, D, Java, Go and Ruby.

9. Which of the lexical analyser can handle Unicode?
a) Java CC
b) JFLex
c) Quex
d) All of the mentioned

Answer: d
Clarification: JavaCC – JavaCC generates lexical analyzers written in Java.
JFLex – A lexical analyzer generator for Java.
Quex – A fast universal lexical analyzer generator for C and C++.
FsLex – A lexer generator for byte and Unicode character input for F#.

10. What is the output of a lexical analyzer?
a) Machine Code
b) Intermediate Code
c) Stream of Token
d) Parse Tree

Answer: c
Clarification: The output given is in the form of tokens.

Leave a Reply

Your email address will not be published. Required fields are marked *