Unit 1 and 2 MCQ

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 11

1.

The output of lexical analyzer is


a) A set of RE
b) Syntax Tree
c) Set of Tokens
d) String Character
View Answer

Answer: c
Explanation: A lexical analyzer coverts character sequences to set of tokens.
2. 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
View Answer

Answer: c
Explanation: Hash table is used as a reference for symbol table because it is
efficient.
3. 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
View 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.
4. 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
View Answer

Answer: c
Explanation: Since the input is the source language and the output that we get
after the analysis is the machine language.
5. Which concept of FSA is used in the compiler?
a) Lexical analysis
b) Parser
c) Code generation
d) Code optimization
View Answer

Answer: a
Explanation: Because the lexer performs its analysis by going from one stage to
another.
6. Which concept of grammar is used in the compiler
a) Lexical analysis
b) Parser
c) Code generation
d) Code optimization
View Answer
Answer: b
Explanation: As the lexical analysis of a grammar takes place in phases hence it is
synonymous to parser.
7. Which of the following are Lexemes?
a) Identifiers
b) Constants
c) Keywords
d) All of the mentioned
View Answer

Answer: d
Explanation: Different Lexical Classes or Tokens or Lexemes Identifiers, Constants,
Keywords, Operators.

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on
�Regular Expression � 1�.

1. A regular expression enables a quick test to determine objects and text strings
with undependable values.
a) True
b) False
View Answer

Answer: a
Explanation: Because it checks for all the values and determines whether the output
string matches with the given string.
2. RE can be used only for values of type string and number.
a) True
b) False
View Answer

Answer: b
Explanation: No not for all values the string and numbers can we use the RE.
3. You can use RE, if you expect the value of a property to change in an
unpredictable way each time its run.
a) True
b) False
View Answer

Answer: b
Explanation: For every cycle the values does not change unpredictably because the
type of grammar that it accepts is defined.
4. All ___________ Are automatically treated as regular expressions.
a) Programmatic description
b) Window
c) Win Object
d) Collection
View Answer

Answer: a
Explanation: The programmatic description is genuinely treated as regular
expression.
5. If a �/� is used before a character that has no special meaning, �/� is ignored.
a) True
b) False
View Answer

Answer: a
Explanation: The backslash carries no significance and it is ignored.
6. The regular expression denote a language comprising all possible strings of even
length over the alphabet (0, 1)
a) 1 + 0(1+0)*
b) (0+1) (1+0)*
c) (1+0)
d) (00+0111+10)*
View Answer

Answer: d
Explanation: Option A does not consider even length criteria for the question.
Option B it can so happen here that from the former bracket it takes 0 or 1 and
takes null from the latter then it forms a string of odd length
Option C it gives either 1 or 0.
Hence Option D is the answer.
7. The RE gives none or many instances of an x or y is
a) (x+y)
b) (x+y)*
c) (x* + y)
d) (xy)*
View Answer

Answer: b
Explanation: Whether x or y is denoted by x+y and for zero or more instances it is
denoted but (x+y)*.

1. Which of the following derivations does a top-down parser use while parsing an
input string?
a) Leftmost derivation
b) Leftmost derivation in reverse
c) Rightmost derivation
d) Rightmost derivation in reverse
View Answer

Answer: a
Explanation: In top down parser takes input from Left to right constructing
leftmost derivation of the sentence.
2. The process of assigning load addresses to the various parts of the program and
adjusting the code and data in the program to reflect the assigned addresses is
called
a) Assembly
b) Parsing
c) Relocation
d) Symbol resolute
View Answer

Answer: c
Explanation: Relocation is the process of replacing symbolic references or names of
libraries with actual usable addresses in memory before running a program. Linker
performs it during compilation.
3. Which of the following statements is false?
a) Left as well as right most derivations can be in Unambiguous grammar
b) An LL (1) parser is a top-down parser
c) LALR is more powerful than SLR
d) Ambiguous grammar can�t be LR (k)
View Answer

Answer: a
Explanation: If a grammar has more than one leftmost (or rightmost) derivation the
grammar is ambiguous. Sometimes in unambiguous grammar the rightmost derivation and
leftmost derivations may differ.
4. Which of the following grammar rules violate the requirements of an operator
grammar?
(i) P -> QR
(ii) P -> QsR
(iii) P -> e
(iV) P -> QtRr
a) (i) only
b) (i) and (iii) only
c) (ii) and (iii) only
d) (iii) and (iv) only
View Answer

Answer: b
Explanation:
An operator precedence parser is a bottom-up parser that interprets an operator-
precedence grammar.
Consider the grammar with the following translation rules and E as the start
symbol.
A -> A1 #B {A.value = A1.value * B.value}
| B {A.value = B.value}
B-> B1 & F {B.value = B1.value + C.value}
|C {B.value= C.value }
C -> num {C.value = num.value}.
5. Compute E.value for the root of the parse tree for the expression:2 # 3 & 5 # 6
&4.
a) 200
b) 180
c) 160
d) 40
View Answer

Answer: c
Explanation:higher precedence operator will never produce an expression with
operator with lower precedence.&># in terms of precedence order.
6. Given the following expression grammar:
E -> E * F | F+E | F
F -> F-F | id
which of the following is true?
a) * has higher precedence than +
b) � has higher precedence than *
c) + and � have same precedence
d) + has higher precedence than *
View Answer

Answer: b
Explanation:Precedence is that a higher precedence operator will never produce an
expression with operator with lower precedence.
In the given grammar MINUS has higher precedence than ASTERIX.
7. Consider a program P that consists of two source modules M1(contains reference
to a function defined in M2) and M2 contained in two different files.
a) Edit time
b) Compile time
c) Link time
d) Load time
View Answer

Answer: c
Explanation:
Compiler transforms source code into the machine language which is in binary .
Kinds of object codes:
defined symbols, which allow it to be called by other modules,
ii undefined symbols, which call the other modules where these symbols are defined,
and
iii symbols which are used internally within object file for relocation.
8. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
a) Removing left recursion only
b) Factoring the grammar alone
c) Factoring & left recursion removal
d) None of the mentioned
View Answer

Answer: d
Explanation:
Factoring as well as left recursion removal do not suffice to convert an arbitrary
CFG to LL(1) grammar.
9. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for
G has n2 states.
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
View Answer

Answer: b
Explanation: SLR parser has less range of context free languages than LALR but
still both n1 & n2 are same for SLR & LALR respectively.
1. Which of the following derivations does a top-down parser use while parsing an
input string?
a) Leftmost derivation
b) Leftmost derivation in reverse
c) Rightmost derivation
d) Rightmost derivation in reverse
View Answer

Answer: a
Explanation: In top down parser takes input from Left to right constructing
leftmost derivation of the sentence.
2. The process of assigning load addresses to the various parts of the program and
adjusting the code and data in the program to reflect the assigned addresses is
called
a) Assembly
b) Parsing
c) Relocation
d) Symbol resolute
View Answer

Answer: c
Explanation: Relocation is the process of replacing symbolic references or names of
libraries with actual usable addresses in memory before running a program. Linker
performs it during compilation.
3. Which of the following statements is false?
a) Left as well as right most derivations can be in Unambiguous grammar
b) An LL (1) parser is a top-down parser
c) LALR is more powerful than SLR
d) Ambiguous grammar can�t be LR (k)
View Answer
Answer: a
Explanation: If a grammar has more than one leftmost (or rightmost) derivation the
grammar is ambiguous. Sometimes in unambiguous grammar the rightmost derivation and
leftmost derivations may differ.
4. Which of the following grammar rules violate the requirements of an operator
grammar?
(i) P -> QR
(ii) P -> QsR
(iii) P -> e
(iV) P -> QtRr
a) (i) only
b) (i) and (iii) only
c) (ii) and (iii) only
d) (iii) and (iv) only
View Answer

Answer: b
Explanation:
An operator precedence parser is a bottom-up parser that interprets an operator-
precedence grammar.
Consider the grammar with the following translation rules and E as the start
symbol.
A -> A1 #B {A.value = A1.value * B.value}
| B {A.value = B.value}
B-> B1 & F {B.value = B1.value + C.value}
|C {B.value= C.value }
C -> num {C.value = num.value}.
5. Compute E.value for the root of the parse tree for the expression:2 # 3 & 5 # 6
&4.
a) 200
b) 180
c) 160
d) 40
View Answer

Answer: c
Explanation:higher precedence operator will never produce an expression with
operator with lower precedence.&># in terms of precedence order.
6. Given the following expression grammar:
E -> E * F | F+E | F
F -> F-F | id
which of the following is true?
a) * has higher precedence than +
b) � has higher precedence than *
c) + and � have same precedence
d) + has higher precedence than *
View Answer

Answer: b
Explanation:Precedence is that a higher precedence operator will never produce an
expression with operator with lower precedence.
In the given grammar MINUS has higher precedence than ASTERIX.
7. Consider a program P that consists of two source modules M1(contains reference
to a function defined in M2) and M2 contained in two different files.
a) Edit time
b) Compile time
c) Link time
d) Load time
View Answer

Answer: c
Explanation:
Compiler transforms source code into the machine language which is in binary .
Kinds of object codes:
defined symbols, which allow it to be called by other modules,
ii undefined symbols, which call the other modules where these symbols are defined,
and
iii symbols which are used internally within object file for relocation.
8. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
a) Removing left recursion only
b) Factoring the grammar alone
c) Factoring & left recursion removal
d) None of the mentioned
View Answer

Answer: d
Explanation:
Factoring as well as left recursion removal do not suffice to convert an arbitrary
CFG to LL(1) grammar.
9. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for
G has n2 states.
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
View Answer

Answer: b
Explanation: SLR parser has less range of context free languages than LALR but
still both n1 & n2 are same for SLR & LALR respectively.
1. Which of the following derivations does a top-down parser use while parsing an
input string?
a) Leftmost derivation
b) Leftmost derivation in reverse
c) Rightmost derivation
d) Rightmost derivation in reverse
View Answer

Answer: a
Explanation: In top down parser takes input from Left to right constructing
leftmost derivation of the sentence.
2. The process of assigning load addresses to the various parts of the program and
adjusting the code and data in the program to reflect the assigned addresses is
called
a) Assembly
b) Parsing
c) Relocation
d) Symbol resolute
View Answer

Answer: c
Explanation: Relocation is the process of replacing symbolic references or names of
libraries with actual usable addresses in memory before running a program. Linker
performs it during compilation.
3. Which of the following statements is false?
a) Left as well as right most derivations can be in Unambiguous grammar
b) An LL (1) parser is a top-down parser
c) LALR is more powerful than SLR
d) Ambiguous grammar can�t be LR (k)
View Answer

Answer: a
Explanation: If a grammar has more than one leftmost (or rightmost) derivation the
grammar is ambiguous. Sometimes in unambiguous grammar the rightmost derivation and
leftmost derivations may differ.
4. Which of the following grammar rules violate the requirements of an operator
grammar?
(i) P -> QR
(ii) P -> QsR
(iii) P -> e
(iV) P -> QtRr
a) (i) only
b) (i) and (iii) only
c) (ii) and (iii) only
d) (iii) and (iv) only
View Answer

Answer: b
Explanation:
An operator precedence parser is a bottom-up parser that interprets an operator-
precedence grammar.
Consider the grammar with the following translation rules and E as the start
symbol.
A -> A1 #B {A.value = A1.value * B.value}
| B {A.value = B.value}
B-> B1 & F {B.value = B1.value + C.value}
|C {B.value= C.value }
C -> num {C.value = num.value}.
5. Compute E.value for the root of the parse tree for the expression:2 # 3 & 5 # 6
&4.
a) 200
b) 180
c) 160
d) 40
View Answer

Answer: c
Explanation:higher precedence operator will never produce an expression with
operator with lower precedence.&># in terms of precedence order.
6. Given the following expression grammar:
E -> E * F | F+E | F
F -> F-F | id
which of the following is true?
a) * has higher precedence than +
b) � has higher precedence than *
c) + and � have same precedence
d) + has higher precedence than *
View Answer

Answer: b
Explanation:Precedence is that a higher precedence operator will never produce an
expression with operator with lower precedence.
In the given grammar MINUS has higher precedence than ASTERIX.
7. Consider a program P that consists of two source modules M1(contains reference
to a function defined in M2) and M2 contained in two different files.
a) Edit time
b) Compile time
c) Link time
d) Load time
View Answer

Answer: c
Explanation:
Compiler transforms source code into the machine language which is in binary .
Kinds of object codes:
defined symbols, which allow it to be called by other modules,
ii undefined symbols, which call the other modules where these symbols are defined,
and
iii symbols which are used internally within object file for relocation.
8. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
a) Removing left recursion only
b) Factoring the grammar alone
c) Factoring & left recursion removal
d) None of the mentioned
View Answer

Answer: d
Explanation:
Factoring as well as left recursion removal do not suffice to convert an arbitrary
CFG to LL(1) grammar.
9. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for
G has n2 states.
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
View Answer

Answer: b
Explanation: SLR parser has less range of context free languages than LALR but
still both n1 & n2 are same for SLR & LALR respectively.
1. S ? C C
C ? c C | d
The grammar is
a) LL(1)
b) SLR(1) but not LL(1)
c) LALR(1) but not SLR(1)
d) LR(1) but not LALR(1)
View Answer

Answer: a
Explanation: Since there is no conflict, the grammar is LL (1) hence a predictive
parse table with no conflicts can be constructed.
2. Which of the following statements is false?
a) Unambiguous grammar has both kind of derivations
b) An LL(1) parser is a top-down parser
c) LALR is more powerful than SLR
d) Ambiguous grammar can�t be LR(k)
View Answer

Answer: a
Explanation:
If a grammar has more than one leftmost (or rightmost) derivation the grammar is
ambiguous.
3. Which of the following derivations does a top-down parser use while parsing an
input string?
a) Leftmost derivation
b) Leftmost derivation in reverse
c) Rightmost derivation
d) Rightmost derivation in reverse
View Answer

Answer: a
Explanation: Left to right constructing leftmost derivation of the sentence.
4. Given the following expression grammar:
E -> E * F | F + E | F
F -> F � F | id
Which of the following is true?
a) * has higher precedence than +
b) � has higher precedence than *
c) + and � have same precedence
d) + has higher precedence than *
View Answer

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

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

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

Answer: b
Explanation: 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) Both a and b
d) None of the mentioned
View Answer

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

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

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

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

You might also like