Cambridge A2 Level Computer Science 9618 · 16.2 Translation Software

Q16 · 9618/31/O/N/21 Q4

Worked solution from the System Software Paper 3 Advanced Theory booklet, Part 2 of 2.

Q169618/31/O/N/21original Q4Structured · 7 marks
Question 4 from 9618/31/O/N/21

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 IDEAA loop in a syntax diagram becomes a recursive rule in BNF, where the rule calls itself.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/31/O/N/21 question 4
VIDEO
▶ Whole paper

Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.