Is there a standard C++ grammar?
Asked Answered
I

5

36

Does the standard specify the official C++ grammar?

I searched, but did not find it anywhere.

Also, I wish to read a bit about C++ grammar in detail, like which category of grammars it falls in, etc. Any links pointing me in the right direction would be helpful.

By category, I mean

Click to enlarge taken from here.

Insist answered 17/5, 2010 at 14:21 Comment(1)
The category is 'horrible mess.'Okeechobee
A
33

Yes, it does.

The grammar is described in detail throughout the standard and is summarized in Appendix A: Grammar Summary (it's Appendix A in both the C++03 standard and the C++0x final committee draft).

You can purchase the C++03 standard or you can download the C++0x FCD (it's document n3092 on that page).

To answer the "what category is it in?" question, the C++ grammar is not context-free (also see the questions linked in answers to that question; they have additional examples of issues related to the C++ grammar and parsing C++).

Anemochore answered 17/5, 2010 at 14:24 Comment(1)
The last SO link is nice. By the way it's now Is C++ context-free or context-sensitive?Ostrogoth
P
10

Alessio Marchetti put a hyperlinked BNF grammar for C++ up at http://www.nongnu.org/hcb/.

Having everything linked together and on a single page makes it easy to navigate between rules.

Poseidon answered 23/10, 2013 at 3:24 Comment(2)
Would be nice if it were updated somehwereWheen
The source says it's updated in 2018, but seems to be pre-c++11 still github.com/alx71hub/hcbWheen
R
6

Andrew Birkett has a thorough overview of parsing C++ on his web site. It covers some of the difficulties in creating a C++ grammar (mixing lexical, syntactic, and semantic analysis) and includes links to several C++ grammars.

Rensselaerite answered 17/5, 2010 at 14:32 Comment(0)
C
2

Bjarne Stroustrup, the creator of C++, wrote a book called The C++ Programming Language which has been updated many times (I read the 3rd edition about 10 years ago). I recall it had very technical details regarding grammar (pre-processor and compiler).

You can probably find this book in on of your local book stores, it may offer you more enjoyment than a standards document from ANSI, depending on how specific you need to be.

Contralto answered 17/5, 2010 at 14:28 Comment(0)
S
0

Not sure but as far as I see, James McNellis's link (to the pdf) contains a note on the first page:

Warning

This document is not an ISO International Standard. It is distributed for review and comment. It is subject to change without notice and may not be referred to as an International Standard.

So, searched and I think this is the correct link to the official ISO: http://www-d0.fnal.gov/~dladams/cxx_standard.pdf

Starvation answered 17/5, 2010 at 14:59 Comment(2)
The PDF to which I linked is for the final committee draft of the forthcoming C++0x standard; it is the latest version of the next C++ standard, and since it hasn't been completed and ratified, it's not "official." The PDF to which you link is the C++98 standard, to which numerous corrections were made in 2003 to give the C++03 standard; most of the changes were minor, but there were some big changes. I'm actually somewhat surprised there is a PDF of that freely available; I believe the only way to legitimately get a copy of the ISO standard is by purchasing it (via the link I gave).Anemochore
Well then we both learnt something new today - you, that these ISO docs are freely available, and me, that the link you've provided is what I want to keep in my PC (: Thank you!Starvation

© 2022 - 2024 — McMap. All rights reserved.