Home > Archive > Compilers > October 2006 > C/C++ header file parser
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
C/C++ header file parser
|
|
| Pankaj Garg 2006-10-01, 4:02 am |
| I am sure this question is asked numerous times but searching the
archives I couldn't find any answer that fits my needs so i am posting
the question again.
I need to parse C/C++ header files and extract information about data
types, functions and function arguments. Which tools/libraries would
be suitable for me? Are there any examples/sample programs for such.
I don't want to build a full fledged yacc based parser so i am looking
for a ready made parser, preferably open source.
Thanks in advance,
Pankaj
| |
| David Wagner 2006-10-03, 7:04 pm |
| Pankaj Garg wrote:
>I need to parse C/C++ header files and extract information about data
>types, functions and function arguments. Which tools/libraries would
>be suitable for me? Are there any examples/sample programs for such.
>
>I don't want to build a full fledged yacc based parser so i am looking
>for a ready made parser, preferably open source.
First, please fix the email address listed in the From: line.
I tried replying by email, but the email bounced.
Regarding your question, search the archives, and you will find
several options listed. One option is that you could try Elsa/Oink:
http://www.cs.berkeley.edu/~smcpeak...d/sources/elsa/
http://www.cubewano.org/oink/features_of_elsa.html
http://www.cubewano.org/oink/
Elsa is a C and C++ parser. Oink is a layer on top of Elsa that
simplifies ("lowers") the C++ and puts it into a canonical form so it
is a little easier to deal with. It's open source. It's not perfect,
but it seems fairly solid. We've been using it in our research to
parse and analyze all Debian C/C++ packages, and it works pretty well:
Elsa can parse most, but not all, of those packages.
| |
| Pascal Bourguignon 2006-10-03, 7:04 pm |
| "Pankaj Garg" <lost_stranger@verizon.net> writes:
> I am sure this question is asked numerous times but searching the
> archives I couldn't find any answer that fits my needs so i am posting
> the question again.
>
> I need to parse C/C++ header files and extract information about data
> types, functions and function arguments. Which tools/libraries would
> be suitable for me? Are there any examples/sample programs for such.
>
> I don't want to build a full fledged yacc based parser so i am looking
> for a ready made parser, preferably open source.
gccxml, www.swig.org, ffigen, etc.
--
__Pascal Bourguignon__ http://www.informatimago.com/
"Logiciels libres : nourris au code source sans farine animale."
| |
| Alex McDonald 2006-10-03, 7:04 pm |
| Pankaj Garg wrote:
> I need to parse C/C++ header files and extract information about data
> types, functions and function arguments. Which tools/libraries would
> be suitable for me? Are there any examples/sample programs for such.
>
> I don't want to build a full fledged yacc based parser so i am looking
> for a ready made parser, preferably open source.
SWIG; http://www.swig.org/
--
Regards
Alex McDonald
| |
| Paul Pluzhnikov 2006-10-03, 7:04 pm |
| "Pankaj Garg" <lost_stranger@verizon.net> writes:
> I need to parse C/C++ header files and extract information about
> data types, functions and function arguments. ...
Since C++ headers can contain inline functions, you need a
full-fledged C++ parser.
> I don't want to build a full fledged yacc based parser
It is very difficult to build a correct yacc parser for C/C++ See:
http://www.nobugs.org/developer/parsingcpp/
> i am looking for a ready made parser, preferably open source.
http://www.cs.berkeley.edu/~smcpeak/elkhound/
Cheers,
--
In order to understand recursion you must first understand recursion.
| |
| Michael Tiomkin 2006-10-03, 7:04 pm |
| Pankaj Garg wrote:
> I need to parse C/C++ header files and extract information about data
> types, functions and function arguments. Which tools/libraries would
> be suitable for me? Are there any examples/sample programs for such.
>
> I don't want to build a full fledged yacc based parser so i am looking
> for a ready made parser, preferably open source.
All the compilers use the type info in order to create the debug
info part of the compiled object. Unfortunately, if the type is not
used, they ignore it. You can take gcc and force it to save the type
info of unused types. Then you can compile any header file and read
its debug info. The only problem would be the C++ templates, because
they usually are not a part of debug info. You can save the precompied
templates somewhere and read them later. Recall that you should run
the compiler with the same options that you use in the project,
because this influences the macro language, struct alignment etc.
A "dirtier" solution can be changing ctags to include the
declarations instead of definitions. ctags has a much simpler parser,
however I'm not sure if the modern ctags can parse C++ files.
Michael
| |
| Ira Baxter 2006-10-12, 7:11 pm |
| "Pankaj Garg" <lost_stranger@verizon.net> wrote in message
> I need to parse C/C++ header files and extract information about data
> types, functions and function arguments. Which tools/libraries would
> be suitable for me? Are there any examples/sample programs for such.
>
> I don't want to build a full fledged yacc based parser so i am looking
> for a ready made parser, preferably open source.
See http://www.semanticdesigns.com/Prod...ppFrontEnd.html
--
Ira Baxter, CTO
www.semanticdesigns.com
|
|
|
|
|