Translators

HLLs (High Level Languages) are written using English-like words, so we can understand them, but computers only understand 1s and 0s.

To translate programs written in a HLL to machine code that is understood by a processor we use a translator program. There are two types of translator programs that we could use:

  • Interpreters
  • Compilers

A translator works by converting the high level language into machine code that the computer can understand.

High level programming language translated into binary.

Interpreters

This type of translator is normally used when you are developing software but have not finished writing the code. An interpreter takes each line of code and translates it into machine code before running it. It then goes to the next line, translates it, runs it, and so on until it has completed every line of code in your program.

Advantages

Program will run even if it's not finished. You do not have to complete your program to see if the part you are currently working on will work.

Easy to find errors. The interpreter will often stop at a line it has a problem with so it is easy to see what line in your code is wrong.

Disadvantages

Code has to be translated each time the program is run. Each time you want to run your program you have to get your HLL translated.

Slows program down as it has to be translated. Because translating your program takes a bit of time (often just a few seconds or less) it will mean your program will run slower as it has to be translated by the interpreter into machine code before it is run.

Need to have translator program running. You can't run the software if you don't have the correct interpreter on your computer. That means you couldn't give the program you wrote to your friend unless they also have the interpreter installed on their computer.

Compiler

Where an interpreter would translate one line and run that line straight away before moving to the next line and repeating the process, a compiler translates the whole program only after every line has been translated.

To translate a program using a compiler, a standalone file in machine code is created. This file is known as object code and is the finished program that can run without the need for source code (the code created in a High Level Language).

Advantages

Program only needs to be translated once. You do not need to run your HLL code through the compiler each time you want to run the program. Just run the machine code program your compiler gave you.

User does not need a translator on their computer. Because a compiler produces a file that has machine code instructions in it, you can give it to other people and they can run it on their computers. People do not need a translator on their computer, as they don't need to translate the HLL to machine code.

Disadvantages

Have to wait until whole program is perfect to run it. As the whole program has to be translated into machine code before it can be run, you have to wait until the whole job is done before you can run the program. This is not an issue for small problems that take a few seconds. But in large programs that have lots of programmers contributing pieces of code, it can take hours to translate the whole program into machine code.

You have to re-translate the whole program each time you make a change. If you make changes to your software and you want to give the new updated software to people who don't have an interpreter on their computer, for example customers, you need to re-compile the whole program.