prasanth.pronda has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I am trying to come up with a script that will list out all the functions & its source code, from a .c file. I tried doing it using Python Lex Yacc. But, it only lists the names of the functions. eg. void foo() { do this & this } I need the script to give me an output similar to the above for all the functions written in a .c file. Does perl provide such facility. Is there any CPAN module already? Any suggestions/advice? Thanks, Prasanth.
  • Comment on Script to list out the functions of a C file

Replies are listed 'Best First'.
Re: Script to list out the functions of a C file
by marto (Cardinal) on May 28, 2010 at 10:33 UTC
Re: Script to list out the functions of a C file
by Corion (Patriarch) on May 28, 2010 at 10:32 UTC
Re: Script to list out the functions of a C file
by moritz (Cardinal) on May 28, 2010 at 11:25 UTC
    ctags extracts function names (including position in the source file) from many different programming languages; C is one of them.

    I'm not sure if it extracts all the information you're interested in, but it's well worth investigating.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Script to list out the functions of a C file
by mr_mischief (Monsignor) on May 28, 2010 at 11:21 UTC
    While Corion and marto already gave you good advice which was Perl-specific as you asked, I'd like to point out that if the Python Lex and Yacc are equivalent to an actual lex and yacc then the shortcoming in parsing C probably isn't your choice of tools. You may want to try gaining a deeper understanding of how to use them, even if that means taking what you learn doing it in Perl back to the Python tools.