# Parsing C/C++ in Ruby

**URL:** <https://www.ruby-forum.com/t/parsing-c-c-in-ruby/157583>\
**Category:** Ruby\
**Created:** [January 13, 2009, 10:55am UTC](https://www.ruby-forum.com/t/parsing-c-c-in-ruby/157583 "2009-01-13T10:55:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sparkymat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@sparkymat](https://www.ruby-forum.com/u/sparkymat)\
**Post date:** [January 13, 2009, 10:55am UTC](https://www.ruby-forum.com/t/parsing-c-c-in-ruby/157583/1 "2009-01-13T10:55:26Z")

</div>

I need to parse a source tree to generate a table of functions used.  
GCC-XML is causing more trouble than helping (I might be using it  
wrong). Is there a C/C++ parser library (written in Ruby) available?  
Failing which, which parser generator would you recommend, that would  
help me write a simple C parser? My CC skills are a bit rusted, and it  
would greatly help if the parser generator library has examples and/or  
tutorials.

---

<div class="post-metadata">

**Author:** ![sparkymat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@sparkymat](https://www.ruby-forum.com/u/sparkymat)\
**Post date:** [January 13, 2009, 1:15pm UTC](https://www.ruby-forum.com/t/parsing-c-c-in-ruby/157583/2 "2009-01-13T13:15:52Z")

</div>

Sparky M. wrote:

> I need to parse a source tree to generate a table of functions used.  
> GCC-XML is causing more trouble than helping (I might be using it  
> wrong). Is there a C/C++ parser library (written in Ruby) available?  
> Failing which, which parser generator would you recommend, that would  
> help me write a simple C parser? My CC skills are a bit rusted, and it  
> would greatly help if the parser generator library has examples and/or  
> tutorials.

I haven’t used gcc-xml but it would seem to me the right tool for the  
job.

As an alternative you could use SWIG, and output the results to xml (use  
the -xml or -xmlout options). Then parse that XML with rexml or libxml.

C++ is a pretty complex language to parse, but SWIG understands most of  
it - certainly enough to locate methods and functions.

a

---

<div class="post-metadata">

**Author:** ![sparkymat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@sparkymat](https://www.ruby-forum.com/u/sparkymat)\
**Post date:** [January 13, 2009, 1:32pm UTC](https://www.ruby-forum.com/t/parsing-c-c-in-ruby/157583/3 "2009-01-13T13:32:23Z")

</div>

On Tue, Jan 13, 2009 at 7:14 AM, Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I haven’t used gcc-xml but it would seem to me the right tool for the job.

What problems are you having with GCC-XML?

Have you checked out rbgccxml? [GitHub - jameskilton/rbgccxml: Account name changed!](http://github.com/jameskilton/rbgccxml)

Jason
