C Parser in C# or generally .Net [closed]

2020-02-07 03:22发布

For my diploma thesis I need to implement certain static C code analysis and I am desperately looking for a framework/library that would allow me to parse C source code, split it up into single functions, for every function determine what variables are changed in the function body and derive certain annotations for the code automatically. Is there any good framework written in C# or generally as .Net class for this purpose?

标签: c# c parsing
4条回答
贼婆χ
2楼-- · 2020-02-07 03:24

I had a similiar problem and having done a research about YACC tools for C# I have chosen Gold Parsing System with Semantic Engine. My project was parsing SQL queries and generating logical query plans (from T-SQL grammar subset).

I really recommend it. Those 2 libraries make parsing stuff painless and allow to map grammar to the object model in your code. It feels very intuitive and made my project successful :) However, it may lack some advanced ANTLR features, so recognize your needs carefully.

Gold Project http://www.devincook.com/goldparser/

Semantic Engine Lib http://code.google.com/p/bsn-goldparser

查看更多
Rolldiameter
3楼-- · 2020-02-07 03:38

You might like to check ANTLR. It comes with versions of several versions, included C and C#. There are some free grammars on ANTLR web site, including C.

查看更多
爷的心禁止访问
4楼-- · 2020-02-07 03:45

What about googling for "C Parser written in C#"?

I got this as first link: http://code.google.com/p/cpp-ripper/

Also, I think the C grammar can be found in quite a lot of places, so you might just want to open up your .NET variant of lex/yacc and go from there?

查看更多
爷、活的狠高调
5楼-- · 2020-02-07 03:46

If you're ok with using GPL'd code, you might want to take a look at the GCC source code. If you need to do it within .Net, you can always use p/invoke to call code from the GCC libraries.

查看更多
登录 后发表回答