Backus-Naur notation (shortly BNF) is a formal mathematical way to describe a language, (to The Backus-Naur Form is a way of defining syntax. It consists of. The standard technique for defining the syntax of a computer language is to use Backus-Naur Form (BNF). The variant used in this tutorial is as follows. A Practical Tutorial on Context Free Grammars. Robert B. . Backus-Naur Form ( BNF) is a notation for expressing a CFG. The notation.

Author: | Gardarr Kazijora |

Country: | Iraq |

Language: | English (Spanish) |

Genre: | Career |

Published (Last): | 13 December 2015 |

Pages: | 102 |

PDF File Size: | 3.28 Mb |

ePub File Size: | 13.41 Mb |

ISBN: | 437-7-44940-135-7 |

Downloads: | 4493 |

Price: | Free* [*Free Regsitration Required] |

Uploader: | Sajora |

Programming languages, protocol specifications, query languages, file formats, pattern languages, memory layouts, formal languages, config files, mark-up languages, formatting languages and meta-languages shape the way we compute.

After reading this article, you will be able to identify and interpret all commonly used notation for grammars. In computer science, the most common type of grammar is the context-free grammar, and these grammars will be the primary focus of this article.

Context-free grammars have sufficient richness to describe the recursive syntactic structure of many though certainly not all languages. When describing languages, Backus-Naur form BNF is a formal notation for encoding grammars intended for human consumption.

The name of a class of literals is usually defined by other means, such as a regular expression or even prose.

Not all of these are strictly a superset, as some change the rule-definition relation:: More important than the minor syntactic differences between the forms of EBNF are the additional operations it allows in expansions.

In EBNF, square brackets around an expansion, [ expansion ]indicates that this expansion is optional. To indicate precedence, Nur grammars may use parentheses,to explictly define the order of expansion. In some forms of EBNF, theoperator explicitly denotes concatenation, rather than anur on juxtaposition.

### Backus-Naur Form (BNF)

ABNF also provides the ability to specify specific byte values exactly — detail which matters in protocols. Here’s a definition of a date and time format taken from RFC It’s common to find regular-expression-like operations inside grammars. For instance, the Python lexical specification uses them.

The definition of floating point literals in Python is a good example of combining several notations:. The grammar for the entire Python language uses a slightly different but still regular notation. Even when grammars are not an object of mathematical study themselves, in texts that deal with discrete mathematical structures, grammars appear to define new notations and new structures.

For more on this, see my article on translating math into code. Regular expressions sit just beneath context-free grammars in descriptive power: But, the reverse is not true: To go beyond the expressive power of context-free grammars, one needs to allow a degree of context-sensitivity in the grammar.

## BNF and EBNF: What are they and how do they work?

Context-sensitivity means that hackus symbols may also appear in the left-hand sides of rules. While this change appears small, it makes grammars equivalent to Turing machines in terms of the languages they can describe. By restricting the rules so that the the left-hand side has strictly fewer symbols than all expansions on the right, context-sensitive grammars are equivalent to decidable linear-bounded automata.

Even though some languages are context-sensitive, context-sensitive grammars are rarely used for describing computer languages. For instance, C is slightly context-sensitive because of the way it handles identifiers and type, but this context-sensitivity is resolved by a special convention, rather than by introducing context-sensitivity into the grammar.

For an comprehensive treatment of parsing techniques, I recommend Grune and Jacobs, Parsing Techniques: As an aside, if you think you’ve invented a new parsing technique, you need to check this book first. Your peer reviewers will check it.

The language of languages [ article index ] [] [ mattmight ] [ rss ]. Defining a language A grammar defines a language.

## Backusâ€“Naur form

I’ll discuss grammars beyond context-free at the end. Components of a context-free grammar A set of rules is the core component of a grammar. Each rule has two parts: For instance, if we were creating a grammar to handle english text, we might add a rule like: Or, if we were describing a programming language, we could add a nauf like: