Regex to pull out C function prototype declarations?

前端 未结 8 645
星月不相逢
星月不相逢 2020-11-30 04:48

I\'m somewhere on the learning curve when it comes to regular expressions, and I need to use them to automatically modify function prototypes in a bunch of C headers. Does

8条回答
  •  误落风尘
    2020-11-30 05:18

    Let's say you have the whole c file read into $buffer. * first create regexp that replaces all comments with equally number of spaces and linefeeds so that row and col positions won't change * create regexp that can handle parenthesised string * then regexp like this finds functions: (static|)\s+(\w+)\s*$parenthezized_regexp+*{

    this reg exp does not handle functions which function definition uses preprocessor directives.

    if you go for lex/yacc you have to combine ansi c and preprocessor grammars to handle those preprocessor directives inside function definitions

提交回复
热议问题