Menu

A translator is a program that converts code written by a programmer into machine code, so that it can be executed. Without one, the instructions a programmer types would just sit in a file and never run.

Why a translator is needed

A processor can only execute machine code — the binary patterns that make up its own instruction set. It cannot act on a readable statement such as score = score + 5, because that is not one of its instructions. So every program written in a high-level language, and every one written in assembly language, has to be turned into machine code before it can run — and that is the translator's job.

Think of two people who speak different languages: the programmer writes in something a person can read, the processor only understands machine code, and the translator sits in between turning one into the other.

Code the programmer writesCan the processor execute it directly?Does it need translating?
Machine codeYesNo — it is already in the right form
Assembly languageNoYes
High-level languageNoYes

Source code

The code written by the programmer is called the source code. It is the version a person can read, edit and store. The translator takes that source code as its input and turns it into machine code the processor can carry out. The two are versions of the same program: one written for a person to read and change, and one written for the processor to carry out.

Source code is translated by a compiler into machine code, which is saved to storage and run by the processor with no source code or compiler needed; an interpreter produces no executable file.

Two types of translator

For high-level languages there are two types of translator: the compiler and the interpreter. Both turn high-level source code into machine code the processor can carry out, but they go about the job in different ways.

Practise this