So I have been slowly building up some methods to break apart pre-processed headers. I just recently began to try and take an inventory of the various functions actually being used in our code base and am stumped. SO here I am again back at the monastery seeking enlightenment. Here is the test function I am trying to parse:
float myFunction(float myfunc_arg0, float myfunc_arg1 ) { if(myfunc_arg0>1){ print "arg0 action\n"; } elsif(myfunc_arg1){ print "arg1 action\n"; } else{ print "take no action\n"; } }
So I think I have the regex to parse the function signature:  /\s*((?:\S+\s+){0,3})(?:(\S+)\(\s*((?:\S+\s+\S+)*)\s*\))\s*/ I want to remove each complete function from the file as I go so that I can come back for a second pass to grab all globally scoped variables in the C code. My problem is advancing the file keeping track of nesting to know when I have left the function. As you may be aware there is no rule the requires the C code function definition or its scoping delimiters "{" and "}" to be on one line. I consider myself an intermediate regex acolyte and am sure that there is an easy way to do this but I have yet to stumble upon it. It seems to me I am unable to use a replace to slurp up the function cause I don't know the depth of the delimiter nesting. I cant come up with an expression to handle arbitrary cases in a replace anyway... I have tried removing all newlines, running through the file that way.. I can successfully grab the function signature but have yet to figure out a way to know when I have passed by the end of the function. Any "perls" of wisdom greatly appreciated.. Your humble student, -jmm

In reply to Parsing C Functions.. by jmmistrot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.