You are on page 1of 4

Computing 9691

Paper 3

Chapter 3.2: The functions and Purpose of

Describe the difference between Interpretation
and compilation
Source code: They are original codes written by a programmer using
an appropriate programming language such as C++, Pascal. It needs to be
translated because the computer cannot understand this language.

Object code: They are the result of translation of the source code.
They are machine codes, executable codes, binary codes and the
computer only understands this type of codes.

Compiler: It is a program which translated high level language to

machine code at one go. An object code is produced which can be saved
and run.
1. No re-compilation is needed to run the program thus it is faster.
2. Object code is more secure
1. Cannot be used if program is not completed.
2. If an error is found, compilation is re started from the beginning
3. Take more memory

Interpreter: It is a program which converts high level code line by line

before executing it and no object code is produced.
1. Easy to locate errors
2. If a program is not complete, part of it can executed and tested.
3. diagnostics will be more complete
4. individual segments can be run
5. allowing errors to be isolated
6. - running will be necessary after very minor changes
7. Occupies less memory
8. In case of error no need to retranslate from the beginning

1. Needs to be interpreted each time it is to be run as no object is
2. Time consuming
3. Not secure
Page | 1

Computing 9691

Paper 3

Assembler: It is a program which converts assembly language to

machine code.
1. Runs faster compared to interpreter because assembly language
is close to machine code

Stages of compilation:
Source program

Lexical analysis

Syntax analysis

Semantic analysis

Intermediate language

Code generation

Code optimisation

Object program

(b)Describe what happens during lexical analysis

1. Removes spaces, tab , blank line
2. Remove comments
3. Checking validity of reserved words
Page | 2

Computing 9691


Paper 3

Tokenises Operators
Creates the symbol tables
Checks validity of symbols/variable names
Simple error checking such as validity of identifier against the rule

of identifier.
8. Data in the symbol table are randomly placed using hashing

What is an identifier?

It can be a program or a function name or variable name.

Rules of identifier:
1. Start with an alphabet
2. It may consists of alphabets , underscore and digits

(c)Describe what happens during syntax analysis,

explaining how errors are handled.

Checks for grammar of statements

Checks that variables have been declared
Checks for existence of library modules
Checks the construct of a statement
Spelling of reserve words
Diagnostic error messages are reported
Intermediate codes are produced
Determine priorities of arithmetic operations in an

9. Label check, flow of control
NO of brackets

(d) Explain the code generation phase

-addresses of variables that have been calculated are stored in symbol
-then intermediate codes are produced
-the intermediate codes are optimised
- These intermediated codes are then converted to machine

Understand the need for optimization

Page | 3

Computing 9691

Paper 3

What is code optimisation?

It makes the code smaller in size by removing redundant instructions to
make the code more efficient.

(e)Explain the purpose of linkers , loaders and library

1. It combines together separately compiled modules
2. It allows library routines to be linked to several programs
3. It matches up address references between modules
1. It takes a set of code from the secondary storage and copies it into
2. The individual modules must be loaded by the loader into memory
3. To put library routines in the memory
Deals with addressing anomalies
4-Particularly relocatable addresses
Describe the use of library program routines


Describe how an assembler produces machine code from assembly language

-Labels are later looked up to determine the actual address / Assembler must allocate

addresses to labels
-Mnemonic looked up in opcode table to find operation code
-Macro instructions used to stand for groups of instructions
(1 per -, max 2)
Explain how errors are recognised and handled during compilation

Page | 4