Backus-Naur form


Backus-Naur form

[¦bäk·əs ¦nau̇r ‚fȯrm] (computer science) A metalanguage that specifies which sequences of symbols constitute a syntactically valid program language. Abbreviated BNF.

Backus-Naur Form

(language, grammar)(BNF, originally "Backus Normal Form") Aformal metasyntax used to express context-free grammars.Backus Normal Form was renamed Backus-Naur Form at thesuggestion of Donald Knuth.

BNF is one of the most commonly used metasyntactic notationsfor specifying the syntax of programming languages, commandsets, and the like. It is widely used for languagedescriptions but seldom documented anywhere (how do youdocument a metasyntax?), so that it must usually be learnedby osmosis (but see RFC 2234).

Consider this BNF for a US postal address:

::=

::= | "."

::= [] |

::= []

::= ","

This translates into English as: "A postal-address consists ofa name-part, followed by a street-address part, followed by azip-code part. A personal-part consists of either a firstname or an initial followed by a dot. A name-part consists ofeither: a personal-part followed by a last name followed by anoptional "jr-part" (Jr., Sr., or dynastic number) andend-of-line, or a personal part followed by a name part (thisrule illustrates the use of recursion in BNFs, covering thecase of people who use multiple first and middle names and/orinitials). A street address consists of an optional apartmentspecifier, followed by a street number, followed by a streetname. A zip-part consists of a town-name, followed by acomma, followed by a state code, followed by a ZIP-codefollowed by an end-of-line."

Note that many things (such as the format of a personal-part,apartment specifier, or ZIP-code) are left unspecified. Theselexical details are presumed to be obvious from context orspecified somewhere nearby.

There are many variants and extensions of BNF, possiblycontaining some or all of the regexp wild cards such as"*" or "+". EBNF is a common one. In fact the exampleabove isn't the pure form invented for the ALGOL 60 report."[]" was introduced a few years later in IBM's PL/Idefinition but is now universally recognised. ABNF isanother extension.

Backus-Naur form

Also known as Backus normal form, it was the first metalanguage to define programming languages. Introduced by John Backus in 1959 to describe the ALGOL 58 language, it was enhanced by Peter Naur and used to define ALGOL 60.