SLIDE 1 / 10
CSZone.co.uk
Click anywhere to advance · Arrow keys also work
AQA 7517 · Paper 2 · 4.6.3b

Compiler, Interpreter
& Assembler

Translators · Language levels · Compilation stages · Section 4.6

WHAT YOU'LL LEARN
Assembler · Compiler stages · Interpreter · Comparison · JIT compilation
AQA SPEC LINK
4.6.3 — Assemblers, compilers, interpreters; stages of compilation
Why Translators?

The Problem: CPU Speaks Binary

CPUs only execute machine code — sequences of 0s and 1s. Humans write in high-level languages (Python, Java) or assembly. A translator converts between them.
High-level language → Machine code: Compiler or Interpreter
Assembly language → Machine code: Assembler
Machine code: directly executed by CPU, no translation needed
Assembler

Assembler

Assembly language — low-level language using mnemonics (ADD, LDA, STO) that map almost 1:1 to machine code
Assembler translates assembly mnemonics into machine code binary instructions
One-to-one translation — each assembly instruction becomes one machine code instruction
Used for device drivers, embedded systems, OS kernels where performance is critical
Machine-specific — assembly for x86 won't run on ARM without rewriting
Compiler

How a Compiler Works

A compiler translates the entire source code into a machine code executable before running. The executable can then run independently without the compiler.
Fast execution — fully optimised machine code
Source code not needed to run the program (IP protection)
All errors reported at once — compiler lists all errors before any code runs
Examples: C, C++, Rust (compile to native .exe or binary)
Compilation Stages

Stages of Compilation

1. Lexical Analysis
Source code → tokens (keywords, identifiers, operators, literals). Removes comments and whitespace.
2. Syntax Analysis (Parsing)
Tokens → parse tree. Checks grammar rules (e.g. correct brackets, valid statements). Generates syntax errors.
3. Semantic Analysis
Checks meaning — type checking, undeclared variables, incompatible operations.
4. Code Generation & Optimisation
Parse tree → machine code. Optimiser removes redundant code, improves performance.
Interpreter

How an Interpreter Works

An interpreter translates and executes source code line by line at runtime. No standalone executable is produced.
Slower execution — translation happens every time the program runs
Stops at first error — reports error immediately on the line where it occurs
Easier debugging — instant feedback; ideal for development and scripting
Source code needed every time — less IP protection
Examples: Python (CPython), JavaScript (V8), Ruby
JIT Compilation

Just-In-Time (JIT) Compilation

JIT combines both approaches — code is compiled at runtime, just before execution
Frequently executed code ("hot paths") is compiled to native machine code and cached
Better performance than pure interpretation; more flexible than ahead-of-time compilation
Used by: Java (JVM), C# (.NET CLR), modern JavaScript engines (V8, SpiderMonkey)
Comparison

Compiler vs Interpreter

FeatureCompilerInterpreter
TranslationAll at once before runLine by line at runtime
SpeedFaster executionSlower
ErrorsAll reported at onceStops at first error
Source needed?No (after compiling)Yes (every time)
AQA Exam Style

Practice Question

AQA 7517 — Paper 2 Style
(a) Describe the difference between a compiler and an interpreter. [4]
(b) List the four stages of compilation in order. [2]
(c) Explain ONE advantage of using an interpreter over a compiler during program development. [1]
(d) State what an assembler does and give ONE use case for assembly language. [2]
[9 marks]
4 marks
(a) Compiler translates all source code before execution [1] producing a standalone executable [1]; Interpreter translates and executes line by line at runtime [1] and requires source code each run [1]
2 marks
(b) Lexical analysis → Syntax analysis → Semantic analysis → Code generation [2 for all 4 in order, 1 for 3 correct]
1 mark
(c) Interpreter stops at the first error and reports it immediately — easier to debug/locate errors during development
2 marks
(d) Assembler translates assembly language mnemonics into machine code [1]. Use: device drivers, embedded systems, OS kernel routines where maximum performance/hardware control is needed [1]
Summary

Key Points to Remember

Assembler — assembly language → machine code; 1:1 mapping; used for low-level programming
Compiler — entire program → machine code executable; fast; all errors at once
Interpreter — line-by-line at runtime; slow; stops at first error; good for debugging
Compilation stages — Lexical → Syntax → Semantic → Code generation
JIT = hybrid; compiles hot paths at runtime; used in Java, C#, modern JS engines
🎉 Lesson complete — move to the quiz!