Translators
Any programSequences of instructions for a computer. written in a high-level languageAlso known as high level language. This is a computer programming language used to write programs. High-level languages need to be translated into machine code through a compiler, interpreter or assembler. is known as source codeThe code behind a computer program, written in a programming language.. However, computers cannot understand source code. Before it can be run, source code must first be translated into machine codeA low level language that on the surface makes very little sense..
A translatorProgram translators convert program code into machine code to be executed by the CPU. There are three types of translator: interpreter, compiler and assembler. is a program that converts source code into machine code. Generally, there are three types of translator:
- compilerA program that translates high-level programming languages into machine code.
- interpreterA program that translates high-level programming languages into machine code. Programs can either be interpreted or compiled.
- assemblerA program that translates assembly languages into machine code.
Compilers
A compiler takes the source code as a whole and translates it into machine code all in one go. Once converted, the machine code can be run at any time. This process is called compilationThe process of translating source code into machine code all in one go. The program can then be executed as a whole..
Compilers have several advantages:
- Compiled programs run quickly, since they have already been translated.
- A compiled program can be supplied as an executableA program that can be run without the need for an interpreter. file. An executable file is a file that is ready to run. Since an executable file cannot be easily modified, programmers prefer to supply executables rather than source code.
- Compilers optimiseTo make a program more efficient. A program can be optimised to run quicker, or to take up less memory. code. Optimised code can run quicker and take up less memoryThe part of a computer that stores data. space.
Compilers have several disadvantages:
- The source code must be re-compiled every time the programmer changes the program.
- Source code compiled for one platform will not run on another - the machine code is specific to the CPU/processorCentral processing unit - the brain of the computer that processes program instructions. architecture.
Interpreters
An interpreter translates source code into machine code one instructionA single action that can be performed by a computer processor. at a time. It is similar to a human translator translating what a person says into another language, sentence by sentence, as they speak. The resulting machine code (sometimes called object code) is then executed immediately. The process is called interpretationThe process of translating source code into machine code one instruction at a time. Each instruction is then executed..
Interpreters have several advantages:
- Instructions are executed as soon as they are translated.
- Errors can be quickly spotted - the moment an error is found, the program stops running and the user is notified at which part of the program the interpretation has failed. This makes interpreters extremely useful when developing programs.
Interpreters also have several disadvantages:
- Interpreted programs run more slowly as the processor has to wait for each instruction to be translated before it can be executed.
- Additionally, the program has to be translated every time it is run.
- Interpreters do not produce an executable file that can be distributed. As a result, the source code program has to be supplied, and this could be modified without permission.
- Interpreters do not optimise code - the translated code is executed as it is.
Assemblers
Assemblers are a third type of translator. The purpose of an assembler is to translate assembly languageA low-level programming language closely related to machine language. Also called assembly code. into machine code. Whereas compilers and interpreters generate many machine code instructions for each high-level instruction, assemblers create one machine code instruction for each assembly instruction.
More guides on this topic
- Decomposition and abstraction - Edexcel
- Algorithms - Edexcel
- Further algorithms - Edexcel
- Truth tables - Edexcel
- Binary and data representation - Edexcel
- Computers - Edexcel
- Networks - Edexcel
- Network security and cybersecurity - Edexcel
- Encryption - Edexcel
- Environmental, ethical and legal concerns - Edexcel