Explain the role of a translator program. How is a compiler different than an assembler?
A translator is a program which converts statements written in one language to statements in another language especially to machine language.
There are three types of translators:
- Assemblers
- Compilers
- Interpreters
The Assembler:
This is a program, which translate assembly language into machine code. One machine instruction is generated for each source instruction. The resulting program can only be executed when the assembly process is completed. The assembler reserves space for the instructions and data, replaces mnemonic operating codes by machine codes and symbolic addresses by numeric addresses while it determines the machine representation of constants.
Functions of the Assembler:
- It translate mnemonic operation codes, and symbolic addresses into machine addresses.
- Includes the necessary linkages for closed subroutines and insert appropriate machine code for macros.
- Allocates area of storage.
- Detects and indicates invalid source language instructions.
- Produces the object program on disk as required.
- Produces a printed listing of the source and object program with comments.
The Compiler:
Compiler translates a high level language into machine language. The compiler translate the whole source program into machine code or object program prior to the object being loaded into main memory and execution. The resulting program can only be executed when compilation is completed. The storage of the object program into a diskette facilities future usage of the high level language source program any other time it is needed.
How the Compiler Does Assembler Work?
- Translates the source program statements into machine code.
- Includes linkage for closed subroutines.
- Allocates areas of main storage.
- Generates the object program on cards, tapes or disc as required.
- Produces a printed copy of the source and object program when required.
Tabulates list of errors found during program compilation e.g. the use of ‘word’ or statement not included in the language vocabulary, the rule of syntax or lexis.