Software

Software

Programming languages and translators

Programming Languages and Translators Paper 1 10 min read

On this page
  1. In this note
  2. What you should already know
  3. High-level and low-level languages
  4. Assembly language and the assembler
  5. Compilers and interpreters
  6. Summary
  7. Ways they test it
  8. What the examiner looks for
  9. Past-paper questions, solved
  10. Common mistakes
  11. Practice
  12. Can I do this?
  13. Quiz

In this note

Syllabus 4.2 Types of programming language, translators and IDEs
  • 4.2.1Explain what is meant by a high-level language and a low-level language, including the advantages and disadvantages of each.
  • 4.2.2Understand that assembly language is a low-level language that uses mnemonics, and that an assembler translates it into machine code.
  • 4.2.3Describe the operation of a compiler and an interpreter: how each translates and how errors are reported.
  • 4.2.4Explain the advantages and disadvantages of a compiler and an interpreter.

Before this: Firmware and interrupts. Next: Integrated development environments (IDEs).

Part 1Learn the topic

The notes: every idea from the start, with our own examples.

What you should already know

Machine code

The CPU can only execute machine code: binary instructions from its instruction set.

Quick check: can the CPU run Python directly?

No: it must be translated into machine code first.

High-level and low-level languages

A high-level language is close to human language (English words and maths symbols), e.g. Python, Java, Visual Basic. A low-level language is close to the language processed by the computer: machine code (binary) or assembly language.

The same job at three levelsCode
high-levelTotal ← Price + Tax
assembly language (low-level)LDA Price
ADD Tax
STO Total
machine code (low-level)0001 1010
0011 1011
0010 1100
High-level languageLow-level language
advantageseasier to read, write and understand → fewer mistakes, written faster
easier to debug
machine independent (portable): runs on different types of computer
programmer can focus on the problem, not the hardware
direct manipulation of the hardware / memory
more memory efficient, faster to execute
can use specialised / machine-specific instructions
(machine code) needs no translator
disadvantagescannot directly manipulate the hardware
may be less efficient (uses more memory, slower)
needs a compiler or interpreter
hard to read and write
hard to debug
machine dependent: only works on one type of CPU
needs knowledge of the hardware
Choosing: a program that must be written quickly, be easy to maintain or run on many computers → high-level. A program that must control hardware directly, use little memory or run very fast (e.g. an embedded system in a vending machine) → low-level.

Assembly language and the assembler

Assembly language is a low-level language that uses mnemonics: short codes such as LDA (load), ADD, STO (store) that stand for machine code instructions. Each assembly instruction usually matches one machine code instruction. An assembler is the translator that converts assembly language into machine code.

Compilers and interpreters

High-level codePython, Java …compiler orinterpreterAssembly languagemnemonicsassemblerMachine codebinary, runs on the CPU
Every program must become machine code before the CPU can execute it.
CompilerInterpreter
how it translatestranslates the whole code at once before executing ittranslates and executes the code line by line
outputproduces an executable file (object code) that runs without the compilerno executable file: the interpreter is needed every time it runs
errorsproduces an error report for the whole code, listing all errors; nothing runs until they are fixedstops execution when an error is found; once it is corrected, execution can continue from that point
speed of runningthe executable runs fast (already translated)slower: every line is translated each time it runs
best usedto translate the final program for distribution (the source code is not given away)while developing a program: test and debug parts as you go
Advantages of an interpreter during developmentAdvantages of a compiler for the final program
errors are found line by line, where they happen → easy to debug
can correct and continue without retranslating everything
can test sections of incomplete code
executable file runs without the translator
runs faster
users cannot see the source code (harder to copy)
all errors reported at once

Try it yourself

1
Which translator converts assembly language into machine code?
Show answer

Answer Assembler

2
Which translator produces an executable file?
Show answer

Answer Compiler

3
Which translator stops when it finds an error?
Show answer

Answer Interpreter

4
Is a high-level language machine dependent or independent?
Show answer

Answer Independent

Summary

  • High-level: close to English; easy to read, write, debug; machine independent; can't manipulate hardware directly.
  • Low-level (machine code, assembly): close to the computer; direct hardware control, memory efficient, fast; hard to read/debug, machine dependent.
  • Assembly language uses mnemonics; an assembler translates it.
  • Compiler: whole code at once, executable file, error report of all errors; used for the final program.
  • Interpreter: line by line, stops at an error, no executable; used during development.

If you see …

  • "describe the operation of a compiler and of an interpreter"whole code / executable / error report vs line by line / stops at error
  • "explain the reasons for your choice" (high or low)match each reason to the scenario: "… so the game can run on any computer"
Part 2How it is examined

Question types, what the examiner gives marks for, and real past-paper questions solved.

Ways they test it

Type 1 Choose a level

"Tick high-level or low-level. Explain the reasons for your choice" [4]

Spot it a scenario.

  1. No mark for the tick: all four marks are for reasons that match it.

Type 2 Low-level / assembly

"Describe what is meant by assembly language" [2]; "identify the translator" [1]

Spot it "assembly".

  1. low-level · mnemonics · communicates directly with hardware · assembler

Type 3 Which translator?

"Identify the translator that converts and executes line by line / creates an executable" [1] each

Spot it a description.

  1. line by line / stops → interpreter; whole code / executable / error report → compiler; mnemonics → assembler.

Type 4 Translator cloze

"A compiler translates the … at once before … it …" [5]

Spot it a word list.

  1. Use the compiler / interpreter table.

Type 5 Advantages

"Describe the advantages of using an interpreter instead of a compiler during software development" [4]

Spot it "during development".

  1. Line by line errors · correct and continue · no retranslating · test sections.

What the examiner looks for

"Describe how the compiler translates the program" [3] and "how it reports errors" [2]

Marking points (one mark each, up to the marks shown)

  • It translates the high-level language into low-level language / machine code / object code
  • It translates all the code before it is executed
  • It creates an executable file
  • It creates an error report after trying to compile … displaying all the errors in the code
  • … which must be corrected before the code can be executed

Keywords all the code before executed executable file error report

Past-paper questions, solved

0478/12/F/M/23 Q2Paper 1 · Computer systems8 marksFull size
High- or low-level for a 3D game; how a compiler and interpreter work

How to start The scenario says "developed as soon as possible", which points to high-level. Then give four reasons with their effect.

Show a full-mark answer and the mark scheme

(a) High-level language. It is easier for the programmer to read and write, so they make fewer mistakes and can write it in a shorter time. It is easier to debug, so errors are found and corrected faster. It is machine independent, so the game can be played on many different computers.

(b) Compiler: translates all the code before executing any of it, produces an executable file, and gives an error report listing all the errors. Interpreter: translates and executes one line at a time, and stops when it finds an error.

PartAnswer / workingMarksGuidance
2(a)No mark for choice. Any four matching reasons: easier to read / write … fewer mistakes / quicker · easier to debug … less time · machine independent … any computer (or low-level: memory efficient · direct manipulation …)B4
2(b)Compiler, two from: checks all code before executing · error report for whole code · executable file. Interpreter, two from: one line translated and executed at a time · stops at an errorB4
Total: 8 marks
2210/12/M/J/25 Q3Paper 1 · Computer systems5 marksFull size
Complete the statements about translators

How to start Five gaps, all from the compiler / interpreter table.

Show a full-mark answer and the mark scheme

A compiler translates the whole code at once before executing it. A compiler produces an error report that displays all errors. An interpreter translates and executes the code line by line. An interpreter stops execution when an error is found and continues once it is corrected.

PartAnswer / workingMarksGuidance
3(b)(i)whole code · executing · all · line by line · errorB5
Total: 5 marks
2210/12/O/N/25 Q3Paper 1 · Computer systems4 marksFull size
Assembly language for a coffee machine

How to start (a) two facts about assembly. (c) which option is a LOW-level advantage?

Show a full-mark answer and the mark scheme

(a) It is a low-level language that uses mnemonics.

(b) Assembler.

(c) B: it is memory efficient.

PartAnswer / workingMarksGuidance
3(a)Any two: low-level · mnemonics · communicates directly with the hardwareB2
3(b)AssemblerB1
3(c)BB1
Total: 4 marks

Common mistakes

  • ✗ "A compiler translates line by line"✓ "An interpreter translates line by line"
  • ✗ "An assembler translates high-level code"✓ "An assembler translates assembly language"
  • ✗ "High-level is easier" (no reason)✓ "easier to read and write, so fewer mistakes"Every reason needs its effect.
  • ✗ "Low-level languages are machine independent"✓ "High-level languages are machine independent"

Practice

Practice: easy, medium, hard

Easy

1
Give one example of a low-level language.
Show answer

Answer Assembly language (or machine code)

2
What are the short codes in assembly language called?
Show answer

Answer Mnemonics

Medium

1
Give two reasons a programmer might write a vending machine program in a low-level language.
Show answer

Answer Direct manipulation of hardware; more memory efficient (also faster, specialised hardware)

2
Give two disadvantages of a high-level language.
Show answer

Answer Cannot directly manipulate hardware; needs a translator (also less memory efficient)

Hard

1
A company sells a finished game. Explain why it is compiled rather than interpreted. [3]
Show answer

Answer Executable runs without the translator; runs faster; users cannot see / copy the source code

Can I do this?

Anything unticked: revise that section first. All ticked: take the quiz.

Quiz

The multiple-choice and guided questions need JavaScript. The concept checks and exam practice below work without it.

Your progress on this note is saved when JavaScript is on.

⬇️ Download this chapter as a PDF: Full notes