tags:

views:

2850

answers:

4

I'm looking for a tool that will be able to build a parser (in C#) if I give it a BNF grammar (eg. http://savage.net.au/SQL/sql-2003-2.bnf)

Does such a generator exist?

+6  A: 

Normally BNF grammars are too ambiguous. ANTLR will be probably good for what you are looking for.

leppie
It seems you are right. I just read this somewhere on the net: "If-then-else cannot be specified unambiguously in a context-free,priority/predicate-free grammar, such as EBNF"
ilitirit
+5  A: 

You will have to tweak the BNF a bit, but TinyPG is a great tool.

Jonathan C Dickinson
Nice find. Thanks.
ilitirit
Tiny PG is really nice, thanks for the tip.
Skurmedel
A: 

How can I use these BNF grammers with TinyPG? I'm new to BNF so approximately what sort of conversion will I have to do to convert BNF to EBNF?

Please see this question for more info.

Jenko
+4  A: 

The Visual Studio SDK actually ships with lexer and parser generation tools. These are called MPPG and MPLex and are part of the Managed Babel package. While the intention of bundling them with the SDK is to develop language extensions for Visual Studio, they are perfectly usable for creating general AST-emitting parsers.

MPLex and MPPG are based on GPLEX and GPPG (projects of Queensland University of Technology) and are used in a similar fashion to Lex and Yacc. The SDK also contains MSBuild actions for making the parser generation a part of the regular build process.

Here's a screencast showing MPLex and MPPG in action:
http://msdn.microsoft.com/en-us/vstudio/cc837016.aspx

Tormod Fjeldskår