Week 3 Language Translators
Week 3 Language 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.
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.
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.
A translator therefore is a program that converts source code into machine code. Generally,
there are three types of translator:
compilers
interpreters
assemblers
Compilers
Compiled programs run quickly, since they have already been translated.
Compilers optimise code. Optimised code can run quicker and take up
less memory space.
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
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:
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.
Interpreted programs run slowly as the processor has to wait for each instruction to
be translated before it can be executed.
Assemblers
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
OCaml
Interpreter List Processing (LISP)
Python
User do not have to run the program on the same machine it was created.
It is not easy to debug as errors are shown at the end of the execution.
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:
It is difficult to maintain.
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.