SourceForge.net Logo BNF for Java: Dialects of BNF


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

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

Dialect 1:

<expr> ::= <term> | <expr> + <term>
<term> ::= <element> | <term> * <element>
<element> ::= x | y | z | ( <expr> )

Dialect 2:

<expr> -> <term> | <expr> + <term>
<term> -> <element> | <term> * <element>
<element> -> x | y | z | ( <expr> )

Dialect 3:

expr ::= term | expr + term
term ::= element | term * element
element ::= x | y | z | ( expr )

Dialect 4:

expr ::= term
     ::= expr + term
term ::= element
     ::= term * element
element ::= x
        ::= y
        ::= z
        ::= ( expr )

Dialect 5:

expr = term | expr "+" term;
term = element | term "*" element;
element = "x" | "y" | "z" | "(" expr ")";

Dialect 6:

algebra expr = complex term | algebra expr, "+", complex term;
complex term = simple element | complex term, "*", simple element;
simple element = "x" | "y" | "z" | "(", algebra expr, ")";

Valid XHTML 1.1!