[Israel.pm] Regex that matches a C-style function definition.

Shmuel Fomberg semuelf at 012.net.il
Sun Nov 11 10:47:01 PST 2007

Hello There.

You might look at Regexp::Common for help, it has an ability to match
balanced parentheses. 
But I suspect that it will be easily confused by comments and strings inside
the C code. For example:
void f() {
   /*  {  */
   print "xyz { xyz \n";

So I can only recommend a do-it-yourself. Parse the file char by char, and a
simple state machine can solve your problem.


>-----Original Message-----
>From: Meron Cohen [mailto:Meron.Cohen at ecitele.com]
>Sent: Sunday, November 11, 2007 2:17 PM
>To: Perl in Israel
>Subject: [Israel.pm] Regex that matches a C-style function definition.
>I'm trying to parse ".c" file and extract a given function's definition.
>void f ()
>    /* definition of f () */
>I know that the name of the function is "f" and what I want is the
>definition of f (), inside the "{" and "}".
>Could you tell me if there is a CPAN module that already does it, or
>give me a Regex that does it.
>Perl mailing list
>Perl at perl.org.il
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.5.503 / Virus Database: 269.15.29/1124 - Release Date:
>11/11/2007 10:12

More information about the Perl mailing list