When BNF evolved, many implementations were improved by their authors.
Suppose we need a grammar to parse these algebra expressions:
1. (x + y) * z 2. x + (y * z) 3. x + y * z
x
, y
, and z
is the complete alphabet of variable-names+
and *
are the operators(
brackets )
may be used to group sub-expressions
On this page, all of the following dialects of BNF have the same meaning.
Dialect 6 conforms to the International Standard
ISO-14977 Syntactic Meta-Language
::=
<expr> ::= <term> | <expr> + <term> <term> ::= <element> | <term> * <element> <element> ::= x | y | z | ( <expr> )
->
<expr> -> <term> | <expr> + <term> <term> -> <element> | <term> * <element> <element> -> x | y | z | ( <expr> )
::=
expr ::= term | expr + term term ::= element | term * element element ::= x | y | z | ( expr )
::=
|
choice symbol,
so a list of single definitions is written like a listexpr ::= term ::= expr + term term ::= element ::= term * element element ::= x ::= y ::= z ::= ( expr )
=
expr = term | expr "+" term; term = element | term "*" element; element = "x" | "y" | "z" | "(" expr ")";