Translators convert high-level programming languages into machine code that the CPU can run. Understanding the difference between compilers and interpreters — and their advantages and disadvantages — is assessed every year at GCSE and A Level.
| Feature | Compiler | Interpreter |
|---|---|---|
| Translation | Whole program at once, before execution | One line at a time, during execution |
| Output | Standalone executable file | No output file — runs directly |
| Execution speed | Fast — machine code runs directly | Slower — translation overhead at runtime |
| Error reporting | All errors reported before running | Stops at first error encountered |
| Portability | Compiled for one specific CPU type | Portable — any machine with the interpreter |
| Distribution | Distribute binary (source hidden) | Must distribute source code |
| Development | Compile → run cycle (slower feedback) | Immediate execution (faster feedback) |
| Examples | C, C++, Rust, Go | Python, JavaScript, Ruby |
A Level extra — stages of compilation:
Lexical analysis → Syntax analysis → Semantic analysis → Intermediate code generation → Optimisation → Code generation. A 4-mark question asking you to list the stages in order appears regularly at A Level.
Try these before expanding the hints. Write your answer, then compare.
State two advantages of using a compiler rather than an interpreter.
Mark scheme hint: Faster execution — compiled code runs directly as machine code without translation overhead [1]; source code is hidden from the user (distributed as machine code binary) [1]; errors reported before execution so the whole program is checked first [1]. Any 2.
State two advantages of using an interpreter rather than a compiler.
Mark scheme hint: Easier to debug — reports the first error encountered and stops, making it easy to locate [1]; more portable — the same source code runs on any machine that has the interpreter installed [1]; useful during development — no separate compile step needed [1]. Any 2.
Explain what an assembler does and state one situation where assembly language would be used instead of a high-level language.
Mark scheme hint: Assembler translates assembly language into machine code [1]. Assembly language has a near one-to-one relationship with machine code instructions [1]. Used for: embedded systems / device drivers / time-critical programs where precise hardware control or maximum speed is needed [1].
Describe the role of the lexical analyser in the compilation process.
Mark scheme hint: The lexical analyser reads source code character by character and groups them into tokens — the smallest meaningful units (keywords, identifiers, operators, literals) [1]; it removes whitespace and comments and outputs a token stream for the parser [1].
Hundreds more exam-style questions with full mark schemes — all free.
Question Bank →"A compiler is better than an interpreter" — this is too vague for any marks.
State the specific advantage: "A compiler produces a standalone executable that runs faster because no translation is needed at runtime. An interpreter is better for debugging because it stops at the first error."
Saying "an interpreter checks for errors before running" — this is wrong. Only a compiler does this.
An interpreter finds errors at runtime — when it reaches an error during execution, it stops. A compiler checks the whole program before running it, so all syntax errors are reported before execution.
Confusing assembler with compiler — saying "an assembler translates high-level code".
An assembler translates ASSEMBLY LANGUAGE (low-level, human-readable mnemonics) to machine code. A compiler translates HIGH-LEVEL language (Python, Java, C). These are different translation tools for different languages.
One-to-one online tutoring with an experienced Computer Science teacher. Work through exactly the topics you find hardest — exam technique, algorithms, programming and more.
A compiler translates the entire source code into machine code all at once before execution — the resulting executable can be run without the compiler. An interpreter translates and executes the source code one line (or statement) at a time during runtime — the interpreter must be present every time the program runs.
A compiled program runs directly as machine code — the CPU executes it without any translation overhead. An interpreted program requires the interpreter to translate each line before executing it, adding processing overhead every time the program runs. However, modern JIT (Just-in-Time) compilers can close much of this gap.
An assembler translates assembly language (low-level, human-readable mnemonics like MOV, ADD, JMP) into machine code (binary instructions the CPU can execute directly). It works similarly to a compiler but for assembly language, which has a near one-to-one mapping to machine code instructions.
The six stages are: (1) Lexical analysis — tokenise the source code; (2) Syntax analysis — parse tokens against grammar rules, build an AST; (3) Semantic analysis — type checking, scope checking; (4) Intermediate code generation — produce platform-independent IR; (5) Optimisation — improve the IR; (6) Code generation — translate IR to target machine code. For GCSE, know that errors are reported before execution. For A Level, know all six stages.