Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a good way to parse C# 3.0 code?

Tags:

c#

c#-3.0

I've been looking for a free (as in "free beer") library that can parse C# 3.0 code (actually, C# 2.0 with lambdas would do it) and return some sort of AST/code DOM for a personal project. However, most alternatives I've seen up to now are inadequate:

  • Microsoft.CSharp.CSharpCodeProvider.Parse throws a NotImpementedException;
  • Visual Studio's "exposed" code parser sucks;
  • The ways of Mono's C# compiler are impenetrable (and next to not documented);
  • The C# Parser project at CodePlex only parses C# 2.0 code and thus we forget lambdas;
  • Another project on SourceForge claims to parse C# to CodeDOM, but it's 2000 days old so I guess it's not C# 3.0;
  • ... and it goes on for several pages of Google results.

So... is there a free, working C# 3.0 parser out there, that can be plugged into another project?

like image 742
zneak Avatar asked Sep 20 '10 22:09

zneak


People also ask

Is C hard to parse?

C is a bit hard to parse because statements like `A * B();` will mean different things if A is defined as a type or note. C++ is much harder to parse because the template syntax is hard to disambiguate from less than or greater than.

Can you parse in C?

Some programs can just process an entire file at once, and other programs need to examine the file line-by-line. In the latter case, you likely need to parse data in each line. Fortunately, the C programming language has a standard C library function to do just that.

Which parser is used in C?

The C/C++ parser is used for C and C++ language source files. The C/C++ parser uses syntax highlighting to identify language elements, including the following elements: Identifiers. Operators.

What does Getopt do in C?

The getopt() function is a builtin function in C and is used to parse command line arguments. Syntax: getopt(int argc, char *const argv[], const char *optstring) optstring is simply a list of characters, each representing a single character option.


1 Answers

Take a look at http://antlrcsharp.codeplex.com/ It is a C# 4 grammar for the Antlr parser generator.

like image 141
Matthew Manela Avatar answered Oct 16 '22 23:10

Matthew Manela