Backus-Naur Form
BNF



   


BNF is a tool for describing the syntax of a context-free grammar. It is used here to describe Regular Expression Syntax.

BNF defines the set of all possible strings of symbols that constitute legal programs (i.e. strings) in a language. Each production rule in the grammar has an analogous BNF rule.

 

   

BNF Production Rules


BNF describes the syntax of a grammar using a set of production rules using terminal and non-terminal symbols.

 

terminal


Terminal symbols (characters or character sequences) are bracketed by the meta-symbol "'". For example: the symbol or character a

     'a'

 

non-terminal


Non-terminal symbols are bracketed by the meta-symbols "<" and ">". For example: the non-terminal symbol set

     <set>

 

production rule


Each production rule has a left hand side (LHS) and a right hand side (RHS) separated by the meta-symbol "::=" (read as "consists of" or "defined as"). The LHS is defined by the RHS.

The LHS is a non-terminal symbol. The RHS is some sequence of terminal and non-terminal symbols that define the rule. For example: set is defined as a subset and another subset.

     <set> ::= <subset> <subset>

 

repetition


A symbol or symbols enclosed in curly brackets ( { and } ) denotes possible repetition of the enclosed symbols zero or more times. For example: set is defines as 0 or more subsets

     <set> ::= { <subset> }

 

alternate


The meta-symbol "|" (read as "or") is used to define alternate RHS definitions. For example: set is defined as a subset or a set and a subset

     <set> ::= <subset> | <set> <subset>

 



Last updated
Copyright © Donald R. Biggar.
dbiggar@sympatico.ca