Compilers Questions and Answers – Lexical Analyser – 2

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Lexical Analyser – 2”.

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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: c
Explanation:
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
View Answer

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

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

Answer: d
Explanation: Two important common lexical categories are white space and comments.
Note: Join free Sanfoundry classes at Telegram or Youtube

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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.
advertisement

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

Answer: a
Explanation: 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
View Answer

Answer: d
Explanation: 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.
advertisement

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

Answer: d
Explanation: 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
View Answer

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

Sanfoundry Global Education & Learning Series – Compilers.

To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.