how to get the function declaration or definitions using regex

后端 未结 7 1028
野的像风
野的像风 2020-12-16 06:43

I want to get only function prototypes like

int my_func(char, int, float)
void my_func1(void)
my_func2()

from C files using regex and pytho

7条回答
  •  别那么骄傲
    2020-12-16 07:14

    There are LOTS of pitfalls trying to "parse" C code (or extract some information at least) with just regular expressions, I will definitely borrow a C for your favourite parser generator (say Bison or whatever alternative there is for Python, there are C grammar as examples everywhere) and add the actions in the corresponding rules.

    Also, do not forget to run the C preprocessor on the file before parsing.

提交回复
热议问题