Programming+Techniques

Backus-Naur Form (BNF)
Computer languages must be rigid in structure, where any minor mistake would prevent the program from running. However, as there are various high-level programming languages each with their own unique syntax, due to the rigidity of Computer Languages, the syntax of one language usually can not be used in another without errors occurring.

One of the methods for defining syntax is BNF. BNF stands for Backus-Naur Form and is used to define syntax used in programming languages. It was named after John Backus and Peter Naur. John Backus first used Chomsky's generative rules to decribe the syntax of a programming language, Algol 58. Peter Naur then developed this form for the programming language Algol 60.

The standard format for BNF is  ::= Character | Character. The word between the angled brackets is the name of what is going to be defined. The two colons and then equals sign is notation for 'is defined as'. The word after the two colons and equals sign is known as the Terminal Symbol. The symbol between the two Character words is notation for or.

For example:

 ::= Car | Motorbike

The above example defines Vehicle as a Car or a Motorbike.

Recursion can also be used within BNF, for example:

 ::=  |   ::= A | B