Flex / Yacc sources for C parser

W

Wolfgang Draxinger

I'm currently working on a laguange similair in concept to Vala
(google for it on the Gnome project site). A (very) high level
language is translated into intermediary C, which is then
compiled to target.

I want to be able to "include" C headers, so that I don't have to
write bindings. That however means, that I have to parse them. I
could now of course write my own Flex / Yacc code, but I
presume, that there are ready to use C parser frameworks, which
can be filled with own code. Mostly it's about to get the
symbols. Preprocessor macros will be handed down into the
generated C code, but my compiler shall understand them to
enable compile time static type checking.

Wolfgang Draxinger
 
S

santosh

Wolfgang said:
I'm currently working on a laguange similair in concept to Vala
(google for it on the Gnome project site). A (very) high level
language is translated into intermediary C, which is then
compiled to target.

I want to be able to "include" C headers, so that I don't have to
write bindings. That however means, that I have to parse them. I
could now of course write my own Flex / Yacc code, but I
presume, that there are ready to use C parser frameworks, which
can be filled with own code. Mostly it's about to get the
symbols. Preprocessor macros will be handed down into the
generated C code, but my compiler shall understand them to
enable compile time static type checking.

Try lcc, which is touted as a re-targetable C compiler. It's often
praised for code clarity and modularity, so you may be able to rip out
the relevant pieces for your use.

<http://www.cs.princeton.edu/software/lcc/>
<http://www.kernel.org/pub/software/devel/sparse/>
 
G

George Peter Staplin

Wolfgang said:
I'm currently working on a laguange similair in concept to Vala
(google for it on the Gnome project site). A (very) high level
language is translated into intermediary C, which is then
compiled to target.

I want to be able to "include" C headers, so that I don't have to
write bindings. That however means, that I have to parse them. I
could now of course write my own Flex / Yacc code, but I
presume, that there are ready to use C parser frameworks, which
can be filled with own code. Mostly it's about to get the
symbols. Preprocessor macros will be handed down into the
generated C code, but my compiler shall understand them to
enable compile time static type checking.

Wolfgang Draxinger

I managed to produce a C99 (mostly GNUC compatible) grammar via some C89
samples on the net.

http://c-faq.com/resources/grammars.html

See also:
http://www.lysator.liu.se/c/ANSI-C-grammar-y.html

That page has a lexer for C, and CPP.

GNUC is difficult to parse entirely and properly with Yacc-based
parsers. GNU's C compiler doesn't seem to use Yacc as much as the
typical compiler (lots of hand written parsing from what I saw).



George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top