9618/03 Specimen Paper 2021 · Question 4 · 7 marks
(a)(i) The output of the lexical analysis stage forms the input to the next stage. Identify this stage. (ii) State two tasks that occur at this stage. (b) One reason for optimisation is to minimise the memory used. State another reason. (c) Suggest what a compiler could do to optimise A ← B + 2 * 6. (d) Suggest what a compiler could do to optimise the code for X ← A + B and Y ← A + B + C (seven lines: LDD 436, ADD 437, STO 612, LDD 436, ADD 437, ADD 438, STO 613).
Points that gain marks
- (a)(i) Syntax analysis.
- (ii) Any two: parsing / construction of a parse tree; checking that the rules of grammar (syntax) have been obeyed; production of an error report.
- (b) To minimise the execution time.
- (c) Replace 2 * 6 with the value 12.
- (d) Remove the second LDD 436 (line 04) …
- … and remove the second ADD 437 (line 05) …
- … because the value needed is already in the accumulator.
In this lab: Levels 5 and 6 are parts (d) and (c).