Jump to content
  • Advertisement
Sign in to follow this  

C++ parser library?

This topic is 4401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!