December 1998
SW204: SOFTWARE AND FILES DESIGN

QUESTION 3

Total Marks: 20 Marks

Click here to access other questions

SUGGESTED SOLUTIONS
Solutions and allocated marks are indicated in green.
Return to Question 3

3. (a) What is the basic purpose of a compiler?
[2]
The basic purpose of a compiler is to translate source code (1 mark) into an equivalent machine code representation (1 mark).

Other sensible answers should also receive credit.

 

(b) Describe four differences which exist between a compiler and an interpreter.

[4]

One mark should be awarded for each correct difference named (up to a maximum of four marks). Examples include the following:

  • A compiler converts a whole program in one go, whereas an interpreter converts a program instruction by instruction.
  • A compiler can retain object code, whereas an interpreter cannot.
  • Code only needs to be translated once by a compiler, whereas translation is needed by an interpreter every time the program is executed.
  • Code optimisation is possible with a compiler, whereas it is virtually impossible with an interpreter.

Other sensible answers should also receive credit.

 

(c) Describe the five functions performed by a compiler when source code is submitted for compilation.
[10]

One mark should be awarded for identifying each stage, and a further mark should be awarded for a satisfactory elaboration (up to a maximum of ten marks).

  • Lexical analysis (1 mark). This involves the ‘tidying up’ of source code, which involves checking for valid ‘words’ and standardising formats (1 mark).
  • Syntax analysis (1 mark). This involves determining the structure of the source program and interpreting its meaning (1 mark).
  • Code generation (1 mark). This involves translating each source statement into its corresponding object form (1 mark).
  • Code optimisation (1 mark). This involves manipulating either the source code or the object code to produce a more efficient object program (1 mark).
  • Error handling (1 mark). This involves detecting, and determining the causes of, errors (1 mark).

Other sensible answers should also receive credit.

 

(d) Draw a diagram to illustrate the behaviour of each of the following types of loader:
(i) Compile-and-go loaders.
[2]
Two marks should be awarded for a correct diagram; only one mark should be awarded if flowchart conventions are not followed; otherwise, no marks should be awarded.

pic4s.gif (16727 bytes)

(ii) Absolute loaders. [2]
Two marks should be awarded for a correct diagram; only one mark should be awarded if flowchart conventions are not followed; otherwise, no marks should be awarded

pic5s.gif (12280 bytes)