A programmer writes a program in a high-level language. The program is translated by a compiler.
Explain why a compiler must translate the whole program before any of it can be executed.
Mark scheme
Award up to two marks for a linked explanation such as:
- The compiler produces object code/machine code for the whole program (1) so there is no complete executable until every line has been translated (1)
- The compiler translates all the source code before producing the object code (1) so the program cannot start until translation has finished (1)
- The compiler checks the whole program for errors during translation (1) so all of the source code must be read before an executable can be produced (1)
For both marks, the expansion must follow/associate with the statement.
Allow 'in one go'/'all at once' for the translation point, but this does not earn the second mark unless it is linked to why the program cannot be executed until translation has finished.
A statement that the whole program is translated, with no linked reason about when the program can be executed, earns 1 mark only.
Do not accept 'a compiler is faster' or 'compiled code runs faster' on its own; this does not explain why translation must finish before execution.
Do not accept 'it translates and runs the program one line at a time', as this describes an interpreter.
Example answers and how they were marked
A compiler produces object code for the whole program, so there is no complete executable until every line has been translated.
Why: Object code for the whole program (1) linked to there being no complete executable until every line is translated (1).
A compiler translates the whole program in one go.
Why: Translation of the whole program only (1); no linked reason about when the program can be executed, so the second mark is not awarded.
A compiler translates and runs the program one line at a time, so it stops when it finds an error.
Why: Confuses a compiler with an interpreter; nothing about translating the whole program before execution, so no creditworthy point.