7Network Working Group                                    D. Crocker, Ed.
 
8Request for Comments: 5234                   Brandenburg InternetWorking
 
10Obsoletes: 4234                                                THUS plc.
 
11Category: Standards Track                                   January 2008
 
14             Augmented BNF for Syntax Specifications: ABNF
 
18   This document specifies an Internet standards track protocol for the
 
19   Internet community, and requests discussion and suggestions for
 
20   improvements.  Please refer to the current edition of the "Internet
 
21   Official Protocol Standards" (STD 1) for the standardization state
 
22   and status of this protocol.  Distribution of this memo is unlimited.
 
26   Internet technical specifications often need to define a formal
 
27   syntax.  Over the years, a modified version of Backus-Naur Form
 
28   (BNF), called Augmented BNF (ABNF), has been popular among many
 
29   Internet specifications.  The current specification documents ABNF.
 
30   It balances compactness and simplicity with reasonable
 
31   representational power.  The differences between standard BNF and
 
32   ABNF involve naming rules, repetition, alternatives, order-
 
33   independence, and value ranges.  This specification also supplies
 
34   additional rule definitions and encoding for a core lexical analyzer
 
35   of the type common to several Internet specifications.
 
58Crocker & Overell           Standards Track                     [Page 1]
 
60RFC 5234                          ABNF                      January 2008
 
65   1.  Introduction . . . . . . . . . . . . . . . . . . . . . . . . .  3
 
66   2.  Rule Definition  . . . . . . . . . . . . . . . . . . . . . . .  3
 
67     2.1.  Rule Naming  . . . . . . . . . . . . . . . . . . . . . . .  3
 
68     2.2.  Rule Form  . . . . . . . . . . . . . . . . . . . . . . . .  4
 
69     2.3.  Terminal Values  . . . . . . . . . . . . . . . . . . . . .  4
 
70     2.4.  External Encodings . . . . . . . . . . . . . . . . . . . .  6
 
71   3.  Operators  . . . . . . . . . . . . . . . . . . . . . . . . . .  6
 
72     3.1.  Concatenation:  Rule1 Rule2  . . . . . . . . . . . . . . .  6
 
73     3.2.  Alternatives:  Rule1 / Rule2 . . . . . . . . . . . . . . .  7
 
74     3.3.  Incremental Alternatives: Rule1 =/ Rule2 . . . . . . . . .  7
 
75     3.4.  Value Range Alternatives:  %c##-## . . . . . . . . . . . .  8
 
76     3.5.  Sequence Group:  (Rule1 Rule2) . . . . . . . . . . . . . .  8
 
77     3.6.  Variable Repetition:  *Rule  . . . . . . . . . . . . . . .  9
 
78     3.7.  Specific Repetition:  nRule  . . . . . . . . . . . . . . .  9
 
79     3.8.  Optional Sequence:  [RULE] . . . . . . . . . . . . . . . .  9
 
80     3.9.  Comment:  ; Comment  . . . . . . . . . . . . . . . . . . .  9
 
81     3.10. Operator Precedence  . . . . . . . . . . . . . . . . . . . 10
 
82   4.  ABNF Definition of ABNF  . . . . . . . . . . . . . . . . . . . 10
 
83   5.  Security Considerations  . . . . . . . . . . . . . . . . . . . 12
 
84   6.  References . . . . . . . . . . . . . . . . . . . . . . . . . . 12
 
85     6.1.  Normative References . . . . . . . . . . . . . . . . . . . 12
 
86     6.2.  Informative References . . . . . . . . . . . . . . . . . . 12
 
87   Appendix A.  Acknowledgements  . . . . . . . . . . . . . . . . . . 13
 
88   Appendix B.  Core ABNF of ABNF . . . . . . . . . . . . . . . . . . 13
 
89     B.1.  Core Rules . . . . . . . . . . . . . . . . . . . . . . . . 13
 
90     B.2.  Common Encoding  . . . . . . . . . . . . . . . . . . . . . 15
 
114Crocker & Overell           Standards Track                     [Page 2]
 
116RFC 5234                          ABNF                      January 2008
 
121   Internet technical specifications often need to define a formal
 
122   syntax and are free to employ whatever notation their authors deem
 
123   useful.  Over the years, a modified version of Backus-Naur Form
 
124   (BNF), called Augmented BNF (ABNF), has been popular among many
 
125   Internet specifications.  It balances compactness and simplicity with
 
126   reasonable representational power.  In the early days of the Arpanet,
 
127   each specification contained its own definition of ABNF.  This
 
128   included the email specifications, [RFC733] and then [RFC822], which
 
129   came to be the common citations for defining ABNF.  The current
 
130   document separates those definitions to permit selective reference.
 
131   Predictably, it also provides some modifications and enhancements.
 
133   The differences between standard BNF and ABNF involve naming rules,
 
134   repetition, alternatives, order-independence, and value ranges.
 
135   Appendix B supplies rule definitions and encoding for a core lexical
 
136   analyzer of the type common to several Internet specifications.  It
 
137   is provided as a convenience and is otherwise separate from the meta
 
138   language defined in the body of this document, and separate from its
 
145   The name of a rule is simply the name itself, that is, a sequence of
 
146   characters, beginning with an alphabetic character, and followed by a
 
147   combination of alphabetics, digits, and hyphens (dashes).
 
151      Rule names are case insensitive.
 
153   The names <rulename>, <Rulename>, <RULENAME>, and <rUlENamE> all
 
154   refer to the same rule.
 
156   Unlike original BNF, angle brackets ("<", ">") are not required.
 
157   However, angle brackets may be used around a rule name whenever their
 
158   presence facilitates in discerning the use of a rule name.  This is
 
159   typically restricted to rule name references in free-form prose, or
 
160   to distinguish partial rules that combine into a string not separated
 
161   by white space, such as shown in the discussion about repetition,
 
170Crocker & Overell           Standards Track                     [Page 3]
 
172RFC 5234                          ABNF                      January 2008
 
177   A rule is defined by the following sequence:
 
181   where <name> is the name of the rule, <elements> is one or more rule
 
182   names or terminal specifications, and <crlf> is the end-of-line
 
183   indicator (carriage return followed by line feed).  The equal sign
 
184   separates the name from the definition of the rule.  The elements
 
185   form a sequence of one or more rule names and/or value definitions,
 
186   combined according to the various operators defined in this document,
 
187   such as alternative and repetition.
 
189   For visual ease, rule definitions are left aligned.  When a rule
 
190   requires multiple lines, the continuation lines are indented.  The
 
191   left alignment and indentation are relative to the first lines of the
 
192   ABNF rules and need not match the left margin of the document.
 
196   Rules resolve into a string of terminal values, sometimes called
 
197   characters.  In ABNF, a character is merely a non-negative integer.
 
198   In certain contexts, a specific mapping (encoding) of values into a
 
199   character set (such as ASCII) will be specified.
 
201   Terminals are specified by one or more numeric characters, with the
 
202   base interpretation of those characters indicated explicitly.  The
 
203   following bases are currently defined:
 
217   respectively specify the decimal and hexadecimal representation of
 
218   [US-ASCII] for carriage return.
 
226Crocker & Overell           Standards Track                     [Page 4]
 
228RFC 5234                          ABNF                      January 2008
 
231   A concatenated string of such values is specified compactly, using a
 
232   period (".") to indicate a separation of characters within that
 
237   ABNF permits the specification of literal text strings directly,
 
238   enclosed in quotation marks.  Hence:
 
240         command     =  "command string"
 
242   Literal text strings are interpreted as a concatenated set of
 
243   printable characters.
 
247      ABNF strings are case insensitive and the character set for these
 
258   will match "abc", "Abc", "aBc", "abC", "ABc", "aBC", "AbC", and
 
261      To specify a rule that is case sensitive, specify the characters
 
266         rulename    =  %d97 %d98 %d99
 
270         rulename    =  %d97.98.99
 
272   will match only the string that comprises only the lowercase
 
282Crocker & Overell           Standards Track                     [Page 5]
 
284RFC 5234                          ABNF                      January 2008
 
2872.4.  External Encodings
 
289   External representations of terminal value characters will vary
 
290   according to constraints in the storage or transmission environment.
 
291   Hence, the same ABNF-based grammar may have multiple external
 
292   encodings, such as one for a 7-bit US-ASCII environment, another for
 
293   a binary octet environment, and still a different one when 16-bit
 
294   Unicode is used.  Encoding details are beyond the scope of ABNF,
 
295   although Appendix B provides definitions for a 7-bit US-ASCII
 
296   environment as has been common to much of the Internet.
 
298   By separating external encoding from the syntax, it is intended that
 
299   alternate encoding environments can be used for the same syntax.
 
3033.1.  Concatenation:  Rule1 Rule2
 
305   A rule can define a simple, ordered string of values (i.e., a
 
306   concatenation of contiguous characters) by listing a sequence of rule
 
315   So that the rule <mumble> matches the lowercase string "aba".
 
317   Linear white space: Concatenation is at the core of the ABNF parsing
 
318   model.  A string of contiguous characters (values) is parsed
 
319   according to the rules defined in ABNF.  For Internet specifications,
 
320   there is some history of permitting linear white space (space and
 
321   horizontal tab) to be freely and implicitly interspersed around major
 
322   constructs, such as delimiting special characters or atomic strings.
 
326      This specification for ABNF does not provide for implicit
 
327      specification of linear white space.
 
329   Any grammar that wishes to permit linear white space around
 
330   delimiters or string segments must specify it explicitly.  It is
 
331   often useful to provide for such white space in "core" rules that are
 
332   then used variously among higher-level rules.  The "core" rules might
 
333   be formed into a lexical analyzer or simply be part of the main
 
338Crocker & Overell           Standards Track                     [Page 6]
 
340RFC 5234                          ABNF                      January 2008
 
3433.2.  Alternatives:  Rule1 / Rule2
 
345   Elements separated by a forward slash ("/") are alternatives.
 
350   will accept <foo> or <bar>.
 
354      A quoted string containing alphabetic characters is a special form
 
355      for specifying alternative characters and is interpreted as a non-
 
356      terminal representing the set of combinatorial strings with the
 
357      contained characters, in the specified order but with any mixture
 
358      of upper- and lowercase.
 
3603.3.  Incremental Alternatives: Rule1 =/ Rule2
 
362   It is sometimes convenient to specify a list of alternatives in
 
363   fragments.  That is, an initial rule may match one or more
 
364   alternatives, with later rule definitions adding to the set of
 
365   alternatives.  This is particularly useful for otherwise independent
 
366   specifications that derive from the same parent ruleset, such as
 
367   often occurs with parameter lists.  ABNF permits this incremental
 
368   definition through the construct:
 
370         oldrule     =/ additional-alternatives
 
374         ruleset     =  alt1 / alt2
 
378         ruleset     =/ alt4 / alt5
 
380   is the same as specifying
 
382         ruleset     =  alt1 / alt2 / alt3 / alt4 / alt5
 
394Crocker & Overell           Standards Track                     [Page 7]
 
396RFC 5234                          ABNF                      January 2008
 
3993.4.  Value Range Alternatives:  %c##-##
 
401   A range of alternative numeric values can be specified compactly,
 
402   using a dash ("-") to indicate the range of alternative values.
 
409         DIGIT       =  "0" / "1" / "2" / "3" / "4" / "5" / "6" /
 
413   Concatenated numeric values and numeric value ranges cannot be
 
414   specified in the same string.  A numeric value may use the dotted
 
415   notation for concatenation or it may use the dash notation to specify
 
416   one value range.  Hence, to specify one printable character between
 
417   end-of-line sequences, the specification could be:
 
419         char-line = %x0D.0A %x20-7E %x0D.0A
 
4213.5.  Sequence Group:  (Rule1 Rule2)
 
423   Elements enclosed in parentheses are treated as a single element,
 
424   whose contents are strictly ordered.  Thus,
 
426         elem (foo / bar) blat
 
428   matches (elem foo blat) or (elem bar blat), and
 
432   matches (elem foo) or (bar blat).
 
436      It is strongly advised that grouping notation be used, rather than
 
437      relying on the proper reading of "bare" alternations, when
 
438      alternatives consist of multiple rule names or literals.
 
440   Hence, it is recommended that the following form be used:
 
442        (elem foo) / (bar blat)
 
444   It will avoid misinterpretation by casual readers.
 
450Crocker & Overell           Standards Track                     [Page 8]
 
452RFC 5234                          ABNF                      January 2008
 
455   The sequence group notation is also used within free text to set off
 
456   an element sequence from the prose.
 
4583.6.  Variable Repetition:  *Rule
 
460   The operator "*" preceding an element indicates repetition.  The full
 
465   where <a> and <b> are optional decimal values, indicating at least
 
466   <a> and at most <b> occurrences of the element.
 
468   Default values are 0 and infinity so that *<element> allows any
 
469   number, including zero; 1*<element> requires at least one;
 
470   3*3<element> allows exactly 3; and 1*2<element> allows one or two.
 
4723.7.  Specific Repetition:  nRule
 
482   That is, exactly <n> occurrences of <element>.  Thus, 2DIGIT is a
 
483   2-digit number, and 3ALPHA is a string of three alphabetic
 
4863.8.  Optional Sequence:  [RULE]
 
488   Square brackets enclose an optional element sequence:
 
4963.9.  Comment:  ; Comment
 
498   A semicolon starts a comment that continues to the end of line.  This
 
499   is a simple way of including useful notes in parallel with the
 
506Crocker & Overell           Standards Track                     [Page 9]
 
508RFC 5234                          ABNF                      January 2008
 
5113.10.  Operator Precedence
 
513   The various mechanisms described above have the following precedence,
 
514   from highest (binding tightest) at the top, to lowest (loosest) at
 
517      Rule name, prose-val, Terminal value
 
531   Use of the alternative operator, freely mixed with concatenations,
 
534      Again, it is recommended that the grouping operator be used to
 
535      make explicit concatenation groups.
 
5374.  ABNF Definition of ABNF
 
541      1.  This syntax requires a formatting of rules that is relatively
 
542          strict.  Hence, the version of a ruleset included in a
 
543          specification might need preprocessing to ensure that it can
 
544          be interpreted by an ABNF parser.
 
546      2.  This syntax uses the rules provided in Appendix B.
 
549         rulelist       =  1*( rule / (*c-wsp c-nl) )
 
551         rule           =  rulename defined-as elements c-nl
 
552                                ; continues if next line starts
 
555         rulename       =  ALPHA *(ALPHA / DIGIT / "-")
 
562Crocker & Overell           Standards Track                    [Page 10]
 
564RFC 5234                          ABNF                      January 2008
 
567         defined-as     =  *c-wsp ("=" / "=/") *c-wsp
 
568                                ; basic rules definition and
 
569                                ;  incremental alternatives
 
571         elements       =  alternation *c-wsp
 
573         c-wsp          =  WSP / (c-nl WSP)
 
575         c-nl           =  comment / CRLF
 
578         comment        =  ";" *(WSP / VCHAR) CRLF
 
580         alternation    =  concatenation
 
581                           *(*c-wsp "/" *c-wsp concatenation)
 
583         concatenation  =  repetition *(1*c-wsp repetition)
 
585         repetition     =  [repeat] element
 
587         repeat         =  1*DIGIT / (*DIGIT "*" *DIGIT)
 
589         element        =  rulename / group / option /
 
590                           char-val / num-val / prose-val
 
592         group          =  "(" *c-wsp alternation *c-wsp ")"
 
594         option         =  "[" *c-wsp alternation *c-wsp "]"
 
596         char-val       =  DQUOTE *(%x20-21 / %x23-7E) DQUOTE
 
597                                ; quoted string of SP and VCHAR
 
600         num-val        =  "%" (bin-val / dec-val / hex-val)
 
603                           [ 1*("." 1*BIT) / ("-" 1*BIT) ]
 
604                                ; series of concatenated bit values
 
605                                ;  or single ONEOF range
 
607         dec-val        =  "d" 1*DIGIT
 
608                           [ 1*("." 1*DIGIT) / ("-" 1*DIGIT) ]
 
610         hex-val        =  "x" 1*HEXDIG
 
611                           [ 1*("." 1*HEXDIG) / ("-" 1*HEXDIG) ]
 
618Crocker & Overell           Standards Track                    [Page 11]
 
620RFC 5234                          ABNF                      January 2008
 
623         prose-val      =  "<" *(%x20-3D / %x3F-7E) ">"
 
624                                ; bracketed string of SP and VCHAR
 
626                                ; prose description, to be used as
 
6295.  Security Considerations
 
631   Security is truly believed to be irrelevant to this document.
 
6356.1.  Normative References
 
637   [US-ASCII]  American National Standards Institute, "Coded Character
 
638               Set -- 7-bit American Standard Code for Information
 
639               Interchange", ANSI X3.4, 1986.
 
6416.2.  Informative References
 
643   [RFC733]    Crocker, D., Vittal, J., Pogran, K., and D. Henderson,
 
644               "Standard for the format of ARPA network text messages",
 
645               RFC 733, November 1977.
 
647   [RFC822]    Crocker, D., "Standard for the format of ARPA Internet
 
648               text messages", STD 11, RFC 822, August 1982.
 
674Crocker & Overell           Standards Track                    [Page 12]
 
676RFC 5234                          ABNF                      January 2008
 
679Appendix A.  Acknowledgements
 
681   The syntax for ABNF was originally specified in RFC 733.  Ken L.
 
682   Harrenstien, of SRI International, was responsible for re-coding the
 
683   BNF into an Augmented BNF that makes the representation smaller and
 
684   easier to understand.
 
686   This recent project began as a simple effort to cull out the portion
 
687   of RFC 822 that has been repeatedly cited by non-email specification
 
688   writers, namely the description of Augmented BNF.  Rather than simply
 
689   and blindly converting the existing text into a separate document,
 
690   the working group chose to give careful consideration to the
 
691   deficiencies, as well as benefits, of the existing specification and
 
692   related specifications made available over the last 15 years, and
 
693   therefore to pursue enhancement.  This turned the project into
 
694   something rather more ambitious than was first intended.
 
695   Interestingly, the result is not massively different from that
 
696   original, although decisions, such as removing the list notation,
 
699   This "separated" version of the specification was part of the DRUMS
 
700   working group, with significant contributions from Jerome Abela,
 
701   Harald Alvestrand, Robert Elz, Roger Fajman, Aviva Garrett, Tom
 
702   Harsch, Dan Kohn, Bill McQuillan, Keith Moore, Chris Newman, Pete
 
703   Resnick, and Henning Schulzrinne.
 
705   Julian Reschke warrants a special thanks for converting the Draft
 
706   Standard version to XML source form.
 
708Appendix B.  Core ABNF of ABNF
 
710   This appendix contains some basic rules that are in common use.
 
711   Basic rules are in uppercase.  Note that these rules are only valid
 
712   for ABNF encoded in 7-bit ASCII or in characters sets that are a
 
713   superset of 7-bit ASCII.
 
717   Certain basic rules are in uppercase, such as SP, HTAB, CRLF, DIGIT,
 
720         ALPHA          =  %x41-5A / %x61-7A   ; A-Z / a-z
 
725                                ; any 7-bit US-ASCII character,
 
730Crocker & Overell           Standards Track                    [Page 13]
 
732RFC 5234                          ABNF                      January 2008
 
739                                ; Internet standard newline
 
750         HEXDIG         =  DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
 
758         LWSP           =  *(WSP / CRLF WSP)
 
759                                ; Use of this linear-white-space rule
 
760                                ;  permits lines containing only white
 
761                                ;  space that are no longer legal in
 
762                                ;  mail headers and have caused
 
763                                ;  interoperability problems in other
 
765                                ; Do not use when defining mail
 
766                                ;  headers and use with caution in
 
775                                ; visible (printing) characters
 
786Crocker & Overell           Standards Track                    [Page 14]
 
788RFC 5234                          ABNF                      January 2008
 
793   Externally, data are represented as "network virtual ASCII" (namely,
 
794   7-bit US-ASCII in an 8-bit field), with the high (8th) bit set to
 
795   zero.  A string of values is in "network byte order", in which the
 
796   higher-valued bytes are represented on the left-hand side and are
 
797   sent over the network first.
 
801   Dave Crocker (editor)
 
802   Brandenburg InternetWorking
 
807   Phone: +1.408.246.8253
 
808   EMail: dcrocker@bbiw.net
 
818   EMail: paul.overell@thus.net
 
842Crocker & Overell           Standards Track                    [Page 15]
 
844RFC 5234                          ABNF                      January 2008
 
847Full Copyright Statement
 
849   Copyright (C) The IETF Trust (2008).
 
851   This document is subject to the rights, licenses and restrictions
 
852   contained in BCP 78, and except as set forth therein, the authors
 
853   retain all their rights.
 
855   This document and the information contained herein are provided on an
 
856   "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
 
857   OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND
 
858   THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS
 
859   OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF
 
860   THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
 
861   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
 
865   The IETF takes no position regarding the validity or scope of any
 
866   Intellectual Property Rights or other rights that might be claimed to
 
867   pertain to the implementation or use of the technology described in
 
868   this document or the extent to which any license under such rights
 
869   might or might not be available; nor does it represent that it has
 
870   made any independent effort to identify any such rights.  Information
 
871   on the procedures with respect to rights in RFC documents can be
 
872   found in BCP 78 and BCP 79.
 
874   Copies of IPR disclosures made to the IETF Secretariat and any
 
875   assurances of licenses to be made available, or the result of an
 
876   attempt made to obtain a general license or permission for the use of
 
877   such proprietary rights by implementers or users of this
 
878   specification can be obtained from the IETF on-line IPR repository at
 
879   http://www.ietf.org/ipr.
 
881   The IETF invites any interested party to bring to its attention any
 
882   copyrights, patents or patent applications, or other proprietary
 
883   rights that may cover technology that may be required to implement
 
884   this standard.  Please address the information to the IETF at
 
898Crocker & Overell           Standards Track                    [Page 16]