Skip to main content

RFC 5234 - Augmented BNF for Syntax Specifications: ABNF

Published: January 2008
Status: Internet Standard (STD 68)
Authors: D. Crocker (Brandenburg InternetWorking), P. Overell (THUS plc.)
Obsoletes: RFC 4234


Abstract

Internet 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.


Status of This Memo

This document specifies an Internet standards track protocol for the Internet community, and requests discussion and suggestions for improvements. Please refer to the current edition of the "Internet Official Protocol Standards" (STD 1) for the standardization state and status of this protocol. Distribution of this memo is unlimited.


Table of Contents

Appendices


ABNF Core Concepts

What is ABNF?

ABNF (Augmented BNF) is a metalanguage used to define syntax, widely used in Internet protocol specifications. It is an extension of the classic Backus-Naur Form (BNF).

Basic Syntax

Rule Definition:

rulename = elements

Example:

postal-address = name-part street zip-part
name-part = *(personal-part SP) last-name [SP suffix] CRLF

Core Operators

OperatorSyntaxDescriptionExample
ConcatenationRule1 Rule2Sequential concatenation"http" "://"
AlternativesRule1 / Rule2Choose one"yes" / "no"
Incremental AltRule1 =/ Rule2Add alternativedigit =/ "A"
Value Range%c##-##Character range%x30-39 (0-9)
Optional[Rule]Zero or one["s"]
Repetition*RuleZero or more*DIGIT
Specific RepnRuleExactly n times3DIGIT
Range Repn*mRulen to m times1*3DIGIT
Grouping(Rule1 Rule2)Group rules("http" / "https")
Comment; commentComment; This is a comment

Core Rules

ABNF defines a set of core rules commonly used in various specifications:

ALPHA          =  %x41-5A / %x61-7A   ; A-Z / a-z
DIGIT = %x30-39 ; 0-9
HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
DQUOTE = %x22 ; " (double quote)
SP = %x20 ; space
HTAB = %x09 ; horizontal tab
WSP = SP / HTAB ; whitespace
LWSP = *(WSP / CRLF WSP) ; linear whitespace
VCHAR = %x21-7E ; visible (printing) characters
CHAR = %x01-7F ; any 7-bit US-ASCII character
OCTET = %x00-FF ; 8-bit data
CTL = %x00-1F / %x7F ; control characters
CR = %x0D ; carriage return
LF = %x0A ; line feed
CRLF = CR LF ; carriage return line feed
BIT = "0" / "1"

Practical Examples

Example 1: Simple Rule

greeting = "Hello" SP name
name = 1*ALPHA

Matches: Hello John, Hello Alice

Example 2: Email Address (Simplified)

email = local-part "@" domain
local-part = 1*(ALPHA / DIGIT / "." / "-" / "_")
domain = subdomain *("." subdomain)
subdomain = 1*(ALPHA / DIGIT / "-")

Matches: [email protected], [email protected]

Example 3: HTTP Version

HTTP-version = "HTTP/" 1*DIGIT "." 1*DIGIT

Matches: HTTP/1.1, HTTP/2.0

Example 4: URI Scheme

scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )

Matches: http, https, ftp, mailto


Repetition Operators Explained

NotationMeaningExampleMatches
*Rule0 or more*DIGIT"", "1", "123"
1*Rule1 or more1*DIGIT"1", "123"
2*4Rule2 to 4 times2*4DIGIT"12", "123", "1234"
3RuleExactly 3 times3DIGIT"123"
[Rule]0 or 1 time["s"]"", "s"

Operator Precedence

From highest to lowest:

  1. Rule names, groups - rulename, (group)
  2. Repetition - *, n*m, n
  3. Value range, strings - %c##-##, "string"
  4. Concatenation - Rule1 Rule2
  5. Alternatives - Rule1 / Rule2

Example:

foo = "a" *("b" / "c")

Matches: a, ab, ac, abc, abb, acc, abbc, ...


Terminal Value Representation

Strings

command = "GET" / "POST"

Numeric Values (Hexadecimal)

CR = %x0D        ; carriage return
LF = %x0A ; line feed

Numeric Ranges

DIGIT = %x30-39  ; 0-9
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z

Sequence Values

CRLF = %x0D.0A   ; carriage return line feed sequence

ABNF vs BNF Comparison

FeatureBNFABNF
Rule definition::==
Alternatives``
Grouping<>()
Optional-[]
Repetition-*, n*m
Terminal valuesQuotesQuotes + numeric
CommentsVaries;

Practical Applications

ABNF is widely used to define:

  • HTTP (RFC 7230, 7231, etc.)
  • URI (RFC 3986)
  • SMTP (RFC 5321)
  • SIP (RFC 3261)
  • JSON (RFC 7159)
  • Nearly all IETF protocols


Important Note: ABNF is a fundamental tool for Internet protocol specifications. Understanding ABNF is crucial for reading and implementing RFC specifications!