Computer systems and networks · GCSE Computer Science

Compilers and interpreters

GCSE Computer Science compilers and interpreters: translate high-level code to machine code, compile-time versus run-time translation, and when each translator is used.

UNDERSTANDRETRIEVEREMEMBER
THE MEMORY HOOK
Compiler translates the whole program before run — one executable. Interpreter translates line by line during run — slower per line, easier to debug.

The important bits

What you need to know

  1. 1

    High-level languages need translation because the CPU executes machine code (binary), not Python or Java syntax directly.

  2. 2

    A compiler translates the entire source program into machine code before execution, producing an executable file.

  3. 3

    An interpreter reads each line, translates it, and runs it immediately — no separate executable file is saved.

  4. 4

    Compiled programs generally run faster after translation because optimisation happens once. Interpreted programs re-translate every run.

  5. 5

    Interpreter errors stop at the first problem line; a compiler lists all syntax errors before run if it fails to compile.

  6. 6

    Some languages use both: Java compiles to bytecode, then the JVM interprets or JIT-compiles bytecode at runtime.

  7. 7

    Embedded systems and performance-critical software often use compiled C/C++. Scripting and teaching often use interpreted Python.

  8. 8

    Translation is part of the development cycle: write source → translate → execute. Debug → edit source → translate again.

Quotations worth analysing

Short evidence. Real method.

Compiler: whole program before execution
GCSE translator comparison

One shot translation. Students who say a compiler runs line by line have described an interpreter. The executable can run without the source present.

Interpreter: translate and execute each line
GCSE translator comparison

Line-by-line at runtime. Easier to test small changes without a full recompile, but repeated work each run.

Machine code is the only language the CPU runs
Why translation exists

High-level code is for humans. Translators bridge to binary. Without them, programmers would write in opcodes.

Go deeper

Compiler workflow

Developer writes C source. Compiler scans entire file: if syntax errors, no executable. If valid, compiler outputs machine code object file, linker may combine modules into .exe. User runs .exe — CPU fetches binary directly. No source needed on the machine. Optimisation passes reorder instructions for speed. Error example: missing semicolon — compiler reports before any run. Large projects: compile time can be minutes; run time is fast. GCSE contrast: compiled code does not need the translator installed on the end-user PC, only the executable (unless dynamic linking).

Go deeper

Interpreter workflow

Python REPL: type line, interpreter parses and runs immediately. Script file: read line 1, translate, execute; line 2, translate, execute. Stops at line with error — lines below never run. No .exe produced; need interpreter installed to run .py. Advantage: portable source, cross-platform if interpreter exists. Disadvantage: slower loops because body re-interpreted each iteration unless bytecode cache (CPython .pyc) helps. Debugging: print statements and incremental testing fit interpreted flow. GCSE exam: name translator, state compile-all versus line-by-line, give one advantage of each.

Go deeper

Choosing in practice

Games engines, operating systems kernels — compiled for speed. Web servers might mix interpreted PHP with compiled modules. Education: Blockly to pseudocode to Python interpreted. Security: compiled malware is harder to read without disassembly; interpreted source may sit on disk readable. Not always GCSE but shows why both exist. Hybrid JVM: compile once to bytecode (portable), JIT hotspot compiler compiles hot loops to native code at runtime — best of both worlds at complexity cost.

WORKED EXAMPLE

See the idea in action

Compare running a C program and a Python script. C: write hello.c → compiler produces hello.exe → double-click runs machine code. No C compiler needed on PC. Python: write hello.py → run python hello.py → interpreter reads each line each time. Python must be installed. If hello.c has a syntax error on line 50, compiler refuses entire build. If hello.py has error line 5, lines 1–4 may have run in interactive mode; in script mode stops at 5. C loop runs native add instructions. Python loop re-interpreted unless bytecode cached.

Exam technique

Turn knowledge into marks

Table answer: Compiler — whole program, before run, executable, faster run, harder to debug line by line. Interpreter — line by line, at run, no exe, slower, stops at error line.

Common mistakes

Do not give these marks away

  1. 01

    Saying a compiler translates during execution line by line.

  2. 02

    Claiming interpreted code never needs translation — it translates at runtime.

  3. 03

    Stating the CPU runs Python directly without any translator.

QUICK RETRIEVAL

Which translator produces an executable file before the program runs?

ACompiler

BInterpreter

CAssembler only at runtime

DDebugger

Show the answer

Compiler. Compiler translates the full source ahead of execution into machine code / executable. Interpreter translates during execution without saving a full executable.

Quick questions

If this is the bit you searched

What is the difference between a compiler and an interpreter?

Compiler translates the entire program before run into machine code. Interpreter translates and executes each line at runtime.

Why translate high-level code?

CPUs execute machine code. High-level languages are human-readable; translators convert to binary the processor understands.

Is Python compiled or interpreted?

Most GCSE answers: interpreted at runtime (with bytecode caching). Technically CPython compiles to bytecode first — hybrid detail beyond most mark schemes.

Which is faster to run?

Generally compiled machine code runs faster because translation and optimisation happen once. Interpreted code re-translates each run.