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

Solution 1

By writing a LOT of code, essentially half a C compiler.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Your most productive approach is probably to use yacc and/or lex. Google is quite helpful for links to these.
  Permalink  

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

  Print Answers RSS
0 mhegazy94 460
1 Sergey Alexandrovich Kryukov 405
2 Kornfeld Eliyahu Peter 275
3 Gihan Liyanage 163
4 Sibeesh KV 156
0 Sergey Alexandrovich Kryukov 6,775
1 OriginalGriff 6,696
2 CPallini 5,345
3 George Jonsson 3,599
4 Gihan Liyanage 2,751


Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100