Compiler Design MCQ Questions And Answers - Lexical Analysis
This section focuses on "Lexical Analysis" in Compiler Design. These Multiple Choice Questions (MCQs) should be practiced to improve the Compiler Design skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. Lexical analysis is the _______ phase of a compiler
A. first
B. second
C. third
D. fourth
View Answer
Ans : A
Explanation: Lexical analysis is the first phase of a compiler
2. lexical analyzer is used to ?
A. remove whitespace
B. removing comments
C. breaks these syntaxes into a series of tokens
D. All of the above
View Answer
Ans : D
Explanation: The lexical analyzer breaks these syntaxes into a series of tokens, by removing any whitespace or comments in the source code.
3. If the lexical analyzer finds a token invalid then?
A. it generates an exception
B. it generates an warning
C. it generates an error
D. reads the whole program
View Answer
Ans : C
Explanation: If the lexical analyzer finds a token invalid, it generates an error.
4. When the lexical analyzer read the source-code, it scans the code?
A. line by line
B. word by word
C. letter by letter
D. reads the whole program
View Answer
Ans : C
Explanation: When the lexical analyzer read the source-code, it scans the code letter by letter; and when it encounters a whitespace, operator symbol, or special symbols, it decides that a word is completed.
5. Which tool/computer program for generating lexical analyzers (scanners or lexers) written by Vern Paxson in C around 1987?
A. FLEX
B. GLEX
C. CLEX
D. SLEX
View Answer
Ans : A
Explanation: FLEX (fast lexical analyzer generator) is a tool/computer program for generating lexical analyzers (scanners or lexers) written by Vern Paxson in C around 1987.
6. The function ________ is automatically generated by the flex when it is provided with a .l file
A. flex()
B. yylex()
C. lex()
D. nnlex()
View Answer
Ans : B
Explanation: The function yylex() is automatically generated by the flex when it is provided with a .l file
7. In the input file, In which section Anything written in this brackets is copied directly to the file lex.yy.c?
A. Rules Section
B. Definition Section
C. User Code Section
D. None of the above
View Answer
Ans : B
Explanation: Definition Section: The definition section contains the declaration of variables, regular definitions, manifest constants. In the definition section, text is enclosed in "%{ %}" brackets.
8. The rule section is enclosed in?
A. %%
B. $$
C. %%%%
D. $$$$
View Answer
Ans : C
Explanation: The rule section is enclosed in ""%% %%"".
9. Which symbol table implementation is based on the property of locality of reference?
A. Linear list
B. Search tree
C. Hash Table
D. Self Organisation
View Answer
Ans : C
Explanation: Hash table is used as a reference for symbol table because it is efficient.
10. System program such a compiler are designed so that they are ________
A. Re-enterable
B. Non-Usable
C. Serially usable
D. None of the above
View Answer
Ans : A
Explanation: For the convince of the user compilers are made re-enterable.
Discussion