This repository has been archived by the owner on Apr 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
C++11 grammar regex rule
kennytm edited this page Sep 25, 2011
·
1 revision
Contents
BINARY-SEPARATED
{T, S} = T ( ( S ) T ) *
COMMA-SEPARATED
{T} =BINARY-SEPARATED
{ T, , }
COMMA-SEPARATED-DDD
{T} =COMMA-SEPARATED
{ T ...? }
COMMA-TRAILED-OPT
{T} = (COMMA-SEPARATED
{ T } ,? )?
ATTRIB-SEQ
{T} = T+ attribute-specifier*
ATTRIB-SEQ-BOTH
{T} = attribute-specifier*ATTRIB-SEQ
{ T }
alignas | alignof | asm | auto | bool | break | case | catch | char | char16_t | char32_t | class | const | constexpr | const_cast | continue | decltype | default | delete | do | double | dynamic_cast | else | enum | explicit | export | extern | false | float | for | friend | goto | if | inline | int | long | mutable | namespace | new | noexcept | nullptr | operator | private | protected | public | register | reinterpret_cast | return | short | signed | sizeof | static | static_assert | static_cast | struct | switch | template | this | thread_local | throw | true | try | typedef | typeid | typename | union | unsigned | using | virtual | void | volatile | wchar_t | while
/\\u[0-9a-f]{4}|\\U[0-9a-f]{8}/i
header-name | identifier | pp-number | character-literal | user-defined-character-literal | string-literal | user-defined-string-literal | preprocessing-op-or-punc | /\S/
identifier | keyword | literal | preprocessing-op-or-punc
/<[^\n>]+>|"[^\n"]+"/
/\.?\d/ ( /e[-+]|[\w.]/i | universal-character-name )*
( /[_a-z]/i | universal-character-name ) ( /\w/ | universal-character-name )*
{ | } | [ | ] | # | ## | ( | ) | <: | :> | <% | %> | %: | %:%: | ; | : | ... | new | delete | ? | :: | . | .* | + | - | * | / | % | ^ | & | | | ~ | ! | = | < | > | += | -= | *= | /= | %= | ^= | &= | |= | << | >> | >>= | <<= | == | != | and | and_eq | bitand | bitor | compl | not | not_eq | or | or_eq | xor | xor_eq
integer-literal | character-literal | floating-literal | string-literal | boolean-literal | pointer-literal | user-defined-literal
integer-literal-without-suffix /ul{0,2}|l{1,2}u?/i?
/[1-9]\d*|0[0-7]*|0x[0-9a-f]+/i
/[uUL]?'/ ( /[^'\n\\]/ | escape-sequence | universal-character-name)+ '
/\\['"?\\abfnrtv]|\\[0-7]{1,3}|\\x[0-9a-fA-F]{1,2}/
floating-literal-without-suffix /[fl]/i?
/(\d*\.\d+|\d+\.)(e[-+]?\d+)|(\d+e[-+]?\d+)/i
/(u8|[uUL])?/ ( " ( /[^"\n\\]/ | escape-sequence | universal-character-name )* " | R raw-string )
/"([^s()\\]*)\(.*?\)\1"/
Note that "\1" here is a back-reference.
true | false
nullptr
user-defined-integer-literal | user-defined-floating-literal | user-defined-string-literal | user-defined-character-literal
integer-literal-without-suffix ud-suffix
floating-literal-without-suffix ud-suffix
string-literal ud-suffix
character-literal ud-suffix
identifier
declaration*
literal | this | ( expression ) | id-expression | lambda-expression
unqualified-id | qualified-id
identifier | operator-function-id | conversion-function-id | literal-operator-id | ~ class-name | ~ decltype-specifier | template-id
One of:
- ::? nested-name-specifier template? unqualified-id
- :: ( identifier | operator-function-id | literal-operator-id | template-id )
( type-name | namespace-name | decltype-specifier ) :: ( ( identifier | template? simple-template-id ) :: )*
lambda-introducer lambda-declarator? compound-statement
[ lambda-capture? ]
One of:
& | =
&? identifier | this
( parameter-declaration-clause ) mutable? exception-specification? attribute-specifier* trailing-return-type?
postfix-expression-head postfix-expression-tail*
One of:
- primary-expression
- ( simple-type-specifier | typename-specifier ) ( ( expression-list ) | braced-init-list )
- ( dynamic_cast | static_cast | reinterpret_cast | const_cast ) < type-id > ( expression )
- typeid ( ( expression | type-id ) )
One of:
- [ ( expression | braced-init-list ) ]
- ( expression-list? )
- ( . | -> ) ( template? id-expression | pseudo-destructor-name )
- ++
- --
initializer-list
One of:
- ::? ( nested-name-specifier? ( type-name :: )? | nested-name-specifier template simple-template-id ::) ) ~ type-name
- ~ decltype-specifier
sizeof* unary-expression-last
One of:
- ( ++ | -- | unary-operator ) cast-expression
- ( sizeof | alignof ) ( type-id )
- sizeof ... ( identifier )
- noexcept-expression
- new-expression
- delete-expression
* | & | + | - | ! | ~
::? new new-placement? ( new-type-id | ( type-id ) ) new-initializer?
( expression-list )
ATTRIB-SEQ
{ type-specifier } new-declarator?
ptr-operator* noptr-new-declarator
[ expression ] attribute-specifier* ( [ constant-expression ] attribute-specifier* )*
( expression-list? ) | braced-init-list
::? delete ( [ ] )? cast-expression
noexcept ( expression )
( ( type-id ) )* unary-expression
BINARY-SEPARATED
{ cast-expression, .* | ->* }
BINARY-SEPARATED
{ pm-expression, * | / | % }
BINARY-SEPARATED
{ multiplicative-expression, + | - }
BINARY-SEPARATED
{ additive-expression, << | >> }
BINARY-SEPARATED
{ shift-expression, < | > | <= | >= }
BINARY-SEPARATED
{ relational-expression, == | != }
BINARY-SEPARATED
{ equality-expression, & }
BINARY-SEPARATED
{ and-expression, ^ }
BINARY-SEPARATED
{ exclusive-or-expression, | }
BINARY-SEPARATED
{ inclusive-or-expression, && }
BINARY-SEPARATED
{ logical-and-expression, || }
logical-or-expression ( ? expression : assignment-expression )?
conditional-expression | logical-or-expression assignment-operator initializer-clause | throw-expression
= | *= | /= | %= | += | -= | >>= | <<= | &= | ^= | |=
COMMA-SEPARATED
{ assignment-expression }
conditional-expression
labeled-statement | declaration-statement | attribute-specifier* ( expression-statement | compound-statement | selection-statement | iteration-statement | jump-statement | try-block )
attribute-specifier* ( identifier | case constant-expression | default ) : statement
expression? ;
{ statement* }
One of:
One of:
One of:
- while ( condition ) statement
- do statement while ( expression ) ;
- for ( for-init-statement condition? ; expression? ) statement
- for ( for-range-declaration : for-range-initializer ) statement
expression-statement | simple-declaration
ATTRIB-SEQ-BOTH
{ type-specifier } declarator
expression | braced-init-list
( break | continue | return ( expression? | braced-init-list ) | goto identifier ) ;
block-declaration
block-declaration | function-definition | template-declaration | explicit-instantiation | explicit-specialization | linkage-specification | namespace-definition | empty-declaration | attribute-declaration
simple-declaration | asm-definition | namespace-alias-definition | using-declaration | static_assert-declaration | alias-declaration | opaque-enum-declaration
using identifier = type-id ;
ATTRIB-SEQ-BOTH
{ decl-specifier }? init-declarator-list? ;
static_assert ( constant-expression , string-literal ) ;
;
attribute-specifier+ ;
storage-class-specifier | type-specifier | function-specifier | friend | typedef | constexpr
register | static | thread_local | extern | mutable
inline | virtual | explicit
identifier
trailing-type-specifier | class-specifier | enum-specifier
simple-type-specifier | elaborated-type-specifier | typename-specifier | cv-qualifier
::? ( nested-name-specifier? type-name | nested-name-specifier template simple-template-id ) | char | char16_t | char32_t | wchar_t | bool | short | int | long | signed | unsigned | float | double | void | auto | decltype-specifier
class-name | enum-name | typedef-name | simple-template-id
decltype ( expression )
One of:
- class-key attribute-specifier* ::? nested-name-specifier? identifier
- class-key ::? nested-name-specifier? template? simple-template-id
- enum ::? nested-name-specifier? identifier
identifier
enum-head { COMMA-TRAILED-OPT
{ enumerator-definition } }
enum-key attribute-specifier* ( identifier? | nested-name-specifier identifier ) enum-base?
enum-key attribute-specifier* identifier enum-base? ;
enum ( class | struct )?
: ATTRIB-SEQ
{ type-specifier }
enumerator ( = constant-expression )?
identifier
original-namespace-name | namespace-alias
identifier
named-namespace-definition | unnamed-namespace-definition
original-namespace-definition | extension-namespace-definition
inline? namespace identifier { namespace-body }
inline? namespace original-namespace-name { namespace-body }
inline? namespace { namespace-body }
declaration*
identifier
namespace identifier = qualified-namespace-specifier ;
::? nested-name-specifier? namespace-name
using ( typename? ::? nested-name-specifier | :: ) unqualified-id ;
attribute-specifier* using namespace ::? nested-name-specifier? namespace-name ;
asm ( string-literal ) ;
extern string-literal ( { declaration* } | declaration )
One of:
-
[ [
COMMA-SEPARATED
{ attribute? | attribute ... }? ] ] - alignment-specifier
alignas ( (type-id | assignment-expression) ...? )
attribute-token attribute-argument-clause?
identifier | attribute-scoped-token
attribute-namespace :: identifier
identifier
( token+ )
The list of tokens should contain balanced (...), [...] and {...}.
COMMA-SEPARATED
{ init-declarator }
declarator initializer?
ptr-declarator | noptr-declarator parameters-and-qualifiers trailing-return-type
ptr-operator* noptr-declarator
( declarator-id attribute-specifier* | ( ptr-declarator ) ) ( parameters-and-qualifiers | [ constant-expression? ] attribute-specifier* )*
( parameter-declaration-clause ) attribute-specifier* cv-qualifier* ref-qualifier? exception-specification?
-> ATTRIB-SEQ
{ trailing-type-specifier } abstract-declarator?
One of:
- ref-qualifier attribute-specifier*
- ( ::? nested-name-specifier )? * attribute-specifier* cv-qualifier*
const | volatile
& | &&
...? id-expression | ::? nested-name-specifier class-name
ATTRIB-SEQ
{ type-specifier } abstract-declarator?
ptr-abstract-declarator | noptr-abstract-declarator? parameters-and-qualifiers trailing-return-type | ...
noptr-abstract-declarator | ptr-operator+ noptr-abstract-declarator?
noptr-abstract-declarator-head noptr-abstract-declarator-tail*
( ptr-abstract-declarator ) | noptr-abstract-declarator-tail
parameters-and-qualifiers | [ constant-expression ] attribute-specifier*
...? | COMMA-SEPARATED
{ parameter-declaration }
( ,? ... )?
ATTRIB-SEQ-BOTH
{ decl-specifier }
( declarator | abstract-declarator? ) ( = initializer-clause )?
ATTRIB-SEQ-BOTH
{ decl-specifier }? declarator
( function-body | = ( default | delete ) ; )
ctor-initializer? compound-statement | function-try-block
brace-or-equal-initializer | ( expression-list )
= initializer-clause | braced-init-list
assignment-expression | braced-init-list
COMMA-SEPARATED-DDD
{ initializer-clause }
{ ( initializer-list ,? )? }
identifier | simple-template-id
class-head { member-specification? }
class-key attribute-specifier* ( class-head-name class-virt-specifier* )? base-clause?
nested-name-specifier? class-name
final | explicit
class | struct | union
( member-declaration | access-specifier : )+
One of:
-
ATTRIB-SEQ-BOTH
{ decl-specifier }?COMMA-SEPARATED
{ member-declarator }? ; - function-definition ;?
- using-declaration
- static_assert-declaration
- template-declaration
- alias-declaration
One of:
- declarator virt-specifier* ( pure-specifier | brace-or-equal-initializer )?
- identifier? attribute-specifier* virt-specifier* : constant-expression
override | final | new
= 0
: base-specifier ...? ( , base-specifier ...? )*
attribute-specifier* ( virtual ^ access-specifier )* base-type-specifier
::? nested-name-specifier? class-name | decltype-specifier
class-or-decltype
private | protected | public
operator conversion-type-id
ATTRIB-SEQ
{ type-specifier } conversion-declarator?
ptr-operator+
: COMMA-SEPARATED-DDD
{ mem-initializer }
mem-initializer-id ( ( expression-list? ) | braced-init-list )
class-or-decltype | identifier
operator operator
new | delete | new [ ] | delete [ ] | + | - | * | / | % | ^ | & | | | ~ | ! | = | < | > | += | -= | *= | /= | %= | ^= | &= | |= | << | >> | >>= | <<= | == | != | <= | && | || | ++ | -- | , | ->* | -> | ( ) | [ ]
operator "" identifier
template < COMMA-SEPARATED
{ template-parameter } >
declaration
type-parameter | parameter-declaration
One of:
- ( (template <
COMMA-SEPARATED
{ template-parameter } >)? class | template ) ...? identifier? - ( class | template ) identifier? = type-id
-
template <
COMMA-SEPARATED
{ template-parameter } > class identifier? = id-expression
template-name < COMMA-SEPARATED-DDD
{ template-argument }? >
simple-template-id | ( operator-function-id | literal-operator-id )
< COMMA-SEPARATED-DDD
{ template-argument }? >
identifier
constant-expression | type-id | id-expression
typename ::? nested-name-specifier ( identifier | template? simple-template-id )
extern? template declaration
template < > declaration
try compound-statement handler+
try ctor-initializer? compound-statement handler+
catch ( exception-declaration ) compound-statement
ATTRIB-SEQ-BOTH
{ type-specifier } ( declarator |
abstract-declarator? ) | ...
throw assignment-expression?
dynamic-exception-specification | noexcept-specification
throw ( COMMA-SEPARATED-DDD
{ type-id }? )
noexcept ( ( constant-exception ) )?