Hi Ryan
I am currently evaluation lexer/parsers for C/C++. I started out with ANTLR3 and the C target (
http://www.antlr.org/wiki/display/ANTLR3/FAQ+-+C+Target).
I succeeded in compiling and I could parse a simple Java file successfully. However, the parser failed on a more complex Java file, that could be parsed correctly with the Java target.
( note, since perhaps you are new to ANTLR: when I say 'target', I don't mean the language that is parsed, but the language version of ANTLR that is used to parse. The default target - the generated lexer/parser code - of ANTLR is Java, and there are targets in Python, C and others. So, the C target can be used to parse Java, C, Python , depending on what .g you use. )
The problems I had with the C target , and the reason why I gave up on it, were, amongst others:
- the C target lacks documentation ( although the code is documented ), especially the error reporting and the customization of it seem to be very different from the Java target and this particular function is important to me ( I want to develop IDE support )
- the C target, is as far as I understand, a brilliant and heroic effort by one individual ( Jim Idle ) who did the port - at least he answers the related questions - , but the port has not the full community support
- Terence Parr, the creator of ANTLR is selling suppot for the Java target only
- the C++/C family is not on the top priority list for ANTLR4, judging from some emails in the forum.
Please note, that these are my personal impressions, and I hope the community will correct me , if necessary.
So I turned to clang (
http://clang.llvm.org/) , a very interesting opensource project, also warmly recommended by Terence ( he has an example in the Wiki , not related to C, though ). It is full production as it ships with Apple development tools ( XCode ) and if this is not enough , it is also sponsored by Google, Intel and Qualcom.
Clang offers a libary, libclang, that offers an API to most of its lexing and parsing functions. It allows you to build tools for rewriting/translation, static analysis and code completion.
To get a feeling, watch the videos here:
http://llvm.org/devmtg/2010-11/ , especially the one by Doug Gregor. There is a conference each year and some of the videos are interesting.
The libclang API is relatively fresh and there is a lack of examples, but I got it working with the tutorials here:
https://github.com/loarabia/Clang-tutorial#readmeIt's not easy - at leat for me as a sub-standard C/C++ guy - , but once you master this, you have world class C/C++ preprocessing, lexing and parsing at your fingertips. And it is very fast. ( because Apple wants it fast )
I use ANTLR for all the other languages I want to experiment with, in particular Java, Javascript and Sparql for which you can find grammars on the Wiki ( all for the use with the Java target, by the way).
But for C ( you might need preprocessing and macro expansion ) and especially for C++ - being a really complicated beast - I feel clang is the better choice for me.
Hope that helps.