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

Phases of a Compiler Questions and Answers

Answer: A

Correct answer: instruction selection to exploit an addressing mode of the target

An optimisation is machine independent if it can be applied to the intermediate code without knowing the target. Instruction selection is the opposite: it exists precisely to exploit a particular machine's instruction set and addressing modes.

The other three qualify. Common subexpression elimination, constant folding and dead code elimination all work on the structure of the computation itself and would improve the program on any target. The distinction is what makes a common intermediate representation worth having.

Please log in or register to report this question.

Answer: B

Correct answer: in the code generation phase of the back end

Registers are a property of the target machine - how many there are, which are reserved, which instructions can use which. Nothing about them exists in the machine-independent intermediate code.

Allocation therefore belongs to the back end, alongside instruction selection and scheduling. Doing it earlier would tie the intermediate form to one architecture and destroy the point of a common representation. The front end deals in an unlimited supply of temporaries; the back end maps them onto real registers and spills the remainder.

Please log in or register to report this question.

Answer: C

Correct answer: choosing target instructions that implement the intermediate operations

Instruction selection maps each intermediate operation, or a pattern of several, onto the machine instructions that realise it - often with several valid choices differing in cost.

A three-address addition might become an add, a load-effective-address, or an increment, according to the operands and the addressing modes available. Because the choice depends entirely on the target's instruction set, it is a back-end task and one of the parts that must be rewritten when a compiler is retargeted.

Please log in or register to report this question.

Answer: D

Correct answer: is a logical stage while a pass is one complete reading of the input

A phase is a conceptual division of the translation - lexical, syntax, semantic and so on. A pass is a physical one: one complete traversal of the program's representation.

The two need not correspond. Several phases are commonly folded into a single pass to avoid writing intermediate forms to disk, and one phase may occasionally need more than one pass. Confusing them is the standard error, and the question turns on nothing else.

Please log in or register to report this question.

Answer: A

Correct answer: reduce the input and output cost of writing intermediate forms

Each pass boundary means writing a representation out and reading it back, which historically dominated compilation time on machines with little memory.

Folding phases together lets one phase's output be handed directly to the next, often a token or a tree node at a time. The constraint is the language: a single pass requires that everything needed be known when it is first encountered, which is why declaration-before-use rules make single-pass compilation feasible.

Please log in or register to report this question.

26.

Assertion (A): A single pass compiler is generally faster than a multipass compiler.
Reason (R): It avoids writing intermediate representations to a file and reading them back again.

Answer: B

Both are true and the reason gives the mechanism, and the trade-off is against optimisation quality. A single pass compiler cannot see the whole program at once, so it must generate code before later information arrives and misses optimisations a multipass compiler would find.

Please log in or register to report this question.

Answer: C

Correct answer: the symbol table entry exists before the name is ever referenced

A single-pass compiler must generate code for a reference at the moment it meets it, which requires the name's type, size and storage already to be known.

Declaration before use guarantees exactly that: the declaration has been processed and the symbol table entry created before any use is scanned. Without the rule, a forward reference would have to be left incomplete and filled in later - backpatching, or a second pass. Semantic analysis is still required, and the rule says nothing about ambiguity.

Please log in or register to report this question.

Answer: D

Correct answer: fill in addresses that were not known when the code was first emitted

A forward jump must be emitted before its destination has been reached, so the address field is left blank and its location recorded on a list.

When the target label is finally seen, the compiler walks the list and patches every waiting instruction with the now-known address. The technique is what lets a single-pass compiler handle forward branches in conditionals and loops without a second traversal - it defers only the address, not the code.

Please log in or register to report this question.

29.

Arrange these components of a language processing system in the order a source file passes through them.
1. assembler
2. preprocessor
3. linker
4. compiler

Answer: A

Correct answer: 2 - 4 - 1 - 3

The source passes through the preprocessor first, which expands macros and includes files to produce a modified source program.

The compiler translates that into assembly, the assembler turns the assembly into relocatable machine code, and the linker combines the object modules with libraries into an executable. Each stage's output is the next stage's input, and the loader - which places the executable in memory - comes after all four, at run time rather than build time.

Please log in or register to report this question.

Answer: B

Correct answer: macro expansion and the inclusion of other source files

The preprocessor works on text before the compiler sees anything, expanding macros, including named files and evaluating conditional compilation directives. Its output is a modified source program.

Because it operates on text rather than on syntax, it knows nothing of types or scopes, which is the source of the classic macro pitfalls. Translation to machine code belongs to the compiler and assembler, resolving external references to the linker, and loading into memory to the loader.

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