Translators Flashcards

1
Q

Different types of Translators

A

1) Compiler
2) Interpreter
3) Assembler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Purpose of Translators

A

Convert from source code ……to object code. Detect errors in source code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Compiler

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Interpreter

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Assembler

A

Translates whole program as a unit. Uses low-level source code. Gives list of errors at end of assembly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Advantages - Compilers

A

Results in an executable code that requires no further translation. Therefore compiled progs execute faster than interpreted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Disadvantages - Compilers

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Advantages - Interpreters

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Disadvantages-Interpreters

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Interpreter error handling

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Source code

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Object code

A

Could be machine code or intermediate code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Machine code

A

Binary notation (in executable form). Set of all instructions available. Instructions operate on bytes of data. Is dependent on architecture / processor design.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Intermediate code

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Adv of Intermediate code

A

Allows sections of program to be written in different HLL. Platform independent so improves portability. Compiled - error free

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Disad of Intermediate code

A

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.

17
Q

Virtual machine

A

Intermediate code is run using an interpreter (for the specific computer).

18
Q

Why compile to mach code

A

Compiled program is executable, they run quickly, do not need a translator to run the program, uses less memory.

19
Q

Assembly Language

A

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.

20
Q

Assemblers

A

Translate a program from assembly language into machine code. One assembly language instruction is (generally) changed into one machine code instruction.

21
Q

Assemblers - tasks

A

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.

22
Q

Library Routines

A

Are pieces of software which perform common tasks such as sorting and searching. Library routines are compiled.

23
Q

Library Routines – why?

A

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.

24
Q

Use of Library Routines

A

Requires use of platform dependent utility programs – Linker and Loader.

25
Q

Linker

A

Is used…to combines modules / library routines…that are already compiled / in object code / in executable form…with program by completing address links to program.

26
Q

Loader

A

Copies modules into memory…from backing store…when program is to be run. It handles addresses ready for execution

27
Q

Linking errors

A

Occur when a compiled program is linked to library routines. E.g. if a particular subroutine is not present in the library or the number of parameters provided is wrong.

28
Q

Compiled code may not be executable

A

As it may need to be linked to library routines. e.g. library for I/O routines or for mathematical functions. It may create intermediate code…i.e. code for a virtual machine …depends on language used

29
Q

Compilation

A

Source Code → Lexical Analysis → Output from lexical analysis → Syntax Analysis → Output from syntax analysis → Code Generation and Optimisation → Machine code.

30
Q

Lexical analysis

A

Source code is used as input. Reserved words are replaced by tokens. A token is a string of binary digits of fixed length. Variable names are checked and entered in the symbol table. Constants are entered in the symbol table. Data type/space required is entered in the symbol table. Error reporting occurs. Unnecessary characters (white space, comments) are removed / program is formatted ready for the next stage (syntax analysis).

31
Q

Syntax analysis

A

Accepts output from lexical analysis. Statements, arithmetic expressions and tokens are checked against the rules of the language e.g. matching brackets . The parser checks the tokens generated by the lexical analyser to see if they are grammatically correct. Parse trees are generated (from which machine/executable/intermediate code can be generated). Further detail is added to the symbol table e.g. data type / scope / address. Errors are reported…as a list at the end of compilation to alert the programmer. Some reported errors may be spurious (not being what it purports to be; false or fake.) if no errors, code is passed to the code generator.

32
Q

Example Syntax Errors

A

Missing the end statement in a selection or iteration construct. E.g. missing closing part of a loop statement – Next i. E.g. missing closing part of an IF statement – End If.

33
Q

Code generation…

A

Occurs after syntax analysis and is the last phase of compilation. Produces machine code program, executable or intermediate code which is equivalent to the source program. Variables and constants are given addresses. Relative addresses are calculated.

34
Q

and optimisation

A

Makes code as efficient as possible. Improves processing speed. Reduces number of instructions. Programmer can choose between speed and size.