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

Phases of a Compiler Questions and Answers

Answer: A

Correct answer: linking of object modules

Linking happens after compilation, combining separately compiled object files and libraries into an executable. It is a distinct tool with its own input and output, not a phase within the compiler.

The other three are all compiler phases: semantic analysis in the front end, and code optimisation and intermediate code generation between the front and back ends. The confusion arises because all four appear in a language processing system; only three are inside the compiler.

Please log in or register to report this question.

Answer: B

Correct answer: poor practice, as the programmer must then recompile for each one

Stopping at the first error makes the edit-compile cycle as long as the number of errors, which is intolerable when a single missing declaration provokes many.

Good compilers therefore recover and continue, reporting as many genuine errors as they can in one run. The difficulty is cascading - one error provoking spurious ones - which is what panic mode and phrase-level recovery address by resynchronising. No standard requires stopping, and the symbol table is not corrupted by an error being reported.

Please log in or register to report this question.

Answer: C

Correct answer: discarding tokens until one of a set of synchronising tokens is found

On detecting an error the parser skips input until it reaches a token from which parsing can plausibly resume - typically a semicolon, a closing brace or a statement keyword.

It is crude, and it may discard a construct containing further errors, but it is simple and it cannot loop. The gain is resynchronisation: the parser reaches a known state and continues, so later independent errors are still found rather than the compilation collapsing at the first fault.

Please log in or register to report this question.

Answer: D

Correct answer: performs a local correction on the remaining input to continue

Phrase-level recovery repairs rather than skips: it inserts a missing token, deletes an extraneous one or substitutes a plausible replacement, and carries on from that point.

The advantage is that little or no input is discarded, so errors within the affected construct are still found. The risk is that a wrong guess produces cascading spurious messages, and the correction must be chosen carefully to guarantee no infinite loop. Error productions in the grammar are a third technique again.

Please log in or register to report this question.

Answer: A

Correct answer: the grammar to be augmented with rules describing common errors

The technique anticipates mistakes and writes productions for them, so that a construct the language does not permit is nonetheless recognised - and recognising it lets the compiler report exactly what is wrong and continue with the parse intact.

The cost is that the grammar grows and must be maintained against the errors programmers actually make. Nothing about the scanner, the semantic analyser or the code generator changes; the recovery lives entirely in the grammar.

Please log in or register to report this question.

Answer: B

Global correction seeks the smallest sequence of insertions and deletions that makes the program legal. The algorithms are expensive and the correction chosen is often not what the programmer intended, so the idea remains largely theoretical.

Please log in or register to report this question.

Answer: C

Correct answer: it emits the same intermediate representation the back end consumes

The interface between front end and back end is the intermediate representation, and nothing else about the two need match.

A front end for any language whatever may be paired with a back end for any machine, provided both speak the same intermediate form. That is exactly what makes \( m+n \) components serve \( m \times n \) combinations. Shared keywords, shared expression syntax and a shared implementation language are all irrelevant to the coupling.

Please log in or register to report this question.

68.

Consider the following statements about the front end and back end.
1. The front end depends on the source language.
2. The back end depends on the target machine.
3. Machine independent optimisation belongs in the back end.

Answer: D

Correct answer: 1 and 2 only

The first two state the division correctly: the front end depends on the source language and the back end on the target machine, which is why retargeting rewrites only the back end.

The third misplaces machine-independent optimisation. It works on the intermediate representation and by definition needs no knowledge of the target, so it sits between the two - the middle end. Only machine-dependent optimisation, such as peephole work on target instructions, belongs to the back end.

Please log in or register to report this question.

Answer: A

Correct answer: a short window of target instructions and improves it locally

The peephole optimiser slides a small window over the generated code and replaces recognised patterns with better ones - deleting a store immediately followed by a load of the same location, or replacing a multiply by a power of two with a shift.

It is deliberately local and cheap, catching the redundancies that a straightforward code generator leaves behind. Global improvements need data flow analysis over the whole flow graph, which is a different kind of work entirely.

Please log in or register to report this question.

Answer: B

Strength reduction substitutes a cheaper operation for a more expensive one that computes the same result. It is machine dependent to the extent that the relative costs of the two instructions differ between processors.

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