D Grammar
The grammar of Cyclone is derived from ISO C99.
It has the following additional keywords:
abstract,
alias,
as,
calloc,
catch,
datatype,
dynregion_t,
export,
fallthru,
inject,
let,
malloc,
namespace,
new,
NULL,
numelts,
offsetof,
rcalloc,
region_t,
region,
regions,
reset_region,
rmalloc,
rnew,
tagcheck,
tag_t,
throw,
try,
using,
valueof,
valueof_t.
As in gcc,
__attribute__
is reserved as well.
The non-terminals
character-constant,
floating-constant,
identifier,
integer-constant,
string,
and
typedef-name
are defined lexically as in C.
A type-var is defined as
a C identifier preceded by a ` (backquote),
optionally followed by ::kind.
The start symbol is translation-unit.
Jump to: declaration ·
struct-or-union-specifier ·
datatype-specifier ·
statement ·
expression ·
declarator ·
pattern
- translation-unit:
-
(empty)
external-declaration translation-unitopt
using identifier ; translation-unit
namespace identifier ; translation-unit
using identifier { translation-unit } translation-unit
namespace identifier { translation-unit } translation-unit
extern "C" { translation-unit } translation-unit
extern "C include" { translation-unit } translation-unit
- external-declaration:
-
function-definition
declaration
- function-definition:
-
declaration-specifiersopt declarator
declaration-listopt compound-statement
- declaration:
-
declaration-specifiers init-declarator-listopt ;
let pattern = expression ;
let identifier-list ;
resetableopt region < type-var >
identifier ;
resetableopt region identifier ;
resetableopt region identifier = (
expression ) ;
alias < type-var > identifier =
expression ;
- declaration-list:
-
declaration
declaration-list declaration
- declaration-specifiers:
-
storage-class-specifier declaration-specifiersopt
type-specifier declaration-specifiersopt
type-qualifier declaration-specifiersopt
function-specifier declaration-specifiersopt
- storage-class-specifier:
-
auto
register
static
extern
extern "C"
typedef
abstract
- type-specifier:
-
_
_::kind
void
char
short
int
long
float
double
signed
unsigned
enum-specifier
struct-or-union-specifier
datatype-specifier
type-var
$( parameter-list )
region_t
region_t < any-type-name >
dynregion_t < any-type-name >
dynregion_t < any-type-name, any-type-name >
tag_t
tag_t < any-type-name >
valueof_t ( expression )
typedef-name type-paramsopt
- kind:
-
identifier
typedef-name
- type-qualifier:
-
const
restrict
volatile
@numelts ( assignment-expression )
@region ( any-type-name )
@thin
@fat
@zeroterm
@nozeroterm
@notnull
@nullable
- enum-specifier:
-
enum identifieropt { enum-declaration-list }
enum identifier
- enum-field:
-
identifier
identifier = constant-expression
- enum-declaration-list:
-
enum-field
enum-field , enum-declaration-list
- function-specifier:
-
inline
- struct-or-union-specifier:
-
struct-or-union { struct-declaration-list }
struct-or-union identifier type-paramsopt { struct-declaration-list }
struct-or-union identifier type-paramsopt
- type-params:
-
< type-name-list >
- struct-or-union:
-
struct
union
@tagged union
- struct-declaration-list:
-
struct-declaration
struct-declaration-list struct-declaration
- init-declarator-list:
-
init-declarator
init-declarator-list , init-declarator
- init-declarator:
-
declarator
declarator = initializer
- struct-declaration:
-
specifier-qualifier-list struct-declarator-list ;
- specifier-qualifier-list:
-
type-specifier specifier-qualifier-listopt
type-qualifier specifier-qualifier-listopt
- struct-declarator-list:
-
struct-declarator
struct-declarator-list , struct-declarator
- struct-declarator:
-
declarator
declaratoropt : constant-expression
- datatype-specifier:
-
@extensibleopt datatype identifier type-paramsopt { datatypefield-list }
@extensibleopt datatype identifier type-paramsopt
@extensibleopt datatype identifier . identifier type-paramsopt
- datatypefield-list:
-
datatypefield
datatypefield ;
datatypefield , datatypefield-list
datatypefield ; datatypefield-list
- datatypefield-scope: one of
-
extern
static
- datatypefield:
-
datatypefield-scopeopt identifier
datatypefield-scopeopt identifier ( parameter-list )
- declarator:
-
pointeropt direct-declarator
- direct-declarator:
-
identifier
( declarator )
direct-declarator [ assignment-expressionopt ] zeroterm-qualifieropt
direct-declarator ( parameter-type-list )
direct-declarator ( effectopt region-orderopt )
direct-declarator ( identifier-listopt )
direct-declarator < type-name-list >
- effect:
-
; effect-set
- region-order:
-
: region-order-list
- region-order-list:
-
atomic-effect > type-var
atomic-effect > type-var, region-order-list
- zeroterm-qualifier: one of
-
@zeroterm @nozeroterm
- pointer:
-
* rangeopt regionopt type-qualifier-listopt pointeropt
@ rangeopt regionopt type-qualifier-listopt pointeropt
? regionopt type-qualifier-listopt pointeropt
- range:
-
{ assignment-expression }
- region:
-
_
type-var
- type-qualifier-list:
-
type-qualifier
type-qualifier-list type-qualifier
- parameter-type-list:
-
parameter-list effectopt region-orderopt
parameter-list , ... effectopt region-orderopt
... injectopt
parameter-declaration effectopt region-orderopt
parameter-list , ... injectopt
parameter-declaration effectopt region-orderopt
- effect-set:
-
atomic-effect
atomic-effect + effect-set
- atomic-effect:
-
{ }
{ region-set }
type-var
regions ( any-type-name )
- region-set:
-
type-var
type-var , region-set
- parameter-list:
-
parameter-declaration
parameter-list , parameter-declaration
- parameter-declaration:
-
specifier-qualifier-list declarator
specifier-qualifier-list abstract-declaratoropt
- identifier-list:
-
identifier
identifier-list , identifier
- initializer:
-
assignment-expression
array-initializer
- array-initializer:
-
{ initializer-listopt }
{ initializer-list , }
{ for identifier < expression : expression }
- initializer-list:
-
designationopt initializer
initializer-list , designationopt initializer
- designation:
-
designator-list =
- designator-list:
-
designator
designator-list designator
- designator:
-
[ constant-expression ]
. identifier
- type-name:
-
specifier-qualifier-list abstract-declaratoropt
- any-type-name:
-
type-name
{ }
{ region-set }
any-type-name + atomic-effect
- type-name-list:
-
any-type-name
type-name-list , type-name
- abstract-declarator:
-
pointer
pointeropt direct-abstract-declarator
- direct-abstract-declarator:
-
( abstract-declarator )
direct-abstract-declaratoropt [ assignment-expressionopt ]zeroterm-qualifieropt
direct-abstract-declaratoropt ( parameter-type-listopt )
direct-abstract-declaratoropt ( effectopt region-orderopt )
direct-abstract-declarator < type-name-list >
- statement:
-
labeled-statement
expression-statement
compound-statement
selection-statement
iteration-statement
jump-statement
reset_region ( expression ) ;
- labeled-statement:
-
identifier : statement
- expression-statement:
-
expressionopt ;
- compound-statement:
-
{ block-item-listopt }
- block-item-list:
-
block-item
block-item block-item-list
- block-item:
-
declaration
statement
- selection-statement:
-
if ( expression ) statement
if ( expression ) statement else statement
switch ( expression ) { switch-clauses }
try statement catch { switch-clauses }
- switch-clauses:
-
(empty)
default : block-item-list
case pattern : block-item-listopt switch-clauses
case pattern && expression : block-item-listopt switch-clauses
- iteration-statement:
-
while ( expression ) statement
do statement while ( expression ) ;
for ( expressionopt ; expressionopt ; expressionopt ) statement
for ( declaration expressionopt ; expressionopt ) statement
- jump-statement:
-
goto identifier ;
continue ;
break ;
return ;
return expression ;
fallthru ;
fallthru ( argument-expression-listopt ) ;
- pattern:
-
_
( pattern )
integer-constant
- integer-constant
floating-constant
character-constant
NULL
identifier
identifier type-paramsopt ( tuple-pattern-list )
$ ( tuple-pattern-list )
identifier ( tuple-pattern-list )
identifieropt { type-paramsopt field-pattern-listopt }
& pattern
* identifier
identifier as pattern
identifier < type-var >
identifier < _ >
- tuple-pattern-list:
-
...
pattern
pattern , tuple-pattern-list
- field-pattern:
-
pattern
designation pattern
- field-pattern-list:
-
...
field-pattern
field-pattern , field-pattern-list
- expression:
-
assignment-expression
expression , assignment-expression
- assignment-expression:
-
conditional-expression
unary-expression assignment-operator assignment-expression
unary-expression :=: assignment-expression
- assignment-operator: one of
-
=
*=
/=
%=
+=
-=
<<=
>>=
&=
^=
|=
- conditional-expression:
-
logical-or-expression
logical-or-expression ? expression : conditional-expression
throw conditional-expression
new array-initializer
new logical-or-expression
rnew ( expression ) array-initializer
rnew ( expression ) logical-or-expression
- constant-expression:
-
conditional-expression
- logical-or-expression:
-
logical-and-expression
logical-or-expression || logical-and-expression
- logical-and-expression:
-
inclusive-or-expression
logical-and-expression && inclusive-or-expression
- inclusive-or-expression:
-
exclusive-or-expression
inclusive-or-expression | exclusive-or-expression
- exclusive-or-expression:
-
and-expression
exclusive-or-expression
^
and-expression
- and-expression:
-
equality-expression
and-expression & equality-expression
- equality-expression:
-
relational-expression
equality-expression == relational-expression
equality-expression != relational-expression
- relational-expression:
-
shift-expression
relational-expression < shift-expression
relational-expression > shift-expression
relational-expression <= shift-expression
relational-expression >= shift-expression
- shift-expression:
-
additive-expression
shift-expression << additive-expression
shift-expression >> additive-expression
- additive-expression:
-
multiplicative-expression
additive-expression + multiplicative-expression
additive-expression - multiplicative-expression
- multiplicative-expression:
-
cast-expression
multiplicative-expression * cast-expression
multiplicative-expression / cast-expression
multiplicative-expression % cast-expression
- cast-expression:
-
unary-expression
( type-name ) cast-expression
- unary-expression:
-
postfix-expression
++ unary-expression
-- unary-expression
unary-operator cast-expression
sizeof unary-expression
sizeof ( type-name )
offsetof ( type-name , identifier )
offsetof ( type-name , integer-constant )
malloc ( assignment-expression )
rmalloc ( assignment-expression , assignment-expression )
calloc ( assignment-expression , sizeof ( type-name ) )
rcalloc ( assignment-expression , assignment-expression , sizeof ( type-name ) )
numelts ( assignment-expression )
tagcheck ( postfix-expression . identifier )
tagcheck ( postfix-expression -> identifier )
valueof ( type-name )
- unary-operator: one of
-
&
*
+
-
~
!
- postfix-expression:
-
primary-expression
postfix-expression [ expression ]
postfix-expression ( argument-expression-listopt )
postfix-expression . identifier
postfix-expression -> identifier
postfix-expression ++
postfix-expression --
( type-name ) { initializer-list }
( type-name ) { initializer-list , }
- primary-expression:
-
identifier
constant
string
( expression )
primary-expression <>
primary-expression @ < type-name-list >
$( argument-expression-list )
identifier { type-paramsopt initializer-list }
( { block-item-list } )
- argument-expression-list:
-
assignment-expression
argument-expression-list , assignment-expression
- constant:
-
integer-constant
character-constant
floating-constant
NULL