1
2
3
4
5
6
7Network Working Group D. Crocker, Ed.
8Request for Comments: 5234 Brandenburg InternetWorking
9STD: 68 P. Overell
10Obsoletes: 4234 THUS plc.
11Category: Standards Track January 2008
12
13
14 Augmented BNF for Syntax Specifications: ABNF
15
16Status of This Memo
17
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.
23
24Abstract
25
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.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58Crocker & Overell Standards Track [Page 1]
59
60RFC 5234 ABNF January 2008
61
62
63Table of Contents
64
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114Crocker & Overell Standards Track [Page 2]
115
116RFC 5234 ABNF January 2008
117
118
1191. Introduction
120
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.
132
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
139 formal status.
140
1412. Rule Definition
142
1432.1. Rule Naming
144
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).
148
149 NOTE:
150
151 Rule names are case insensitive.
152
153 The names <rulename>, <Rulename>, <RULENAME>, and <rUlENamE> all
154 refer to the same rule.
155
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,
162 below.
163
164
165
166
167
168
169
170Crocker & Overell Standards Track [Page 3]
171
172RFC 5234 ABNF January 2008
173
174
1752.2. Rule Form
176
177 A rule is defined by the following sequence:
178
179 name = elements crlf
180
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.
188
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.
193
1942.3. Terminal Values
195
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.
200
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:
204
205 b = binary
206
207 d = decimal
208
209 x = hexadecimal
210
211 Hence:
212
213 CR = %d13
214
215 CR = %x0D
216
217 respectively specify the decimal and hexadecimal representation of
218 [US-ASCII] for carriage return.
219
220
221
222
223
224
225
226Crocker & Overell Standards Track [Page 4]
227
228RFC 5234 ABNF January 2008
229
230
231 A concatenated string of such values is specified compactly, using a
232 period (".") to indicate a separation of characters within that
233 value. Hence:
234
235 CRLF = %d13.10
236
237 ABNF permits the specification of literal text strings directly,
238 enclosed in quotation marks. Hence:
239
240 command = "command string"
241
242 Literal text strings are interpreted as a concatenated set of
243 printable characters.
244
245 NOTE:
246
247 ABNF strings are case insensitive and the character set for these
248 strings is US-ASCII.
249
250 Hence:
251
252 rulename = "abc"
253
254 and:
255
256 rulename = "aBc"
257
258 will match "abc", "Abc", "aBc", "abC", "ABc", "aBC", "AbC", and
259 "ABC".
260
261 To specify a rule that is case sensitive, specify the characters
262 individually.
263
264 For example:
265
266 rulename = %d97 %d98 %d99
267
268 or
269
270 rulename = %d97.98.99
271
272 will match only the string that comprises only the lowercase
273 characters, abc.
274
275
276
277
278
279
280
281
282Crocker & Overell Standards Track [Page 5]
283
284RFC 5234 ABNF January 2008
285
286
2872.4. External Encodings
288
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.
297
298 By separating external encoding from the syntax, it is intended that
299 alternate encoding environments can be used for the same syntax.
300
3013. Operators
302
3033.1. Concatenation: Rule1 Rule2
304
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
307 names. For example:
308
309 foo = %x61 ; a
310
311 bar = %x62 ; b
312
313 mumble = foo bar foo
314
315 So that the rule <mumble> matches the lowercase string "aba".
316
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.
323
324 NOTE:
325
326 This specification for ABNF does not provide for implicit
327 specification of linear white space.
328
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
334 ruleset.
335
336
337
338Crocker & Overell Standards Track [Page 6]
339
340RFC 5234 ABNF January 2008
341
342
3433.2. Alternatives: Rule1 / Rule2
344
345 Elements separated by a forward slash ("/") are alternatives.
346 Therefore,
347
348 foo / bar
349
350 will accept <foo> or <bar>.
351
352 NOTE:
353
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.
359
3603.3. Incremental Alternatives: Rule1 =/ Rule2
361
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:
369
370 oldrule =/ additional-alternatives
371
372 So that the ruleset
373
374 ruleset = alt1 / alt2
375
376 ruleset =/ alt3
377
378 ruleset =/ alt4 / alt5
379
380 is the same as specifying
381
382 ruleset = alt1 / alt2 / alt3 / alt4 / alt5
383
384
385
386
387
388
389
390
391
392
393
394Crocker & Overell Standards Track [Page 7]
395
396RFC 5234 ABNF January 2008
397
398
3993.4. Value Range Alternatives: %c##-##
400
401 A range of alternative numeric values can be specified compactly,
402 using a dash ("-") to indicate the range of alternative values.
403 Hence:
404
405 DIGIT = %x30-39
406
407 is equivalent to:
408
409 DIGIT = "0" / "1" / "2" / "3" / "4" / "5" / "6" /
410
411 "7" / "8" / "9"
412
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:
418
419 char-line = %x0D.0A %x20-7E %x0D.0A
420
4213.5. Sequence Group: (Rule1 Rule2)
422
423 Elements enclosed in parentheses are treated as a single element,
424 whose contents are strictly ordered. Thus,
425
426 elem (foo / bar) blat
427
428 matches (elem foo blat) or (elem bar blat), and
429
430 elem foo / bar blat
431
432 matches (elem foo) or (bar blat).
433
434 NOTE:
435
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.
439
440 Hence, it is recommended that the following form be used:
441
442 (elem foo) / (bar blat)
443
444 It will avoid misinterpretation by casual readers.
445
446
447
448
449
450Crocker & Overell Standards Track [Page 8]
451
452RFC 5234 ABNF January 2008
453
454
455 The sequence group notation is also used within free text to set off
456 an element sequence from the prose.
457
4583.6. Variable Repetition: *Rule
459
460 The operator "*" preceding an element indicates repetition. The full
461 form is:
462
463 <a>*<b>element
464
465 where <a> and <b> are optional decimal values, indicating at least
466 <a> and at most <b> occurrences of the element.
467
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.
471
4723.7. Specific Repetition: nRule
473
474 A rule of the form:
475
476 <n>element
477
478 is equivalent to
479
480 <n>*<n>element
481
482 That is, exactly <n> occurrences of <element>. Thus, 2DIGIT is a
483 2-digit number, and 3ALPHA is a string of three alphabetic
484 characters.
485
4863.8. Optional Sequence: [RULE]
487
488 Square brackets enclose an optional element sequence:
489
490 [foo bar]
491
492 is equivalent to
493
494 *1(foo bar).
495
4963.9. Comment: ; Comment
497
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
500 specifications.
501
502
503
504
505
506Crocker & Overell Standards Track [Page 9]
507
508RFC 5234 ABNF January 2008
509
510
5113.10. Operator Precedence
512
513 The various mechanisms described above have the following precedence,
514 from highest (binding tightest) at the top, to lowest (loosest) at
515 the bottom:
516
517 Rule name, prose-val, Terminal value
518
519 Comment
520
521 Value range
522
523 Repetition
524
525 Grouping, Optional
526
527 Concatenation
528
529 Alternative
530
531 Use of the alternative operator, freely mixed with concatenations,
532 can be confusing.
533
534 Again, it is recommended that the grouping operator be used to
535 make explicit concatenation groups.
536
5374. ABNF Definition of ABNF
538
539 NOTES:
540
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.
545
546 2. This syntax uses the rules provided in Appendix B.
547
548
549 rulelist = 1*( rule / (*c-wsp c-nl) )
550
551 rule = rulename defined-as elements c-nl
552 ; continues if next line starts
553 ; with white space
554
555 rulename = ALPHA *(ALPHA / DIGIT / "-")
556
557
558
559
560
561
562Crocker & Overell Standards Track [Page 10]
563
564RFC 5234 ABNF January 2008
565
566
567 defined-as = *c-wsp ("=" / "=/") *c-wsp
568 ; basic rules definition and
569 ; incremental alternatives
570
571 elements = alternation *c-wsp
572
573 c-wsp = WSP / (c-nl WSP)
574
575 c-nl = comment / CRLF
576 ; comment or newline
577
578 comment = ";" *(WSP / VCHAR) CRLF
579
580 alternation = concatenation
581 *(*c-wsp "/" *c-wsp concatenation)
582
583 concatenation = repetition *(1*c-wsp repetition)
584
585 repetition = [repeat] element
586
587 repeat = 1*DIGIT / (*DIGIT "*" *DIGIT)
588
589 element = rulename / group / option /
590 char-val / num-val / prose-val
591
592 group = "(" *c-wsp alternation *c-wsp ")"
593
594 option = "[" *c-wsp alternation *c-wsp "]"
595
596 char-val = DQUOTE *(%x20-21 / %x23-7E) DQUOTE
597 ; quoted string of SP and VCHAR
598 ; without DQUOTE
599
600 num-val = "%" (bin-val / dec-val / hex-val)
601
602 bin-val = "b" 1*BIT
603 [ 1*("." 1*BIT) / ("-" 1*BIT) ]
604 ; series of concatenated bit values
605 ; or single ONEOF range
606
607 dec-val = "d" 1*DIGIT
608 [ 1*("." 1*DIGIT) / ("-" 1*DIGIT) ]
609
610 hex-val = "x" 1*HEXDIG
611 [ 1*("." 1*HEXDIG) / ("-" 1*HEXDIG) ]
612
613
614
615
616
617
618Crocker & Overell Standards Track [Page 11]
619
620RFC 5234 ABNF January 2008
621
622
623 prose-val = "<" *(%x20-3D / %x3F-7E) ">"
624 ; bracketed string of SP and VCHAR
625 ; without angles
626 ; prose description, to be used as
627 ; last resort
628
6295. Security Considerations
630
631 Security is truly believed to be irrelevant to this document.
632
6336. References
634
6356.1. Normative References
636
637 [US-ASCII] American National Standards Institute, "Coded Character
638 Set -- 7-bit American Standard Code for Information
639 Interchange", ANSI X3.4, 1986.
640
6416.2. Informative References
642
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.
646
647 [RFC822] Crocker, D., "Standard for the format of ARPA Internet
648 text messages", STD 11, RFC 822, August 1982.
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674Crocker & Overell Standards Track [Page 12]
675
676RFC 5234 ABNF January 2008
677
678
679Appendix A. Acknowledgements
680
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.
685
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,
697 came as a surprise.
698
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.
704
705 Julian Reschke warrants a special thanks for converting the Draft
706 Standard version to XML source form.
707
708Appendix B. Core ABNF of ABNF
709
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.
714
715B.1. Core Rules
716
717 Certain basic rules are in uppercase, such as SP, HTAB, CRLF, DIGIT,
718 ALPHA, etc.
719
720 ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
721
722 BIT = "0" / "1"
723
724 CHAR = %x01-7F
725 ; any 7-bit US-ASCII character,
726 ; excluding NUL
727
728
729
730Crocker & Overell Standards Track [Page 13]
731
732RFC 5234 ABNF January 2008
733
734
735 CR = %x0D
736 ; carriage return
737
738 CRLF = CR LF
739 ; Internet standard newline
740
741 CTL = %x00-1F / %x7F
742 ; controls
743
744 DIGIT = %x30-39
745 ; 0-9
746
747 DQUOTE = %x22
748 ; " (Double Quote)
749
750 HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
751
752 HTAB = %x09
753 ; horizontal tab
754
755 LF = %x0A
756 ; linefeed
757
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
764 ; contexts.
765 ; Do not use when defining mail
766 ; headers and use with caution in
767 ; other contexts.
768
769 OCTET = %x00-FF
770 ; 8 bits of data
771
772 SP = %x20
773
774 VCHAR = %x21-7E 6532:236 ../message/todo.go:7
775 ; visible (printing) characters
776
777 WSP = SP / HTAB
778 ; white space
779
780
781
782
783
784
785
786Crocker & Overell Standards Track [Page 14]
787
788RFC 5234 ABNF January 2008
789
790
791B.2. Common Encoding
792
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.
798
799Authors' Addresses
800
801 Dave Crocker (editor)
802 Brandenburg InternetWorking
803 675 Spruce Dr.
804 Sunnyvale, CA 94086
805 US
806
807 Phone: +1.408.246.8253
808 EMail: dcrocker@bbiw.net
809
810
811 Paul Overell
812 THUS plc.
813 1/2 Berkeley Square,
814 99 Berkeley Street
815 Glasgow G3 7HR
816 UK
817
818 EMail: paul.overell@thus.net
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842Crocker & Overell Standards Track [Page 15]
843
844RFC 5234 ABNF January 2008
845
846
847Full Copyright Statement
848
849 Copyright (C) The IETF Trust (2008).
850
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.
854
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.
862
863Intellectual Property
864
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.
873
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.
880
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
885 ietf-ipr@ietf.org.
886
887
888
889
890
891
892
893
894
895
896
897
898Crocker & Overell Standards Track [Page 16]
899
900