🔒
Unlock Everything
£7.99/month
or £59/year
Subscribe now →
💻 Component 2 · 2.5 Languages & IDEs
2.5.2b Translators — Compilers, Interpreters & Assemblers
OCR J277 · GCSE Computer Science · ~13 min read
Notes
Video
Slides
Worksheet
Quiz

🎓 Final Lesson — OCR J277 Component 2

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

FeatureCompilerInterpreter
Translation timingBefore execution (all at once)During execution (line by line)
Execution speedFaster (already translated)Slower (translates at runtime)
Error reportingAll errors at end of compilationStops at first error — shows exact line
DebuggingHarder — errors listed at endEasier — immediate feedback per line
Source code distributionNot needed to run .exeMust distribute source code
Best forFinished software, performance-critical appsDevelopment, testing, scripting
ExamplesC, C++, RustPython, JavaScript

Summary — All Three Translators

TranslatorInputOutputTimingRatio
AssemblerAssembly languageMachine codeBefore execution1:1 (mnemonic → instruction)
CompilerHigh-level languageMachine code (.exe)Before executionMany:Many (one line → many instructions)
InterpreterHigh-level languageExecuted directly (no file saved)During executionLine 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!
TermDefinition
🎯

Mini Test — 2.5.2b Translators

10 questions · 21 marks · 10 minutes

← 2.5.2a IDEs 🎓 Final lesson Back to Dashboard →