3. Advanced Theory
A section of Computer Science, 9608
Listing 10 of 228 questions
9608_w15_qp_31
THEORY
2015
Paper 3, Variant 1
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.
9608_w15_qp_32
THEORY
2015
Paper 3, Variant 2
9608_w15_qp_33
THEORY
2015
Paper 3, Variant 3
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.
9608_w18_qp_31
THEORY
2018
Paper 3, Variant 1
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.
9608_w18_qp_33
THEORY
2018
Paper 3, Variant 3
Questions Discovered
228