Quoted definition from wikipedia:
In computer science, BNF (Backus Normal Form or Backus–Naur Form) is one of the two main notation techniques for context-free grammars, often used to describe the syntax of languages used in computing, such as computer programming languages, document formats, instruction sets and communication protocols.
A BNF specification is a set of derivation rules, written as:
|
|
where <symbol>
is a nonterminal, and __expression__
consists of one or more sequences of symbols seperated by |
, indicating a choice, the whole being a possible substitution for the <symbol>
.
Symbols that never appear on a left side are terminals, and symbols appear on the left are nonterminals always enclosed between the pair <>
. And what’s more, ::=
means that the symbol on the left must be replaced with the expression on the right.
There are many variants and extensions of BNF, generally either for the sake of simplicity and succinctness, or to adapt it to a specific application. Like ABNF (Augmented), EBNF (Extended).
ABNF: based on BNF but consisting of its own syntax and derivation rules, often serves as the definition languages for IETF communications protocols. Defined in RFC 5234. RFC 7404 updates it.
EBNF: based on BNF but provides extra function like concatenation, optional, repetition, grouping…Any grammar defined in EBNF can also be represented in BNF, but representations in the latter are generally lengthier.
For example:
|
|
CSS Definition Syntax
W3C’s CSS property value definition syntax is based on the concept of BNF, but with some differences. Recently I’ve translated an article about this.
An example of line-height
property:
|
|
where normal
and inherit
are keyword values, and <number>
, <length>
, <percentage>
are basic data types.
|
|
Reference: line-height, Tokenization