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

Phases of a Compiler Questions and Answers

41.

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.

44.

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.

Answer: C

The assembler translates mnemonic instructions into machine encodings and leaves addresses relocatable. Combining several such modules and resolving the references between them is the linker's task, not the assembler's.

Please log in or register to report this question.

Answer: D

Correct answer: a program is usually built from several separately compiled modules

Separate compilation is what makes the linker necessary. A module referring to a routine defined elsewhere cannot have that address filled in when it is compiled, since the other module may not yet exist.

The linker combines the object files, resolves those external references, and produces a single executable. Libraries are brought in the same way. The assembler produces perfectly good relocatable code on its own, and the operating system loads what the linker has produced.

Please log in or register to report this question.

Answer: A

Correct answer: placing the executable in memory and adjusting relocatable addresses

The loader operates at run time, not build time. It reads the executable, allocates memory, copies the image in and adjusts any addresses that depend on where it was placed.

Combining object modules is the linker's work, done earlier; macro expansion is the preprocessor's, done earlier still; and type checking belongs to the compiler's semantic analysis. The loader is the last stage of the chain and the only one that runs each time the program is started.

Please log in or register to report this question.

49.

Match each tool with its principal output.
List I
A. preprocessor
B. compiler
C. assembler
D. linker
List II
1. relocatable machine code
2. modified source program
3. executable machine code
4. target assembly program

Answer: B

Correct answer: A-2, B-4, C-1, D-3

Each tool's output is the next one's input, so the chain settles the matching. The preprocessor produces a modified source program, still text.

The compiler produces a target assembly program. The assembler produces relocatable machine code, relocatable because its final addresses are not yet fixed. The linker produces executable machine code, having resolved the external references and combined the modules. The progression runs from text to assembly to relocatable object to executable.

Please log in or register to report this question.

Answer: C

An interpreter carries out the operations of the source program on the inputs supplied. It still analyses the program, but instead of emitting code it performs the actions, which usually makes execution slower and diagnostics better.

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