Compilers Questions and Answers – Lexical Analysis – 1
This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Lexical Analysis – 1”.
The output of lexical analyzer is
a) A set of RE
b) Syntax Tree
c) Set of Tokens
d) String Character
Answer
Answer: c
Explanation: A lexical analyzer coverts character sequences to set of tokens.
The context free grammar is ambiguous if
a) The grammar contains non-terminals
b) Produces more than one parse tree
c) Production has two non-terminals side by side
d) None of the mentioned
Answer
Explanation: Since more than one parse tree is generated hence one than option is available .Therefore it’s ambiguous.
The symbol table implementation is based on the property of locality of reference is
a) Linear list
b) Search tree
c) Hash Table
d) Self Organisation
Answer
Answer: c
Explanation: Hash table is used as a reference for symbol table because it is efficient.
Which one is a type of Lexeme
a) Identifiers
b) Constants
c) Keywords
d) All of the mentioned
Answer
Explanation: All of them along with Operators are different types of lexemes.
For operator precedence parsing, which one is true?
a) For all pair of non-terminal
b) For all pair of non-terminals
c) To delimit the handle
d) None of the mentioned
Answer
Answer: a
Explanation: There are two important properties for these operator precedence parsers is that it does not appear on the right side of any production and no production has two adjacent non-terminals. Implying that no production right side is empty or has two adjacent non-terminals. So accordingly to property option (A) is correct.
Another Name for Lexical Analyser
a) Linear Phase
b) Linear Analysis
c) Scanning
d) All of the mentioned
Answer
Explanation: Lexical Analyzer is also called “Linear Phase” or “Linear Analysis” or “Scanning“.
Object program is a
a) Program written in machine language
b) Program to be translated into machine language
c) Translation of high-level language into machine language
d) None of the mentioned
Answer
Answer: c
Explanation: Since the input is the source language and the output that we get after the analysis is the machine language.
A________ is a string of characters which form a syntactic unit.
a) Lexeme
b) Lex
c) Lexeme & Lex
d) None of the mentioned
Answer
Explanation: A lexeme is a string of characters which forms a syntactic unit.
Which concept of FSA is used in the compiler?
a) Lexical analysis
b) Parser
c) Code generation
d) Code optimization
Answer
Answer: a
Explanation: Because the lexer performs its analysis by going from one stage to another.
Which concept of grammar is used in the compiler
a) Lexical analysis
b) Parser
c) Code generation
d) Code optimization
Answer
Answer: b
Explanation: As the lexical analysis of a grammar takes place in phases hence it is synonymous to parser.
Which of the following are Lexemes?
a) Identifiers
b) Constants
c) Keywords
d) All of the mentioned
Answer
Answer: d
Explanation: Different Lexical Classes or Tokens or Lexemes Identifiers, Constants, Keywords, Operators.
Which phase of the compiler is Lexical Analyser?
a) First
b) Second
c) Third
d) None of the mentioned
Answer
Explanation: Lexical Analyzer is First Phase of Compiler.
In a compiler the module that checks every character of the source text is called
a) The code generator
b) The code optimizer
c) The lexical analyzer
d) The syntax analyzer
Answer
Explanation: Lexical analysis is the process of converting a sequence of characters into a sequence of tokens.
An individual token is called ________
a) Lexeme
b) Lex
c) Lexeme & Lex
d) None of the mentioned
Answer
Explanation: Individual Token is also Called Lexeme.
Lexical Analyser’s Output is given to Syntax Analysis.
a) True
b) False
Answer
Explanation: Lexical Analyzer’s Output is given to Syntax Analysis.
Input to Lexical Analyser is
a) Source Code
b) Object Code
c) Lexeme
d) None of the mentioned
Answer
Explanation: Lexical analyser’s Input is Source Code.
Lexical Analysis Identifies Different Lexical Units in a _______
a) Source Code
b) Object Code
c) Lexeme
d) None of the mentioned
Answer
Explanation: Lexical Analysis Identifies Different Lexical Units in a source Code.