Languages / Concept
BNF
How you write down a grammar.
BNF is a notation for describing the grammar of a language: a set of rules that say how valid programs are built from smaller pieces. It was devised by John Backus and refined by Peter Naur for the ALGOL 60 report in 1960 — the first time a real programming language was given a precise, machine- independent syntax before its compilers existed.
A rule looks like <expr> ::= <expr> "+" <term> | <term>: a name, a
definition, alternatives separated by |. It is a practical notation for a
context-free grammar, and nearly every language specification and parser
generator since owes it a debt. Extended forms (EBNF) add convenient
shorthand, but the idea is Backus’s and Naur’s.
Sources
- Naur (ed.), “Revised Report on the Algorithmic Language ALGOL 60” (1963) — see BNF used to define a real language.
See also: ALGOL.