Translators
A translator is a program that converts source code into machine code so that a processor can carry out the instructions. You write in a language that suits a person: meaningful names such as pupil_total, and English-like words such as if and while. A processor, however, only carries out machine code, which is a pattern of binary instructions. Code that has not been translated cannot run at all, which is why every program you write must be translated before it can run.
| Translator | What it takes in | What it produces |
|---|---|---|
| Compiler | High-level source code, translated as a whole program in one go | Machine code, saved as an object code file that can be run later |
| Interpreter | High-level source code, taken one line at a time | No saved file: each line is translated and then run straight away |
| Assembler | Assembly language, a low-level language written one instruction per line | Machine code |
A compiler and an interpreter both start from the same thing, high-level source code, and both produce machine code instructions for the processor. The difference is the order in which they work. A compiler translates the entire program first, and only then is the finished program run. An interpreter translates the first line, runs it, translates the second line, runs it, and carries on like that to the end.
Picture a program of 40 lines. A compiler works through all 40 lines, produces one complete machine code file, and the program starts afterwards. An interpreter turns line 1 into machine code and carries it out at once, then does the same for line 2, so the program is already doing something while the later lines are still untranslated.
The third kind of translator is the assembler, and it is different again because of what it starts with. Assembly language sits close to the processor: one line, such as ADD 12, matches a single machine code instruction, so the assembler swaps each line for the matching binary instruction without any restructuring.
Edexcel GCSE Computer Science · Translators