Annex A (informative) Grammar summary [gram]

This summary of C++ grammar is intended to be an aid to comprehension.
It is not an exact statement of the language.
In particular, the grammar described here accepts a superset of valid C++ constructs.
Disambiguation rules ([stmt.ambig], [dcl.spec], [class.member.lookup]) must be applied to distinguish expressions from declarations.
Further, access control, ambiguity, and type rules must be used to weed out syntactically valid but meaningless constructs.

A.1 Keywords [gram.key]

A.2 Lexical conventions [gram.lex]

h-char:
any member of the source character set except new-line and >
q-char:
any member of the source character set except new-line and "
nondigit: one of
a b c d e f g h i j k l m
n o p q r s t u v w x y z
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z _
digit: one of
0 1 2 3 4 5 6 7 8 9
keyword:
any identifier listed in Table tab:lex.key
import-keyword
module-keyword
export-keyword
preprocessing-operator: one of
# ## %: %:%:
operator-or-punctuator: one of
{ } [ ] ( )
<: :> <% %> ; : ...
? :: . .* -> ->* ~
! + - * / % ^ & |
= += -= *= /= %= ^= &= |=
== != < > <= >= <=> && ||
<< >> <<= >>= ++ -- ,
and or xor not bitand bitor compl
and_eq or_eq xor_eq not_eq
binary-digit: one of
0 1
octal-digit: one of
0 1 2 3 4 5 6 7
nonzero-digit: one of
1 2 3 4 5 6 7 8 9
hexadecimal-prefix: one of
0x 0X
hexadecimal-digit: one of
0 1 2 3 4 5 6 7 8 9
a b c d e f
A B C D E F
unsigned-suffix: one of
u U
long-suffix: one of
l L
long-long-suffix: one of
ll LL
encoding-prefix: one of
u8  u  U  L
c-char:
any member of the basic source character set except the single-quote ', backslash \, or new-line character
escape-sequence
universal-character-name
simple-escape-sequence: one of
\'  \"  \?  \\
\a  \b  \f  \n  \r  \t  \v
sign: one of
+ -
floating-point-suffix: one of
f l F L
s-char:
any member of the basic source character set except the double-quote ", backslash \, or new-line character
escape-sequence
universal-character-name
r-char:
any member of the source character set, except a right parenthesis ) followed by
   the initial d-char-sequence (which may be empty) followed by a double quote ".
d-char:
any member of the basic source character set except:
   space, the left parenthesis (, the right parenthesis ), the backslash \, and the control characters
   representing horizontal tab, vertical tab, form feed, and newline.
boolean-literal:
false
true
pointer-literal:
nullptr

A.3 Basics [gram.basic]

A.4 Expressions [gram.expr]

simple-capture:
identifier ...
& identifier ...
this
* this
fold-operator: one of
+   -   *   /   %   ^   &   |   <<   >>
+=  -=  *=  /=  %=  ^=  &=  |=  <<=  >>=  =
==  !=  <   >   <=  >=  &&  ||  ,   .*   ->*
unary-operator: one of
* & + - ! ~
delete-expression:
:: delete cast-expression
:: delete [ ] cast-expression
assignment-operator: one of
= *= /= %= += -= >>= <<= &= ^= |=

A.5 Statements [gram.stmt]

A.6 Declarations [gram.dcl]

storage-class-specifier:
static
thread_­local
extern
mutable
cv-qualifier:
const
volatile
enum-key:
enum
enum class
enum struct
alignment-specifier:
alignas ( type-id ... )
alignas ( constant-expression ... )
balanced-token:
( balanced-token-seq )
[ balanced-token-seq ]
{ balanced-token-seq }
any token other than a parenthesis, a bracket, or a brace

A.7 Modules [gram.module]

module-declaration:
export-keyword module-keyword module-name module-partition attribute-specifier-seq ;
private-module-fragment:
module-keyword : private ; declaration-seq

A.8 Classes [gram.class]

class-key:
class
struct
union
virt-specifier:
override
final
access-specifier:
private
protected
public

A.9 Overloading [gram.over]

operator: one of
new delete new[] delete[] co_await () [] -> ->*
~ ! + - * / % ^ &
| = += -= *= /= %= ^= &=
|= == != < > <= >= <=> &&
|| << >> <<= >>= ++ -- ,

A.10 Templates [gram.temp]

type-parameter-key:
class
typename
explicit-instantiation:
extern template declaration

A.11 Exception handling [gram.except]

A.12 Preprocessing directives [gram.cpp]

pp-private-module-fragment:
module : private ; new-line group
lparen:
a ( character not immediately preceded by white-space
new-line:
the new-line character
has-include-expression:
_­_­has_­include ( header-name )
_­_­has_­include ( header-name-tokens )
has-attribute-expression:
_­_­has_­cpp_­attribute ( pp-tokens )
pp-module:
export module pp-tokens ; new-line
pp-import:
export import header-name pp-tokens ; new-line
export import header-name-tokens pp-tokens ; new-line
export import pp-tokens ; new-line
va-opt-replacement:
__VA_­OPT__ ( pp-tokens )