SWM ISO c/C++ parser library / class

R

Rick

.... must be able and willing to convert a slew of c/c++ and associated files
into tokens -- preferably into XML.

Hi folks. I've had no luck going down the BNF or YACC route on this one.
Is there a class out there which can take a file / number of files as
parameters and spew me an XML stream or file? This is simply going to be
used in a tool to add code in source for a client's project. I was going to
use regexes for this, but wanted to explore this route first.

I also realize how monumental this request may be. Just wanted to know if
the work has already been done.
 
L

llewelly

Rick said:
... must be able and willing to convert a slew of c/c++ and associated files
into tokens -- preferably into XML.

You might find what you need in the gcc_xml project. Note that it
doesn't handle function bodies.
http://www.gccxml.org/HTML/Index.html
Hi folks. I've had no luck going down the BNF or YACC route on this
one.

I can't tell how far you want to go with this. Do you want complete
parsing, or will something partial and sloppy like what Doxygen
does do? C++ in particular is viewed as one of the hardest
languages to parse correctly.

For complete parsing, C is parse-able with YACC, but C++ is hostile
to YACC or any other LALR tool. I think with C++ you
are better off either trimming down your needs until you can
survive with just regex and no real parsing, or you should try to
write a recursive descent parser. (The gcc-3.4 (but not the
gcc_xml) parser is recursive decent.)
 
A

Attila Feher

llewelly wrote:
[SNIP]
For complete parsing, C is parse-able with YACC, but C++ is hostile
to YACC or any other LALR tool. I think with C++ you
are better off either trimming down your needs until you can
survive with just regex and no real parsing, or you should try to
write a recursive descent parser. (The gcc-3.4 (but not the
gcc_xml) parser is recursive decent.)

This seems to handle C++ parsing, or at least they are in the process of
making the C++ BNF for it: http://www.codeworker.org
 

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
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top