Python script to print all function definitions of a C/C++ file

parsing, python, string

Solution

I would suggest using the PLY lex/yacc tool. There's a prebuilt C parser, and the parser itself is quite fast. Once you have the file parsed, it shouldn't be too hard to find all of the functions.

http://www.dabeaz.com/ply/

Problem

I want a python script to print list of all functions defined in a C/C++ file. e.g. `abc.c` defines two functions as: ``` void func1() { } int func2(int i) { printf("%d", i); return 1; } ``` I just want to search the file (`abc.c`) and print all the functions defined in it (function names only). In the example above, I would like to print `func1`, `func2` using python script.

Original source

Related problems