9618/31/O/N/25 question 8: worked solution (October/November 2025, paper 31)
Show as plain textHide plain text
Cambridge A2 Level Computer Science 9618 · 16.2 Translation Software Worked solution from the System Software Paper 3 Advanced Theory booklet, Part 2 of 2. Q38 9618/31/O/N/25 original Q8 Structured · 8 marks Worked solution (a) Write any two of these: To turn the high-level source code into a sequence of tokens [1] To pass the tokens on to the parser for syntax analysis, or to create a symbol table , or to remove white space and comments [1] (b) Work out the brackets first, then the multiply and the divide from left to right. (2 – 6) gives 2 6 –. (13 + 7) gives 13 7 +. 2 6 – 13 7 + [1] Complete answer: 2 6 – 13 7 + * 5 / [1] (c) Read the RPN left to right. Push a value for a letter. For an operator, pop two values and push the result. Values: d = 5, a = 6, b = 12, c = 15. Each row shows the stack, with the top first. Step Stack (top first) push d 5 push a 6, 5 push b 12, 6, 5 + (6 + 12) 18, 5 * (5 * 18) 90 push c 15, 90 push a 6, 15, 90 - (15 – 6) 9, 90 / (90 / 9) 10 Stacks for d, a, b and + correct [1] Stack after * correct (90) [1] Stacks for c, a and - correct [1] Final stack after / holds 10 [1] KEY IDEA RPN is evaluated with a stack: push values, and for each operator pop two, work out the result and push it back. TOTAL 8 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.