Translators Flashcards
(34 cards)
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
Disad of Intermediate code
Program runs more slowly than executable code because it has to be translated each time it is run. Need additional software e.g. interpreter or virtual machine.
Virtual machine
Intermediate code is run using an interpreter (for the specific computer).
Why compile to mach code
Compiled program is executable, they run quickly, do not need a translator to run the program, uses less memory.
Assembly Language
Related closely to the computer being programmed. Low level language so machine specific. Uses descriptive names (for data stores), mnemonics (for instructions), labels to allow branching (selection). Each instruction is generally translated into one machine code instruction. Translated by an assembler. Typically used for writing drivers / easier than mc, but harder than HLL.
Assemblers
Translate a program from assembly language into machine code. One assembly language instruction is (generally) changed into one machine code instruction.
Assemblers - tasks
Reserves storage for instructions and data. Replaces mnemonic opcodes by machine codes. Replaces symbolic addresses by numeric addresses. Creates symbol table to match labels to addresses. Checks syntax and offers diagnostics for errors.
Library Routines
Are pieces of software which perform common tasks such as sorting and searching. Library routines are compiled.
Library Routines – why?
To perform common tasks. They are error free and tested. Ready to use, saves work and time. May be used multiple times
May have been written in a different source language. Use other programmers’ expertise.
Use of Library Routines
Requires use of platform dependent utility programs – Linker and Loader.