BNF and Syntax Diagrams
Aligned to the AQA 7517 specification
- Level
- Advanced
- Reading time
- 6 min
- Published
- 13 June 2026
- Updated
- 1 July 2026
On this page
Key takeaways
- Backus-Naur Form (BNF) is a formal notation for describing the grammar of a language using production rules of the form <non-terminal> ::= definition.
- Terminals are the actual symbols of the language and cannot be broken down further, while non-terminals are syntactic categories written in angle brackets that expand into further rules.
- BNF rules can be recursive, with a non-terminal appearing on both sides of a rule, which allows infinite languages to be described with a finite grammar.
- A grammar written in BNF generates a context-free language, which is more expressive than a regular language and can describe arithmetic expressions and most programming language syntax.
- In a syntax diagram, rectangular boxes contain non-terminals and rounded (oval) boxes contain terminals; swapping these is a mark-scheme error.
Worth saving these ideas?
Turn what you've read into instant revision cards. Free to get started.
Key terms
- Backus-Naur Form (BNF)
- A formal notation for describing the grammar (syntax rules) of a language using production rules.
- Production rule
- A BNF rule of the form <non-terminal> ::= definition, where ::= means "is defined as".
- Terminal
- An actual symbol of the language that cannot be broken down further, written as a literal value.
- Non-terminal
- A syntactic category written in angle brackets that expands into further rules.
- Derivation
- The step-by-step replacement of non-terminals until only terminals remain.
- Recursive rule
- A BNF rule where a non-terminal appears on both sides, allowing infinite languages to be described with a finite grammar.
- Syntax diagram
- A visual alternative to BNF, also called a railroad diagram, that represents a grammar as a flowchart-like diagram.
- Context-free language
- A language where each production rule replaces a single non-terminal regardless of surrounding context.
- Parse tree
- A tree representing the derivation of a string from a grammar, with non-terminals at internal nodes and terminals at the leaves.
- Ambiguous grammar
- A grammar where a string has more than one parse tree, making the meaning of an expression unclear.
Frequently asked questions
A terminal is an actual symbol of the language that cannot be broken down further, written as a literal value such as 0, 1, or +. A non-terminal is a syntactic category, a placeholder written in angle brackets such as <digit> or <expression>, that expands into further rules.
Many languages cannot be described by regular expressions alone, for example arithmetic with brackets. Recursive BNF (context-free grammars) is needed because it can express nested and recursive structures, which is why compilers use BNF rather than regular expressions to parse arithmetic.
No. BNF describes context-free languages. Some languages require context-sensitive rules, such as C's type declarations, and need more powerful grammars. BNF cannot express every possible language.
Generate revision on any topic you study
Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.
Lessons on anything
Structured, level-matched lessons on any topic you study
Practice quizzes
Find out what you actually know before the exam does
Flashcard sets
Lock in key concepts with instant revision cards
Ask Aica
Stuck on something? Get a clear explanation, any time
Regular Expressions
Complexity and Big-O Notation
Related lessons
5 min
8 min