Most of us work with High Level programming languages when writing code such as:
The CPU cannot directly execute the high level source code - it needs to be translated into
For example, one kind of translator is a compiler to compile the code into an executable file:
Note: the machine-code executable can only be created once all of the errors in the code have been fixed.
Because the executable file does not need to be re-translated and runs extremely quickly, compiled code is most often used in performance critical scenarios, such as systems requiring real-time processing (eg edge devices), video games, scientific simulations...
An interpreter is another kind of translator.
It translates each line of source code (eg C++) into machine code and executes it. It then moves on to the next line of source code.
So, an interpreter does not produce a single executable file which can run on demand very quickly.
It simply translates and executes source code line by line. Hence errors are detected during runtime, not during compilation.
In systems where compilation takes a long time, finding errors can be time-consuming.
Using an interpreter means that errors can be found quickly and fixed. This is perfect for Rapid Development and Testing scenarios.
This means the translation process occurs everytime the source code needs to be executed - it is definitely a slower process than using a compiled executable file!
The issue with compilers is that the compiled executable file will be specific to a certain OS eg Windows or Mac.
So, multiple executables will have to be developed.
By using a Bytecode Interpreter, an executable file containing bytecode is created.
This file can be executed by a Virtual Machine on any operating system.
So, as long as an appropriate Virtual Machine is installed on a system, the same bytecode file can be executed on different systems.
Hence bytecode interpreted programs are incredibly portable.
If a company runs different operating systems and requires the same program to run, bytecode interpreted files are a good choice.
A note on assemblers (not in our syllabus).
Assemblers translate Assembly Language into Machine Code.
Read through the information above again. Create a graphic which clearly shows the advantages and disadvantages of each type of translator.