# Parsing C header files

**URL:** <https://www.ruby-forum.com/t/parsing-c-header-files/111146>\
**Category:** Ruby\
**Created:** [August 3, 2007, 2:51am UTC](https://www.ruby-forum.com/t/parsing-c-header-files/111146 "2007-08-03T02:51:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wayne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/0ea827/32.png) [@wayne](https://www.ruby-forum.com/u/wayne)\
**Post date:** [August 3, 2007, 2:51am UTC](https://www.ruby-forum.com/t/parsing-c-header-files/111146/1 "2007-08-03T02:51:40Z")

</div>

I was wondering if there is a tool that can parse a C header file and  
give me an AST that would allow me to process it in Ruby. Does anyone  
know of a relatively easy way to do this? I was thinking that a lot  
of people probably need to parse API’s for one reason or another.

My situation is that we have a large application that was originally  
written in Ada, but now has a C interface. We need to make the API  
available to Matlab/Simulink, which is a model-based development  
system (basically it’s programming with diagrams). This is done in  
Matlab via S-functions (system functions). This system is pretty  
large and writing all the S-functions by hand would be a big job.  
Seems to me that a tool is the best choice and Ruby seems like the  
tool to do it.

---

<div class="post-metadata">

**Author:** ![wayne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/0ea827/32.png) [@wayne](https://www.ruby-forum.com/u/wayne)\
**Post date:** [August 4, 2007, 10:13am UTC](https://www.ruby-forum.com/t/parsing-c-header-files/111146/2 "2007-08-04T10:13:56Z")

</div>

On Aug 2, 2007, at 17:50, Wayne wrote:

> large and writing all the S-functions by hand would be a big job.  
> Seems to me that a tool is the best choice and Ruby seems like the  
> tool to do it.

Take a look at h2rb in ext/dl/ in a ruby checkout/tarball.
