Compilers and interpreters Cambridge IGCSE Computer Science revision

Not started

Learn it

In plain words

A program written in a high-level language has to be translated into machine code before a processor can run it. There are two ways to do the job.

A compiler is like a translator who takes a whole book away and hands back the finished translation. An interpreter is like someone translating a speech as it is given, one sentence at a time.

7 things to know

  1. A compiler translates the whole of the code at once, before any of it is run. It produces an executable file.
  2. A compiler gives a report of all the errors in the whole code, if it finds any. No executable file is made until they are corrected.
  3. An interpreter translates and executes the code one line at a time. No executable file is produced.
  4. An interpreter stops when it finds an error, at that line. That makes errors easy to find and fix.
  5. A compiled program runs without the compiler and runs fast, and the source code does not need to be given to the user. But it must be compiled again after every change.
  6. An interpreted program needs the interpreter every time it runs, and it runs more slowly.
  7. So an interpreter is mostly used when developing a program, and a compiler is used to translate the final program.

Worked example

A student is writing and testing a new program. Later the finished program will be sold. Which translator suits each stage?

  1. While writing and testing: an interpreter. It stops at the line with the error, so each mistake can be fixed straight away without translating the whole program again.
  2. For selling: a compiler. It produces an executable file that runs fast, needs no translator on the buyer's computer, and keeps the source code private.

Tips and tricks

  • Do not say an interpreter "translates line by line" and stop. Say it translates and executes each line, and stops when it meets an error.
  • "Produces an executable file" is the key fact about a compiler. An interpreter never does.
5 questions, about 2 minutes.

It lands in your notebook with its questions as flashcards.

Compilers and interpreters: 5 questions and answers

These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.

  1. What does a compiler do?
    • translates and runs one line at a time
    • translates the whole program at once and produces an executable file (the answer)
    • runs machine code
    • finds viruses

    The executable file can then be run without the compiler.

  2. How does an interpreter report errors?
    • in a list at the end
    • it stops when it reaches an error (the answer)
    • it ignores them
    • it corrects them

    Execution stops at the line with the error.

  3. Which is an advantage of a compiled program?
    • It is easier to debug.
    • It runs without needing the translator. (the answer)
    • It never contains errors.
    • It can be changed without translating it again.

    The executable file is all the user needs.

  4. When is an interpreter mostly used?
    • while a program is being developed (the answer)
    • when the final program is sold
    • to translate assembly language
    • to compress a program

    It makes finding and fixing errors easier.

  5. Why does an interpreted program usually run more slowly?
    • It is longer.
    • Each line is translated every time the program runs. (the answer)
    • It uses more colours.
    • It has more errors.

    A compiled program has already been translated.

Still stuck on this one?Ask in the Papermunch Discord, or help someone else who is. Discord is for ages 13 and up.Join the server

Things you can type

Or go straight to

Or browse a shelf