Skip to main content
EnglandComputer ScienceSyllabus dot point

How is source code turned into something the processor can run, and what does each stage of compilation do?

The need for, and the characteristics of, translators (assemblers, compilers, interpreters), the stages of compilation (lexical analysis, syntax analysis, code generation, optimisation), and the role of linkers, loaders and libraries.

An OCR H446 answer on translators and compilation: the characteristics of assemblers, compilers and interpreters, when each is used, the four stages of compilation (lexical analysis, syntax analysis, code generation and optimisation), and the roles of linkers, loaders and libraries.

Generated by Claude Opus 4.813 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

OCR wants the three types of translator with their characteristics and when each is used, the four stages of compilation in order, and the roles of linkers, loaders and libraries. Expect a "compare a compiler and an interpreter" question and a "describe the stages of compilation" question.

The answer

Why translators are needed

Assemblers, compilers and interpreters

The four stages of compilation

Linkers, loaders and libraries

Examples in context

Python normally uses an interpreter, which is why it is popular for rapid development and scripting; C and C++ are compiled for speed and to ship closed-source binaries. Java compiles to platform-independent bytecode that a virtual machine then interprets or just-in-time compiles, blending the approaches. Dynamic libraries (DLLs on Windows, shared objects on Linux) let many programs share one copy of common code, saving memory. OCR ties this to assembly language and to the trade-offs between high-level and low-level programming.

Try this

Q1. State one advantage of using a compiler rather than an interpreter to distribute software. [1 mark]

  • Cue. The executable can be distributed without the source code (protecting it) and runs fast with no translation overhead.

Q2. State what is produced by the lexical analysis stage of compilation. [1 mark]

  • Cue. Tokens (with the symbol table begun), after removing whitespace and comments.

Q3. Explain the role of a linker. [2 marks]

  • Cue. It combines the compiled object code of separate modules with the library code they use into one executable, resolving references between them.

Exam-style practice questions

Practice questions written in the style of OCR exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

OCR 20186 marksCompare the use of a compiler and an interpreter for translating a high-level language program, referring to error reporting, execution speed and distribution of the program.
Show worked answer →

Award up to two marks each for error reporting, speed and distribution.

Error reporting: a compiler translates the whole program at once and reports all syntax errors together after the attempt, so debugging happens in batches; an interpreter translates and executes one statement at a time and stops at the first error, which is convenient for development and locating errors.

Execution speed: compiled code runs as native machine code, so it executes quickly with no translation overhead at run time; interpreted code is translated each time it runs, so it is slower, and a statement inside a loop is retranslated on every pass.

Distribution: a compiler produces a standalone executable that can be distributed without the source code (protecting it) but is platform-specific; an interpreter needs the source code and the interpreter present on the target machine, which aids portability but exposes the source. Markers reward a clear point on each of the three aspects.

OCR 20225 marksDescribe the stages of compilation, naming what happens at lexical analysis, syntax analysis and code generation.
Show worked answer →

Award marks for each stage described in order (up to 5).

Lexical analysis: the source code is read and broken into tokens; whitespace and comments are removed and a symbol table is begun to record identifiers and keywords.

Syntax analysis (parsing): the tokens are checked against the rules of the language grammar, building a structure such as an abstract syntax tree; syntax errors are reported here and the symbol table is completed.

Code generation: the syntax tree is translated into object code (machine code or an intermediate form). An optional fourth stage, optimisation, then improves the code to run faster or use less memory, for example removing redundant instructions. Markers reward tokens at lexical, grammar checking at syntax, and machine/object code at code generation.

Related dot points

Sources & how we know this