Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I scan a complete c code and get the relations between valuables and functions?Result printed to be a table?
Posted
Comments
Sergey Alexandrovich Kryukov 27-Dec-12 21:54pm    
You got some answers, but I would rather wonder — why?
—SA
叶千 28-Dec-12 10:46am    
Part of my program need this function
Sergey Alexandrovich Kryukov 28-Dec-12 12:34pm    
....

Your most productive approach is probably to use yacc and/or lex. Google is quite helpful for links to these.
 
Share this answer
 
Hello 叶千

you might start here[^]. This is a python based c-parser that looks promising to me. I have not used it, though.

There might be several C parsers around (for sure several yacc grammars, e.g. http://www.lysator.liu.se/c/ANSI-C-grammar-y.html[^]). The C language is not so complex to parse compared to C++, C#, etc.

The real challenge starts with the analysis you want to perform on the parsed AST.
It is not clear to me what exactly you want to extract from the "scan".

Cheers
Andi
 
Share this answer
 
Ummm... you could write a program to do that I suppose. The problem being that you would essentially be writing a good portion (parser? lexer?) of a C compiler. Beware that the code would need to be pre-processed before you run your analyzer on it or macros would probably cause you trouble.
 
Share this answer
 
By writing a LOT of code, essentially half a C compiler.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900