Augmented BNF for Syntax Specifications: ABNFBrandenburg InternetWorking675 Spruce Dr.SunnyvaleCA94086US+1.408.246.8253dcrocker@bbiw.netTHUS plc.1/2 Berkeley Square, 99 Berkeley StreetGlasgowG3 7HRUKpaul.overell@thus.netABNFAugmentedBackus-NaurFormelectronicmailInternet technical specifications often need to define a formal
syntax. Over the years, a modified version of Backus-Naur Form
(BNF), called Augmented BNF (ABNF), has been popular among many
Internet specifications. The current specification documents ABNF.
It balances compactness and simplicity with reasonable
representational power. The differences between standard BNF and
ABNF involve naming rules, repetition, alternatives, order-
independence, and value ranges. This specification also supplies
additional rule definitions and encoding for a core lexical
analyzer of the type common to several Internet specifications.
Internet technical specifications often need to define a formal
syntax and are free to employ whatever notation their authors deem
useful. Over the years, a modified version of Backus-Naur Form
(BNF), called Augmented BNF (ABNF), has been popular among many
Internet specifications. It balances compactness and simplicity
with reasonable representational power. In the early days of the
Arpanet, each specification contained its own definition of ABNF.
This included the email specifications,
and then , which came to be the common
citations for defining ABNF. The current document separates those
definitions to permit selective reference. Predictably, it also
provides some modifications and enhancements. The differences between standard BNF and ABNF involve naming
rules, repetition, alternatives, order-independence, and value
ranges. supplies rule definitions and
encoding for a core lexical analyzer of the type common to several
Internet specifications. It is provided as a convenience and is
otherwise separate from the meta language defined in the body of
this document, and separate from its formal status. The name of a rule is simply the name itself, that is, a
sequence of characters, beginning with an alphabetic character,
and followed by a combination of alphabetics, digits, and
hyphens (dashes).Rule names are case insensitive. The names <rulename>, <Rulename>,
<RULENAME>, and <rUlENamE> all
refer to the same rule. Unlike original BNF, angle brackets ("<", ">")
are not required. However, angle brackets may be used around a
rule name whenever their presence facilitates in discerning the
use of a rule name. This is typically restricted to rule name
references in free-form prose, or to distinguish partial rules
that combine into a string not separated by white space, such
as shown in the discussion about repetition, below. A rule is defined by the following sequence: where <name> is the name of the rule,
<elements> is one or more rule names or terminal
specifications, and <crlf> is the end-of-line
indicator (carriage return followed by line feed). The equal
sign separates the name from the definition of the rule. The
elements form a sequence of one or more rule names and/or value
definitions, combined according to the various operators
defined in this document, such as alternative and repetition. For visual ease, rule definitions are left aligned. When a
rule requires multiple lines, the continuation lines are
indented. The left alignment and indentation are relative to
the first lines of the ABNF rules and need not match the left
margin of the document. Rules resolve into a string of terminal values, sometimes
called characters. In ABNF, a character is merely a
non-negative integer. In certain contexts, a specific mapping
(encoding) of values into a character set (such as ASCII) will
be specified. Literal text strings are interpreted as a concatenated set of
printable characters.ABNF strings are case insensitive and the character set
for these strings is US-ASCII. To specify a rule that is case sensitive, specify the
characters individually. External representations of terminal value characters will
vary according to constraints in the storage or transmission
environment. Hence, the same ABNF-based grammar may have
multiple external encodings, such as one for a 7-bit US-ASCII
environment, another for a binary octet environment, and still
a different one when 16-bit Unicode is used. Encoding details
are beyond the scope of ABNF, although
provides definitions for a 7-bit US-ASCII environment as has
been common to much of the Internet. By separating external encoding from the syntax, it is
intended that alternate encoding environments can be used for
the same syntax. A rule can define a simple, ordered string of values (i.e., a
concatenation of contiguous characters) by listing a sequence
of rule names. For example: So that the rule <mumble> matches the lowercase
string "aba". Linear white space: Concatenation is at the core of the ABNF
parsing model. A string of contiguous characters (values) is
parsed according to the rules defined in ABNF. For Internet
specifications, there is some history of permitting linear
white space (space and horizontal tab) to be freely and
implicitly interspersed around major constructs, such as
delimiting special characters or atomic strings. NOTE: This specification for ABNF does not provide for
implicit specification of linear white space. Any grammar that wishes to permit linear white space around
delimiters or string segments must specify it explicitly. It is
often useful to provide for such white space in "core" rules
that are then used variously among higher-level rules. The
"core" rules might be formed into a lexical analyzer or simply
be part of the main ruleset. Elements separated by a forward slash ("/") are alternatives.
Therefore,A quoted string containing alphabetic characters is a
special form for specifying alternative characters and is
interpreted as a non-terminal representing the set of
combinatorial strings with the contained characters, in
the specified order but with any mixture of upper- and
lowercase. It is sometimes convenient to specify a list of alternatives
in fragments. That is, an initial rule may match one or more
alternatives, with later rule definitions adding to the set of
alternatives. This is particularly useful for otherwise
independent specifications that derive from the same parent
ruleset, such as often occurs with parameter lists. ABNF
permits this incremental definition through the construct:It is strongly advised that grouping notation be used,
rather than relying on the proper reading of "bare"
alternations, when alternatives consist of multiple rule
names or literals. The sequence group notation is also used within free text to
set off an element sequence from the prose. Default values are 0 and infinity so that
*<element> allows any number, including zero;
1*<element> requires at least one;
3*3<element> allows exactly 3; and
1*2<element> allows one or two. That is, exactly <n> occurrences of
<element>. Thus, 2DIGIT is a 2-digit number, and
3ALPHA is a string of three alphabetic characters. A semicolon starts a comment that continues to the end of
line. This is a simple way of including useful notes in
parallel with the specifications. The various mechanisms described above have the following
precedence, from highest (binding tightest) at the top, to
lowest (loosest) at the bottom: Rule name, prose-val, Terminal valueCommentValue rangeRepetitionGrouping, OptionalConcatenationAlternative Use of the alternative operator, freely mixed with
concatenations, can be confusing. Again, it is recommended that the grouping operator be
used to make explicit concatenation groups. This syntax requires a formatting of rules that is
relatively strict. Hence, the version of a ruleset
included in a specification might need preprocessing
to ensure that it can be interpreted by an ABNF
parser.This syntax uses the rules provided in . Security is truly believed to be irrelevant to this document.Coded Character Set -- 7-bit American Standard Code for
Information InterchangeAmerican National Standards
InstituteStandard for the format of ARPA network text messagesThe Rand Corporation, Information Sciences
Department1700 Main StSanta MonicaCA90406USDCrocker@Rand-UnixBolt Beranek and Newman Inc. (BBN)50 Moulton St.CambridgeMA02138USVittal@BBN-TenexDMassachusets Institute of Technology (MIT),
Laboratory for Computer Science545 Technology SquareCambridgeMA02139USPogran@MIT-MulticsBolt Beranek and Newman Inc. (BBN)50 Moulton St.CambridgeMA02138USHenderson@BBN-TenexDStandard for the format of ARPA Internet text messagesUniversity of Delaware, Dept. of Electrical
EngineeringNewarkDE19711USDCrocker@UDel-Relay The syntax for ABNF was originally specified in RFC 733. Ken L.
Harrenstien, of SRI International, was responsible for re-coding
the BNF into an Augmented BNF that makes the representation
smaller and easier to understand. This recent project began as a simple effort to cull out the
portion of RFC 822 that has been repeatedly cited by non-email
specification writers, namely the description of Augmented BNF.
Rather than simply and blindly converting the existing text into a
separate document, the working group chose to give careful
consideration to the deficiencies, as well as benefits, of the
existing specification and related specifications made available
over the last 15 years, and therefore to pursue enhancement. This
turned the project into something rather more ambitious than was
first intended. Interestingly, the result is not massively
different from that original, although decisions, such as removing
the list notation, came as a surprise. This "separated" version of the specification was part of the
DRUMS working group, with significant contributions from Jerome
Abela, Harald Alvestrand, Robert Elz, Roger Fajman, Aviva Garrett,
Tom Harsch, Dan Kohn, Bill McQuillan, Keith Moore, Chris Newman,
Pete Resnick, and Henning Schulzrinne.Julian Reschke warrants a special thanks for converting the Draft
Standard version to XML source form.This appendix contains some basic rules that are in common use.
Basic rules are in uppercase. Note that these rules are only valid
for ABNF encoded in 7-bit ASCII or in characters sets that are a
superset of 7-bit ASCII. Certain basic rules are in uppercase, such as SP, HTAB, CRLF,
DIGIT, ALPHA, etc. Externally, data are represented as "network virtual ASCII"
(namely, 7-bit US-ASCII in an 8-bit field), with the high (8th)
bit set to zero. A string of values is in "network byte order",
in which the higher-valued bytes are represented on the
left-hand side and are sent over the network first.