1

I am trying to make a tool that can detect a change impact on C source-code. Impacted variables, functions or interfaces, i was thinking about making my own static code analyzer using language grammar rules based on the different forms of impact(Assignment, passing by reference...).

After some google search, i founded that Flex and Bison could be suitable, but the fact that GCC has stopped using these tools and switched to handwritten parser for about ten years made me thinking again. Could ANTLR4, Boost Spirit or Boost Axe be a good alternative?

A.Thabet
  • 113
  • 3
  • 9
  • 3
    If you want to analyze C/C++ then your best bet is probably to use an existing parser, such as clang or even gcc. But I don't see the reasoning behind "gcc replaced tool A with a handwritten parser so I'll use tool B"; if tool B were more appropriate, probably gcc would have switched to it rather than to a handwritten parser, no? The bottom line is that c++ is hard to parse; c not so much, but still tricky. If you write your own grammar, you'll probably learn a lot about parsing but it might not help you produce the analysis tool. – rici Feb 04 '16 at 01:59
  • Actually static-analysis would be a more suitable tag than code-metrics, but OP should respond to rici's comment as well. – Thomas Dickey Feb 04 '16 at 10:16
  • Thanks for your comments, I forgot to mention that I want to parse C source-code, that's right rici, but the handwritten parser uses a lot of hacks which effective to improve syntactic error diagnostics, I want to use my own actions when the production rules are verified, and that's what I can do with parser generators. – A.Thabet Feb 04 '16 at 12:18
  • You're not making much sense. If you have to ask the question you ***clearly*** should not be writing the C parser here. As is the question is too broad to be answered. The most valuable hints are in the first comments. – sehe Feb 04 '16 at 14:41
  • You have no idea how much work it is to build a working C parser (yes, not as much as a C++ parser but still amazingly a lot;m the committee and compiler guys have made a real mess). If you really want to build a tool that analyzes any property of a C program and hope to finish in a reasonable amount of time, get a C parser that already works so you can concentrate on your analysis. Frankly, to do your analyzer, you need *a lot more* than just a parser. See my essay on "Life After Parsing" http://www.semdesigns.com/Products/DMS/LifeAfterParsing.html?Home=DMSToolkit – Ira Baxter Feb 16 '16 at 08:37

1 Answers1

1

There is an open-source tool CScout which is a source code analyzer and refactoring browser for C. Since it accurately resolves identifiers and differentiates them according to their scope, it could be useful for you.

Tushar
  • 790
  • 7
  • 12