Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

¿Are there any (full) ANSI C parsers written in Perl 5?

and also, ¿Are any including GNU extensions?

Thanks

Replies are listed 'Best First'.
Re: ANSI C Parser in Perl?
by snoopy (Curate) on Feb 25, 2009 at 21:43 UTC
    Another approach is to let gcc do the parse for you, then load the result.

    You can do this by running gcc on the source files with -fdump-translation-unit option. GCC::TranslationUnit can then be used to examine the parse tree.

    From the GCC::TranslationUnit doco:

    use GCC::TranslationUnit; # echo '#include <stdio.h>' > stdio.c # gcc -fdump-translation-unit -c stdio.c $node = GCC::TranslationUnit::Parser->parsefile('stdio.c.tu')->root; # list every function/variable name while($node) { if($node->isa('GCC::Node::function_decl') or $node->isa('GCC::Node::var_decl')) { printf "%s declared in %s\n", $node->name->identifier, $node->source; } } continue { $node = $node->chain; }
      Nice!

      This is what I need

      Many thanks

Re: ANSI C Parser in Perl?
by kennethk (Abbot) on Feb 25, 2009 at 18:56 UTC

    Why do you want to parse C? I suspect there is a better solution to your actual problem.

    There are two associated with the Inline::C project, specifically Inline::C::ParseRecDescent and Inline::C::ParseRegExp, though I'm still going through their guts myself so I don't know if they'll fit your bill.

Re: ANSI C Parser in Perl?
by samtregar (Abbot) on Feb 25, 2009 at 21:18 UTC
Re: ANSI C Parser in Perl?
by casiano (Pilgrim) on Feb 26, 2009 at 11:55 UTC