[antlr-interest] Extract C Function Definitions Using Parser

Joshua Garcia joshuaga at usc.edu
Sun Mar 18 20:55:14 PDT 2012


Hi Everyone,

I've been working on modifying an ANTLR C grammar so that it produces a
parser that simply outputs function definitions it recognizes to different
files. I need to do this in order to apply some information retrieval
techniques to C source code.

Is there a way to get the generated parser to recognize only the function
definitions (including the function body) and comments while ignoring
everything else? I've found it too troublesome to deal with comments so
I've been ignoring them for now.

If not, is there a way to get the generated parser to recognize only the
function definitions (including the function body) and ignore everything
else? I've been able to modify the grammar so that it can recognize a large
majority of the functions in pre-processed files of a version of bash.
However, the pre-processed files tend to transform some function definition
text to extern declarations. Therefore, I lose function definition text
that I need. Furthermore, the parser does not ignore everything else that's
not part of a function definition, but instead, I've added rules to the
grammar in order to recognize as much of the bash version I'm parsing as
possible.

In particular, I've been trying to use this grammar:

http://www.antlr.org/grammar/1153358328744/C.g

Thanks,
Josh


More information about the antlr-interest mailing list