9608_w15_qp_32
A paper of Computer Science, 9608
Questions:
6
Year:
2015
Paper:
3
Variant:
2

Login to start this paper & get access to powerful tools

1
2
In this question, you are shown pseudocode in place of a real high-level language. A compiler uses a keyword table and a symbol table. Part of the keyword table is shown below. • Tokens for keywords are shown in hexadecimal. • All the keyword tokens are in the range 00 to 5F. Keyword Token + = IF 4A THEN 4B ENDIF 4C ELSE 4D FOR 4E STEP 4F TO INPUT OUTPUT ENDFOR Entries in the symbol table are allocated tokens. These values start from 60 . Study the following piece of code: Start 0.1 // Output values in loop FOR Counter Start TO 10 OUTPUT Counter + Start ENDFOR Complete the symbol table below to show its contents after the lexical analysis stage. Symbol Token Value Type Start Variable 0.1 Constant Each cell below represents one byte of the output from the lexical analysis stage. Using the keyword table and your answer to part complete the output from the lexical analysis. The compilation process has a number of stages. The output of the lexical analysis stage forms the input to the next stage. Name this stage. State two tasks that occur at this stage. The final stage of compilation is optimisation. There are a number of reasons for performing optimisation. One reason is to produce code that minimises the amount of memory used. State another reason for the optimisation of code. What could a compiler do to optimise the following expression? A B + 2 * 6 These lines of code are to be compiled: X A + B Y A + B + C Following the syntax analysis stage, object code is generated. The equivalent code, in assembly language, is shown below: LDD 436 //loads value A ADD 437 //adds value B STO 612 //stores result in X LDD 436 //loads value A ADD 437 //adds value B ADD 438 //adds value C STO 613 //stores result in Y Rewrite the equivalent code, given above, following optimisation.
3
4
5
6