Appendix B: C++ Subset Syntax

This documentation contains the C++ subset syntax that can be used in the semantic actions of a parser and in the rules and actions of a lexer.

Declarations

block‑declaration namespace‑alias‑definition | using‑directive | using‑declaration | simple‑declaration
simple‑declaration decl‑specifier‑seq? init‑declarator‑list? ;
decl‑specifier‑seq decl‑specifier+ | type‑name
decl‑specifier storage‑class‑specifier | type‑specifier | typedef
storage‑class‑specifier auto | register | static | extern | mutable
type‑specifier simple‑type‑specifier | cv‑qualifier
simple‑type‑specifier char | char8_t | char16_t | char32_t | wchar_t | bool | short | int | long | signed | unsigned | float | double | void
type‑name qualified‑cpp‑id (< template‑argument‑list >)?
template‑argument‑list template‑argument ( , template‑argument )*
template‑argument type‑id | assignment‑expression
typedef typedef
cv‑qualifier const | volatile
namespace‑alias‑definition namespace cpp‑identifier = qualified‑cpp‑id ;
using‑declaration using qualified‑cpp‑id ;
using‑directive using namespace qualified‑cpp‑id ;

Declarators

init‑declarator‑list init‑declarator ( , init‑declarator )*
init‑declarator declarator initializer?
declarator direct‑declarator | ptr‑operator declarator
direct‑declarator declarator‑id ( [ constant‑expression ] | [ ] | ( declarator ) )*
declarator‑id id‑expression | type‑name
type‑id (type‑specifier‑seq | type‑name ) abstract‑declarator?
type‑specifier‑seq type‑specifier+
abstract‑declarator ptr‑operator abstract‑declarator? | direct‑abstract‑declarator
direct‑abstract‑declarator ( [ constant‑expression ] | [ ] | ( abstract‑declarator ) )+
ptr‑operator * cv‑qualifier‑seq? | &
cv‑qualifier‑seq cv‑qualifier+
initializer = initializer‑clause | ( expression‑list )
initializer‑clause assignment‑expression | { initializer‑list } | { }
initializer‑list initializer‑clause ( , initializer‑clause )*

Expressions

expression assignment‑expression ( , assignment‑expression )*
constant‑expression expression
assignment‑expression logical‑or‑expression asssignment‑op assignment‑expression | conditional‑expression | throw‑expression
assignment‑op = | *= | /= | %= | += | -= | <<= | >>= | &= | ^= | |=
conditional‑expression logical‑or‑expression ( ? expression : expression )?
throw‑expression throw assignment‑expression?
logical‑or‑expression logical‑and‑expression ( || logical‑and‑expression )*
logical‑and‑expression inclusive‑or‑expression ( && inclusive‑or‑expression )*
inclusive‑or‑expression exclusive‑or‑expression ( | exclusive‑or‑expression )*
exclusive‑or‑expression and‑expression ( ^ and‑expression )*
and‑expression equality‑expression ( & equality‑expression )*
equality‑expression relational‑expression ( eq‑op relational‑expression )*
eq‑op == | !=
relational‑expression shift‑expression ( rel‑op shift‑expression )*
rel‑op < | > | <= | >=
shift‑expression additive‑expression ( shift‑op additive‑expression )*
shift‑op << | >>
additive‑expression multiplicative‑expression ( add‑op multiplicative‑expression )*
add‑op + | -
multiplicative‑expression pm‑expression ( mul‑op pm‑expression )*
mul‑op * | / | %
pm‑expression cast‑expression ( pm‑op cast‑expression )*
pm‑op .* | ‑>* |
cast‑expression ( ( type‑id ) cast‑expression ) | unary‑expression
unary‑expression postfix‑expression | postcast‑expression | ++ unary‑expression | -- unary‑expression | unary‑op cast‑expression | sizeof ( type‑id ) | sizeof unary‑expression | new‑expression | delete‑expression
unary‑op * | & | + | - | ! | ~
postfix‑expression primary‑expression ( [ expression ] | ( expression‑list ) | . id‑expression | ‑> id‑expression | ++ | -- )*
postcast‑expression ( static_cast | dynamic_cast | const_cast | reinterpret_cast ) < type‑id > ( expression ) | typeid ( expression )
expression‑list assignment‑expression ( , assignment‑expression )*
primary‑expression literal | this | ( expression ) | id‑expression
id‑expression qualified‑cpp‑id :: operator‑function‑id | ::? operator‑function‑id | qualified‑cpp‑id
new‑expression ::? new new‑placement? (new‑type‑id | ( type‑id )) new‑initializer?
new‑placement ( expression‑list )
new‑type‑id (type‑specifier‑seq | type‑name) new‑declarator?
new‑declarator ptr‑operator new‑declarator? | direct‑new‑declarator
new‑initializer ( expression‑list? )
direct‑new‑declarator [ expression ] ([ constant‑expression ])*
delete‑expression ::? delete ([ ])? cast‑expression
operator‑function‑id operator operator
operator [] | () | ‑>* | ‑> | , | -- | ++ | || | && | <= | >= | != | <= | >= | == | <<= | >>= | << | >> | |= | &= | ^= | %= | /= | *= | -= | += | < | > | = | ! | ~ | & | ^ | | | % | / | * | - | + | new [] | delete [] | new | delete

Identifiers

cpp‑identifier identifier
qualified‑cpp‑id ::? cpp‑identifier ( :: cpp‑identifier )*

Literals

literal integer‑literal | floating‑literal | char‑literal | string‑literal | true | false | nullptr

Statements

statement labeled‑statement | empty‑statement | compound‑statement | selection‑statement | iteration‑statement | jump‑statement | declaration‑statement | try‑statement | expression‑statement
labeled‑statement identifier : statement | case constant‑expression : statement | default : statement
empty‑statement ;
compound‑statement { statement* }
selection‑statement if‑statement | switch‑statement
if‑statement if ( condition ) statement ( else statement )?
switch‑statement switch ( condition ) statement
iteration‑statement while‑statement | do‑statement | range‑for‑statement | for‑statement
while‑statement while ( condition ) statement
do‑statement do statement while ( expression ) ;
range‑for‑statement for ( for‑range‑declaration : expression ) statement
for‑range‑declaration decl‑specifier‑seq declarator
for‑statement for ( for‑init‑statement condition? ; expression? ) statement
for‑init‑statement empty‑statement | expression‑statement | simple‑declaration
jump‑statement break‑statement | continue‑statement | return‑statement | goto‑statement
break‑statement break ;
continue‑statement continue ;
return‑statement return expression? ;
goto‑statement goto identifier ;
declaration‑statement block‑declaration
condition type‑id declarator = assignment‑expression | expression
try‑statement try compound‑statement handler‑seq
handler‑seq handler handler‑seq?
handler catch ( exception‑declaration ) compound‑statement
exception‑declaration type‑specifier‑seq ( declarator | abstract‑declarator )? | ...
expression‑statement expression ;