Find function names from C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Berlin Brown

    Find function names from C

    I am parsing a C file and want to find the function names, is this
    python worthy or is Emacs-Lisp better for this. I have searched for
    some libraries but coming up null. I just need the function names, no
    args or anything else. I would probably have to run a regular
    expression pattern looking for int,void,static , etc and then the
    enclosing { }.

  • Josiah Carlson

    #2
    Re: Find function names from C

    Berlin Brown wrote:
    [color=blue]
    > I am parsing a C file and want to find the function names, is this
    > python worthy or is Emacs-Lisp better for this. I have searched for
    > some libraries but coming up null. I just need the function names, no
    > args or anything else. I would probably have to run a regular
    > expression pattern looking for int,void,static , etc and then the
    > enclosing { }.
    >[/color]

    That sounds like something a recursive descent (sp?) parser could do
    very well (or really any other programming language parser). In
    general, a regular expression would not be sufficient, due to nested
    blocks of {} like the following:

    int main () {
    if (1) {
    return 4;
    } else {
    return 3;
    }
    return 2;
    }

    FYI: regular expressions are those languages that can be recognized by
    finite state automata. Because most modern programming languages are
    context-free grammars, they are not recognized by regular expressions
    and thusly finite state automata.

    I would be willing to bet that someone has already implemented a parser
    for C/C++ in Python. If not, talk to someone taking a compilers class,
    they'll be able to help you.

    - Josiah

    Comment

    • Jey Kottalam

      #3
      Re: Find function names from C

      "Berlin Brown" <bigbinc097_DON T_SPAM@comcast. net> wrote in message
      news:zaCdnSd72a necoPdRVn-jg@comcast.com. ..[color=blue]
      > I am parsing a C file and want to find the function names, is this
      > python worthy or is Emacs-Lisp better for this. I have searched for
      > some libraries but coming up null. I just need the function names, no
      > args or anything else. I would probably have to run a regular
      > expression pattern looking for int,void,static , etc and then the
      > enclosing { }.
      >[/color]

      Look into www.gcc-xml.org or there's an ANSI-C parser at
      http://www.lysator.liu.se/c/ANSI-C-grammar-y.html that could easily be
      adapted for your needs. (Yes, that's with C and yacc, not python. sorry.)

      -Jey Kottalam


      Comment

      • Berlin Brown

        #4
        Re: Find function names from C

        Jey Kottalam wrote:[color=blue]
        > "Berlin Brown" <bigbinc097_DON T_SPAM@comcast. net> wrote in message
        > news:zaCdnSd72a necoPdRVn-jg@comcast.com. ..
        >[color=green]
        >>I am parsing a C file and want to find the function names, is this
        >>python worthy or is Emacs-Lisp better for this. I have searched for
        >>some libraries but coming up null. I just need the function names, no
        >>args or anything else. I would probably have to run a regular
        >>expression pattern looking for int,void,static , etc and then the
        >>enclosing { }.
        >>[/color]
        >
        >
        > Look into www.gcc-xml.org or there's an ANSI-C parser at
        > http://www.lysator.liu.se/c/ANSI-C-grammar-y.html that could easily be
        > adapted for your needs. (Yes, that's with C and yacc, not python. sorry.)
        >
        > -Jey Kottalam
        >
        >[/color]

        I have to go back to the books, dont know python or lisp very well,
        yacc,lex, for one thing, that is exactly what lisp does in emacs
        anyway, the way it matches one { with another }

        Comment

        • Chun-Chieh Huang

          #5
          Re: Find function names from C

          Berlin Brown <bigbinc097_DON T_SPAM@comcast. net> writes:
          [color=blue]
          > I have to go back to the books, dont know python or lisp very well,
          > yacc,lex, for one thing, that is exactly what lisp does in emacs
          > anyway, the way it matches one { with another }[/color]

          Well, how about etags in Emacs or ctags in vi? I don't know if this is
          exactly what you want, but typing "etags *.c" will generate a "TAGS"
          file, which contains all function names in those c source files. And
          then you can use Emacs to do function name searching. Take a look for
          the functionality in Emacs, maybe you don't have to write it by your
          own.

          Good luck!

          --
          Chun-Chieh Huang, aka Albert E-mail: jjhuang AT cm.nctu.edu.tw
          ¶À«T³Ç
          Department of Computer Science
          National Tsing Hua University MIME/ASCII/PDF/PostScript are welcome!
          HsinChu, Taiwan NO MS WORD DOC FILE, PLEASE!

          Comment

          Working...