I'm planning to write a C# 3.0 compiler in C#. Where can I get th开发者_开发问答e grammar for parser generation?
Preferably one that works with ANTLR v3 without modification.
Take a look at C# Language Specification. In the chapter B. Grammar you'll find the grammar.
I ran into ANTLR C# Grammar on CodePlex. It's a relatively new project and uses ANTLR 3.2. It says it supports C# 4.0 and is licensed under the Eclipse Public License (EPL).
I played with it a little. It has a bunch of test files containing expressions. It supports lambdas, unsafe context, ... as you'd naturally expect. It parses a C# file and hands you an abstract syntax tree. You can do whatever you want with it.
Are you looking for something like this or this?
Please also refer to C# ANLTR grammar question.
Take a look at COCO/R it seems that they have the language specification for C# 3.0.
精彩评论