Variants of Backus-Naur/Normal-Forms

Since the invention of BNF (Backus Normal Form, later Backus Naur Form, defined by Jim Backus and Pete Naur for the definition of Algol 60), the formal description of grammars has been modified numerous times by many people. Milestones were the changes of Niklaus Wirth (EBNF) used in Pascal and the standardisations ISO/IEC 14977 for EBNF and BS 6154 - the last examples are widely unused. Another extension called ABNF is defined in the RFC 2234.

Minor and sometimes embarrasing or even annoying changes to BNF are the uncountable definitions of different variants like the one defining XML (poorly defined; see various examples for XML grammars generated from the definitions directly) or used in some RFCs (RFC 822, Chap. 2; RFC 1808, Chap. 2.2; RFC 2224) each with some unnecessary changes. Very close to the original BNF is the form used for defining YACC/Bison grammars. It seems to be normal, that a SGML Syntax Summary uses another different notation from XML or better that XML did not reuse the SGML or another variant. (Sometimes it seems that computer scientists don't read documents from others or are even unable to do so!)

One major difference between the BNF versions is the existence and form of comments. The second is the description of repetitions and options.

No responsability for errors resulting from the use of this information is assumed. Neither is any liability assumed for any problems or damage resulting from the use of this information.

Necessary german law court amendment only: Ich distanziere mich selbstverständlich vom Inhalt aller verlinkten Seiten!

The following table tries to specify the characteristics of this garden full of weeds.

BNF Yacc/Bison EBNF ISO/IEC 14977:1996 BS 6154 ABNF (RFC 2234) XML SGML XBNF
Rule symbol ::= : = = = ::= = ::=
Rule continuation NL whitespace NL whitespace NL whitespace NL whitespace
End of rule ; ; . ; .
Recursion yes yes yes yes yes yes yes yes yes
Names space
Single char terminals %d13.10 #xAB [regexp]
Terminals unquoted UPPERCASE/String String String String unquoted String
Non-terminals <phrase> names names names names names names
Alternatives | | | | / ! | / %x30-39 | | |
Sequences space space , , space space , space
Strings '...' '...' "..." '...' "..." "..."
Grouping (...) (...) (...) (...) (...) (...)
Option ? [...] [...] (/.../) [...] [...] O(...)
Repetition * {...} {...} (:...:) {...} #(...)
Repetition + N(...)
Regexp option a? a?
Regexp repetition a* a+ a* a+
Regular expressions [a-zA-Z]
Numbers Decimal digit sequence b101 d197 xAB
Numeric factors 2 * aaa 3*4 aaa 4*aaa *4aaa 4aaa
Exceptions - - ~
Incremental operators =/
Precedence *-,|=; space / ()?*+,|&
Comments C-statements (*...*) ;...eol /*...*/ [wfc:] [nr] Reference {...}Used in:
Characteristics ?...? *-symbol

You want to watch grammars at work: click here. Grammars are user to parse the input for the generation of syntax diagrams.

Valid HTML 4.01

Last change: 4. Dec. 2013, F. Braun Impressum