Translators

Contents
  1. Translators
  2. Interpreters
  3. Compilers

1. Translators

CPUs can only understand Machine Code, therefore any program written in another language must be translated to Machine Code so that the CPU can execute its instructions.

There are three types of translators:

  • Assemblers - translating Assmebly Langauge to Machine Code
  • Interpreters - translating specific High Level Langauges line by line to Machine Code
  • Compilers - translates specific High Level Languages to Machine Code ahead of time

2. Interpreters

An interpreter reads source code and translates it one line at a time into machine code to be executed on the CPU. Once the machine code instructions have been executed, the next line of source code is then translated, and so on.

To run a program that is written in an interpreted language the computer it runs on must have the interpreter installed.

interpretered Langauges include: Python, JavaScript, PHP, and Ruby.

In order for a user to run an interpreted program the user must have the source code. This means that the user will have access to change the source code and could copy it. 

Interpreted Langauges tend to be highly portable, and can be ran on a computer system providing the interpreter is available for the specific hardware.

Due to interpreter programs being translated like by line, the programs tend to be less performant and are not used in applications which require higher performance.

Interpreted Langauges are easier to debug because the program will crash as they are translated at the line of source code where there is an error.


3. Compilers

A Compiler translates all the source code for a program into machine code before it is executed. This process is carried out by the developer when they are ready to ship their program.

A compiler produces an executable which contains the machine code instructions which allows it to run its instructions on a CPU. This can be ran without the source code or the compiler being installed. Due to being converted into machine code ahead of time compiled programs tend to be more performant.

Executables cannot be shared between different types of CPU. A different executable must be compiled for each type of CPU or platform it needs to run on. If download a program off the internet you may find various versions of an executable, for example x86, x86_64 and ARM64.