Find file History


C# grammar with full support of C# 6 features and below. CSharpLexer.g4 and CSharpPreprocessor.g4 are runtime dependent (contains specific actions), because of directive preprocessors and string interpolation (these things make grammar context-sensitive). C# and Java versions supported. But CSharpParser.g4 is runtime independent. This ANTLR 4 C# grammar is based on the C# ANTLR 3 grammar from ChristianWulf/CSharpGrammar.


Due to uncompiled code can be placed after such preprocessor directives:

#if SILVERLIGHT && WINDOWS_PHONE || DEBUG || foo == true
// Some code

at first stage it's necessary to calculate whether condition satisfied in directive. This step performed by runtime code in gist: CSharpAntlrParser.


I put into repository AllInOne.cs file (from Roslyn) with most common syntax and also I tested this grammar on the following most popular .NET projects:

There are some problems with deep recursion (TestData.g.cs in CoreFx), unicode chars (sjis.cs in Roslyn) and preprocessor directives.

ANTLR parser from this grammar approximately ~5-7 slowly than Roslyn parser.


Eclipse Public License - v 1.0