I'm planning to write a C# 3.0 compiler in C#. Where can I get the grammar for parser generation?
Preferably one that works with ANTLR v3 without modification.
I'm planning to write a C# 3.0 compiler in C#. Where can I get the grammar for parser generation?
Preferably one that works with ANTLR v3 without modification.
Are you looking for something like this or this?
Please also refer to C# ANLTR grammar question.
There isn't one apart from bits in ECMA docs and modified all over the place, and even that is insufficient. The language that is supposed to be open has enough quirks with 2.0 parsing to not bother..
That's why you see a lot of handmade parsers, and semantics will show up sooner or later.
Lambdas can easily target 2.0 (ie. same CLR 2.0 as always at least before NET 4.0) and often are, and all you have to do is get to the IL and decompiled anonymous method (via x tools out there).. probably not what you're looking for either, especially as it requires multiple roundtrips.
Parsing proprietary LINQ (and for what really), automatic properties (what a farce facility) and similar is a total suicide and waste of brain cells.. If you really need something badly, best to talk to JetBrain guys or stick to Mono.
If MS wants to know why people want control and less stupidity in not giving choices of inlining, deciding on struct heuristics for us, poor generics and 'using'-s non-DRYs, and much more, it's very simple (plenty of valid engineering and well documented reasons out there):
Reversibility / Machine-readability / Independence from next (5.0, 6.0, etc) idiot-waves and maintaining an investment in existing sources. That reads tech-neutral..
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.