You are on page 1of 6

TRANSLATORS

Introduction
A subset of the commercially available software that deserves special attention is language
translators. These software applications allow users to write and develop custom software.

Language translators allow computer programmers to write sets of instructions in


specific programming languages. These instructions are converted by the language
translator into machine code. The computer system then reads these machine code
instructions and executes them. Hence, a language translator is a program that translates
from one computer language to another. Why should this be necessary?

It was mentioned earlier in this chapter that CPUs could only understand machine code or
machine language (expressed in binary code). Machine code is hardware-specific, and
hence there are as many machine codes as there are hardware designs. Although
machine code makes complete sense for computers, it is a very difficult and tedious
language in which to write programs. Hence programmers developed other less difficult
languages in which to write programs. Over the years, these programming languages are
moving closer and closer to human language. Consequently there are several generations
of computer programming languages.

First generation languages (1GLs). 1GLs constitute the actual code that computers
understand; that is machine code. In the early days of computing, programmers needed to
learn the specific pattern of 1's and 0's of all computing instructions in order to tell the
computer what to do. For example, a machine code instruction to load a value of 1 may
be 10101001 00000001.

Second generation languages (2GLs). 2GLs are called assembly languages. Each machine
code instruction is given a mnemonic, making it easier to remember specific codes. The
above example in assembly language would be LDA #$01, where LDA stands for LoaD the
following value into a memory Address.

Third generation languages (3GLs). 3GLs are called procedural languages or high level
languages. They are easier to understand because they resemble our own English language
more than 1GLs and 2GLs. However, specific training is still required to program in these
languages. Some examples of 3GLs are BASIC, COBOL, Pascal, Fortran, C, C++, Perl and Ada.
One of the latest languages to hit the market is called JAVA. Developed by Sun
Microsystems, this language allows programmers to write applications that can be used on
any operating system (platform-independent). Its main use is in web pages where JAVA is
used to write applets (short applications) to enhance the look and feel of a web page.

Fourth generation languages (4GLs). 4GLs are sometimes called problem-oriented


languages or non-procedural languages, and require less training than 3GLs. In these
languages one tells the computer what to do, not how to do it. Programmers and end-users
use 4GLs to develop software applications. Some examples are SQL, ACCESS, Informix and
FOCUS.

Fifth generation languages (5GLs). Called natural languages, 5GLs translate human
instructions, including spelling mistakes and bad grammar, into machine code. They are
designed to give people a more natural connection with computers. These languages are
the objects of considerable research. It is hoped that they would be able to remember as
people do, and then improve upon it.

With the exception of first generation languages, all computing languages need to be
converted to machine code to enable the computer system to execute the instructions. Two
kinds of language translators are used to achieve this.

Any program written in a high-level language is known as source code. However,


computers cannot understand source code. Before it can be run, source code must first be
translated into a form which a computer understands.

A translator therefore is a program that converts source code into machine code. Generally,
there are three types of translator:

 compilers
 interpreters
 assemblers

Compilers

A compiler is a translator used to convert high-level programming language to low-level


programming language. The compiler takes time to do its work as it translates high-level
code to lower-level code all at once and then saves it to memory. A compiler takes the
source code as a whole and translates it into machine code all in one go. Once converted,
the object code can be run unassisted at any time. This process is called compilation.

Compilers have several advantages:

 Compiled programs run quickly, since they have already been translated.

 A compiled program can be supplied as an executable 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 optimise code. Optimised code can run quicker and take up
less memory space.

Compilers also have disadvantages:

 The source code must be re-compiled every time the programmer changes the
program.

 Source code compiled on one platform will not run on another - the machine code is
specific to the processor's architecture.

Interpreters

Just like a compiler, is a translator used to convert high-level programming language to


low-level programming language. An interpreter translates source code into machine code
one instruction 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 is
then executed immediately. The process is called interpretation.

An interpreter reports errors detected at once while doing the conversion. With this, it is
easier to detect errors than in a compiler. It is often used as a debugging tool for software
development as it can execute a single line of code at a time. An interpreter is also more
portable than a compiler as it is not processor-dependent, you can work between hardware
architectures.
Interpreters have several advantages:

 Instructions are executed as soon as they are translated.

 Errors can be quickly spotted - once 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 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 language 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.

Examples of Translators

Here are some examples of translators per type:


Translator Examples

Microsoft Visual Studio


Compiler GNU Compiler Collection (GCC)
Common Business Oriented Language (COBOL)

OCaml
Interpreter List Processing (LISP)
Python

Fortran Assembly Program (FAP)


Assembler Macro Assembly Program (MAP)
Symbolic Optimal Assembly Program (SOAP)

Advantages and Disadvantages of Translators

Here are some advantages of the Compiler:

 The whole program is validated so there are no system errors.

 The executable file is enhanced by the compiler, so it runs faster.

 User do not have to run the program on the same machine it was created.

Here are some disadvantages of the Compiler:

 It is slow to execute as you have to finish the whole program.

 It is not easy to debug as errors are shown at the end of the execution.

 Hardware specific, it works on specific machine language and architecture.

Here are some advantages of the Interpreter:

 You discover errors before you complete the program, so you learn from your
mistakes.

 Program can be run before it is completed so you get partial results immediately.

 You can work on small parts of the program and link them later into a whole
program.
Here are some disadvantages of the Interpreter:

 There’s a possibility of syntax errors on unverified scripts.

 Program is not enhanced and may encounter data errors.

 It may be slow because of the interpretation in every execution.

Here are some advantages of the Assembler:

 The symbolic programming is easier to understand thus time-saving for the


programmer.

 It is easier to fix errors and alter program instructions.

 Efficiency in execution just like machine level language.

Here are some disadvantages of the Assembler:

 It is machine dependent, cannot be used in other architecture.

 A small change in design can invalidate the whole program.

 It is difficult to maintain.

Differences between compiler and interpreter

S/N Compiler Interpreter

1 Performs the translation of a program Performs statement by statement


as a whole. translation.

2 Execution is faster. Execution is slower.

3 Requires more memory as linking is Memory usage is efficient as no


needed for the generated intermediate intermediate object code is generated.
object code.

4 Debugging is hard as the error It stops translation when the first error is
messages are generated after scanning met. Hence, debugging is easy.
the entire program only.

5 Programming languages like C, C++ Programming languages like Python,


uses compilers. BASIC, and Ruby uses interpreters.

You might also like