views:

313

answers:

3

I want to come up with a language syntax. I have read a bit about these three, and can't really see anything that one can do that another can't. Is there any reason to use one over another? Or is it just a matter of preference?

+1  A: 

You can achieve what you want by using any of them, but each one is concise and effective in representing your language depending on what are the features that your language consists of.

I have read BNF, EBNF and ABNF from wikipedia and it has described some differences and why EBNF and ABNF came into picture based on BNF

Mahesh Velaga
+4  A: 

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

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

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

while with a 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 a EBNF or ABNF thanks to synctactic sugar but not with a normal BNF.. the ABNF extends the EBNF allowing you to do more complicated things, like specifying how many occurence of a symbol can be found together (like 4*DIGIT)

So choosing a ABNF or a EBNF will make your work easier, since you will be more expressive without filling you grammar of useless symbols that will be generated anyway by your parser generator, but you won't care about them!

Jack
Relative to 4*DIGIT: the same can be done in EBNF using the same syntax.
Kamarey
+1  A: 

The EBNF is the extended/newer version of BNF, so the problem becomes simpler: EBNF vs ABNF. I'm not an expert, but think that it should depend on a language, whose syntax you want to define. Also there are some visualizers for EBNF (http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Ebnf-Visualizer), but didn't see any for ABNF,

Kamarey