Agosto

The form of Backus-Naur (often shortened in BNF , of English Backus-Naur Form ) is a notation making it possible to describe the syntactic rules of the computer programming languages. It is thus a Métalangage. It is used in certain books to describe the studied language, but also by many Logiciel S of Analyze syntactic to work on source files of several different languages. It is a notation for formal grammars of the type out-context (because one defines the terms out of their context, to then replace the definition of the aforesaid terms in this context).

This syntax was conceived by John Backus and Peter Naur during the creation of the grammar of the language Algol 60. Initially called normal Backus form (“normal form of Backus”), it became the “form of Backus-Naur” to the suggestion of Donald Knuth.

BNF and training

Although the awareness of a language requires a knowledge of the rudiments of its syntax, the BNF is not adapted to teaching. The reason is that the BNF has as a role to fix rules at Compilateur S and not at human users. The initial training of a language does not need the degree of accuracy of the BNF, which can constitute a handicap even there.

Experiments tried about 1967-1972 in the École des Mines, for example, showed all failures. Nevertheless, certain lesson of this metalanguage constitutes a success. An alive example: the BNF continues to be taught in certain schools, in particular with the Université of Liege, within the framework of the general training of the civil engineers and the students data processing specialists.

On the other hand, this form of description is appropriate very well like helps with the writing of Compilateur S.

Syntax

In BNF, one distinguishes the méta-symbols, the terminals and nonthe terminals. The méta-symbols are quite simply the symbols of BNF. The nonfinal symbols are the names of the categories which one defines, while the terminals are symbols of the language described.

Let us take an example defining the structure if Langage C: :: = yew " (" ")" " {" < code> "}" , and < code> is nonterminals. :: = is a meaning méta-symbol “is defined by”. if, " (" , ")" , " {" and "}" is terminals. When the terminals make only one character, that they contain characters not Alphanumérique S or that they can be confused with méta-symbols, one puts them between quotation marks.

It often happens that nona terminal can be defined in several ways. In this case, one uses the méta-symbol |. :: = | | … Brackets are sometimes also used: :: = ( | ) who is equivalent to: :: = |

Extensions

Various extensions (see in particular the Extended Backus-Naur Form) were proposed in order to facilitate the drafting and the reading of a document BNF.

The hooks ( and ) surround the optional elements: :: = yew " (" ")" " {" < code> "}" else " {" < code> "}" ] The accodances ( { and } ) surround the elements to repeat an indefinite number of times.

With that, we will try a better definition of if… else: :: = {else } else ( " ; " | " {" { " ; " } "}" )] :: = yew " (" ")" ( " ; " | " {" { " ; " } "}" ) Obviously, it misses with this definition the definitions of nonthe terminals and .

Distorsions

BNF is sometimes used by Logiciel S of checking syntactic. However, in order to facilitate the drafting and the reading of this type of documents, of many authors create BNF, not intended to be used within such a framework, by carrying out some small distorsions, which very often are very easy to include/understand:

It happens that the authors do not define certain rules or define them with a sentence: :: =. any ASCII character. It is also current, in a list, to indicate only the first and the last element: :: = “has”. “Z” | “Has”. “Z” or :: = - “Z “has”” | - “Z “HAS””

Lastly, in certain books, for reasons of legibility, one removes them < and > for nonthe terminals and one boldfaces the terminals: ifelse:: = yew {''' else ''' yew} ''' else ''' (instruction ; | { {instruction ; } } )]

yew:: = yew ( condition ) (instruction ; | { {instruction ; } } )

External bonds

  • the site of the BNF Web Club proposes the BNF of several languages in the form of syntactic diagrams (English site).

Random links:Louis-Marie de Blignières | Bestiary of Aberdeen | Tornado (catamaran) | Crowned plover