9618/32/M/J/22 question 4: worked solution (May/June 2022, paper 32)

Show as 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. Q18 9618/32/M/J/22 original Q4 Structured · 13 marks Worked solution (a) Check each statement against the diagram: variable = variable operator variable, and a variable is one letter followed by an unsigned integer. X1 = Y2 – 12: 12 is an unsigned integer, not a variable (it has no letter), so the last item is invalid [1] Z = Y12 + Z1: Z is not a valid variable because there is no unsigned integer after the letter [1] (b) Write each rule using | for choices: <variable> ::= <letter><unsigned_integer> <unsigned_integer> ::= <digit> | <digit><digit> <digit> ::= 1 | 2 | 3 <operator> ::= + | - | * <assignment_statement> ::= <variable> = <variable><operator><variable> <variable> ::= <letter><unsigned_integer> [1] <unsigned_integer> ::= <digit> | <digit><digit> [1] <digit> ::= 1 | 2 | 3 and <operator> ::= + | - | * [1] <assignment_statement> ::= <variable> = [1] ... <variable><operator><variable> to finish the rule [1] (c)(i) Draw the same diagram as before: variable, then the = circle, then a branch, then operator, then a second branch. At each of the two places where a variable was, add a choice: one path through the variable box and another path through an unsigned integer box, joining again afterwards. Both unsigned integer boxes added [1] Correct positions and connectors (a bypass line around each variable box that joins back to the main line) [1] The rest correct: variable, =, operator in order, with arrows in and out and the name assignment statement [1] (c)(ii) Write the BNF with an extra helper rule for the two choices: <operand> ::= <variable> | <unsigned_integer> <assignment_statement> ::= <variable> = <operand><operator><operand> <operand> ::= <variable> | <unsigned_integer> [1] <assignment_statement> ::= <variable> = [1] <operand><operator><operand> completes the rule [1] Another accepted answer lists all four combinations after <variable> = : two or three correct options score 1, all four score 2. KEY IDEA A variable is a letter then digits; to allow two choices in a diagram or BNF, add a bypass path or an <operand> rule. TOTAL 13 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.