Impressive

Sep 15, 2009 at 5:00 AM

This project is one of teh top results returned by Google for "antlr grammar" and I think I'm going to learn a lot from studying it.

Do I understand correctly that you have created a complete lexer and parser for C# 3 and that it passes all of the .NET regressions for C# ?

Do you plan to offer any kind of readme or faq?  A couple things I noticed right away...

it's not obvious to me as a new antlr user what the difference between the antlrcsharp and csharp projects is. 

- It looks like antlrcsharp is a vc++ project that actually defines the lexer and parser. Why the vcproj and not csproj ?

- it looks like csharp is the beginning of a test harness with an external visitor?  Is that right?

I see that the cs.g 'options' clause appears to use the old CSharp (C# 1.x) target instead of the newer CSharp2 (C# 2.x) target.  Is that right, and is there a reason not to use CSharp2 ?

Is the Antlr3Runtime.dll the same one from the Antlr 3.1.x runtime at www.antlr.org ?

It looks like you're integrated pretty tightly with visual studio.  Where can I read more about that?

Sorry to hit you with so many questions.  I'm just very interested in what I can learn from your work.

I managed to build UnitTest and run a few of the tests.  Yeah!

Thanks!

Coordinator
Sep 15, 2009 at 9:17 PM

Google is very smart ;)

I'm not sure there are any public .Net regression files, so I tried to use a large publicly available repository of source files.  The reference source from Microsoft, which is all the CSharp source for the .Net runtimes, seemed like a good choice.  I'm sure it's not perfect by any means but it parses a very high percentage of CSharp files.

Crap, I have a readme.txt but didn't include it in the project.  I'd be happy to write a FAQ / add more to the readme.txt but I haven't had many questions so far.

In answer to your question about Visual Studio, the AntlrCSharp project builds the grammar.  The project generates csLexer.cs and csParser.cs which are compiled in the CSharp project.  VS has a feature for external tools called Custom Build Rules.  These only exist in C++ projects.  So that is why the grammar is in a VC++ project.  It does nothing more than launch Java to build the lexer/parser.  See the AntlrCSharp project properties for setting Antlr options.

The CSharp project is nothing more than the compiled parser and lexer.  See the antlr.org site for more detail but the public methods on csParser.cs are nothing more than the rule names found in the grammar.  If you have the CSharp.dll you actually don't need to build cs.g from scratch, though of course you can.  UnitTest is the test harness

I didn't use CSharp2 because I didn't know it existed :)

Yes the Antlr3Runtime.dll is the one from 3.1.x.  Just trying to make your life easier.

You can read about differert ways to integrate wth Visual Studio here http://www.antlr.org/wiki/display/ANTLR3/Integration+with+Development+Environments  The MSBuild method doesn't allow you to specify options from the project page, so everyone would have to edit the project files themselves.  That didn't seem like a great alternative.  Running the Antlr tool with different options would mean changing the project file everytime.  If you bring up the project properties page for AntlrCSharp, the C++ utility project, you will see that Antlr has a section where you can specify different options.

I also had some troubles with the MSBuild integration method where the generated files were not flushed to disk by the time MSBuild went to compile them.  To be fair, I also have that trouble on occasion with the C++ project method as well.

Hope that helps.

/Andrew