问题
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.
回答1:
This may be waaaay too late, but you can get a C# 4 grammar.
回答2:
Here's a C# grammar link, as well as an overview of C# and ANTLR. There are others for the other languages you mentioned here.
回答3:
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.
回答4:
You can find C# 6 ANTLR grammar at official grammars repository.
来源:https://stackoverflow.com/questions/358052/c-sharp-antlr-grammar