bnf.rst
changeset 1905 fba288d59662
child 1912 8b81a8f0f692
equal deleted inserted replaced
1904:78357d58b7ab 1905:fba288d59662
       
     1 .. -*- coding: utf-8; -*-
       
     2 .. include:: HEADER.rst
       
     3 
       
     4 =====
       
     5  BNF
       
     6 =====
       
     7 
       
     8 What is BNF?
       
     9 ============
       
    10 .. contents::
       
    11    :local:
       
    12 
       
    13 BNF is an acronym for "Backus Naur Form". John Backus and Peter Naur introduced
       
    14 for the first time a formal notation to describe the syntax of a given language
       
    15 (ALGOL 60 programming language).
       
    16 
       
    17 See: :rfc:`2234`.
       
    18 
       
    19 BNF syntax
       
    20 ==========
       
    21 
       
    22 The meta-symbols of BNF are:
       
    23 
       
    24   ``::=``
       
    25     Meaning "is defined as".
       
    26   ``|``
       
    27     Meaning "or".
       
    28   ``<``,  ``>``
       
    29     Angle brackets used to surround category names (some times skipped).
       
    30   ``[``,  ``]``
       
    31     Optional items are enclosed in.
       
    32   ``{``,  ``}``
       
    33     Repetitive items (zero or more times) are enclosed in.
       
    34   ``"abc..."``
       
    35     Terminals are enclosed in to distinguish them from meta-symbols.
       
    36 
       
    37 BNF in BNF
       
    38 ==========
       
    39 ::
       
    40 
       
    41   syntax     ::=  { rule }
       
    42   rule       ::=  identifier  "::="  expression
       
    43   expression ::=  term { "|" term }
       
    44   term       ::=  factor { factor }
       
    45   factor     ::=  identifier |
       
    46                   quoted_symbol |
       
    47                   "("  expression  ")" |
       
    48                   "["  expression  "]" |
       
    49                   "{"  expression  "}"
       
    50   identifier ::=  letter { letter | digit }
       
    51   quoted_symbol ::= """ { any_character } """
       
    52