Machine-translated by Google. Questions are authored in English.
Top

Phases of a Compiler Questions and Answers

Answer: C

Correct answer: a maximal sequence of instructions entered only at its first

A basic block is a straight-line sequence with one entry, at the top, and one exit, at the bottom - no branch enters part-way and none leaves except at the end.

That property is what makes it the unit of local optimisation: within a block, execution is guaranteed to run from first instruction to last, so the compiler can reason about the sequence without considering alternative paths. "Maximal" matters, the block being extended until a branch or a label forces a boundary.

Please log in or register to report this question.

Answer: D

Correct answer: basic blocks as nodes with edges showing possible control flow

The flow graph abstracts the program to its control structure: each node is a basic block, and an edge from one to another means control may pass between them.

Loops appear as cycles and conditionals as branching and rejoining paths. It is the structure on which global data flow analysis runs, since questions such as "which definitions reach this point" are answered by propagating facts along the edges until they settle.

Please log in or register to report this question.

Answer: A

Correct answer: gather facts about values that hold at each point in the program

Data flow analysis propagates information around the flow graph until it stabilises, answering questions such as which definitions reach a point, which variables are live, and which expressions are available.

Those facts are what make optimisation safe: common subexpression elimination needs to know the operands are unchanged, dead code elimination needs to know a value is never used. The analysis produces no code itself; it establishes the conditions under which a transformation is permitted.

Please log in or register to report this question.

Answer: B

Correct answer: infer the types of expressions from their use in the program

Absence of declarations does not mean absence of types. The compiler deduces them from how values are used - from literals, from the operators applied, and from the requirements of the functions a value is passed to.

Hindley-Milner inference is the classical algorithm, and ML and Haskell rest on it. Semantic analysis is certainly not abandoned; if anything it does more work, since it must reconstruct what a declaring language would simply have been told.

Please log in or register to report this question.

Answer: C

Correct answer: target code, either assembly or relocatable machine instructions

Code generation is the last phase of the compiler, so its output is the compiler's output: assembly text for a subsequent assembler, or relocatable machine code directly.

It is not yet an executable - external references remain unresolved until the linker has run, and addresses are not fixed until the loader places the image. An annotated syntax tree is the semantic analyser's product, several phases earlier, and diagnostics are a by-product rather than the output.

Please log in or register to report this question.

76.

State whether the following is true or false.
Every compiler must include a code optimisation phase to be correct.

Answer: D

Correct answer: False

Optimisation improves the target program; it has nothing to do with correctness. A compiler that omits it entirely produces code that is slower and larger but perfectly correct, which is exactly what a debug build does.

The phase is optional in the classical model for that reason, and compilers expose it as a set of levels. If anything the relationship runs the other way: an aggressive optimiser is a source of correctness risk, since a faulty transformation changes observable behaviour.

Please log in or register to report this question.

Answer: A

Correct answer: a transformation that changes the observable behaviour of the program

An optimisation is legitimate only if the program's observable behaviour is preserved. A transformation resting on an assumption the program violates - about aliasing, about arithmetic overflow, about the absence of undefined behaviour - produces code that is faster and wrong.

Such faults are hard to find, since the program works unoptimised. Compilation memory and target size are engineering costs rather than risks, and neither threatens the correctness of the result.

Please log in or register to report this question.

Answer: B

Correct answer: reports a suspicious construct that is nonetheless legal

A warning concerns code the language permits but which is likely to be a mistake: an unused variable, an assignment inside a condition, a comparison whose result is constant.

Because the code is legal, compilation continues and an executable is produced - which is the practical difference from an error. That also makes warnings easy to accumulate and ignore, and is why serious projects turn them into errors deliberately.

Please log in or register to report this question.

Answer: C

Correct answer: white space and comments from the stream handed to the parser

Comments and white space carry no meaning for the grammar, so the scanner discards them and hands the parser a clean token stream.

The removal is not quite unconditional: white space still separates lexemes, so the scanner uses it before dropping it, and it is significant in languages that use indentation for structure. Operators and identifiers are the very things the scanner produces tokens for, and dead code elimination happens much later.

Please log in or register to report this question.

Answer: D

Correct answer: diagnostic messages can point the programmer to the right place

An error message giving no location is nearly useless in a large file, so the scanner records line and column with each token and later phases carry the information through the tree.

The same information also feeds the debugging tables, which map machine addresses back to source lines. Optimisation, linking and loading all work on representations from which source positions have been abstracted away; only the diagnostics need to reach back.

Please log in or register to report this question.

Loading…
Tags: Phases of a Compiler Questions and Answers || Phases of a Compiler MCQ Questions and Answers || Phases of a Compiler GK Questions and Answers || Phases of a Compiler GK MCQ Questions || Phases of a Compiler Multiple Choice Questions and Answers || Phases of a Compiler GK || GK on Phases of a Compiler || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design