본문 바로가기

Labs · 9618 A2 16.2

BNF and Syntax Diagrams

Grammar rules for a language. Check strings against BNF, build a string step by step, and write your own rules. Every rule is drawn as a syntax diagram.

7 levelsFree bench

In the exam

Exam questions on what this lab teaches, with the points that gain marks.

9618/32 May/June 2022 · Question 4(a)2 marks

The assignment statements X1 = Y2 – 12 and Z = Y12 + Z1 are invalid. State the reason in each case.

Points that gain marks

  1. X1 = Y2 – 12: an unsigned integer, 12, is used instead of the last variable.
  2. Z = Y12 + Z1: the variable Z is not valid: there is no unsigned integer after the Z.

In this lab: Level 1 has both strings, and shows the parse tree of every valid one.

9618/32 May/June 2023 · Question 3(b)3 marks

<word> contains one or more letters. Complete the BNF for <word> and use this to complete the BNF for <variable>.

Points that gain marks

  1. <word> ::= <letter> | <word><letter>
  2. <variable> ::= <word> | <word><digit>

In this lab: Level 6 tests your rules on hundreds of strings and draws their syntax diagrams.

The question as printed in the exam paper

More real experiments

All labs →

로그인 또는 계정 만들기

IGCSE, A-Level & AP