[Haskell-cafe] C++ Parser?
yinwang0 at gmail.com
Wed Feb 1 21:42:33 CET 2012
I have written a C++ parser in Scheme, with a Parsec-style parser
combinator library. It can parse a large portion of C++ and I use it
to do structural comparison between ASTs. I made some macros so that
the parser combinators look like the grammar itself.
It's code is at:
A demo of the parse tree based comparison tool is at:
The bit of information I can tell you about parsing C++:
- C++'s grammar is not that bad if you see the consistency in it.
Parsing a major portion of C++ is not hard. I made the parser in two
just need to fix some corner cases later.
- It is better to delay semantic checks to a later stage. Don't put
those into the parser. Parse a larger language first, and then walk
the parse tree to eliminate semantically wrong programs.
- Don't try translating from the formal grammar or parser generator
files for C++. They contain years of bugs and patches and you will
probably be confused looking at them. I wrote the parser just by
looking at some example C++ programs.
On Tue, Jan 24, 2012 at 5:06 AM, Christopher Brown
<cmb21 at st-andrews.ac.uk> wrote:
> I have stumbled across language-c on hackage and I was wondering if anyone is aware if there exists a full C++ parser written in Haskell?
> Many thanks,
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe