Good tools for creating a C/C++ parser/analyzer [closed]

Parsing C++ is extremely hard because the grammar is undecidable. To quote Yossi Kreinin:

Outstandingly complicated grammar

“Outstandingly” should be interpreted literally, because all popular languages have context-free (or “nearly” context-free) grammars, while C++ has undecidable grammar. If you like compilers and parsers, you probably know what this means. If you’re not into this kind of thing, there’s a simple example showing the problem with parsing C++: is AA BB(CC); an object definition or a function declaration? It turns out that the answer depends heavily on the code before the statement – the “context”. This shows (on an intuitive level) that the C++ grammar is quite context-sensitive.

Leave a Comment