250+ TOP MCQs on Lexical Analyser and Answers

Compilers Multiple Choice Questions on “Lexical Analyser”.

1. 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: a
Clarification: Lexical analysis is the process of converting a sequence of characters into a sequence of tokens.

2. 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: b
Clarification: Since more than one parse tree is generated hence one than option is available .Therefore it’s ambiguous.

3. What is another name for Lexical Analyser?
a) Linear Phase
b) Linear Analysis
c) Scanning
d) All of the mentioned

Answer: d
Clarification: Lexical Analyzer is also called “Linear Phase” or “Linear Analysis” or “Scanning“.

4. An individual token is called ________
a) Lexeme
b) Lex
c) Lexeme & Lex
d) None of the mentioned

Answer: a
Clarification: Individual Token is also Called Lexeme.

5. Lexical Analyser’s Output is given to Syntax Analysis.
a) True
b) False

Answer: a
Clarification: Lexical Analyzer’s Output is given to Syntax Analysis.

6. Which phase of the compiler is Lexical Analyser?
a) First
b) Second
c) Third
d) None of the mentioned

Answer: a
Clarification: Lexical Analyzer is First Phase of Compiler.

7. Input to Lexical Analyser is _________
a) Source Code
b) Object Code
c) Lexeme
d) None of the mentioned

Answer: a
Clarification: Lexical analyser’s Input is Source Code.

8. Lexical Analysis Identifies Different Lexical Units in a _______
a) Source Code
b) Object Code
c) Lexeme
d) None of the mentioned

Answer: a
Clarification: Lexical Analysis Identifies Different Lexical Units in a source Code.

9. Which one is a type of Lexeme?
a) Identifiers
b) Constants
c) Keywords
d) All of the mentioned

Answer: d
Clarification: All of them along with Operators are different types of lexemes.

10. A ________ is a string of characters which form a syntactic unit.
a) Lexeme
b) Lex
c) Lexeme & Lex
d) None of the mentioned

Answer: a
Clarification: A lexeme is a string of characters that form a syntactic unit.

250+ TOP MCQs on Handle of Right sentinel Grammar and Answers

Compilers online test on “Handle of Right Sentinel Grammar”.

1. Input to code generator is __________
a) Source code
b) Intermediate code
c) Target code
d) All of the mentioned

Answer: b
Clarification: Intermediate code is the input to the code generator.

2. A synthesized attribute is an attribute whose value at a parse tree node depends on __________
a) Attributes at the siblings only
b) Attributes at parent node only
c) Attributes at children nodes only
d) None of the mentioned

Answer: c
Clarification: Synthesized attribute’s value depend on children node only.

3. In a bottom up evaluation of a syntax direction definition, inherited attributes can __________
a) Always be evaluated
b) Be evaluated only if the definition is L –attributed
c) Evaluation only done if the definition has synthesized attributes
d) None of the mentioned

Answer: c
Clarification: Bottom-up parsing identifies and processes the text’s lowest-level, before its mid-level structures, and the highest-level overall structure to last are left.

4. The graph that shows basic blocks and their successor relationship is called __________
a) DAG
b) Flow Chart
c) Control Graph
d) Hamilton graph

Answer: b
Clarification: Flow chart shows basic blocks.

5. _________ or scanning is the process where the stream of characters making up the source program is read from left to right and grouped into tokens.
a) Lexical Analysis
b) Diversion
c) Modelling
d) None of the mentioned

Answer: a
Clarification: Lexical analysis is the process of converting a sequence of characters into a sequence of tokens.

6. _____________ is a graph representation of a derivation.
a) The parse tree
b) Oct tree
c) Binary tree
d) None of the mentioned

Answer: a
Clarification: Parse tree is a representation of the derivation.

7. Which of the following symbols table implementation is based on the property of locality of reference?
a) Hash Table
b) Search tree
c) Self organizing list
d) Linear list

Answer: c
Clarification: Self Organizing list is based on locality of reference.

8. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. Hence which one is true?
a) N1 is necessarily less than n2
b) N1 is necessarily equal to n2
c) N1 is necessarily greater than n2
d) None of the mentioned

Answer: b
Clarification: The output of lexical analyzer is output token.

250+ TOP MCQs on SDT Schemes to Specify Translation of various Programming Language Construct

Compilers Questions and Answers for Campus interviews on “Sdt Schemes to Specify Translation of Various Programming Language Construct“.

1. In which addressing mode the operand is given explicitly in the instruction?
a) Absolute mode
b) Immediate mode
c) Indirect mode
d) Index mode

Answer: b
Clarification: In Immediate addressing mode operand is directly found from the instruction.

2. Which of the following is not true?
a) UGL doesn’t support high level seven interaction
b) Many DBMS support 4GLs
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: It supports HLL.

3. Non modifiable procedures are called ___________
a) Concurrent procedures
b) Serially usable procedures
c) Re-entrant procedures
d) Top down procedures

Answer: b
Clarification: These can’t be modified.

4. Which of the following is not a type of assembler?
a) One pass
b) Two pass
c) Three pass
d) Load and go

Answer: c
Clarification: No 3 pass assembler created as yet.

5. Daisy chain is a device for ___________
a) None of the mentioned
b) Connecting devices to a controller
c) Connecting controller to devices
d) All of the mentioned

Answer: b
Clarification: Combines multiple devices in sequence or a ring.

6. What is the input of Lex?
a) Set to regular expression
b) Statement
c) Numeric data
d) ASCII data

Answer: a
Clarification: Input is a string.

7. Yacc semantic action is a sequence of ___________
a) Tokens
b) Expression
c) Statement
d) Rules

Answer: c
Clarification: Yacc is yet another compiler which is a set of statements.

8. Which of the following software tool is parser generator?
a) Lex
b) Yacc
c) Lex & Yacc
d) None of the mentioned

Answer: b
Clarification: YACC is a LALR parser.

9. A Lex compiler generates ___________
a) Lex object code
b) Transition tables
c) Tokens
d) None of the mentioned

Answer: b
Clarification: The output of Lex is a string of tokens.

10. A Compiler has __________ phases.
a) 7
b) 6
c) 8
d) None of the mentioned

Answer: c
Clarification: It has 8 phases.

250+ TOP MCQs on Relations and Answers

Compilers Questions and Answers for Freshers on “Relations”.

1. If A ∩ B = B, then?
a) A ⊂ B
b) A = ø
c) B ⊂ A
d) B = ø

Answer: c
Clarification: Since A ∩ B = B, hence B ⊂ A.

2. Empty set is a _____________
a) Invalid set
b) Infinite set
c) Finite set
d) None of the mentioned

Answer: c
Clarification: Empty set is a finite set.

3. If A, B and C are any three sets, then A – (B ∪ C) is equal to _____________
a) (A – B) ∪ (A – C)
b) (A – B) ∪ C
c) (A – B) ∩ (A – C)
d) (A – B) ∩ C

Answer: c
Clarification: it is De’ Morgan law.

4. A = {x: x ≠ x} represents?
a) {0]
b) {1}
c) {}
d) {x}

Answer: c
Clarification: That is a fact.

5. If A, B, C be three sets such that A ∪ B = A ∪ C and A ∩ B = A ∩ C, then?
a) A=B
b) A=C
c) B=C
d) A=B=C

Answer: c
Clarification: Transition Law.

6. The number of proper subsets of the set {1, 2, and 3} is?
a) 8
b) 6
c) 7
d) 5

Answer: b
Clarification: Number of proper subsets of the set {1, 2, 3) = 23 – 2 = 6.

7. If A and B are any two sets, then A ∪ (A ∩ B) is equal to _____________
a) A
b) B
c) A^C
d) B^C

Answer: a
Clarification: A ∩ B ⊆ A Hence A ∪ (A ∩ B) = A.

8. If A, B and C are any three sets, then A × (B ∪ C) is equal to _____________
a) (A × B) ∪ (A × C)
b) (A × B) ∩ (A × C)
c) (A ∪ B) × (A ∪ C)
d) None of the mentioned

Answer: a
Clarification: It is distributive law.

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.

250+ TOP MCQs on LR Parser and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “LR Parser”.

1. Which of these is also known as look-head LR parser?
a) SLR
b) LR
c) LLR
d) None of the mentioned

Answer: c
Clarification: LLR is the look ahead parser.

2. What is the similarity between LR, LALR and SLR?
a) Use same algorithm, but different parsing table
b) Same parsing table, but different algorithm
c) Their Parsing tables and algorithm are similar but uses top down approach
d) Both Parsing tables and algorithm are different

Answer: a
Clarification: The common grounds of these 3 parser is the algorithm but parsing table is different.

3. An LR-parser can detect a syntactic error as soon as __________
a) The parsing starts
b) It is possible to do so a left-to-right scan of the input
c) It is possible to do so a right-to-left scan of the input
d) Parsing ends

Answer: b
Clarification: Error is found when it the input string is scanned.

4. Which of these is true about LR parsing?
a) Is most general non-backtracking shift-reduce parsing
b) It is still efficient
c) Is most general non-backtracking shift-reduce parsing & It is still efficient
d) None of the mentioned

Answer: c
Clarification: LR parsers are a type of bottom-up parsers that efficiently handle deterministic context-free languages in guaranteed linear time.

5. Which of the following is incorrect for the actions of A LR-Parser I) shift s ii) reduce A->ß iii) Accept iv) reject?
a) Only I)
b) I) and ii)
c) I), ii) and iii)
d) I), ii) , iii) and iv)

Answer: c
Clarification: Only reject out of the following is a correct LR parser action.

6. If a state does not know whether it will make a shift operation or reduction for a terminal is called _________
a) Shift/reduce conflict
b) Reduce /shift conflict
c) Shift conflict
d) Reduce conflict

Answer: a
Clarification: As the name suggests that the conflict is between shift and reduce hence it is called shift reduce conflict.

7. When there is a reduce/reduce conflict?
a) If a state does not know whether it will make a shift operation using the production rule i or j for a terminal
b) If a state does not know whether it will make a shift or reduction operation using the production rule i or j for a terminal
c) If a state does not know whether it will make a reduction operation using the production rule i or j for a terminal
d) None of the mentioned

Answer: c
Clarification: It occurs when If a state does not know whether it will make a reduction operation using the production rule i or j for a terminal.

8. When ß (in the LR(1) item A -> ß.a,a) is not empty, the look-head _________
a) Will be affecting
b) Does not have any affect
c) Shift will take place
d) Reduction will take place

Answer: b
Clarification: There is no terminal before the non terminal beta.

9. When ß is empty (A -> ß.,a), the reduction by A-> a is done by _________
a) If next symbol is a terminal
b) Only If the next input symbol is a
c) Only If the next input symbol is A
d) Only if the next input symbol is a

Answer: d
Clarification: The next token is considered in this case it’s a.

10. The construction of the canonical collection of the sets of LR (1) items are similar to the construction of the canonical collection of the sets of LR (0) items. Which is an exception?
a) Closure and goto operations work a little bit different
b) Closure and goto operations work similarly
c) Closure and additive operations work a little bit different
d) Closure and associatively operations work a little bit different

Answer: a
Clarification: Closure and goto do work differently in case of LR (0) and LR (1).