250+ TOP MCQs on Three-Address Statements and Answers

Compilers Multiple Choice Questions on “Three-Address Statements”.

1. Which languages necessarily need heap allocation in the runtime environment?
a) Those that support recursion
b) Those that use dynamic scoping
c) Allow dynamic data structure
d) Those that use global variables

Answer: c
Clarification: E.g.: Heap.

2. Given the language L-{ab, aa, baa}, which of the following strings are in LG?

1) abaabaaabaa
2) aaaabaaaa 
3) baaaaabaaaab 
4) baaaaabaa

a) 1,2 and 3
b) 2,3 and 4
c) 1,2 and 4
d) 1,3 and 4

Answer: c
Clarification: Generates strings like aaaabaaaa
baaaaabaa

3. The lexical analyzer takes _________ as input and produces a stream of _______ as output.
a) Source program, tokens
b) Token, source program
c) Either A and B
d) None of the mentioned

Answer: a
Clarification: Lexical analyser takes source program as input and token as output.

4. The action of parsing the source program into proper syntactic classes is called ________
a) Syntax analysis
b) Lexical analysis
c) Interpretation analysis
d) General syntax analysis

Answer: b
Clarification: Checks for correct syntax.

5. What is the task of the lexical analysis?
a) None of the mentioned
b) To build a literal and identifier table
c) To build a uniform symbol table
d) To build a uniform symbol table, literal and identifier table

Answer: d
Clarification: It is the task performed.

250+ TOP MCQs on Error Recovery in LR phase and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Error Recovery in LR phase”.

1. Choose the correct statement.
a) CFG is not LR
b) Ambiguous Grammar can never be LR
c) CFG is not LR & Ambiguous Grammar can never be LR
d) None of the mentioned

Answer: c
Clarification: Mentioned reason is true.

2. How is the parsing precedence relations defined?
a) None of the mentioned
b) All of the mentioned
c) To delimit the handle
d) Only for a certain pair of terminals

Answer: b
Clarification: The reason why the precedence operations is performed.

3. When will the relationship between ‘+’ and ‘-’ be <?
a) For unary minus
b) Minus is right associative
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: Both statements are true.

4. When will the relationship between ‘<’ and ‘>’ be <?
a) >
b) <
c) =
d) Undefined

Answer: d
Clarification: Undefined. There is no existing relationship between the two.

250+ TOP MCQs on Regular Expression and Answers

Compilers Multiple Choice Questions on “Regular Expression”.

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

Answer: a
Clarification: 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

Answer: b
Clarification: 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

Answer: b
Clarification: 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

Answer: a
Clarification: 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

Answer: a
Clarification: The backslash carries no significance and it is ignored.

6. The regular expression denotes 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)*

Answer: d
Clarification: Option 1 + 0(1+0)* → It does not consider even length criteria for the question.
Option (0+1) (1+0)* → 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 (1+0) → It gives either 1 or 0.
Hence Option (00+0111+10)* 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)*

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

250+ TOP MCQs on Obtaining the regular Expression from the Finite automata and Answers

Compilers Multiple Choice Questions on “Obtaining the regular Expression from the finite automata”.

1. Which of the following pairs of regular expression are equivalent?
a) 1(01)* and (10)*1
b) X(xx)* and (xx)*x
c) 1(01)* and (10)*1 & X(xx)* and (xx)*x
d) None of the mentioned

Answer: c
Clarification: R1 and R2 are reverse of each other. If ant one of them can be generated them the other can be generated as well.

2. Given an arbitrary non-deterministic finite automaton (NFA) with N states, the maximum number of states in an equivalent minimized DFA is at least?
a) N2
b) 2N
c) 2N
d) N!

Answer: c
Clarification: If the NFA has n states, the resulting DFA may have up to 2n states, an exponentially larger number, which sometimes makes the construction impractical for large NFAs.

3. What can be said about a regular language L over {a} whose minimal finite state automaton has two states?
a) L must be {an| n is odd}
b) L must be {an| n is even}
c) L must be {an| n is even}
d) Either L must be {an | n is odd}, or L must be {an | n is even}

Answer: d
Clarification: There are two states. When first state is final, it accepts even no. of a’s. When second state is final, it accepts odd no. of a’s.

4. How many minimum states are required to find whether a string has odd number of 0’s or not?
a) 1
b) 2
c) 3
d) 4

Answer: b

5. Consider alphabet ∑ = {0, 1}, the null/empty string λ and the sets of strings X0, X1 and X0. How are X1 and X2 are related?

X0 = 1 X1
X1 = 0 X1 + 1 X2
X2 = 0 X1 + {λ}

Which one of the following represents the strings in X0?
a) 10 (0* + (10)*)1
b) 10 (0* + (10)*)*1
c) 10 (0* + (10)*)*1
d) 10 (0 + 10)*1 + 110 (0 + 10)*1

Answer: c
Clarification: The smallest possible string by given grammar is “11”.
X0 = 1X1
= 11X2 [Replacing X1 with 1X2]
= 11 [Replacing X2 with λ]
The string “11” is only possible with option 10 (0* + (10)*)*1.

6. Which of the following languages is/are regular?

L1: {wxwR ⎪ w, x ∈ {a, b}* and ⎪w⎪, ⎪x⎪ >0} wR is the reverse of string w
L2: {anbm ⎪m ≠ n and m, n≥0}
L3: {apbqcr ⎪ p, q, r ≥ 0}

a) L1 and L3 only
b) L2
c) L2 and L3 only
d) L3 only
Answer: a

7. The reorganizing capability of NDFA and DFA is?
a) May be different
b) Must be different
c) Must be same
d) None of the mentioned

Answer: c
Clarification: Given any NDFA one can construct an equivalent DFA.

8. Which of the following is not regular?
a) String whose length is perfect square and consists of 0s
b) Palindromes consisting of 0’s and 1’s
c) String whose length is perfect square and consists of 0s & Palindromes consisting of 0’s and 1’s
d) None of the mentioned

Answer: c
Clarification: Strings of odd numbers of zeros can be generated by regular expression (00)*0.

250+ TOP MCQs on Bottom-Up Parsing and Answers

Compilers Multiple Choice Questions & Answers on “Bottom – Up Parsing”.

1. Which of the following is the fastest logic?
a) TTL
b) ECL
c) CMOS
d) LSI

Answer: b
Clarification: In electronics, emitter-coupled logic (ECL) is a high-speed integrated circuit.

2. A bottom up parser generates __________
a) Right most derivation
b) Rightmost derivation in reverse
c) Leftmost derivation
d) Leftmost derivation in reverse

Answer: b
Clarification: This corresponds to starting at the leaves of the parse tree also known as shift-reduce parsing.

3. A grammar that produces more than one parse tree for some sentence is called __________
a) Ambiguous
b) Unambiguous
c) Regular
d) None of the mentioned

Answer: a
Clarification: ambiguous grammar has more than one parse tree.

4. An optimizer Compiler __________
a) Is optimized to occupy less space
b) Is optimized to occupy less space & Optimize the code
c) Optimize the code
d) None of the mentioned

Answer: d
Clarification: In computing, an optimizing compiler is a compiler that tries to minimize or maximize some attributes of an executable computer program.

5. The linker __________
a) Is similar to interpreter
b) Uses source code as its input
c) Is required to create a load module
d) None of the mentioned

Answer: c
Clarification: It is a program that takes one or more object files generated by a compiler and combines them into a single executable file, library file, or another object file.

6. A latch is constructed using which two cross coupled?
a) AND OR gates
b) AND gates
c) NAND and NOR gates
d) NAND gates

Answer: d
Clarification: It has two inputs and one output.

7. Pee Hole optimization __________
a) Loop Optimization
b) Local Optimization
c) Constant folding
d) Data Flow analysis

Answer: c
Clarification: More loops are added.

8. The optimization which avoids test at every iteration is?
a) Loop unrolling
b) Loop jamming
c) Constant folding
d) None of the mentioned

Answer: a
Clarification: Execution speed is enhanced by sacrificing bits.

9. Scissoring enables __________
a) A part of data to be displayed
b) Entire data to be displayed
c) None of the mentioned
d) No data to be displayed

Answer: a
Clarification: Displays only some part of the data.

10. Shift reduce parsers are __________
a) Top down Parser
b) Bottom Up parser
c) May be top down or bottom up
d) None of the mentioned

Answer: b
Clarification: Also known as shift reduce parser.

250+ TOP MCQs on Three-Address Statements and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Three-Address Statements”.

1. In a two pass assembler, adding literals to literal table and address resolution of local symbols are done using?
a) First pass and second respectively
b) Both second pass
c) Second pass and first respectively
d) Both first pass

Answer: d
Clarification: A two pass assembler does two passes over the source file (the second pass can be over a file generated in the first pass).

2. In Two pass assembler the object code generation is done during the ______________
a) Second pass
b) First pass
c) Zeroth pass
d) Not done by assembler

Answer:a
Clarification: On the second pass, the assembler:
• source statements into machine code
• error messages, if error has occurred.

3. Pick the machine independent phase of the compiler.
a) Syntax analysis
b) Code generation
c) Lexical analysis
d) All of the mentioned

Answer: d
Clarification: Machine independent phases are Lexical analysis, Syntax analysis, Semantic analysis, Intermediate code generation and sometime code optimization.

4. A system program that combines the separately compiled modules of a program into a form suitable for execution is?
a) Assembler
b) Linking loader
c) Cross compiler
d) Load and Go

Answer: b
Clarification: Combines the modules which have been compiled separately.

5. Which of the following type of software should be used if you need to create, edit and print documents?
a) Word processing
b) Spreadsheet
c) Desktop publishing
d) UNIX

Answer: an
Clarification: Application software such as word processors.

6. Output file of the Lex is _________ is the input file is Sam.
a) sam
b) sam.yy.c
c) sam.lex
d) sam.obj

Answer: b
Clarification: This Produce the file “sam.yy.c”, which we can then compile with g++.

7. Type checking is normally done during ____________
a) Lexical analysis
b) Syntax analysis
c) Syntax directed translation
d) Code generation

Answer: c
Clarification: It enables the compiler to do type checking.

8. Yacc is available as a command on the ____________
a) MINIX
b) UNIX
c) DOS
d) None of the mentioned

Answer: b
Clarification: Unix provides with a YACC command.

9. Loading process can be divided into two programs. The first is binder the other is ____________
a) Linkage editor
b) Module Loader
c) Relocate
d) None of the mentioned

Answer: b
Clarification: A module loader is an answer.

10. In Lex, a class is complemented by first placing ____________
a) ^
b) OR
c) –
d) NOT

Answer: a
Clarification: ^ =complement.