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

Phases of a Compiler Questions and Answers

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.

34.

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.

Answer: D

Correct answer: compiles to bytecode which is then interpreted or compiled again

A hybrid system splits the translation. The source is compiled ahead of time into bytecode for a virtual machine, and that bytecode is then executed - interpreted, or compiled to native code by a just-in-time compiler while the program runs.

The arrangement buys portability from the first step and speed from the second: the bytecode runs anywhere the virtual machine exists, and the hot parts still reach native performance. It is neither pure interpretation nor pure ahead-of-time compilation.

Please log in or register to report this question.

Answer: A

Correct answer: intermediate code to machine code during the execution of a program

A just-in-time compiler translates bytecode or intermediate code into native machine code while the program is running, typically after a method has been executed often enough to be worth compiling.

Doing it at run time has a real advantage over compiling ahead of time: the compiler can see the actual types and branch behaviour and specialise for them. The cost is the time spent compiling, which is why interpretation handles the cold code and only the hot paths are compiled.

Please log in or register to report this question.

Answer: B

Correct answer: runs on one machine and produces code for a different machine

A cross compiler executes on a host machine and emits code for a different target. It is the normal arrangement for embedded work, where the target may have no operating system, little memory and no development tools at all.

It is also how a new architecture is bootstrapped: the first compiler for it must run somewhere else. Nothing about it produces universal code, translates between source languages, or handles multiple languages at once.

Please log in or register to report this question.

Answer: C

Correct answer: a program in another high level language rather than machine code

A source-to-source translator, or transpiler, takes a program in one high-level language and emits an equivalent one in another - TypeScript to JavaScript, or a modern dialect to an older one.

It performs the same analysis phases as any compiler; only the synthesis differs, producing readable source instead of machine code. The output must then be compiled or interpreted in the usual way, so the translator does not produce anything executable on its own.

Please log in or register to report this question.

Answer: D

Correct answer: six, spanning lexical analysis through to code generation

The classical model has lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimisation and code generation.

The first three are the analysis phase or front end and the last three the synthesis phase or back end, which is the two-part division the third option describes at a coarser grain. Alongside them run the symbol table manager and the error handler, which interact with every phase rather than occupying a position in the sequence.

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