Friday, February 4, 2011

Regular expression to match (C) function calls

Does anyone have a regular expression for matching function calls in C programs ?

  • Since C isn't a regular language and C function calls can contain arbitrary argument expressions, I fear the answer to your question is “no.”

  • I doubt you can find a regex that matches all (and only) the function calls in some source code. But maybe you could use a tool like Understand, or your IDE, to browse your code.

  • After a bit more searching I decided to let the compiler do the hard work.

    Get the compiler to produce a Register Transfer Language (RTL) file using the -dr options of gcc.

    The produced RTL file has the suffix .rtl or .expand.

    This file is far easier to parse as the functions calls are already identified.

    From David

0 comments:

Post a Comment