SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 1 · Topic 1.5.3

Translators

Assembler · Compiler · Interpreter · Stages of Compilation

CSZone Cambridge International AS & A Level Computer Science 9618
Assembler

Translating Assembly Language → Machine Code

An assembler converts assembly language (mnemonics like LDM, ADD, STO) into machine code (binary). Unlike a compiler, there is a near 1-to-1 relationship — one mnemonic → one machine code instruction.
TWO-PASS ASSEMBLY
Pass 1: scans all code, builds symbol table (maps labels → memory addresses). Pass 2: translates instructions, resolving all label references using the symbol table.
OUTPUT
Machine code object file. Can be directly executed by the CPU. Platform-specific: must be reassembled for different CPU architectures.
Compiler

Whole-Program Translation Before Execution

A compiler translates the entire high-level language source code into machine code in one go, before execution. The resulting executable file runs directly without needing the compiler again.
Produces a standalone executable — faster at runtime (no translation overhead)
Comprehensive error checking before any code runs — all syntax errors shown at once
Code is optimised during compilation — compiler applies optimisations to improve performance
Platform-specific — must be recompiled for different operating systems or CPU architectures
Compilation can be slow — not ideal for rapid development/testing
Stages of Compilation

From Source Code to Machine Code

1. Lexical Analysis — tokenises source code: removes comments and whitespace; identifies tokens (keywords, identifiers, operators, literals); builds symbol table
2. Syntax Analysis (Parsing) — checks tokens obey grammar rules; builds abstract syntax tree (AST); reports syntax errors
3. Semantic Analysis — checks meaning: type checking, variable declarations, scope rules; detects semantic errors (e.g. adding string to integer)
4. Code Generation — converts AST to intermediate code then to target machine code
5. Code Optimisation — improves efficiency: remove redundant code, improve loops, register allocation; done at multiple stages
Interpreter

Line-by-Line Translation and Execution

An interpreter translates and executes source code one line at a time. No separate executable is produced — the interpreter must be present each time the program runs.
ADVANTAGES
Immediate error feedback — stops at first error
Easier to debug — can test line by line
Platform independent (if interpreter available)
Good for scripting and rapid prototyping
DISADVANTAGES
Slower execution — translation overhead every run
Interpreter must be installed on target machine
Source code exposed — not protected
Cannot distribute compiled binary
Compiler vs Interpreter Comparison

Key Differences

FeatureCompilerInterpreter
TranslationWhole program at onceLine by line during execution
OutputStandalone executableNo separate file produced
Execution speedFaster (pre-translated)Slower (translates every run)
Error reportingAll errors at compile timeStops at first error found
DistributionShare executable (no source)Must share source code
PortabilityPlatform-specific executablePortable (interpreter needed)
DebuggingHarder (all errors at once)Easier (line-by-line testing)
Exam Practice

Cambridge-style questions

Question 1
A student is learning to program and wants to test code frequently. Explain whether a compiler or an interpreter is more suitable, giving two reasons.
4 marks
1 mark
An interpreter is more suitable for learning and testing
1 mark
Reason 1: The interpreter stops immediately at the first error and reports it — easier to identify and fix mistakes one at a time
1 mark
Reason 2: No separate compilation step needed — code can be run and tested immediately after writing each line
1 mark
Compiler reports all errors at once which can be overwhelming for a beginner; also requires a full compilation cycle before testing
Common Mistakes

Don't lose easy marks

1
Saying a compiler is always better than an interpreter — for development and testing, an interpreter is often better. Compilers are better for final deployment (speed, security). Context matters in exam answers.
2
Saying an interpreter produces an executable file — it does NOT. An interpreter translates and executes directly, producing no output file. Only a compiler produces a separate executable.
3
Forgetting that an assembler is also a type of translator — some exam questions ask "name three types of translator": the answer is assembler, compiler, interpreter. Students often only name two.
Topic Summary — 1.5.3

What You Need to Know

ASSEMBLER
Assembly → machine code. 1-to-1 mapping. Two-pass: symbol table then translate.
COMPILER
Translates all at once → executable. Faster at runtime. Stages: lexical → syntax → semantic → code gen → optimise.
INTERPRETER
Line by line, no output file. Stops at first error. Slower but easier to debug. Good for learning/scripting.
COMPILATION STAGES
1. Lexical: tokenise, symbol table
2. Syntax: grammar/AST, syntax errors
3. Semantic: meaning/type checks
4. Code generation: intermediate/machine code
5. Optimisation: improve efficiency
CSZone

Next Video

1.5.4
High & Low Level Languages
Features · Comparison · Generations · When to Use Each
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools