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

Phases of a Compiler Questions and Answers

Answer: C

Semantic analysis walks the tree, consults the symbol table for the types of names, computes the type of each expression and records it on the node. The annotated tree is then passed on to intermediate code generation.

Please log in or register to report this question.

Answer: D

Coercion is the automatic conversion of one type to another where the language permits it. Semantic analysis detects the mismatch and inserts an explicit conversion node into the tree so later phases see a consistent type.

Please log in or register to report this question.

Answer: A

Correct answer: decide which declaration a given use of a name refers to

The same identifier may be declared several times in nested scopes, and a use must be bound to exactly one of them - ordinarily the innermost enclosing declaration.

Scope information in the symbol table is what makes that resolution possible, and the type of the reference follows from it. Everything downstream depends on getting it right: type checking, storage allocation and code generation all concern the particular object bound, not merely the name.

Please log in or register to report this question.

Answer: B

Correct answer: in the back end, once the target machine layout is known

An offset within an activation record depends on the sizes and alignments of the target's data types and on its calling convention - none of which the front end knows.

The decision therefore belongs to the back end, along with register allocation and instruction selection. The linker resolves addresses between modules rather than within a frame, the scanner has no notion of layout, and the preprocessor works on text before any of this arises.

Please log in or register to report this question.

55.

If a compiler is to be retargeted to a new machine, the part most likely to require rewriting is

Answer: C

Correct answer: the back end comprising code generation and machine dependent parts

The front end depends on the source language and the back end on the target machine, so changing the target leaves the front end untouched.

Instruction selection, register allocation, instruction scheduling and the machine-dependent optimisations all have to be rewritten. That separation is the whole argument for a common intermediate representation: front ends and back ends can be combined freely, so \( m \) languages and \( n \) machines need \( m+n \) components rather than \( m \times n \).

Please log in or register to report this question.

56.

Assertion (A): The intermediate representation is the pivot on which retargeting turns.
Reason (R): It is defined independently of both the source language and the target machine.

Answer: D

Both are true and the reason gives the mechanism, and this is why m languages and n machines need m plus n components rather than m times n. Any front end can feed any back end provided both agree on the intermediate form.

Please log in or register to report this question.

57.

A compiler suite supports 4 source languages and 5 target machines using a common intermediate representation. How many front ends and back ends are needed in total?

Answer: A

Correct answer: 9

With a common intermediate representation each language needs one front end and each machine one back end, and any front end may be paired with any back end:

\[ 4 + 5 = 9 \]

The saving grows with the numbers, which is the whole argument for the arrangement. Adding a sixth machine costs one back end and immediately serves all four languages, where without the common form it would cost four separate translators.

Please log in or register to report this question.

58.

Without a common intermediate representation, how many separate translators would 4 source languages and 5 target machines require?

Answer: B

Correct answer: 20

Without a shared intermediate form every language-machine pair needs its own translator:

\[ 4 \times 5 = 20 \]

against the 9 that a common representation requires. The contrast between \( m \times n \) and \( m + n \) is the point, and it widens rapidly: ten languages and ten machines would need 100 translators against 20 components. It is also why retargeting means rewriting only a back end.

Please log in or register to report this question.

Answer: C

Correct answer: writing a compiler for a language in that same language

Bootstrapping is the technique of writing a compiler for a language in the language itself, which appears circular until the first step is supplied.

That step is a compiler for a subset, written in some other language or by hand. It compiles a fuller compiler written in the subset, which compiles a fuller one still, and so on. The payoff is that the language's own features can be used to build its compiler, and every improvement to the compiler benefits the next version of itself.

Please log in or register to report this question.

Answer: D

Correct answer: the source language, target language and implementation language

A T diagram is a notation with three arms: the source language on the left, the target on the right, and the implementation language below. Placing the shapes side by side shows which combinations can be composed.

It is used chiefly to reason about bootstrapping and cross compilation, where three languages are in play at once and it is easy to lose track of which compiler runs where. The other options describe data structures and flows rather than a notation for compilers.

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