In simple terms
A friendly intro before the formal notes — no formulas yet.
From Human Code to Machine Speak
Computers only understand binary instructions, known as machine code. Language translators act as interpreters, converting the high-level code we write into the low-level instructions the processor can execute.
Imagine you've written a novel in English and want a friend in Japan to read it. A compiler is like a professional translator who translates the entire book into Japanese, prints it, and gives you the finished Japanese version to send. An interpreter is like having a friend on a video call who translates your English sentences into Japanese, one by one, as you speak them.
- 1
A programmer writes source code in a high-level language like Python or Java.
- 2
The source code is fed into a language translator program (e.g., a compiler or an interpreter).
- 3
The translator converts the code. A compiler creates a complete, standalone executable file of machine code. An interpreter translates and runs the code line by line.
- 4
The CPU executes the resulting machine code, carrying out the program's instructions.
Explore the concept
Use the live diagram and synced steps — play it or tap a step card to walk through.
Full topic notes
Formal explanation with the rigour you need for the exam.
The Need for Translators
The gap between high-level languages and machine code is vast. A single line of high-level code, like , might correspond to dozens of low-level machine instructions for loading values into registers, performing arithmetic, and storing the result in memory. Language translators automate this complex conversion, allowing programmers to work at a higher level of abstraction, focusing on problem-solving rather than the intricate details of the CPU's architecture.
Compilers vs. Interpreters: Two Approaches to Translation
Compilers and interpreters are the two primary types of translators for high-level languages. While their goal is the same—to get the computer to understand the source code—their methods are fundamentally different, leading to significant trade-offs in performance, portability, and development workflow.
Compiler: Scans the entire program first. It translates the whole source code into a standalone executable file (object code). This file can be run multiple times without re-compilation. Any errors are reported all at once after the entire scan.
Interpreter: Processes the program line by line. It translates and executes the first line, then the second, and so on. It does not create a separate executable file. An error will halt execution at the line where the error occurred.
Execution Speed: Compiled programs generally run much faster because the translation is already done. Interpreted programs are slower as translation happens during execution.
Distribution: Compiled programs are easy to distribute as a single executable file. The end-user does not need the compiler. Interpreted programs require the user to have the interpreter installed.
Debugging: Interpreters are often better for debugging as they pinpoint errors on the exact line they occur. Compilers report a list of errors which can sometimes be harder to trace back to the original cause.
Platform Dependence: A compiled executable is specific to a CPU architecture and operating system. An interpreted program can run on any platform that has the correct interpreter available.
The Four Stages of Compilation
The compilation process isn't a single monolithic step. It's a pipeline of distinct stages, each with a specific task. Understanding these stages is key to appreciating how a compiler works and diagnoses errors.
1. Lexical Analysis: The compiler reads the source code as a stream of characters. It removes comments and whitespace and groups characters into meaningful sequences called 'tokens'. For example, would be broken into tokens: IDENTIFIER(total), , , SEMICOLON.
2. Syntax Analysis (Parsing): The stream of tokens is checked against the grammar rules of the programming language. The compiler determines if the tokens form a valid statement. It often builds a data structure called a 'parse tree' or 'abstract syntax tree' (AST) to represent the grammatical structure of the code. If the syntax is incorrect (e.g., ), a syntax error is generated.
3. Code Generation: The compiler traverses the parse tree and generates the equivalent machine code or an intermediate code. This is the stage where the high-level logic is translated into low-level instructions for the target processor.
4. Optimisation: This optional but crucial stage analyses the generated code to make it more efficient. It might rearrange instructions, remove redundant code, or use clever tricks to make the program run faster or use less memory. The level of optimisation can often be controlled by the programmer.
Exam questions frequently ask you to 'compare and contrast' compilers and interpreters. For full marks, you must provide both similarities (e.g., both translate HLLs) and differences (e.g., speed, error handling, output). Use a structured approach, addressing one point of comparison at a time for both translators.
Assemblers: The Low-Level Specialist
An assembler is a different kind of translator that works with assembly language, a low-level language that is very close to machine code. Unlike a compiler, which translates from a high-level language, an assembler performs a more direct, almost one-to-one conversion. Each assembly language mnemonic (e.g., ADD, MOV, SUB) corresponds directly to a single machine code instruction. Assemblers are used when direct hardware control and maximum performance are absolutely critical, such as in device drivers or embedded systems.
Worked examples
See the formulas applied — reveal one step at a time, like the exam.
A software company is developing a high-performance 3D graphics engine for a commercial video game to be sold to the public. Justify, with two distinct reasons, whether a compiler or an interpreter would be more suitable for distributing the final product.
- 1
Translator: Compiler [1 mark]
A student is learning to code in Python for their A-Level project. They are constantly writing, testing, and debugging small sections of their program. Explain why an interpreter is beneficial in this scenario.
- 1
Benefit 1 (Immediate Feedback): Python is an interpreted language. When the student runs their code, the interpreter executes it line by line. If there is a syntax or runtime error, the program stops immediately and reports the error and the line number where it occurred. [1 mark] This makes it very easy for a learner to quickly identify and fix mistakes without needing to recompile an entire program. [1 mark]
How it all connects
The big idea sits in the middle — tap a linked idea to explore the link.
Tap a linked idea to see how it connects back to the main topic — that connection is what examiners reward.
Glossary
Try to recall each definition before you reveal it.
Quick check
Answer in your head first — then tap to check. No pressure.
Revision flashcards
Flip the card. Test yourself before the exam.
What is a language translator?
A program that converts source code written in a programming language into machine code or another target language that a computer can execute.
Key takeaways
Review these before you close the topic — retrieval beats re-reading.
- ✓
Compiler: Scans the entire program first. It translates the whole source code into a standalone executable file (object code). This file can be run multiple times without re-compilation. Any errors are reported all at once after the entire scan.
- ✓
Interpreter: Processes the program line by line. It translates and executes the first line, then the second, and so on. It does not create a separate executable file. An error will halt execution at the line where the error occurred.
- ✓
Execution Speed: Compiled programs generally run much faster because the translation is already done. Interpreted programs are slower as translation happens during execution.
- ✓
Distribution: Compiled programs are easy to distribute as a single executable file. The end-user does not need the compiler. Interpreted programs require the user to have the interpreter installed.
- ✓
Debugging: Interpreters are often better for debugging as they pinpoint errors on the exact line they occur. Compilers report a list of errors which can sometimes be harder to trace back to the original cause.
- ✓
Platform Dependence: A compiled executable is specific to a CPU architecture and operating system. An interpreted program can run on any platform that has the correct interpreter available.
Practice — then mark it
The whole point: a real Cambridge question, marked mark-by-mark.
Test Your Knowledge on Language Translators
Test Your Knowledge on Language Translators
Extra simulations & links
PhET, GeoGebra and other curated tools — open in a new tab.
Frequently asked
Checkpoint
One marked question is worth ten re-reads — close the loop before you move on.
Reading it isn’t knowing it — prove it.
Before you move on: do Test Your Knowledge on Language Translators on paper, snap a photo, and get examiner-style feedback on exactly where you win and lose marks.