Backus–Naur Form

In computer science, Backus–Naur Form (BNF) is a metasyntax used to express context-free grammars: that is, a formal way to describe formal languages. John Backus and Peter Naur developed a context free grammar to define the syntax of a programming language by using two sets of rules: i.e., lexical rules and syntactic rules.

BNF is widely used as a notation for the grammars of computer programming languages, instruction sets and communication protocols, as well as a notation for representing parts of natural language grammars. Many textbooks for programming language theory and/or semantics document the programming language in BNF.

There are many extensions and variants of BNF, including "Extended" and "Augmented" Backus–Naur Forms (EBNF and ABNF).

History

John Backus created the notation in order to express the grammar of ALGOL. At the first World Computer Congress, which took place in Paris in 1959, Backus presented "The syntax and semantics of the proposed international algebraic language of the Zurich ACM-GAMM Conference", a formal description of the international algebraic language(IAL) which was later called ALGOL 58. The formal language he presented was based on Emil Post's production system. Generative grammars were an active subject of mathematical study, e.g. by Noam Chomsky, who was applying them to the grammar of natural language.cite journal
last= Chomsky
first= Noam
authorlink= Noam Chomsky
title= Three Models for the Description of Language
journal= IRE Transactions on Information Theory
volume= Vol. 2
issue= No. 2
pages= pp. 113–123
year= 1956
doi= 10.1109/TIT.1956.1056813
] cite book
last= Chomsky
first= Noam
title= Syntactic Structures
publisher= Mouton
location= The Hague
year=1957
]

Peter Naur (ALGOL 60, 1963) identified Backus's notation as Backus Normal Form, and simplified it to minimize the character set used, and, at the suggestion of Donald Knuth, his name was added in recognition of his contribution, his initial replacing the N for "Normal" since, Knuth argued, the BNF is "not a normal form in any sense". [cite journal
last= Knuth
first= Donald E.
authorlink= Donald Knuth
title= Backus Normal Form vs. Backus Naur Form
journal= Communications of the ACM
volume= 7
issue= 12
pages= pp. 735–736
year= 1964
doi= 10.1145/355588.365140
] The Backus–Naur Form or BNF grammars have significant similarities to Unicode|Pāṇini's grammar rules, and the notation is sometimes also referred to as Panini–Backus Form. [P.Z. Ingerman (1967)]

Introduction

A BNF specification is a set of derivation rules, written as ::= __expression__

where <symbol> is a "nonterminal", and the __expression__ consists of one or more sequences of symbols; more sequences are separated by the vertical bar, '|', indicating a choice, the whole being a possible substitution for the symbol on the left. Symbols that never appear on a left side are "terminals". On the other hand, symbols that appear on a left side are "non-terminals" and are always enclosed between the pair <>.

Example

As an example, consider this possible BNF for a U.S. postal address: ::= ::=
::= | "." ::= ::= "," ::= "Sr." | "Jr." | | "" This translates into English as: :* A postal address consists of a name-part, followed by a street-address part, followed by a zip-code part. :* A name-part consists of either: a personal-part followed by a last name followed by an optional "jr-part" (Jr., Sr., or dynastic number) and end-of-line, or a personal part followed by a name part (this rule illustrates the use of recursion in BNFs, covering the case of people who use multiple first and middle names and/or initials). :* A personal-part consists of either a first name or an initial followed by a dot. :* A street address consists of an optional apartment specifier, followed by a house number, followed by a street name, followed by an end-of-line.:* A zip-part consists of a town-name, followed by a comma, followed by a state code, followed by a ZIP-code followed by an end-of-line.

Note that many things (such as the format of a first-name, apartment specifier, ZIP-code, and Roman numeral) are left unspecified here. If necessary, they may be described using additional BNF rules.

Further examples

BNF's syntax itself may be represented with a BNF like the following: ::= | ::= "<" ">" "::=" ::= " " | "" ::= | "|" ::= | ::= | ::= | "<" ">" ::= '"' '"' | "'" "'" This assumes that no whitespace is necessary for proper interpretation of the rule. represents the appropriate line-end specifier (in ASCII, carriage-return and/or line-feed, depending on the operating system). and are to be substituted with a declared rule's name/label or literal text, respectively.

Variants

There are many variants and extensions of BNF, generally either for the sake of simplicity and succinctness, or to adapt it to a specific application. One common feature of many variants is the use of regexp repetition operators such as * and +. The Extended Backus–Naur Form (EBNF) is a common one. In fact the example above is not the pure form invented for the ALGOL 60 report. The bracket notation " [] " was introduced a few years later in IBM's PL/I definition but is now universally recognised. ABNF is another extension commonly used to describe IETF protocols.

Parsing expression grammars build on the BNF and regular expression notations to form an alternative class of formal grammar, which is essentially analytic rather than generative in character.

Many BNF specifications found online today are intended to be human readable and are non-formal. These often include many of the following syntax rules and extensions:

* Optional items enclosed in square brackets. E.g. []
* Items repeating 0 or more times are enclosed in curly brackets or suffixed with an asterisk. E.g. ::= {}
* Items repeating 1 or more times are followed by a '+'
* Terminals may appear in bold and NonTerminals in plain text rather than using italics and angle brackets
* Alternative choices in a production are separated by the ‘|’ symbol. E.g., |
* Where items need to be grouped they are enclosed in simple parentheses

ee also

* Extended Backus–Naur Form.
* Ashtadhyayi (Sanskrit grammar with mathematical structure).
* Syntax diagram (Railroad diagram).
* GOLD BNF parser.
* GNU bison GNU version of yacc.
* Wirth syntax notation An alternative to BNF from 1977.
* Yacc parser generator (used with Lex pre-processor).
* ANTLR Another parser generator written in Java.
* John Backus

References

External links

* [http://www.lrz-muenchen.de/~bernhard/Algol-BNF.html Algol-60 BNF] , the original BNF.
* Sample grammars at the [http://cui.unige.ch/db-research/Enseignement/analyseinfo/BNFweb.html BNF Web club] .
* [http://compilers.iecc.com/comparch/article/93-07-017] contains a posting on news:comp.compilers that explains some of the history of the two names (Backus–Naur Form vs. Backus Normal Form).
* Article " [http://www.garshol.priv.no/download/text/bnf.html BNF and EBNF: What are they and how do they work?] " by Lars Marius Garshol.
* [ftp://ftp.rfc-editor.org/in-notes/rfc4234.txt RFC 4234] Augmented BNF for Syntax Specifications: ABNF
* [http://www-cgi.uni-regensburg.de/~brf09510/grammartypes.html Comparision of different variants of BNF]
* [http://www-cgi.uni-regensburg.de/~brf09510/syntax/lazyebnf.ebnf.html Syntax diagram of EBNF]
* [http://www-cgi.uni-regensburg.de/~brf09510/syntax.html Generation of syntax diagrams from EBNF]


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Backus-Naur form — Saltar a navegación, búsqueda El Backus Naur form (BNF) (también conocido como Backus Naur formalism, Backus normal form o Panini Backus Form) es una metasintaxis usada para expresar gramáticas libres de contexto: es decir, una manera formal de… …   Wikipedia Español

  • Backus-Naur-Form —   [Abk. BNF], eine von John Backus (*1921) und Peter Naur (*1928) entwickelte Notationsform (Metasprache) zur Definition der Syntax einer Programmiersprache. Sie wurde erstmalig zur Notation von Algol 60 eingesetzt. Heute definiert man die Syntax …   Universal-Lexikon

  • Backus-Naur Form — Die Backus Naur Form oder Backus Normalform, kurz BNF, ist eine kompakte formale Metasprache zur Darstellung kontextfreier Grammatiken (Typ 2 Grammatiken in der Chomsky Hierarchie). Hierzu zählt die Syntax gängiger höherer Programmiersprachen.… …   Deutsch Wikipedia

  • Backus-Naur-Form — Die Backus Naur Form oder Backus Normalform, kurz BNF, ist eine kompakte formale Metasprache zur Darstellung kontextfreier Grammatiken (Typ 2 Grammatiken in der Chomsky Hierarchie). Hierzu zählt die Syntax gängiger höherer Programmiersprachen.… …   Deutsch Wikipedia

  • Backus-Naur Form — Forme de Backus Naur Pour les articles homonymes, voir BNF. La forme de Backus Naur (souvent abrégée en BNF, de l anglais Backus Naur Form) est une notation permettant de décrire les règles syntaxiques des langages de programmation. C’est donc un …   Wikipédia en Français

  • Backus Naur Form — Forme de Backus Naur Pour les articles homonymes, voir BNF. La forme de Backus Naur (souvent abrégée en BNF, de l anglais Backus Naur Form) est une notation permettant de décrire les règles syntaxiques des langages de programmation. C’est donc un …   Wikipédia en Français

  • Backus Naur form — Forme de Backus Naur Pour les articles homonymes, voir BNF. La forme de Backus Naur (souvent abrégée en BNF, de l anglais Backus Naur Form) est une notation permettant de décrire les règles syntaxiques des langages de programmation. C’est donc un …   Wikipédia en Français

  • Backus naur form — Forme de Backus Naur Pour les articles homonymes, voir BNF. La forme de Backus Naur (souvent abrégée en BNF, de l anglais Backus Naur Form) est une notation permettant de décrire les règles syntaxiques des langages de programmation. C’est donc un …   Wikipédia en Français

  • Backus-Naur form — Bekaus ir Nauro forma statusas T sritis informatika apibrėžtis ↑Metakalba formalios kalbos sintaksei apibrėžti. Plačiau žr. priede. priedas( ai) MS Word formatas atitikmenys: angl. Backus Naur form ryšiai: dar žiūrėk – metakalba …   Enciklopedinis kompiuterijos žodynas

  • Backus-Naur form — noun A formal notation for context free grammars. Syn: Backus normal form …   Wiktionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”