5

Is there any C# parser which I could use to parse incomplete c source code. I'm trying to implement source code evolution anlysis tool of c code based on analyzing different versions of C code. So far I've tried get familiar with antlr4 for this purpose but it seem's to not work with incomplete code at all.

So can anybody recomend me any parser which could do this.

  • ANTLR offers C grammars, so it might appear to be a good starting point. However, I don't think it has any capability for parsing code fragments. Nor do I believe the C grammars provided come with C preprocessing capability,. which is a likely element of any practical solution. – Ira Baxter Mar 22 '15 at 9:28
2

Our DMS Software Reengineering Toolkit with its C Front End can parse "incomplete code".

In particular, given a DMS-based parser, DMS provides both

  • nonterminal pattern parsers (that is, DMS will parse any string which is a nonterminal such as expression, statement, declaration. Such parses if successful produce an AST for a designate nonterminal.
  • arbitrary substring parsers, which parse just that. The result is a sequence of ASTs that cover the substring. If the substring turns out to be a nonterminal, you get just one tree.

Complications ensue if the fragment uses macros or preprocessor conditionals. You can preconfigure the context of a parse with the necessary macro definitions.

Of course DMS will parse complete compilation units, has a full preprocessor (for which you can control how much of it "expands" vs. is retained by parsing), as well as symbol table construction and control and data flow analysis. The latter bits apply only to whole programs, but could be adapted for program fragments with some effort.

Summary:

  • C# based parser: NO
  • Parses C (and other language) fragments: YES
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.