For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2007 > Re: Matching C functions using a perl script: Help needed









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Matching C functions using a perl script: Help needed
arunbabu.n@gmail.com

2007-05-16, 6:59 pm

Thank you very much for your suggestions and pointers. The non-greedy
approach took care of the issue.

When I started adding more functionality, say if i want to parse
f1() {
for(;;)
{}
}
f2(){}

After reading the reference materials, i came up with the following:
s/([a-zA-Z_]+\w*::[a-zA-Z_]+\w*)(\s*?)(\()(.*?)(\))(\s*?)((\{.*?)+?)
((.*?\})+?)/$1$2$3$4$5$6$7$9\/\* $1 \*\//gs;

the innermost set of {} is causing a problem. upto the innermost { the
matching happens fine because of non-greedy patterns.
But after that, the pattern matches the immediate } and what i get is:
f1() {
for(;;)
{} /* f1 */
}
f2(){}

(Changing $9 to greedy match wont help becuase it wud take the } of
f2)

Could you please help me with a suggention to tackle this? What is the
way to match the curlyl braces?

(sorry if this is a duplicate post)

Thank you
Arun
On May 15, 5:42 pm, Paul Lalli <mri...@gmail.com> wrote:
> On May 15, 5:32 pm, "arunbab...@gmail.com" <arunbab...@gmail.com>
> wrote:
>
>
>
>
>
>
>
>
> You need to make your quantifier non-greedy. Just put a ? after the *
>
> Please read:
> perldoc perlretut
> perldoc perlre
> perldoc perlreref
>
> Paul Lalli



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com