intelfx
intelfx

Reputation: 2744

C++ BNF grammar with parsing/matching examples

I'm developing a C++ parser (for an IDE), so now trying to understand C++ grammar in details. While I've found an excellent grammar source at http://www.nongnu.org/hcb/, I'm having trouble understanding some parts of it - and, especially, which "real" language constructs correspond to various productions.

So I'm looking for a C/C++ BNF grammar guide with examples of code that match various productions/rules. Are there any?

Upvotes: 8

Views: 6709

Answers (1)

Ira Baxter
Ira Baxter

Reputation: 95334

A hyperlinked (purported) grammar is not necessarily one on which you can build a parser easily. That is determined by the nature of your parsing engine, and which real dialect of C and C++ you care about (ANSI? GNU? C99? C++11? MS?).

Building a working C++ parser is really hard. See my answer to Why C++ cannot be parsed with a LR(1) parser? for some of the reasons. If you want a "good" parser, I suggest you use one of the existing ones. One worth looking at might be Elsa, since it is open source.

Upvotes: 7

Related Questions