Translators
In order for instructions to be executed by a computer's processor, they must be in the form of machine code. This means that programs written in assembly language or high-level languages need to be translated into machine code before they can be executed by a computer.
Types of Translators
There are three types of program translator: assemblers, compilers and interpreters.
Assemblers
Assemblers are used to convert assembly code into machine code. Because each assembly language instruction has a 1-to-1 relationship to a machine code instruction, translation between the two languages is fairly quick and straightforward.
Assemblers are platform specific, meaning that a different assembler must exist for each type of processor instruction set.
Compilers
Compilers are used to convert code written in a high-level language such as C# into machine code. Compilers take a high-level program as their source code, check it for any errors and then translate the entire program at once. If the source code contains an error, it will not be translated. Compilers are said to be platform specific as they produce machine code.
Once translated, a compiled program can be run without the requirement for any other software to be present. This is not the case with interpreters.
If a particular subroutine or method is never used at runtime, it is never compiled to machine code
Interpreters
An interpreter translates high-level languages into machine code line-by-line. Interpreters have procedures that can be used to translate each kind of program instruction. Instead of checking for errors before the translation begins, , interpreters check for errors as they go. This means that a program with errors in can be partially translated by an interpreter until the error is reached.
When a program is translated by an interpreter, both the program source code and the interpreter itself must be present. This results in poor protection of the source code compared to compilers which make the original code difficult to extract.
Compilers vs Interpreters
Errors are checked before translation
Translation begins immediately
Entire source code translated at once
Each line is checked for errors and then translated sequentially
No need for source code or compiler when translated code is executed
Both the source code and the interpreter must be present when the program is executed
Protects the source code from extraction
Offers little protection of source code
Compilers with Intermediate Languages
Some compilers donβt produce machine code straight away but instead translate source code into an intermediate language. This intermediate language, which is often bytecode, allows for platform independence.
A compiler that uses an intermediate language will translate high-level code into an intermediate language such as bytecode and then use a virtual machine to execute the bytecode on different processors.
Each different processor instruction set will have its own virtual machine. Using an intermediate language allows the interpreter to translate the source code just once, while still being able to execute the translated code with a variety of different processors.
Source Code vs Object Code
Last updated