9618/31/O/N/21 question 4: worked solution (October/November 2021, 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. Q16 9618/31/O/N/21 original Q4 Structured · 7 marks Worked solution (a) BNF lists the allowed items with | meaning 'or'. The diagram for character allows $, %, &, * or #. Write: <character> ::= $ | % | & | * | # Starts with <character> ::= [1] The five symbols separated by | [1] (b)(i) A password starts with one character, then one or more digits or capital letters. Write an example such as $A9E3 [1] (b)(ii) The loop after the first character means one or more digits or capital letters, so a helper rule that repeats itself (recursion) is needed. Write: <password> ::= <character><code> <code> ::= <digit> | <capital_letter> | <digit><code> | <capital_letter><code> <password> ::= <character><code> (a character followed by the helper rule) [1] <code> ::= starts a rule for one or more digits or capital letters [1] The single options <digit> | <capital_letter> [1] The recursive options <digit><code> | <capital_letter><code> [1] KEY IDEA A loop in a syntax diagram becomes a recursive rule in BNF, where the rule calls itself. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.