Interpreters and compilers (Edexcel GCSE Computer Science): Revision Notes
Interpreters and compilers

Why do we need translators?
When programmers write code, they usually use high-level languages like Python, Java, or C++. These languages are easy for humans to understand because they use words and symbols that make sense to us. However, computers can only understand machine code - a language made up of binary numbers (0s and 1s).
This means that before any programme can run on a computer, it needs to be translated from the high-level language into machine code. The programmes that do this translation are called translators. There are three main types of translators: compilers, interpreters, and assemblers.
The fundamental challenge in programming is bridging the gap between human-readable code and machine-executable instructions. This is why translators are absolutely essential in the software development process.
Compilers
A compiler is a translator that converts your entire programme from source code (the original high-level code you write) into machine code all in one go. The machine code version is called object code and can be saved as a separate executable file.
How compilers work
Translation Process Example: Book Translation Analogy
Think of a compiler like translating an entire book from English to French before anyone reads it. The compiler:
- Takes your complete source code
- Translates the whole programme into machine code
- Creates a new executable file that the computer can run directly
- Only needs to do this translation once
Just like how you'd translate an entire book once and then distribute the French version to readers, a compiler processes your entire programme once and creates a standalone executable.
Advantages of compilers
✅ Fast execution: Once compiled, the programme runs quickly because it's already in machine code
✅ Standalone programmes: The compiled programme can run without needing the original source code or compiler
✅ Source code protection: You can share the executable file without revealing your original code to competitors
✅ One-time translation: You only need to compile once, then you can run the programme many times
Disadvantages of compilers
❌ Slow error detection: If there are errors in your code, the compiler tries to translate everything first, then reports all errors at the end
❌ Harder to modify: If you want to change even one line of code, you have to edit the source code and recompile the entire programme
❌ Platform-specific: Compiled programmes usually only work on the type of computer and operating system they were compiled for
Interpreters
An interpreter is a translator that converts your programme from high-level code to machine code line by line while the programme is running. It doesn't create a separate executable file - instead, it translates and runs each instruction immediately.
How interpreters work
Translation Process Example: Live Conference Interpreter
Think of an interpreter like a live translator at a conference who translates each sentence as the speaker says it. The interpreter:
- Reads the first line of your source code
- Translates that line into machine code
- Executes that line immediately
- Moves to the next line and repeats the process
- Does this every single time you run the programme
Just like how a live interpreter must translate each sentence in real-time, a code interpreter processes each line of your programme as it encounters it during execution.
Advantages of interpreters
✅ Immediate error reporting: When an error is found, the interpreter stops immediately and tells you exactly where the problem is
✅ Cross-platform: The same source code can run on different operating systems as long as they have the interpreter installed
✅ Easy to edit: You can make changes to your source code and test them immediately without any compilation process
✅ Interactive development: Great for testing small pieces of code quickly
Disadvantages of interpreters
❌ Slower execution: The programme runs more slowly because each line needs to be translated every time it runs
❌ Requires interpreter: The interpreter programme must be installed on any computer that wants to run your code
❌ Source code exposure: Your original source code needs to be available, which means others can see how you wrote your programme
Assemblers
Assemblers are special translators that work with assembly language. Assembly language uses mnemonics (memory aids like "ADD" for addition) instead of the 0s and 1s of machine code, but it's still very close to what the processor understands.
Assembly language has a direct one-to-one relationship with machine code instructions - each assembly instruction corresponds to exactly one machine code instruction. This makes assembly language a low-level programming language that provides direct control over the computer's hardware.
Key differences summary
| Feature | Compiler | Interpreter |
|---|---|---|
| Translation timing | Before running (all at once) | During running (line by line) |
| Speed of execution | Fast | Slower |
| Error detection | At the end of compilation | Immediately when error is reached |
| File created | Executable file | No separate file |
| Ease of editing | Must recompile after changes | Can test changes immediately |
| Platform dependency | Platform-specific | Cross-platform (with interpreter installed) |
Exam tips
Critical Points for Exams:
- Remember the main difference: Compilers translate the whole programme once before running, while interpreters translate line by line each time the programme runs
- For advantages/disadvantages questions: Think about speed (compilers are faster to run, interpreters are faster to test and debug)
- Real-world examples: Games and system software often use compilers for speed, while scripting and educational programming often use interpreters for flexibility
Remember!
Key Points to Remember:
- Translators are essential because computers can only execute machine code, not high-level programming languages
- Compilers translate the entire programme once and create a standalone executable file that runs quickly
- Interpreters translate and execute code line by line each time the programme runs, making them slower but more flexible for development
- Compilers are better for final products that need to run fast, while interpreters are better for development and testing because they provide immediate feedback
- Assemblers translate assembly language mnemonics into machine code instructions with a one-to-one correspondence