Augmented Backus–Naur form

From Wikipedia, the free encyclopedia

(Redirected from Augmented Backus-Naur form)
Jump to: navigation, search

The augmented Backus–Naur form (ABNF) extends the Backus-Naur form.

The augmented Backus–Naur form (ABNF) is based on Backus–Naur form (BNF), but consists of its own syntax and derivation rules. The motive principle for this metalanguage is to describe a formal system of a language which is a protocol (bidirectional specification). It is documented in RFC 4234 and often serves as the definition language for IETF communication protocol.

RFC 4234 corrects problems in and obsoletes RFC 2234.

Contents

An ABNF specification is a set of derivation rules, written as

rule = definition ; comment CR LF

where rule is a case-sensitive nonterminal, the definition consists of sequences of symbols that define the rule, a comment for documentation, and ending with a carriage return and line feed.

Rule names are case insensitive: , , , and all refer to the same rule. Rule names consist of a letter followed by letters, numbers, and hyphens.

Angle brackets (“<”, “>”) are not required around rule names (as they are in BNF). However they may be used to delimit a rule name when used in prose to discern a rule name.

ABNF is encoded in 7-bit ASCII in an 8-bit field with the high bit set to zero.

Terminals are specified by one or more numeric characters.

Numeric characters may be specified as the percent sign “%”, followed by the base (b = binary, d = decimal, and x = hexadecimal), followed by the value, or concatenation of values (indicated by “.”). For example a carriage return is specified by %d13 in decimal or %x0D in hexadecimal. A carriage return followed by a line feed may be specified with concatenation as %d13.10.

Literal text is specified through the use of a string enclosed in quotation-marks ("). These strings are case-insensitive and the character set used is US-ASCII. Therefore the string “abc” will match “abc”, “Abc”, “aBc”, “abC”, “ABc”, “AbC”, “aBC”, and “ABC”. For a case-sensitive match the explicit characters must be defined: to match “aBc” the definition will be %d97 %d66 %d99.

Whitespace is used to separate elements of a definition: for space to be recognized as a delimiter it must be explicitly included.

Rule1 Rule2

A rule may be defined by listing a sequence of rule names.

To match the string “aba” the following rules could be used:

  1. fu = %x61 ; a
  2. bar = %x62 ; b
  3. mumble = fu bar fu

Rule1 / Rule2

A rule may be defined by a list of alternative rules separated by a solidus (“/”).

To accept the rule or the rule the following rule could be constructed:

  1. fubar = fu / bar

Rule1 =/ Rule2

Additional alternatives may be added to a rule through the use of “=/” between the rule name and the definition.

The rule

  1. ruleset = alt1 / alt2 / alt3 / alt4 / alt5

is equivalent to

  1. ruleset = alt1 / alt2
  2. ruleset =/ alt3
  3. ruleset =/ alt4 / alt5

%c##-##

A range of numeric values may be specified through the use of a hyphen (“-”).

The rule

  1. OCTAL = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7"

is equivalent to

  1. OCTAL = %x30-37

(Rule1 Rule2)

Elements may be placed in parentheses to group rules in a definition.

To match “elem fubar snafu” or “elem tarfu snafu” the following rule could be constructed:

  1. group = elem (fubar / tarfu) snafu

To match “elem fubar” or “tarfu snafu” the following rules could be constructed:

  1. group = elem fubar / tarfu snafu
  2. group = (elem fubar) / (tarfu snafu)

n*nRule

To indicate repetition of an element the form *element is used. The optional gives the minimum number of elements to be included with the default of 0. The optional gives the maximum number of elements to be included with the default of infinity.

Use *element for zero or more elements, 1*element for one or more elements, and 2*3element for two or three elements.

nRule

To indicate an explicit number of elements the form element is used and is equivalent to *element.

Use 2DIGIT to get two numeric digits and 3DIGIT to get three numeric digits. (DIGIT is defined below under 'Core rules'. Also see zip-code in the example below.)

[Rule]

To indicate an optional element the following constructions are equivalent:

  1. [fubar snafu]
  2. *1(fubar snafu)
  3. 0*1(fubar snafu)

; comment

A semi-colon (“;”) starts a comment that continues to the end of the line.

The above operators have the given precedence from tightest binding to loosest binding:

  1. Strings, Names formation
  2. Comment
  3. Value range
  4. Repetition
  5. Grouping, Optional
  6. Concatenation
  7. Alternative

Use of the alternative operator with concatenation may be confusing and it is recommended that grouping be used to make explicit concatenation groups.

The core rules are defined in the ABNF standard.

Rule Formal Definition Meaning
ALPHA %x41-5A / %x61-7A Upper and lowercase ASCII letters (A-Z a-z)
DIGIT %x30-39 Decimal digits (0-9)
HEXDIG DIGIT / "A" / "B" / "C" / "D" / "E" / "F" Hexadecimal digits (0-9 A-F a-f)
DQUOTE %x22 Double Quote
SP %x20 space
HTAB %x09 horizontal tab
WSP SP / HTAB space and horizontal tab
LWSP *(WSP / CRLF WSP) linear white space (past newline)
VCHAR %x21-7E visible (printing) characters
CHAR %x01-7F any 7-bit US-ASCII character, excluding NUL
OCTET %x00-FF 8 bits of data
CTL %x00-1F / %x7F controls
CR %x0D carriage return
LF %x0A linefeed
CRLF CR LF Internet standard newline
BIT "0" / "1"

The postal address example given in the Backus-Naur form (BNF) page may be specified as:

postal-address   = name-part street zip-part

name-part        = *(personal-part SP) last-name [SP suffix] CRLF
name-part        =/ personal-part CRLF

personal-part    = first-name / (initial ".")
first-name       = *ALPHA
initial          = ALPHA
last-name        = *ALPHA
suffix           = ("Jr." / "Sr." / 1*("I" / "V" / "X"))

street           = [apt SP] house-num SP street-name CRLF
apt              = 1*4DIGIT
house-num        = 1*8(DIGIT / ALPHA)
street-name      = 1*VCHAR

zip-part         = town-name "," SP state 1*2SP zip-code CRLF
town-name        = 1*(ALPHA / SP)
state            = 2ALPHA
zip-code         = 5DIGIT ["-" 4DIGIT]

  • RFC 4234 Augmented BNF for Syntax Specifications: ABNF
  • RFC 2234 Augmented BNF for Syntax Specifications: ABNF (Obsolete)
Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.