This is the last lesson in the OCR J277 GCSE Computer Science course. Complete it and you've covered the entire specification!
Why Are Translators Needed?
The CPU can only directly execute machine code (binary 0s and 1s). Programs written in high-level languages (Python, Java) or assembly language must be translated into machine code before the CPU can run them. Three types of translator exist: compiler, interpreter, and assembler.
Compiler
Compiler
A compiler translates the entire high-level language source code into machine code all at once, before the program runs. The output is an executable file (e.g. .exe) — the original source code is no longer needed to run the program.
✅ Advantages: Compiled programs run faster (no translation at runtime); source code is not needed to distribute the program (protects intellectual property); all errors are reported together at the end of compilation (easier to review); optimisations applied during compilation improve performance.
❌ Disadvantages: All errors are reported at the end — harder to debug during development; full recompilation needed after every change; compiled code is platform-specific (a Windows .exe won't run on Mac without recompiling); compilation takes time before the program can first run.
Examples of compiled languages: C, C++, Rust, Go. Java uses a hybrid approach (compiled to bytecode, then interpreted by JVM).
Interpreter
Interpreter
An interpreter translates and executes the source code line by line at runtime. There is no separate compilation step — the interpreter reads one line, translates it, executes it, then moves to the next. The source code must be present every time the program runs.
✅ Advantages: Easier to debug — stops at the first error and shows exactly which line failed; no compilation step means faster to test changes (just run the code); more portable — the same source code runs on any machine with the right interpreter; useful for testing and development.
❌ Disadvantages: Slower execution — translation happens at runtime every time the program runs; source code must be distributed with the program (exposes intellectual property); stops at the first error, so all subsequent errors remain hidden until earlier ones are fixed.
Examples of interpreted languages: Python, JavaScript (traditionally), Ruby, PHP.
Assembler
Assembler
An assembler translates assembly language (mnemonics like ADD, MOV, LDD) into machine code. Unlike a compiler which handles a many-to-many translation, an assembler works on a one-to-one basis — each assembly mnemonic translates to exactly one machine code instruction.
✅ Direct translation — one mnemonic → one machine code instruction; produces highly efficient, compact machine code; essential for programming hardware at a low level.
❌ Still produces processor-specific machine code; assembly is harder to write than high-level languages.
Comparison Table — Compiler vs Interpreter
Feature
Compiler
Interpreter
Translation timing
Before execution (all at once)
During execution (line by line)
Execution speed
Faster (already translated)
Slower (translates at runtime)
Error reporting
All errors at end of compilation
Stops at first error — shows exact line
Debugging
Harder — errors listed at end
Easier — immediate feedback per line
Source code distribution
Not needed to run .exe
Must distribute source code
Best for
Finished software, performance-critical apps
Development, testing, scripting
Examples
C, C++, Rust
Python, JavaScript
Summary — All Three Translators
Translator
Input
Output
Timing
Ratio
Assembler
Assembly language
Machine code
Before execution
1:1 (mnemonic → instruction)
Compiler
High-level language
Machine code (.exe)
Before execution
Many:Many (one line → many instructions)
Interpreter
High-level language
Executed directly (no file saved)
During execution
Line by line at runtime
Exam tip: The most tested comparison is compiler vs interpreter. Remember: compiler = fast execution, all errors at end, no source needed; interpreter = slow execution, stops at first error, source code always needed. For assembler: it translates assembly → machine code, one-to-one. A common 6-marker asks you to compare compiler and interpreter — give 3 differences with advantages of each.
⚠️ Common Mistakes
Saying compilers are slower than interpreters — compiled programs run FASTER (but compilation itself takes time)
Saying interpreters save the machine code to a file — they don't; they translate and execute line by line without saving
Confusing assembler with compiler — assembler translates ASSEMBLY language (mnemonics), not high-level languages
Saying an interpreter "finds all errors" — it stops at the FIRST error; subsequent errors are hidden
Forgetting that an interpreter needs the SOURCE CODE every time the program runs — it's not compiled to an .exe
✅ Notes completed!
▶
Video coming soon
Click slide or press arrow keys to navigate
Worksheet — 2.5.2b Translators
8 questions · 23 marks
Q1What is the purpose of a translator program?[1]
✅ Mark scheme
To convert (translate) source code written in a high-level or assembly language into machine code that the CPU can directly execute [1].
Q2Explain how a compiler works and state two advantages it has over an interpreter.[4]
✅ Mark scheme
A compiler translates the entire source code into machine code all at once before execution [1]. Advantages — any two from: Compiled programs run faster (no translation at runtime) [1]; Source code not needed to run the compiled program (protects IP) [1]; Optimisations applied during compilation improve performance [1].
Q3Explain how an interpreter works and state two advantages it has over a compiler.[4]
✅ Mark scheme
An interpreter translates and executes source code line by line at runtime [1]. Advantages — any two from: Stops at the first error and shows exactly which line failed (easier debugging) [1]; Faster development cycle — no compilation step, just run and test [1]; More portable — same source runs anywhere with the right interpreter [1].
Q4Explain what an assembler does. How does it differ from a compiler?[3]
✅ Mark scheme
An assembler translates assembly language (mnemonics) into machine code [1]. Difference 1: it translates assembly, not a high-level language [1]. Difference 2: it works on a one-to-one basis — each mnemonic translates to exactly one machine code instruction, whereas a compiler converts one high-level statement into many machine code instructions [1].
Q5A programmer releases a Python game. Their friend wants to play it but doesn't have Python installed. Explain why this is a problem and how it relates to how Python is translated.[3]
✅ Mark scheme
Python is an interpreted language [1]. The interpreter translates the code line by line at runtime — this means the Python interpreter must be installed on the machine to run the program [1]. Without the interpreter, the source code cannot be translated and executed [1]. (Unlike a compiled language where the .exe runs without the original translator.)
Q6A program compiled with a C++ compiler produces a .exe file. A program run in Python needs the Python interpreter. State one advantage of the compiled approach and one advantage of the interpreted approach.[2]
✅ Mark scheme
Compiled advantage: the .exe runs without needing the compiler — faster execution, source code protected [1]. Interpreted advantage: the Python programmer can see exactly which line failed when an error occurs, making debugging easier [1].
Q7Why might a software company choose to compile their software before releasing it to customers, rather than distributing the source code for an interpreter to run?[2]
✅ Mark scheme
Customers do not need the source code to run a compiled .exe — this protects the company's intellectual property / prevents copying [1]. Compiled programs also run faster as no translation is needed at runtime, providing a better user experience [1].
Q8Compare how a compiler and an interpreter handle errors in a program that has five syntax errors. Include what each reports and when.[4]
✅ Mark scheme
Compiler: translates the whole program first, then reports all five errors together at the end of compilation [1]. The programmer can review all errors at once and fix them before running [1]. Interpreter: stops at the very first error encountered and reports that line [1]. The programmer fixes it and reruns — the interpreter then reaches error 2, stops again, etc. Only one error visible at a time [1].
?
out of 23 — self-mark above
Topic Quiz
Question 1 of 15
You scored
out of 15
🎓 OCR J277 Component 2 complete!
Card 1 of 8
Click to reveal definition
🎉
All terms complete!
Term
Definition
🎯
Mini Test — 2.5.2b Translators
10 questions · 21 marks · 10 minutes
⏱ 10:00
21 marks
Section A — Multiple Choice [5 marks]
Q1A compiler translates source code...
Q2Which translator is used to convert assembly language into machine code?
Q3An interpreter encounters an error on line 7 of a 50-line program. What happens?
Q4Which of the following is an advantage of a compiled program over an interpreted program?
Q5Python is an interpreted language. Which of the following must be true?
Section B — Short Answer [16 marks]
Q6State two advantages of using an interpreter compared to a compiler.
Mark schemeAny two: Stops at first error — easier to debug [1]; No compilation step — faster to test changes during development [1]; More portable — same source code runs anywhere with the interpreter installed [1].
Q7A company writes a game in C++. Explain why they would compile it before releasing it to customers.
Mark schemeCompiled programs run faster — no translation at runtime [1]. Customers receive only the .exe file — the source code is not distributed, protecting intellectual property [1]. Customers do not need the compiler installed to run the game [1].
Q8Explain what an assembler does and how it differs from a compiler. State the ratio of input to output instructions.
Mark schemeAn assembler translates assembly language (mnemonics) into machine code [1]. Difference: assembler translates assembly, not high-level language [1]. Ratio: one-to-one — each mnemonic produces exactly one machine code instruction [1]. A compiler's ratio is many-to-many (one high-level line → many machine code instructions) [1].
Q9A program has five errors. Compare what a compiler and an interpreter would each report, and when.
Mark schemeCompiler: translates the entire program, then reports all five errors at the end [1]. Interpreter: stops at the first error, reports it, and does not continue — subsequent errors only discovered one at a time as each preceding error is fixed [1]. The compiler approach lets programmers fix all errors at once [1]; the interpreter approach makes it clearer exactly where each individual error is [1].
Q10Why do compiled programs generally run faster than interpreted programs?
Mark schemeCompiled programs have already been translated into machine code before they run [1]. The CPU executes the machine code directly with no translation overhead [1]. An interpreted program must be translated line by line each time it runs, adding processing time for every instruction [1].
MCQ Score
—
🎓 You've completed the OCR J277 Component 2 course!