Parser for C#

2018-12-31 23:37发布

Which parsers are available for parsing C# code?

I'm looking for a C# parser that can be used in C# and give me access to line and file informations about each artefact of the analysed code.

标签: c# parsing
15条回答
泪湿衣
2楼-- · 2019-01-01 00:01

Works on source code:

Works on assembly:

The problem with assembly "parsing" is that we have less informations about line and file (the informations is based on .pdb file, and Pdb contains lines informations only for methods)

I personnaly recommend Mono.Cecil and NRefactory.

查看更多
不流泪的眼
3楼-- · 2019-01-01 00:03

If you're familiar with ANTLR, you can use Antlr C# grammar.

查看更多
初与友歌
4楼-- · 2019-01-01 00:05

Consider to use reflection on a built binary instead of parsing the C# code directly. The reflection API is really easy to use and perhaps you can get all the information you need?

查看更多
闭嘴吧你
6楼-- · 2019-01-01 00:10

GPPG might be of use, if you are willing to write your own parser (which is fun).

查看更多
听够珍惜
7楼-- · 2019-01-01 00:11

Maybe you could try with Irony on irony.codeplex.com.

It's very fast and a c# grammar already exists.

The grammar itself is written directly in c# in a BNF like way (acheived with some operators overloads)

The best thing with it is that the "grammar" produces the AST directly.

查看更多
登录 后发表回答