Translators
OCR J277 Paper 2 sets 4–6 mark questions comparing compilers and interpreters, and asking what an assembler does. You need to know what each translator takes as input, what it outputs, and the practical trade-offs.
Why are translators needed?
A CPU only executes machine code (binary). High-level source code (Python, Java, C#) and assembly code must be translated before they can run.
Compiler
- Input — the entire source-code file (high-level).
- Output — a separate executable file containing machine code for a specific platform.
- The translation happens once, before the program is run; after that the executable runs directly without the compiler.
Pros — fast execution after compilation; no need to ship the source code; cross-organisation distribution is easier.
Cons — slow develop-test cycle (recompile after every change); error messages list errors after the whole file is processed; produced executable is platform-specific.
Interpreter
- Input — source code, line by line at run time.
- Output — none (it executes each line directly).
- Translation happens every time the program is run.
Pros — fast develop-test cycle (run code immediately); easier to debug because execution stops at the first error with the line number; same source can run on any platform that has the interpreter (Python, JavaScript).
Cons — slower execution than compiled code; the interpreter must be installed on the target machine; source code is exposed.
Assembler
- Input — assembly language (mnemonics like MOV, ADD, JMP).
- Output — machine code for a specific CPU architecture.
- Almost a one-to-one mapping — each assembly instruction usually corresponds to a single machine-code instruction.
Used for embedded systems, device drivers, performance-critical or low-level code where direct hardware control is needed.
Comparison table
| Feature | Compiler | Interpreter |
|---|---|---|
| Translates | Whole program | One line at a time |
| When | Once, before run | Every time the program runs |
| Output | Executable machine code | None — executes directly |
| Run speed | Faster | Slower |
| Develop-test speed | Slower (recompile) | Faster |
| Error reporting | After the whole file | Stops at first error |
| Source distributed? | No (executable shipped) | Yes (or interpreter ships with bytecode) |
| Portability | Compiled per platform | Same source, any platform with interpreter |
Common OCR exam mistakes
- Saying compilers are "always faster" — at run time, yes; but compiling itself is slow and must be redone after every change.
- Forgetting that an assembler is for assembly language, not machine code already.
- Mixing "interpreter translates line by line" with "interpreter executes line by line" — it does both: translate then execute, one line at a time.
- Saying both produce machine code — interpreters do not write a separate executable.
AI-generated · claude-opus-4-7 · v3-ocr-computer-science-leaves