[Search] [txt|pdf|bibtex] [Tracker] [WG] [Email] [Diff1] [Diff2] [Nits]

Versions: 00 01 02 03 04 rfc2234                                        
Network Working Group                    D. Crocker (editor)
Internet-Draft                      Internet Mail Consortium
                                                Paul Overell
Expiration <7/97>                         Demon Internet Ltd

        Augmented BNF for Syntax Specifications: ABNF


This document is an Internet-Draft.  Internet-Drafts are
working documents of the Internet Engineering Task Force
(IETF), its areas, and its working groups.  Note that other
groups may also distribute working documents as Internet-

Internet-Drafts are draft documents valid for a maximum of
six months and may be updated, replaced, or obsoleted by
other documents at any time.  It is inappropriate to use
Internet- Drafts as reference material or to cite them other
than as ``work in progress.''

To learn the current status of any Internet-Draft, please
check the ``1id-abstracts.txt'' listing contained in the
Internet- Drafts Shadow Directories on ftp.is.co.za (Africa),
nic.nordu.net (Europe), munnari.oz.au (Pacific Rim),
ds.internic.net (US East Coast), or ftp.isi.edu (US West


         1. INTRODUCTION

                2.1 Rule Naming
                2.2 Rule Form
                2.3 End-of-Rule
                2.4 Terminal Values
                2.5 External Encodings

                3.1 Concatenation:  Rule1 Rule2
                3.2 Alternatives:  Rule1 / Rule2
                3.3 Incremental Alternatives: Rule1 =/ Rule2
                3.4 Sequence Group:  (Rule1 Rule2)
                3.5 Set Group:  {Rule 1 Rule2}
                3.6 Variable Repetition: *Rule
                3.7 Specific Repetition: nRule
                3.8 Optional Sequence: [RULE]
                3.9 Lists:  #Rule
                3.10 Value Ranges: a..b
                3.11 ; Comment
                3.12 Operator Precedence





     8. CONTACT


Internet technical specifications often need to define a
format 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, RFC733 and then RFC822 which have come
to be the common citations for defining ABNF.  The current
document separates out that definition, to permit selective
reference.  Predictably, it also provides some enhancements.

The differences between standard BNF and the ABNF defined
here involve naming rules, repetition, alternatives, and
order-independence, and rules that add alternatives to
existing rules, lists, and value ranges.  Appendix A (Core)
supplies rule definitions 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 its
formal status.


2.1  Rule Naming

The name of  a rule is simply the name itself; that is, a
sequence of characters, not beginning with  a digit, with an
asterisk ("*"), or with a number (pound) sign ("#").  (This
avoids ambiguity with the various repetition mechanisms,
defined below.)  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 used around a rule
reference whenever their presence will facilitate 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
linear white space, such as shown in the discussion about
repetition, below.

2.2  Rule Form

A rule is defined by the following sequence:

     name =  elements

where <name> is the name of the rule and <elements> is one or
more rules or terminal specifications.  The equal sign
separates the name from the definition of the rule.  The
elements are 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

2.3  End-of-Rule

Formally the grammar requires a one-token look-ahead to find
the "=" token, which indicates that the previous token is the
name of a new rule.  For visual ease, rules should start in
column 1, with rule continuation indicated by blank (linear
white space) in column 1.  In some documentation, "column 1"
might be virtual, with a consistent indentation from the left
margin, for all rules.

2.4  Terminal Values

Rules resolve into a string of terminal values, sometimes
called characters.  Values within ABNF are represented as
decimal numbers.  Hence, an ABNF parser processes a sequence
of characters.  Each character is represented as a decimal
number.  A string of values is in "network byte order" with
the higher-valued bytes represented on the left-hand side and
begin sent over the network first..

Terminals are specified by one or more numerica characters
with the base interpretation of those characters indicated
explicitly.  The following bases are currently defined:

     b    =  binary

     d    =  decimal

     x    =  hexadecimal


     CR   =  %d13

     CR   =  %x0D

respectively specify the decimal and hexadecimal
representation of [US-ASCII] for carriage return.

A string of such values is specified compactly, using a
period (".") to indicate separation of characters within that
value.  Hence:

     CRLF =  %d13.10

For a sequence of values which can be represented as simple,
graphical characters (letters), they may be specified as a
string of literals, enclosed in quotation-marks.  Hence:

     rule =    "rule-name = rule-value"

specifies the rule "rule" which contains the characters of an
ABNF rule specification.



     rulename = "abc"

will match "abc", "Abc", "aBc", "abC", "ABc", "aBC", and

To specify a rule which IS case SENSITIVE, specify the
characters individually.  For example:

     rulename = %d97 %d9 %d99


     rulename = %d97.98.99

will match only the string which comprises only lowercased
characters, abc.

2.5  External Encodings

External representations of these 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 Appendix A
(Core) 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.


3.1  Concatenation:  Rule1 Rule2

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:

     foo =  %x61         ; a

     bar =  %x62         ; b

     mumble =  foo bar foo

So that the rule <mumble> defines the lower-case string

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-interspered around major constructs, such as
delimiting special characters or atomic strings.


Any grammar which 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.

3.2  Alternatives:  Rule1 / Rule2

Elements separated by forward slash ("/") are alternatives.

     foo / bar

will accept <foo> or <bar>.

3.3  Incremental Alternatives: Rule1 =/ Rule2

It is sometimes convenient to specify a list of alternatives
in fragments.  That is, an initial rule may define one or
more alternatives, with later rule definitions adding to the
set of alternatives.  This is particularly useful for
otherwise-independent specifications which derive from the
same parent rule set, such as often occurs with parameter
lists.  ABNF permits this incremental definition through the

     oldrule =/ additional-alternatives

So that the rule set

     ruleset = alt1 / alt2

     ruleset =/ alt3

     ruleset =/ alt4 / alt5

is the same as specifying

     ruleset = alt1 / alt2 / alt3 / alt4 / alt5

3.4  Sequence Group:  (Rule1 Rule2)

Elements enclosed in parentheses are  treated  as  a  single
element, whose contents are STRICTLY ORDERED.   Thus,

     (elem foo) / (bar blat) elem

allows the token sequences (elem foo elem) and (bar blat
elem).   Without the grouping, the rule:

     elem foo / bar elem

would match (elem foo elem) or (elem bar elem).  The local
grouping notation is also used within free text to set off an
element sequence from the prose.

3.5  Set Group:  {Rule 1 Rule2}

Elements enclosed in braces (squiggly brackets) are treated
as a single, UNORDERED element.  Its contents may occur in
any order.  Hence:

     {elem foo} bar

would match (elem foo bar) and (foo elem bar).

NOTE: Specifying alternatives is quite different from
specifying set grouping.  Alternatives indicate the matching
of exactly one (sub-)rule out of the total grouping.  The set
mechanism indicates the matching of a string which contains
all of the elements within the group; however the elements
may occur in any order.

3.6  Variable Repetition:  *Rule

The operator "*" preceding an element indicates repetition.
The full form is:


where <a> and <b> are optional decimal values, indicating at
least <a> and at most <b> occurrences  of  element.

Default values are 0 and infinity so that <*element> allows
any number, including zero; <1*element> requires at  least
one;  <3*3element> allows exactly 3 and <1*2element> allows
one or two.

3.7  Specific Repetition:  nRule

A rule of the form:


is equivalent to


That is, exactly  <N>  occurrences  of <element>. Thus 2DIGIT
is a 2-digit number, and 3ALPHA is a string of three
alphabetic characters.

3.8  Optional Sequence:  [RULE]

Square brackets enclose an optional element sequence:

     [foo bar]

is equivalent to

     *1(foo bar).

3.9  Lists:  #Rule

A construct "#" is defined as being similar to "*", for a
list sequence:


indicates at least <a> and at most <b> elements, each
separated by one or more commas (","). This makes the usual
form of lists very easy; a rule such as:

     element *("," element)

can therefore be shown as


Wherever this construct is used, null elements are allowed,
but do not  contribute to the count  of  elements present.
That  is,


is  permitted,  but counts as only two elements.  Therefore,
where at least one  element  is required, at least one non-
null element must be present.

Default values are 0 and infinity so that <#element> allows
any number,  including  zero; <1#element> requires at least
one; and <1#2element> allows one or two.

3.10 Value Ranges: a..b

Values separated by double periods ("..") specify a range of
values from the lowest, on the left-hand side, to the highest
on the right-hand side.   Values may be specifiednumericallyl
or with rule references.  The form:




represents a value in the range 12 to 15, inclusively.  When
the values are specified using rules rather than explicit
decimal numbers, the rules must reduce to single, decimal
values.  Hence:

     CR = %d12

     LF = %d15

     smallrange = LF..CR

is valid and indicates the decimal value range 12 to 15.

3.11 ; Comment

A semi-colon starts  a comment that continues to the end of
line.  This is a simple way of including useful notes in
parallel  with  the specifications.

3.12 Operator Precedence

The various mechanisms described above have the following
precedence, from highest (binding tightest) at the top, to
lowest and loosest at the bottom:

     Value range
     Repetition, List
     Grouping, Optional

Use of the alternative operator, freely mixed with
concatenations can be confusing.  It is STRONGLY recommended
that the grouping operator be used to make explicit
concatenation groups.


This syntax uses the rules provided in Appendix A (Core).

     rule           =  rulename *WSP ("=" / "=/") value
                       [comment] *WSP CRLF
                            ; continues if next line starts
                               with white space
                            ; basic rules definition and
                               incremental alternatives

     bin-val        =  "b" 1*("0".."1")
                       [ 1*("." 1*("0".."1"))
                       / (".." 1*("0".."1")) ]

     comment        =  *WSP ";" *(WSP / %x21..%x7E)

     dec-val        =  "d" 1*DIGIT
                       [ 1*("." 1*DIGIT)
                       / (".." 1*DIGIT) ]

     el-component   =  rulename / set / group / option /
                       num-val / lit-val / prose-val

     element        =  [repeat] el-component

     group          =  *WSP "(" value *WSP ")"

     hex-val        =  "x" 1*(DIGIT / "A".."F")
                       [ 1*("." 1*(DIGIT / "A".."F"))
                       / (".." 1*(DIGIT / "A".."F")) ]

     lit-val        =  *WSP <"> *PCHAR <">

     num-val        =  *WSP "%" (bin-val / dec-val / hex-val)

     option         =  *WSP "[" value *WSP "]

     prose-val      =  *WSP "<"
                        <description of value> ">"

     set            =  *WSP "{" 2*element *WSP "}"
                            ; elements in any order

     range          =  value *WSP ".." value
                            ; values must reduce to single
                               decimal values

     repeat         =  repeat-num /
                       [repeat-num] *WSP
                       ("*" / "#") [repeat-num]

     repeat-num     =  *WSP 1*DIGIT

     rulename       =  *WSP ALPHA *( ALPHA / DIGIT / "-" )

     value          =  1*element *(*WSP "/" 1*element)


This Appendix is provided as a convenient core for specific
grammars.  The definitions may be used as a core set of

Certain  basic  rules  are  in uppercase, such as SPACE, TAB,

     ALPHA          = "A".."Z"
                            ; case not significant

     CHAR           =  %x00..7F
                            ; us-ascii

     CR             =  %d13

     CRLF           =  CR LF

     CTL            =  %d0..31 / %d127

     DIGIT          =  "0".."9"

     HTAB           =  %d9

     LF             =  %d10

     LWSP           =  SP / HTAB

     SPACE          =  " "

     PCHAR          =  %x20..7E

     WSP            =  LWSP / CRLF LWSP

Externally, data are represented as "network virtual ASCII",
namely 7-bit US-ASCII in an 8th bit field, with the high
(8th) bit set to zero.


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.  The current
round of specification was part of the DRUMS working group,
with significant contributions from Bill McQuillan, Keith
Moore, Pete Resnick, Jerome Abela and Chris Newman.


[US-ASCII]     Coded Character Set--7-Bit American Standard
Code for Information Interchange, ANSI X3.4-1986.


David H. Crocker                 Paul Overell
                                 Demon Internet Ltd
Internet Mail Consortium         Dorking Business Park
675 Spruce Dr.                   Dorking
Sunnyvale, CA 94086 USA          Surrey, RH4 1HN
Phone:    +1 408 246 8253
Fax:      +1 408 249 6205