What do you mean by the translator? Discuss different types of translators in brief.

Translator

A translator is defined as a software program that takes as input a program written in the source language and produces as output a program in another language called the object or target language. The concept of translating a program from source to object or target language is shown in the figure.

At least, their languages are involved in the development of translators:
(i) The source language to be translated,
(ii) The °lied or target language to be generated, and
(iii) The host language to be used for implementing the translator.

it is not always necessary that the translator’s output should be a machine language program. Therefore, depending upon the source and object program there are different types of translators. These are discussed as given below:

1. Compiler

A compiler is a translator (a software program) that translates a High-level language program into a functionally equivalent low-level machine language program that can be executed directly. Individual source language statements usually map into many machine-level instructions.

Compiler: A compiler also generates diagnostic messages wherever the specifications of the source language are violated by the programmer. A compiler is basically a translator whose source language (i.e., language to be translated) is the high-level language, and the target language i.e., a low-level language, i.e., a compiler is used to implement a high-level language on a computer.

2. Interpreter:

An interpreter like the compiler is a translator that translates a high-level language program into functionally equivalent low-level machine code, but it does it at the moment the program is run. An interpreter reads a source program written in a high-level programming language as well as data for this program, and it runs the program against the data to produce some results. The interpreter takes the source program, one line at a time, and translates each line before running it. The interpreter has no “memory” for the translated lines, so if it comes across lines of the program within a loop, it must translate them afresh every time that particular line runs. An interpreter, therefore, translates high-level instructions into an intermediate form, which it then executes.

3. Assembler:

An assembler is a translator that translates an assembly-level language program into a low-level machine language program which can then be executed directly. Individual source language statements usually map one-for-one to machine-level instructions. The translation using an assembler is shown in the figure.

4. Macro Assembler:

A macro-assembler is a translator that translates the assembly level language instructions into machine code and is a variation on the assembler. Most source language statements map one-for-one into their target language equivalents, but some macro statements map into a sequence of machine-level instructions-effectively providing a text replacement facility, and thereby extending the assembly language to suit, the user. The concept of the macro is shown in the figure.

5. Preprocessor :

A preprocessor is a translator that translates a superset of a high-level language into Ow original high-level language, or that perform simple text substitutions before the translation lakes place. This enables the statements of the source program to be processed before it is being inputted to main compiler. Preprocessor are also a part of a compiler but it recognizes the statements to be processed first by means of certain directives and its meaning is substituted in the source program before it goes to final compilation. The best-known pre-processor is probably that which performs an integral part of implementations of the language C, and which provides many of the features, that contribute to the widely-held perception that C is the only really portable language. As an example of the preprocessor the statement #include, forces the inclusion of definition and meaning of header files in the source program, then it goes to compilation.

6. High-Level Translator :

A high-level translator translates one high-level language usually one for which sophisticated compilers already exist on a range of machines. Such translators are particularly useful as components of a two-stage compiling system, or in assisting with the bootstrapping techniques.

7. Decompiler and Disassembler :

The terms decompiler and disassemblers refers to translators which attempt to take object code at a low level and regenerate source code at a higher level. While this can be done quite successfully for the production of a assembler level code, it is much more difficult when one tries to recreate source code originally written in, say, Pascal.

Leave a Reply