tags:

views:

1224

answers:

3
+5  Q: 

C# ANTLR grammar?

I'm looking for turn-key ANTLR grammar for C# that generates a usable Abstract Syntax Tree (AST) and is either back-end language agnostic or targets C#, C, C++ or D.

It doesn't need to support error reporting.

P.S. I'm not willing to do hardly any fix-up as the alternative is not very hard.

+4  A: 
George Stocker
That's only for C# 1.0. C# 2.0 requires a substantially stronger parser to handle generics, but ANTLR should be able to handle it. Good luck with C# 3.0 and LINQ! :)
leppie
+2  A: 

The DMS Software Reengineering Toolkit provides a full, validated grammar for C# 1.2, 2.0 and 3.0 with generics and LINQ expressions.

It automatically builds ASTs, allows you programmatic access to the ASTs for analysis or tranformation, or you can apply source-to-source transformations that also directly manipulate the tree. The resulting AST can be prettyprinted back to source code, even retaining indentation and comments.

DMS also has mature front ends for other languages such as Java, PHP5, JavaScript, COBOL, C and C++.

EDIT: 1/31/2010: The DMS C# parser has been extended to handle full C# 4.0.

Ira Baxter
Not free, but that looks kinda cool.
BCS
+3  A: 

This may be waaaay too late, but you can get a C# 4 grammar.

RCIX