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

Bob Smith bsmith at linuxtoys.org
Tue Jun 7 10:54:44 PDT 2016


On 06/07/2016 08:22 AM, Ivan Sergio Borgonovo wrote:
> 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.


Sounds like an interesting problem.  One approach
would be to use yacc/lex to build the parser for
you.  A web search for "yacc bison flex 'c parser'"
will lead to a bison file that implements the C
grammar.  Yacc/bison grammars are pretty easy to
read and you can trim the grammar down to whatever
subset you want to use.

hth
Bob Smith



More information about the svlug mailing list