Languages
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.
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 writes | Can the processor execute it directly? | Does it need translating? |
|---|---|---|
| Machine code | Yes | No — it is already in the right form |
| Assembly language | No | Yes |
| High-level language | No | Yes |
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.
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.
OCR GCSE Computer Science · Languages
OCR GCSE Computer Science · Integrated Development Environments