[svlug] simple C parser in C/C++/python

Ivan Sergio Borgonovo mail at webthatworks.it
Tue Jun 7 08:22:34 PDT 2016

I've to generate some C code from some C code [sic].
I've a C struct, some #define in some headers and I should generate some 
C code from them. The resulting C code will then be further compiled 
into another program.

Currently I wrote a C++ program that simply include the #define and the 
struct, get compiled, the resulting C program get executed and produce 
the C code.

That somehow is mostly OK since I can relay on a C compiler and it's as 
efficient as it needs to be, but I find it a bit messy.

One option that came to mind was to use some parsing C library that 
digest the C source and output C source, making the program self 
sufficient and avoiding one compilation step.

I highly doubt I can find a C parsing library that is going to make this 
easy enough to be worth to try but that could be compensated by the fact 
I'll learn something that I'm pretty sure I'll find useful in the future.

Another approach would be to "include" the C source in the bash script 
and pipe it to gcc but this makes the C code harder to maintain.

Any alternative approach would be welcome.

Ivan Sergio Borgonovo

More information about the svlug mailing list