0
votes

I'm trying to use Antlr4.5 to generate a lexer/parser (in C#) for a SQL grammar. What sort of tools would you recommend in order to write the grammar and to test it?

I'm trying antlrworks2 but I find it a bit confusing (can't find a way to enter sample text and see the parse tree - not sure if it's not there or I'm blind or just plain dumb, but I'm pretty sure antlrworks v1 had such a feature).

The Visual Studio VSIX plugin from Sam Harwell looks great but it also confuses the heck out of me, the lexer and parser get generated in the obj\ folder instead of inside the project. Also, it won't help me much when writing the grammar as far as showing me a syntax diagram, letting me try out the grammar with sample text and so on.

I'm pretty confident that antlr is a good way to go, but I'm really not sure about the tooling and the approach I should take when defining and testing my grammar. I would appreciate any suggestions.

1
Why can't you use a grammar for C# from the ANTLR site? Surely they have one. [If you do, you will find that parsing isn't your problem. Check my bio, or search for "life after parsing" to see where your real problems lie.] - Ira Baxter
Thanks for your comment Ira. I don't need a C# grammar, I want the lexer/parser to be generated as C# code. I'm actually trying to add code completion functionality to a tool I'm building. The language I'm parsing is SQL, but since I want to provide code completion the grammar has to be modified to allow malformed SQL. All I really need from the parser is what part of the statement the user might be entering, and aliases and their scopes. It doesn't have to be perfect either, if the parsed gets confused, I can offer all alternatives to the user which will get filtered as they type. - anakic

1 Answers

0
votes

My question wasn't brilliant because tooling is pretty independent of the antlr target language, but FWIW I ended up using the free version of IntelliJ IDEA with the antlr plugin. I started liking IntelliJ, it's very good. The antl plugin is also very good for the most part, it a bit rough around the edges here and there, but all the important stuff works very well and in general it's amazingly useful.