AQA GCSE CSPaper 2 · Unit 4Lesson 5

Paper 2 · Unit 4 · CS-L4-05

Programming Languages & Translators

60 minutes · AQA 8525 · Paper 2 — Computer systems

Spec & Goals 3 min

AQA Spec 3.4.4 · Programming languages and translators

By the end of this lesson you can:

  1. Describe the difference between a low-level and a high-level language.
  2. State what an assembler, a compiler and an interpreter each do.
  3. Compare a compiler and an interpreter and give one advantage of each.

Warm-Up 5 min

Last lesson you sorted software into system and application types. Code is written in a programming language — but the CPU only understands binary, so the code must be translated first.

Quick starter

Aiman writes a game in Python. The CPU cannot run Python directly. What must happen to the Python code before the processor can run it?

Reveal the idea

It must be translated into machine code (binary) that the CPU can run. A program that does this is called a translator.

Key Concept — languages and translators 14 min

A programming language is used to write instructions for a computer. Languages sit at two levels: low-level (close to the hardware) and high-level (close to English).

Low-level languages

Low-level languages are close to the way the processor works. There are two kinds.

Machine code runs directly on the CPU but is very hard for humans to read or write. Assembly language replaces binary with mnemonics, yet it is processor-specific — code for one CPU may not run on another.

High-level languages

High-level languages, such as Python, are closer to English.

They are easier to read, write and maintain, and the same program can run on different machines. The trade-off: a high-level program must be translated before the CPU can run it.

Translators

A translator converts source code into machine code. There are three types in the spec.

TranslatorWhat it does
AssemblerTranslates assembly language into machine code (one-to-one).
CompilerTranslates the whole high-level program into machine code in one go, producing an executable.
InterpreterTranslates and runs the program one line at a time.

Worked Example — compiler vs interpreter 12 min

Problem: A student must choose between a compiler and an interpreter for a high-level program. Compare the two so the choice is clear.

CompilerInterpreter
How it translatesThe whole program at onceOne line at a time
Output producedAn executable (machine-code) fileNo separate file — runs as it translates
Speed when runningFast — already machine codeSlower — translated again each run
Error reportingAll errors reported at the endStops at the first error / line by line
Best forFinished programs that must run fastWriting and debugging code

So a compiler suits a finished, distributed program that must run quickly. An interpreter suits development, because errors are found line by line as you go.

Try It Yourself 12 min

🟢 Easy

Goal: State one reason machine code is hard for humans to work with.

Hint: think about what machine code is actually made of.

🟡 Medium

Goal: Describe two differences between assembly language and a high-level language.

Hint: compare how readable each is and whether it is tied to one processor.

🔴 Stretch

Goal: A team is still developing a large program with frequent bugs. Recommend a compiler or an interpreter and justify your choice.

📝 Exam Practice 10 min

Answer the way the examiner expects — the command word and the marks tell you how much to write.

State[2 marks]

State one difference between a low-level and a high-level language.

Mark scheme
  • A low-level language is close to the hardware / machine code / processor-specific (1).
  • A high-level language is closer to English / easier to read and write / portable (1).
Describe[2 marks]

Describe one difference between a compiler and an interpreter.

Mark scheme
  • A compiler translates the whole program in one go (1).
  • An interpreter translates and runs the program one line at a time (1).
State[1 mark]

State what an assembler does.

Mark scheme
  • Translates assembly language into machine code (1).
Give[1 mark]

Give one advantage of a high-level language.

Mark scheme
  • Easier to read / write / understand / maintain, or portable (runs on different processors) (1).

Recap & Key Terms 3 min

Low-level languages (machine code and assembly) are close to the hardware; high-level languages are close to English and portable but need translating. An assembler translates assembly into machine code. A compiler translates a whole program at once and runs fast; an interpreter translates line by line and is easy to debug.

Low-level language
A language close to the hardware, such as machine code or assembly language.
High-level language
A language close to English that is easier to read and write, and is portable.
Machine code
Binary instructions the CPU can run directly, with no translation needed.
Assembly language
A low-level language using mnemonics, with a one-to-one link to machine code; processor-specific.
Compiler
A translator that converts a whole high-level program into machine code at once, producing an executable.
Interpreter
A translator that converts and runs a high-level program one line at a time.
Assembler
A translator that converts assembly language into machine code.

Homework 1 min

Task (≤ 15 min): A games studio in Penang ships a finished program to customers. State which translator it should use and give one reason why.

Model answer

A compiler, because it produces an executable that runs fast and does not need translating again each time it is run.

Award marks for: correct translator named — compiler (1); a valid reason — fast to run / produces an executable / no re-translation needed (1).