BNF vs EBNF vs ABNF: which to choose?

You have to think about EBNF and ABNF as extensions that help you just to be more concise and expressive while developing your grammars.

For example think about an optional non-terminal symbol, in a BNF grammar you would define it by using intermediate symbols like:

A        ::= OPTIONAL OTHER
OPTIONAL ::= opt_part | epsilon

while with EBNF you can do it directly using optional syntax:

A ::= [opt_part] OTHER

Then since there’s no way to express precedence in a BNF you have to use always intermediate symbols also for nested choices:

BNF
A ::= B C
B ::= a | b | c

EBNF
A ::= (a | b | c) C

This is true for many syntax issues that are allowed in an EBNF or ABNF grammar, thanks to syntactic sugar but not with a normal BNF. ABNF extends EBNF, allowing you to do more complicated things, like specifying how many occurrence of a symbol can be found together (i.e. 4*DIGIT)

So choosing an ABNF or an EBNF as language of choice for your grammar will make your work easier, since you will be more expressive without filling you grammar with useless symbols that will be generated anyway by your parser generator, but you won’t care about them!

Leave a Comment