🎯 Syllabus & Goals 3 min
Cambridge 4.2 · Translators: compilers, interpreters, assemblers Paper 1 · Computer Systems
By the end of this lesson you can:
- Describe how a compiler and an interpreter translate and run a high-level program, and how each reports errors.
- Describe what an assembler does.
- Give the advantages and disadvantages of compilers and interpreters, and choose one for a scenario.
Textbook: Chapter 4, §4.2.3–4.2.4 (pp. 168–170)
Recap / Warm-Up 5 min
Last lesson: the CPU only understands machine code. High-level and assembly programs must be translated first. Today we meet the three programs that do the translating.
Quick starter
A tourist and a local do not share a language. Would you rather have a human interpreter beside you, or a phrasebook translated in advance? Give one reason for each.
Reveal the answer
The interpreter handles each sentence as it comes and can fix mistakes on the spot, but must be with you every time. The phrasebook is prepared once and used again and again with no helper. That is the interpreter/compiler trade-off exactly.
🧠 Key Concept 14 min
1 · Translators
The program the programmer writes is the source code. The translated machine code is the object code. There are three kinds of translator, and each does a different job.
2 · Compilers
- The entire program is translated before any of it runs.
- If there are errors, an error report for the whole program is produced instead of a compiled program.
- The executable can be run again and again without re-compiling, and without the compiler.
- One high-level statement can become several machine code instructions.
3 · Interpreters
- It reads a statement, translates it, performs the action, then moves to the next statement.
- If a statement has an error, execution stops and an error message is shown — sometimes with a suggested correction.
- No executable file is produced. The program must be interpreted again every time it runs.
- The interpreter must be present every time the program runs.
4 · Assemblers
One assembly statement usually becomes one machine code instruction. Like a compiler, an assembler produces an executable file that is run without the assembler and can be used again and again.

| Compiler | Interpreter | Assembler | |
|---|---|---|---|
| Translates | high-level → machine code | high-level, one statement at a time, and executes it | assembly → machine code |
| Executable file? | Yes | No | Yes |
| Statements → instructions | one → several | one → several | one → usually one |
| Needed to run the program? | No | Yes, every time | No |
| Errors | report for the whole program | stops at the first error | — |
| Typical use | finished programs for distribution | while a program is being developed | finished low-level programs |
5 · Advantages and disadvantages
Interpreter
+ easier and quicker to debug and test during development
+ easier to edit programs during development
− programs cannot run without the interpreter
− programs can take longer to execute
Compiler
+ compiled program can be stored ready to use
+ runs without the compiler
+ takes less memory when executed, and runs faster
− takes longer to write, test and debug during development
Worked Example 12 min
(a) One buggy program, two translators
This program has two errors: line 04 is an incomplete expression, and line 06 misspells OUTPUT.
01 DECLARE Price, Total : REAL 02 OUTPUT "Enter a price" 03 INPUT Price 04 Total ← Price * 1.2 + 05 OUTPUT "Total is ", Total 06 OUTPT "Thank you"
With a compiler
- The whole program is translated first.A compiler works on all of the source code in one go.
- Errors are found on lines 04 and 06.It checks every line, so both appear in the error report.
- No executable is produced; nothing runs.An error report is produced instead of a compiled program.
With an interpreter
- Lines 01–03 run: "Enter a price" appears and the user types 10.Each line is translated and executed before the next is read.
- Line 04 fails; execution stops with an error message.An interpreter stops at the first error it meets.
- Line 06's error is not reported yet.It is only found after line 04 is fixed and the program runs again.
Enter a price 10 Error on line 04: expression incomplete after "+"
What this shows: the interpreter gives quick feedback on the exact line, which helps while developing. The compiler lists all the errors together, but only after translating everything.
(b) Choosing a translator for the job
Mia writes a quiz program in a high-level language. Her friend must run it tomorrow on a laptop with unknown software and a very slow internet connection.
- While writing and testing, Mia uses an interpreter.She can test each part as she goes and fix errors line by line.
- For her friend, Mia uses a compiler.It produces an executable file of machine code.
- Her friend does not need a translator installed.A compiled program runs without the compiler — useful when the laptop's software is unknown.
- There is no need to download an interpreter over the slow connection.Only the executable has to be copied across.
- The program will also run faster and use less memory.It is already translated, so no translation happens at run time.
Try It Yourself 12 min
Goal: True or false? (a) An assembler translates a high-level language. (b) You need the compiler to run a compiled program. (c) An interpreted program runs more slowly than a compiled one.
Goal: Write a 5-line pseudocode program with an error on line 2 and another on line 5. Describe what a compiler reports and what an interpreter does.
Goal: A company sells a paid app and does not want customers to see or change its source code. Explain which translator it should use to produce the version it sells, and why.
Hint
What does the customer receive in each case — machine code, or the program itself plus a translator?
📝 Exam Practice 10 min
Describe the differences between a compiler and an interpreter.
Mark scheme
Any four:
- A compiler translates the whole program in one go; an interpreter translates and executes one statement at a time (1).
- A compiler produces an executable file; an interpreter does not (1).
- A compiled program runs without the compiler; an interpreted program needs the interpreter every time (1).
- A compiler gives an error report for the whole program; an interpreter stops at the first error (1).
- A compiled program runs faster than an interpreted one (1).
Give one advantage and one disadvantage of using an interpreter.
Mark scheme
- Advantage, e.g. easier/quicker to debug and test during development / easier to edit / errors shown line by line (1).
- Disadvantage, e.g. program cannot run without the interpreter / takes longer to execute / must be re-translated each run (1).
Describe the differences between a compiler and an assembler.
Mark scheme
- A compiler translates a high-level language; an assembler translates assembly language (1).
- A compiler turns one statement into several machine code instructions; an assembler usually turns one into one (1).
- A compiler's input is hardware-independent; an assembler's input is machine-dependent (1).
(Both produce an executable file, so this is not a difference.)
A programmer has written a program in a high-level language for a customer. The customer wants to use it immediately on their own computer. The programmer does not know what software is installed, and the customer's internet connection is very slow. Explain which type of translator the programmer should use. Give reasons for your choice.
Mark scheme
- Compiler (1).
- It produces an executable file (of machine code) (1).
- The executable runs without the compiler / no translator needed on the customer's computer (1).
- The unknown software does not matter / no interpreter needs to be installed (1).
- Nothing large needs to be downloaded over the slow connection (1).
- The compiled program runs faster / can be used immediately / source code is not shared (1).
🗝️ Recap & Key Terms 3 min
A compiler translates a whole high-level program into an executable, reporting all errors first. An interpreter translates and runs one statement at a time and stops at the first error. An assembler turns assembly language into machine code, usually one-to-one. Interpreters suit development; compilers suit distribution.
- Translator
- Converts a program written in a high-level or assembly language into machine code.
- Compiler
- Translates a high-level source program into machine code in one go, producing an executable file.
- Interpreter
- Analyses and executes a high-level program one statement (line) at a time.
- Assembler
- Translates assembly language into machine code.
- Source code
- The program as written by the programmer, before translation.
- Object code / executable
- The machine code produced by a compiler or assembler, which can run without the translator.
Homework 1 min
Task (≤ 15 min): Give one advantage and one disadvantage of a compiler. Then explain why many programmers use an interpreter while writing a program but a compiler when it is finished. [4]
Model answer
- Advantage: the compiled program runs without the compiler / runs faster / can be stored ready to use (1).
- Disadvantage: it takes longer to write, test and debug during development (1).
- An interpreter shows each error as soon as its line runs, so testing and editing are quicker (1).
- A compiled executable can be distributed and run by users with no translator installed (1).