468,513 Members | 1,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

Flex / Yacc sources for C parser

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
--
E-Mail address works, Jabber: he******@jabber.org, ICQ: 134682867

Dec 25 '07 #1
2 3711
Wolfgang Draxinger wrote:
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/>

Dec 25 '07 #2
Wolfgang Draxinger wrote:
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
Dec 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Peter Kleiweg | last post: by
8 posts views Thread by pavel.orehov | last post: by
4 posts views Thread by Profetas | last post: by
6 posts views Thread by Volker Hetzer | last post: by
1 post views Thread by c/c++ | last post: by
3 posts views Thread by Tinkertim | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.