C++ parser library?

Started by
7 comments, last by Kitt3n 17 years, 11 months ago
I'm looking for a way to parse C++ in order to make a code analyzer (the end product will issue a series of warnings and errors that a compiler would miss). Does anyone know of a C++ parser library that could help me to accomplish this?
Advertisement
boost::spirit might work
http://www.boost.org/libs/spirit/index.html
Beware, C++ cannot be parsed by a context-free grammar. Simply parsing the syntax will not give you enough meaningful information that you can do better than a compiler at finding code problems. Just to parse C++ properly you have to perform semantic analysis.

Stephen M. Webb
Professional Free Software Developer

How about this one:
http://www.gccxml.org/HTML/Index.html
Quote:Original post by nmi
How about this one:
http://www.gccxml.org/HTML/Index.html


Excellent, that's just the kind of thing I was looking for. No template support, but a good starting point.
synopsis
openc++
elsa
A full C++ parsing engine with complete name and type resolution
is available from
http://www.semanticdesigns.com/Products/FrontEnds/CppFrontEnd.html
You can customize it to enable arbitrary checks, and therefore
produce your "warnings and errors a compiler would miss".

Which warning and errors are you considering?

-- IDB
Quote:Original post by Wixner
boost::spirit might work
http://www.boost.org/libs/spirit/index.html


As already suggested, boost::spirit lacks currently support for some features required to properly parse C++ without hackish workarounds.
However, if you check out the Google Summer of Code pages, you will see that boost is a SoC mentor organization, and on their "project ideas" page there is a proposal for a C++ parser implementation using the Boost/Spirit libraries.
This sounds like an interesting and challenging project, so if anybody here is an eligible student, you may want to consider checking it out.

http://code.google.com/soc/boost/about.html
Now what would really be cool is to use that code-parser to make
an 'header optimization-tool, moving headers from .h's to .cpp's
and using forward declaration where possible'...

Ah, going through that manually just plain sucks lol :)
visit my website at www.kalmiya.com

This topic is closed to new replies.

Advertisement