Translators Flashcards
Different types of Translators
1) Compiler
2) Interpreter
3) Assembler
Purpose of Translators
Convert from source code ……to object code. Detect errors in source code.
Compiler
Translates whole program as a unit. Uses high-level source code. Gives list of errors at end of compilation. Creates an executable program or intermediate program when program is completed. Protects program from malicious use. They are architecture specific Can carry out optimisation which improves program speed and size. Compiler is no longer needed once executable code is produced.
Interpreter
Translates and executes one line at a time. Uses high-level source code. Reports errors as they are found one at a time. Interpreter must be present each time program is run. Program runs more slowly due to translation
Assembler
Translates whole program as a unit. Uses low-level source code. Gives list of errors at end of assembly.
Advantages - Compilers
Results in an executable code that requires no further translation. Therefore compiled progs execute faster than interpreted.
Disadvantages - Compilers
Use a lot of computer resources. Has to be loaded in the computer’s memory at the same time as the source code and there has to be sufficient memory to hold the object code. Has to be sufficient memory for working storage while the translation is taking place. Errors in the original program are difficult to pin-point.
Advantages - Interpreters
Need less memory than compilers (useful in early computers - limited power and memory). Continual compilation of whole code is wasteful during testing particularly if very minor changes have been made. As each error message is produced on the line where the error was encountered, it is easier to identify the instruction causing the problem. Individual segments can be run without needing compile the whole program.
Disadvantages-Interpreters
Slower execution (compared to compiled) as the original program has to be translated every time it is executed. Instructions inside a loop have to be translated each time the loop is entered.
Interpreter error handling
Interpreter stops at first error, an error message is produced, error would be corrected, program can restart from any point, this is repeated until all errors are removed when program will run.
Source code
The original code written by the programmer. Often in a high-level language. May be in assembly language. Source code can be understood by people…but cannot be executed (until translated).
Object code
Could be machine code or intermediate code.
Machine code
Binary notation (in executable form). Set of all instructions available. Instructions operate on bytes of data. Is dependent on architecture / processor design.
Intermediate code
Simplified code which is partly translated. Can run on a variety of computers using an interpreter. This improves portability. The same intermediate code can be obtained from different high level languages. It is used in a virtual machine e.g. Java.
Adv of Intermediate code
Allows sections of program to be written in different HLL. Platform independent so improves portability. Compiled - error free