Syntax Definition

A contex free grammar, CFG, (synonyms: Backus-Naur Firm of BNF) is a common notation for specifying the syntax of a languages

For example, an "IF-ELSE" statement in c-language has the form
        IF         (Expr)         stmt         ELSE         stmt

In other words, it is the concatenation of:

The syntax of an 'IF-ELSE' statement can be specified by the following 'production rule' in the CFG.
        stmt          IF     (Expr)     stmt     ELSE     stmt

The arrow (  ) is read as "can have the form".

A context-free grammar (CFG) has four components:

  1. A set of tokens called terminals.
  2. A set of variable called nonterminals.
  3. A set of production rules.
  4. A designation of one of the nonterminals as the start symbol.

Multiple production with the same nonterminal on the left like:

list   + digit
list    - digit
list   

may be grouped together separated by vertical bars, like:

list     list + digit | list - digit | digit