9608_w18_qp_33
A paper of Computer Science, 9608
Questions:
6
Year:
2018
Paper:
3
Variant:
3

Login to start this paper & get access to powerful tools

1
2
3
4
5
6
The compilation process has a number of stages. The first stage is lexical analysis. A compiler uses a keyword table and a symbol table. Part of the keyword table is shown. • Tokens for keywords are shown in hexadecimal. • All of the keyword tokens are in the range 00 – 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 code. Start INPUT Number // Output values in a loop FOR Counter Start TO 12 OUTPUT Number * Counter ENDFOR Complete the symbol table to show its contents after the lexical analysis stage. Symbol Token Value Type Start Variable Constant The output from the lexical analysis stage is stored in the following table. Each cell stores one byte of the output. Complete the output from the lexical analysis stage. Use the keyword table and your answer to part . The output of the lexical analysis stage is the input to the syntax analysis stage. Identify two tasks in syntax analysis. The final stage of compilation is optimisation. Code optimisation produces code that minimises the amount of memory used. Give one additional reason why code optimisation is performed. A student uses the compiler to compile some different code. After the syntax analysis stage is complete, the compiler generates object code. The following lines of code are compiled. X A + B Y A + B + C Z A + B + C + D The compilation produces the following assembly language code. LDD 236 // loads value A to accumulator ADD 237 // adds value B to accumulator STO 512 // stores accumulator in X LDD 236 // loads value A to accumulator ADD 237 // adds value B to accumulator ADD 238 // adds value C to accumulator STO 513 // stores accumulator in Y LDD 236 // loads value A to accumulator ADD 237 // adds value B to accumulator ADD 238 // adds value C to accumulator ADD 239 // adds value D to accumulator STO 514 // stores accumulator in Z Rewrite the assembly language code after it has been optimised.