Language translators

Computer Science AS · System software. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science AS topics

The idea

A processor can only run machine code, so every program written in another language needs a translator. An assembler translates assembly language (mnemonics) into machine code. A compiler and an interpreter both translate a high-level language, but they work in different ways.

A compiler translates the whole program before it is run and produces an executable file. An interpreter translates and runs one statement at a time and produces no executable file. Some languages, such as Java, use both: the source code is compiled to bytecode, then a virtual machine interprets the bytecode.

An IDE is software that gives the programmer an editor, a translator and debugging tools in one place.

In simpler words

A CPU only runs machine code. So other code must be translated. An assembler translates assembly language. A compiler translates a whole high-level program first and makes a file you can run. An interpreter translates and runs one line at a time and makes no such file. Java uses both. An IDE puts an editor, a translator and debugging tools in one place.

An everyday comparison

A compiler is like translating a whole book before anyone reads it: slow to prepare, but readers then go fast without the translator. An interpreter is like a live interpreter at a meeting, translating sentence by sentence and stopping at the first problem. The comparison stops working because a compiler reports all errors after translating, and the output is an executable file the processor runs, not text for a person.

Rules to remember

Common mistake

Do not say that an interpreter produces an executable file or that compiled code needs the compiler to run. Only a compiler produces an executable, and after that the compiler is no longer needed.

In the exam

Compare compiler and interpreter point by point, in matching pairs: when translation happens, whether an executable is produced, how errors are reported (all together, or stop at the first), speed of running, whether the translator must be present. Then say when each suits: an interpreter during development, a compiler for the finished product. For IDE features, name the feature and what it does, e.g. breakpoint stops the program at a chosen line, single stepping runs one line at a time.

Worked example

A programmer is testing a new game and will later sell it to the public. Which translator suits each stage, and why?

  1. While testing, the programmer wants to find and fix errors quickly and run parts of the program. An interpreter stops at the line with the error, so it suits this stage.
  2. When selling, customers should not see or change the source code and should not need a translator. A compiler produces an executable file that meets both needs.
  3. The compiled executable also runs faster, which matters for a game.

Answer: Interpreter during development; compiler for the version that is sold.

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← Operating systemsData security →Take a Computer Science AS test