2

Separate from frontend implementers' experiences, are there formal standards that syntactic extensions to the C++ grammar are required to meet? That is, are proposed extensions subjected to any form of mechanical analysis before being accepted?

I ask because I have read that the two most widely used C++ compilers, g++ and clang, both use hand written, recursive descent parsers. Does that mean that as the grammar evolves, it needs to remain LL(1) (or maybe LL(n)) with the proviso that certain implementation tricks are allowed / assumed / expected?

cigien
  • 57,834
  • 11
  • 73
  • 112
John Yates
  • 1,027
  • 1
  • 7
  • 18
  • 2
    C++ compilers use hand-written parsers (in part) because the C++ grammar is *not* context-free (and hence not LL(k). – Sneftel Aug 28 '21 at 16:02
  • The standard counterexample and some discussion are at https://stackoverflow.com/questions/44141686/how-to-make-c-language-context-free – Nate Eldredge Aug 28 '21 at 17:24

1 Answers1

3

The C++ standard defines a language; it does not restrict what that language might become in the future. (The C standard does contain a section called "future directions", but that is more a warning to users of features which have been deprecated, and which identifiers might be reserved in the future, rather than being a limitation on future standards.)

That said, the standards process is basically conservative, since the committee includes representatives of the major compilers as well as major user groups, none of whom are likely to accept changes which make the language even harder to parse.

As far as I know, there is no mechanical validation of proposed changes. But there is a lot of manual analysis by people with a lot of experience and expertise. Moreover, proposed changes are generally accompanied by proof-of-concept implementations to demonstrate their viability and utility.

cigien
  • 57,834
  • 11
  • 73
  • 112
rici
  • 234,347
  • 28
  • 237
  • 341