Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: ANSI C Parser in Perl?

by snoopy (Deacon)
on Feb 25, 2009 at 21:43 UTC ( #746389=note: print w/ replies, xml ) Need Help??


in reply to ANSI C Parser in Perl?

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; }


Comment on Re: ANSI C Parser in Perl?
Download Code
Replies are listed 'Best First'.
Re^2: ANSI C Parser in Perl?
by Anonymous Monk on Feb 26, 2009 at 07:30 UTC
    Nice!

    This is what I need

    Many thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://746389]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2015-07-28 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls