Compiler Construction MCQ :Code Generation and Optimization-Compilation of expression, intermediate codes for expressions : Link1

Compiler Construction MCQ :Code Generation and Optimization-Compilation of expression, intermediate codes for expressions : Link1

Compiler Construction MCQ & Answers

       Are you worried about the answers to Compiler Construction questions :Code Generation and Optimization-Compilation of expression, intermediate codes for expressions? We have arranged the Show Answer button under the each question. Candidates can click on it to know the right option among the given alternatives. Furthermore, the applicants can check our web portal @ www.totalmcq.com to take part in more MCQ on various subject. Wish, the given information about the Compiler Construction MCQ will helpful to the advance and can learn the various types of questions and answers.


Q.1. Some code optimizations are carried out on the intermediate code because------

A. they enhance the portability of the compiler to other target processors
B. program analysis is more accurate on intermediate code than on machine code
C. the information from dataflow analysis cannot otherwise be used for optimization
D. the information from the front end cannot otherwise be used for optimization

Q.2. Which one of the following is FALSE?

A. A basic block is a sequence of instructions where control enters the sequence at the beginning and exits at the end.
B. Available expression analysis can be used for common subexpression elimination.
C. Live variable analysis can be used for dead code elimination.
D. x = 4 ∗ 5 => x = 20 is an example of common subexpression elimination

Q.3. One of the purposes of using intermediate code in compilers is to---------

A. make parsing and semantic analysis simpler.
B. improve error recovery and error reporting.
C. increase the chances of reusing the machine-independent code optimizer in other compilers
D. improve the register allocation.

Q.4. Which one of the following is false?

A. The code contains loop invariant computation
B. There is scope of common sub-expression elimination in this code
C. There is scope of strength reduction in this code
D. There is scope of dead code elimination in this code

Q.5. Consider the grammar rule E → E1 - E2 for arith¬metic expressions. The code generated is targeted to a CPU having a single user register. The sub¬traction operation requires the first operand to be in the register. If E1 and E2 do not have any com¬mon sub expression, in order to get the shortest possible code

A. E1 should be evaluated first
B. E2 should be evaluated first
C. Evaluation of E1 and E2 should necessarily be interleaved
D. Order of evaluation of E1 and E2 is of no consequence

Q.6. Consider the intermediate code given below:
1. i = 1
2. j = 1
3. t1 = 5 * i
4. t2 = t1 + j
5. t3 = 4 * t2
6. t4 = t3
7. a[t4] = –1
8. j = j + 1
9. if j ≤ 5 goto(3)
10. i = i + 1
11. if i < 5 goto(2)
The number of nodes and edges in the control-flow-graph constructed for the above code, respectively, are------

A. 5 and 7                                                                     B. 6 and 7
C. 5 and 5                                                                    D. 7 and 8

Q.7. Consider the following source code :
c = a + b
d = c
c = c – e
a = d – e
b = b * e
b = d/b
Which of the following is correct optimization of given code?

A] c = a + b
t = b * e
a = d – e
b = d/t
c = a

B] c = a + b
d = c
c = c – e
a = d – e
b = d/b

C] d = c
c = c – e
a = d – e
b = b * e
b = d/b
D] None of the above

Q.8.Consider the code segment
int i, j, x, y, m, n;
n=20;
for (i = 0, i < n; i++)
{
for (j = 0; j < n; j++)
{
if (i % 2)
{
x + = ((4*j) + 5*i);
y += (7 + 4*j);
}
}
}
m = x + y;
Which one of the following is false.

A. The code contains loop invariant computation
B. There is scope of common sub-expression elimination in this code
C. There is scope of strength reduction in this code
D. There is scope of dead code elimination in this code

Q.9. Peephole optimization is form of------

A. Loop optimization                                             B. Local optimization
C. Constant folding                                                D. Data flow analysis

Q.10. In compiler terminology reduction in strength means-----

A. Replacing run time computation by compile time computation
B. Removing loop invariant computation
C. Removing common subexpressions
D. replacing a costly operation by a relatively cheaper one

Q.11. Substitution of values for names (whose values are constants) is done in----------

A. Local optimization                                                                B. Loop optimization
C. Constant folding                                                                   D. Strength reduction

Q.12. Which of the following comment about peep-hole optimization is true?

A. It is applied to small part of the code and applied repeatedly
B. It can be used to optimize intermediate code
C. It can be applied to a portion of the code that is not contiguous
;D. It is applied in symbol table to optimize the memory requirements

Q.13. CWhich of the following statements about peephole optimization is False?

A. It is applied to a small part of the code
B. It can be used to optimize intermediate code
C. To get the best out of this, it has to be applied repeatedly
D. It can be applied to the portion of the code that is not contiguous

Q.14. Quadruple is a record structure with four fields-------

A. Op, arg1, arg2 and result                                    B. op1, op2, arg2 and result
C. arg1, arg2, result and op                                     D. All of the above.

Q.15. Graph used to represent semantic network is ----

A. Undirected graph                                                      B. Directed graph
C. Directed Acyclic graph (DAG)                                  D. Directed complete graph