Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard C++ grammar?

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.

like image 677
Lazer Avatar asked May 17 '10 14:05

Lazer


People also ask

Does C have a context-free grammar?

C is a very good example, because it is one of the most popular languages in use and because its grammar is so almost context free that it serves as a good model to demonstrate what I'm talking about. Now, a CFG has several definitions in relation to formal languages and programming languages.

What is C grammar?

the third letter of the English alphabet, a consonant. 2. any spoken sound represented by the letter C or c, as in cat, race, or circle.

What is the C language standard?

What is the C programming language standard? It is the standard way defined for the compiler creators about the compilation of the code. The latest C standard was released in June 2018 which is ISO/IEC 9899:2018 also known as the C11.

What type of grammar is used in C++?

A context-sensitive grammar for this language is possible, and a Type-0 grammar is provided in the answer to this question: https://math.stackexchange.com/questions/163830/context-sensitive-grammar-for-the-copy-language .


3 Answers

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++).

like image 184
James McNellis Avatar answered Oct 11 '22 20:10

James McNellis


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.

like image 36
Nate Kohl Avatar answered Oct 11 '22 21:10

Nate Kohl


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.

like image 6
Josh Kelley Avatar answered Oct 11 '22 20:10

Josh Kelley