Перейти к содержанию

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

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

  • X1 = Y2 – 12: an unsigned integer, 12, is used instead of the last variable.
  • 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

  • <word> ::= <letter> | <word><letter>
  • <variable> ::= <word> | <word><digit>

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

More real experiments

Войти или создать аккаунт

IGCSE, A-Level & AP