Augmented Backus–Naur form (ABNF) is a metalanguage used to formally describe the syntax of languages, protocols, and data formats. It is an extension of Backus–Naur form (BNF) designed to provide a more precise and machine-parsable notation, particularly for bidirectional communications protocols.
Standardized by the Internet Engineering Task Force (IETF), the current specification is defined in RFC 5234 (January 2008), which obsoletes RFC 4234 and RFC 2234. ABNF is the standard syntax notation used in the definition of Internet Standards (STD documents) and Request for Comments (RFC) documents.
Key Characteristics
- Terminal Values: Defined by numeric character codes (e.g.,
%d65for 'A',%x41for 'A') or case-insensitive literal strings (e.g.,"ABC"). - Concatenation: Implicit by listing rule names sequentially (e.g.,
rule1 rule2). - Alternation: Denoted by a forward slash (
/), e.g.,rule1 / rule2. - Repetition: Specified using the
*operator (e.g.,*elementfor zero or more,1*3elementfor one to three). - Grouping: Parentheses
()group elements into a single unit. - Optional Sequences: Square brackets
[]denote an optional element (equivalent to0*1(element)). - Comments: Initiated by a semicolon (
;) and continue to the end of the line. - Core Rules: ABNF defines a set of core rules (e.g.,
ALPHA,DIGIT,SP,CRLF,VCHAR) that serve as basic building blocks.
Usage
ABNF is the primary formalism for defining the syntax of:
- Internet protocols (e.g., HTTP in RFC 7230, SMTP in RFC 5321, SIP in RFC 3261).
- Header field values and message bodies in email (RFC 5322) and MIME (RFC 2045).
- Uniform Resource Identifiers (URI) syntax (RFC 3986).
- Many other IETF standards-track documents.
Relationship to BNF
While standard BNF (as defined in the ALGOL 60 report or ISO/IEC 14977 for EBNF) uses symbols like ::=, |, { }, and [ ], ABNF uses =, /, *, and [] respectively. ABNF's use of explicit numeric character codes and defined core rules reduces ambiguity regarding character encoding and whitespace handling, which is critical for interoperable network protocol implementations.