views:

37

answers:

1

I am working on a project which requires generating some metrices of a code (it can be C/C++/Java/Python). One of the metrices can be that I create a callgraph after parsing the code entered (the programs are expected to be small - probably under 1000L).

As of now, I am looking for a way to create a program (it can be C/Python) which can take as input a file (C/C++/Python/Java) and then create a textual output containing approximate calling sequence as well as tokens in the code file.

As of now, I have looked at some other tools which do the same thing - like splint, pylint, codeviz etc. So, I have two ways of solving my problem:

  1. Read and understand the algorithm these tools use (tokenization->graph generation etc)
  2. Or, have a basic algo (something like very high level steps) and then sit down to create each of them as I want them to be.

I know, re-inventing the wheel is not a good idea, but, I would still like to give option (2) a shot. Only issue is, currently I am a blank.

My question: Does any one have any knowhow about how to create code graphs? Any hints as to what I should do? Any top levels steps which I can follow?

Thanks a lot.

+1  A: 

pycallgraph does it (in Python, for Python only) and it should be easier to understand and adapt than bigger programs like the ones you mention.

Alex Martelli
Yes, that is nice tool, but unfortunately it is specifically for Python. This is one of the main reasons that I would like to create a custom tool because I still cannot find a generic (or, almost generic) callgraph generator. Thanks anyways for the useful link - I will go through the code and try and make sense out of it.
Shrey
I did say it's for Python only -- but the point is that the algorithms it employs are more clearly and simply on display, thus easier to grasp than those in other tools, I believe.
Alex Martelli
@alex Yes, I do apologize for not reading your post properly and restating the obvious fact 'it is for python'. I am still trying to understand the algo - thanks for pointing to this code.
Shrey
@Shrey, NP -- always glad to be of help!
Alex Martelli