Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 555
intelfx Avatar asked Aug 06 '12 08:08

intelfx


1 Answers

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.

like image 78
Ira Baxter Avatar answered Sep 28 '22 15:09

Ira Baxter