Is there a standard C++ grammar?

浪尽此生 提交于 2019-11-28 16:52:27
James McNellis

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

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.

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!