Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

D Grammar

Lexical Syntax

Refer to the page for lexical syntax.

Modules

Module:
    ModuleDeclaration DeclDefs
    DeclDefs
DeclDefs: DeclDef DeclDef DeclDefs
DeclDef: AttributeSpecifier Declaration Constructor Destructor Postblit Allocator Deallocator ClassInvariant StructInvariant UnitTest AliasThis StaticConstructor StaticDestructor SharedStaticConstructor SharedStaticDestructor ConditionalDeclaration DebugSpecification VersionSpecification StaticAssert TemplateDeclaration TemplateMixinDeclaration TemplateMixin MixinDeclaration ;
ModuleDeclaration:
    ModuleAttributesopt module ModuleFullyQualifiedName ;
ModuleAttributes: ModuleAttribute ModuleAttribute ModuleAttributes
ModuleAttribute: DeprecatedAttribute UserDefinedAttribute
ModuleFullyQualifiedName: ModuleName Packages . ModuleName
ModuleName: Identifier
Packages: PackageName Packages . PackageName
PackageName: Identifier
ImportDeclaration:
    import ImportList ;
    static import ImportList ;
ImportList: Import ImportBindings Import , ImportList
Import: ModuleFullyQualifiedName ModuleAliasIdentifier = ModuleFullyQualifiedName
ImportBindings: Import : ImportBindList
ImportBindList: ImportBind ImportBind , ImportBindList
ImportBind: Identifier Identifier = Identifier
ModuleAliasIdentifier: Identifier
MixinDeclaration:
    mixin ( AssignExpression ) ;

Declarations

Declaration:
    FuncDeclaration
    VarDeclarations
    AliasDeclaration
    AggregateDeclaration
    EnumDeclaration
    ImportDeclaration
    ConditionalDeclaration
    StaticForeachDeclaration
    StaticAssert
VarDeclarations:
    StorageClassesopt BasicType Declarators ;
    AutoDeclaration
Declarators: DeclaratorInitializer DeclaratorInitializer , DeclaratorIdentifierList
DeclaratorInitializer: VarDeclarator VarDeclarator TemplateParametersopt = Initializer AltDeclarator AltDeclarator = Initializer
DeclaratorIdentifierList: DeclaratorIdentifier DeclaratorIdentifier , DeclaratorIdentifierList
DeclaratorIdentifier: VarDeclaratorIdentifier AltDeclaratorIdentifier
VarDeclaratorIdentifier: Identifier Identifier TemplateParametersopt = Initializer
AltDeclaratorIdentifier: BasicType2 Identifier AltDeclaratorSuffixesopt BasicType2 Identifier AltDeclaratorSuffixesopt = Initializer BasicType2opt Identifier AltDeclaratorSuffixes BasicType2opt Identifier AltDeclaratorSuffixes = Initializer
Declarator: VarDeclarator AltDeclarator
VarDeclarator: BasicType2opt Identifier
AltDeclarator: BasicType2opt Identifier AltDeclaratorSuffixes BasicType2opt ( AltDeclaratorX ) BasicType2opt ( AltDeclaratorX ) AltFuncDeclaratorSuffix BasicType2opt ( AltDeclaratorX ) AltDeclaratorSuffixes
AltDeclaratorX: BasicType2opt Identifier BasicType2opt Identifier AltFuncDeclaratorSuffix AltDeclarator
AltDeclaratorSuffixes: AltDeclaratorSuffix AltDeclaratorSuffix AltDeclaratorSuffixes
AltDeclaratorSuffix: [ ] [ AssignExpression ] [ Type ]
AltFuncDeclaratorSuffix: Parameters MemberFunctionAttributesopt
Type:
    TypeCtorsopt BasicType BasicType2opt
TypeCtors: TypeCtor TypeCtor TypeCtors
TypeCtor: const immutable inout shared
BasicType: BasicTypeX . IdentifierList IdentifierList Typeof Typeof . IdentifierList TypeCtor ( Type ) TypeVector
BasicTypeX: bool byte ubyte short ushort int uint long ulong cent ucent char wchar dchar float double real ifloat idouble ireal cfloat cdouble creal void
BasicType2: BasicType2X BasicType2opt
BasicType2X: * [ ] [ AssignExpression ] [ AssignExpression .. AssignExpression ] [ Type ] delegate Parameters MemberFunctionAttributesopt function Parameters FunctionAttributesopt
IdentifierList: Identifier Identifier . IdentifierList TemplateInstance TemplateInstance . IdentifierList Identifier [ AssignExpression ]. IdentifierList
StorageClasses:
    StorageClass
    StorageClass StorageClasses
StorageClass: LinkageAttribute AlignAttribute deprecated enum static extern abstract final override synchronized auto scope const immutable inout shared __gshared Property nothrow pure ref
Initializer:
    VoidInitializer
    NonVoidInitializer
NonVoidInitializer: ExpInitializer ArrayInitializer StructInitializer
ExpInitializer: AssignExpression
ArrayInitializer: [ ArrayMemberInitializationsopt ]
ArrayMemberInitializations: ArrayMemberInitialization ArrayMemberInitialization , ArrayMemberInitialization , ArrayMemberInitializations
ArrayMemberInitialization: NonVoidInitializer AssignExpression : NonVoidInitializer
StructInitializer: { StructMemberInitializersopt }
StructMemberInitializers: StructMemberInitializer StructMemberInitializer , StructMemberInitializer , StructMemberInitializers
StructMemberInitializer: NonVoidInitializer Identifier : NonVoidInitializer
AutoDeclaration:
    StorageClasses AutoDeclarationX ;
AutoDeclarationX: AutoDeclarationY AutoDeclarationX , AutoDeclarationY
AutoDeclarationY: Identifier TemplateParametersopt = Initializer
AliasDeclaration:
    alias StorageClassesopt BasicType Declarators ;
    alias StorageClassesopt BasicType FuncDeclarator ;
    alias AliasDeclarationX ;
AliasDeclarationX: AliasDeclarationY AliasDeclarationX , AliasDeclarationY
AliasDeclarationY: Identifier TemplateParametersopt = StorageClassesopt Type Identifier TemplateParametersopt = FunctionLiteral
Typeof:
    typeof ( Expression )
    typeof ( return )
VoidInitializer:
    void

Attributes

AttributeSpecifier:
    Attribute :
    Attribute DeclarationBlock
Attribute: LinkageAttribute AlignAttribute DeprecatedAttribute VisibilityAttribute Pragma static extern abstract final override synchronized auto scope const immutable inout shared __gshared AtAttribute nothrow pure ref return
AtAttribute: @ disable @ nogc Property @ safe @ system @ trusted UserDefinedAttribute
Property: @ property
DeclarationBlock: DeclDef { DeclDefsopt }
LinkageAttribute:
    extern ( LinkageType )
    extern ( C++, IdentifierList )
LinkageType: C C++ D Windows Pascal System Objective-C
AlignAttribute:
    align
    align ( AssignExpression )
DeprecatedAttribute:
    deprecated
    deprecated ( AssignExpression )
VisibilityAttribute:
    private
    package
    package ( IdentifierList )
    protected
    public
    export
UserDefinedAttribute:
    @ ( ArgumentList )
    @ Identifier
    @ Identifier ( ArgumentListopt )
    @ TemplateInstance
    @ TemplateInstance ( ArgumentListopt )

Pragmas

Pragma:
    pragma ( Identifier )
    pragma ( Identifier , ArgumentList )

Expressions

Expression:
    CommaExpression
CommaExpression: AssignExpression AssignExpression , CommaExpression
AssignExpression:
    ConditionalExpression
    ConditionalExpression = AssignExpression
    ConditionalExpression += AssignExpression
    ConditionalExpression -= AssignExpression
    ConditionalExpression *= AssignExpression
    ConditionalExpression /= AssignExpression
    ConditionalExpression %= AssignExpression
    ConditionalExpression &= AssignExpression
    ConditionalExpression |= AssignExpression
    ConditionalExpression ^= AssignExpression
    ConditionalExpression ~= AssignExpression
    ConditionalExpression <<= AssignExpression
    ConditionalExpression >>= AssignExpression
    ConditionalExpression >>>= AssignExpression
    ConditionalExpression ^^= AssignExpression
ConditionalExpression:
    OrOrExpression
    OrOrExpression ? Expression : ConditionalExpression
OrOrExpression:
    AndAndExpression
    OrOrExpression || AndAndExpression
AndAndExpression:
    OrExpression
    AndAndExpression && OrExpression
OrExpression:
    XorExpression
    OrExpression | XorExpression
XorExpression:
    AndExpression
    XorExpression ^ AndExpression
AndExpression:
    CmpExpression
    AndExpression & CmpExpression
CmpExpression:
    ShiftExpression
    EqualExpression
    IdentityExpression
    RelExpression
    InExpression
EqualExpression:
    ShiftExpression == ShiftExpression
    ShiftExpression != ShiftExpression
IdentityExpression:
    ShiftExpression is ShiftExpression
    ShiftExpression !is ShiftExpression
RelExpression:
    ShiftExpression < ShiftExpression
    ShiftExpression <= ShiftExpression
    ShiftExpression > ShiftExpression
    ShiftExpression >= ShiftExpression
InExpression:
    ShiftExpression in ShiftExpression
    ShiftExpression !in ShiftExpression
ShiftExpression:
    AddExpression
    ShiftExpression << AddExpression
    ShiftExpression >> AddExpression
    ShiftExpression >>> AddExpression
AddExpression:
    MulExpression
    AddExpression + MulExpression
    AddExpression - MulExpression
    CatExpression
CatExpression:
    AddExpression ~ MulExpression
MulExpression:
    UnaryExpression
    MulExpression * UnaryExpression
    MulExpression / UnaryExpression
    MulExpression % UnaryExpression
UnaryExpression:
    & UnaryExpression
    ++ UnaryExpression
    -- UnaryExpression
    * UnaryExpression
    - UnaryExpression
    + UnaryExpression
    ! UnaryExpression
    ComplementExpression
    ( Type ) . Identifier
    ( Type ) . TemplateInstance
    DeleteExpression
    CastExpression
    PowExpression
ComplementExpression:
    ~ UnaryExpression
NewExpression:
    new AllocatorArgumentsopt Type
    NewExpressionWithArgs
NewExpressionWithArgs: new AllocatorArgumentsopt Type [ AssignExpression ] new AllocatorArgumentsopt Type ( ArgumentListopt ) NewAnonClassExpression
AllocatorArguments: ( ArgumentListopt )
ArgumentList: AssignExpression AssignExpression , AssignExpression , ArgumentList
DeleteExpression:
    delete UnaryExpression
CastExpression:
    cast ( Type ) UnaryExpression
    cast ( TypeCtorsopt ) UnaryExpression
PowExpression:
    PostfixExpression
    PostfixExpression ^^ UnaryExpression
PostfixExpression:
    PrimaryExpression
    PostfixExpression . Identifier
    PostfixExpression . TemplateInstance
    PostfixExpression . NewExpression
    PostfixExpression ++
    PostfixExpression --
    PostfixExpression ( ArgumentListopt )
    TypeCtorsopt BasicType ( ArgumentListopt )
    IndexExpression
    SliceExpression
IndexExpression:
    PostfixExpression [ ArgumentList ]
SliceExpression:
    PostfixExpression [ ]
    PostfixExpression [ Slice ,opt ]
Slice:
    AssignExpression
    AssignExpression , Slice
    AssignExpression .. AssignExpression
    AssignExpression .. AssignExpression , Slice
PrimaryExpression:
    Identifier
    . Identifier
    TemplateInstance
    . TemplateInstance
    this
    super
    null
    true
    false
    $
    IntegerLiteral
    FloatLiteral
    CharacterLiteral
    StringLiterals
    ArrayLiteral
    AssocArrayLiteral
    FunctionLiteral
    AssertExpression
    MixinExpression
    ImportExpression
    NewExpressionWithArgs
    BasicTypeX . Identifier
    BasicTypeX ( ArgumentListopt )
    TypeCtor ( Type ) . Identifier
    TypeCtor ( Type ) ( ArgumentListopt )
    Typeof
    TypeidExpression
    IsExpression
    ( Expression )
    SpecialKeyword
    TraitsExpression
StringLiterals:
    StringLiteral
    StringLiterals StringLiteral
ArrayLiteral:
    [ ArgumentListopt ]
AssocArrayLiteral:
    [ KeyValuePairs ]
KeyValuePairs: KeyValuePair KeyValuePair , KeyValuePairs
KeyValuePair: KeyExpression : ValueExpression
KeyExpression: AssignExpression
ValueExpression: AssignExpression
FunctionLiteral:
    function Typeopt ParameterWithAttributes opt FunctionLiteralBody
    delegate Typeopt ParameterWithMemberAttributes opt FunctionLiteralBody
    ParameterMemberAttributes FunctionLiteralBody
    FunctionLiteralBody
    Lambda
ParameterWithAttributes: Parameters FunctionAttributesopt
ParameterWithMemberAttributes: Parameters MemberFunctionAttributesopt
FunctionLiteralBody: BlockStatement FunctionContractsopt BodyStatement
Lambda:
    function Typeopt ParameterAttributes => AssignExpression
    delegate Typeopt ParameterMemberAttributes => AssignExpression
    ParameterMemberAttributes => AssignExpression
    Identifier => AssignExpression
AssertExpression:
    assert ( ContractArguments )
ContractArguments: AssignExpression ,opt AssignExpression , AssignExpression ,opt
MixinExpression:
    mixin ( AssignExpression )
ImportExpression:
    import ( AssignExpression )
TypeidExpression:
    typeid ( Type )
    typeid ( Expression )
IsExpression:
    is ( Type )
    is ( Type : TypeSpecialization )
    is ( Type == TypeSpecialization )
    is ( Type : TypeSpecialization , TemplateParameterList )
    is ( Type == TypeSpecialization , TemplateParameterList )
    is ( Type Identifier )
    is ( Type Identifier : TypeSpecialization )
    is ( Type Identifier == TypeSpecialization )
    is ( Type Identifier : TypeSpecialization , TemplateParameterList )
    is ( Type Identifier == TypeSpecialization , TemplateParameterList )
TypeSpecialization: Type struct union class interface enum function delegate super const immutable inout shared return __parameters
SpecialKeyword:
    __FILE__
    __FILE_FULL_PATH__
    __MODULE__
    __LINE__
    __FUNCTION__
    __PRETTY_FUNCTION__

Statements

Statement:
    ;
    NonEmptyStatement
    ScopeBlockStatement
NoScopeNonEmptyStatement: NonEmptyStatement BlockStatement
NoScopeStatement: ; NonEmptyStatement BlockStatement
NonEmptyOrScopeBlockStatement: NonEmptyStatement ScopeBlockStatement
NonEmptyStatement: NonEmptyStatementNoCaseNoDefault CaseStatement CaseRangeStatement DefaultStatement
NonEmptyStatementNoCaseNoDefault: LabeledStatement ExpressionStatement DeclarationStatement IfStatement WhileStatement DoStatement ForStatement ForeachStatement SwitchStatement FinalSwitchStatement ContinueStatement BreakStatement ReturnStatement GotoStatement WithStatement SynchronizedStatement TryStatement ScopeGuardStatement ThrowStatement AsmStatement PragmaStatement MixinStatement ForeachRangeStatement ConditionalStatement StaticForeachStatement StaticAssert TemplateMixin ImportDeclaration
ScopeStatement:
    NonEmptyStatement
    BlockStatement
ScopeBlockStatement:
    BlockStatement
LabeledStatement:
    Identifier :
    Identifier : NoScopeStatement
    Identifier : Statement
BlockStatement:
    { }
    { StatementList }
StatementList: Statement Statement StatementList
ExpressionStatement:
    Expression ;
DeclarationStatement:
    StorageClassesopt Declaration
IfStatement:
    if ( IfCondition ) ThenStatement
    if ( IfCondition ) ThenStatement else ElseStatement
IfCondition: Expression auto Identifier = Expression TypeCtors Identifier = Expression TypeCtorsopt BasicType Declarator = Expression
ThenStatement: ScopeStatement
ElseStatement: ScopeStatement
WhileStatement:
    while ( Expression ) ScopeStatement
DoStatement:
    do ScopeStatement  while ( Expression ) ;
ForStatement:
    for ( Initialize Testopt ; Incrementopt ) ScopeStatement
Initialize: ; NoScopeNonEmptyStatement
Test: Expression
Increment: Expression
AggregateForeach:
    Foreach ( ForeachTypeList ; ForeachAggregate )
ForeachStatement: AggregateForeach NoScopeNonEmptyStatement
Foreach: foreach foreach_reverse
ForeachTypeList: ForeachType ForeachType , ForeachTypeList
ForeachType: ForeachTypeAttributesopt BasicType Declarator ForeachTypeAttributesopt Identifier ForeachTypeAttributesopt alias Identifier
ForeachTypeAttributes ForeachTypeAttribute ForeachTypeAttribute ForeachTypeAttributesopt
ForeachTypeAttribute: ref TypeCtor enum
ForeachAggregate: Expression
RangeForeach:
    Foreach ( ForeachType ; LwrExpression .. UprExpression )
LwrExpression: Expression
UprExpression: Expression
ForeachRangeStatement: RangeForeach ScopeStatement
SwitchStatement:
    switch ( Expression ) ScopeStatement
CaseStatement: case ArgumentList : ScopeStatementList
CaseRangeStatement: case FirstExp : .. case LastExp : ScopeStatementList
FirstExp: AssignExpression
LastExp: AssignExpression
DefaultStatement: default : ScopeStatementList
ScopeStatementList: StatementListNoCaseNoDefault
StatementListNoCaseNoDefault: StatementNoCaseNoDefault StatementNoCaseNoDefault StatementListNoCaseNoDefault
StatementNoCaseNoDefault: ; NonEmptyStatementNoCaseNoDefault ScopeBlockStatement
FinalSwitchStatement:
    final switch ( Expression ) ScopeStatement
ContinueStatement:
    continue Identifieropt ;
BreakStatement:
    break Identifieropt ;
ReturnStatement:
    return Expressionopt ;
GotoStatement:
    goto Identifier ;
    goto default ;
    goto case ;
    goto case Expression ;
WithStatement:
    with ( Expression ) ScopeStatement
    with ( Symbol ) ScopeStatement
    with ( TemplateInstance ) ScopeStatement
SynchronizedStatement:
    synchronized ScopeStatement
    synchronized ( Expression ) ScopeStatement
TryStatement:
    try ScopeStatement Catches
    try ScopeStatement Catches FinallyStatement
    try ScopeStatement FinallyStatement
Catches: Catch Catch Catches
Catch: catch ( CatchParameter ) NoScopeNonEmptyStatement
CatchParameter: BasicType Identifier
FinallyStatement: finally NoScopeNonEmptyStatement
ThrowStatement:
    throw Expression ;
ScopeGuardStatement:
    scope(exit) NonEmptyOrScopeBlockStatement
    scope(success) NonEmptyOrScopeBlockStatement
    scope(failure) NonEmptyOrScopeBlockStatement
AsmStatement:
    asm FunctionAttributesopt { AsmInstructionListopt }
AsmInstructionList: AsmInstruction ; AsmInstruction ; AsmInstructionList
PragmaStatement:
    Pragma NoScopeStatement
MixinStatement:
    mixin ( AssignExpression ) ;

Structs and Unions

AggregateDeclaration:
    ClassDeclaration
    InterfaceDeclaration
    StructDeclaration
    UnionDeclaration
StructDeclaration: struct Identifier ; struct Identifier AggregateBody StructTemplateDeclaration AnonStructDeclaration
AnonStructDeclaration: struct AggregateBody
UnionDeclaration: union Identifier ; union Identifier AggregateBody UnionTemplateDeclaration AnonUnionDeclaration
AnonUnionDeclaration: union AggregateBody
AggregateBody: { DeclDefsopt }
Postblit:
    this ( this ) MemberFunctionAttributesopt ;
    this ( this ) MemberFunctionAttributesopt FunctionBody
StructInvariant:
    invariant ( ) BlockStatement
    invariant BlockStatement
    invariant ( ContractArguments ) ;

Classes

ClassDeclaration:
    class Identifier ;
    class Identifier BaseClassListopt AggregateBody
    ClassTemplateDeclaration
BaseClassList: : SuperClass : SuperClass , Interfaces : Interfaces
SuperClass: BasicType
Interfaces: Interface Interface , Interfaces
Interface: BasicType
Constructor:
    this Parameters MemberFunctionAttributesopt ;
    this Parameters MemberFunctionAttributesopt FunctionBody
    ConstructorTemplate
Destructor:
    ~ this ( ) MemberFunctionAttributesopt ;
    ~ this ( ) MemberFunctionAttributesopt FunctionBody
StaticConstructor:
    static this ( ) MemberFunctionAttributesopt ;
    static this ( ) MemberFunctionAttributesopt FunctionBody
StaticDestructor:
    static ~ this ( ) MemberFunctionAttributesopt ;
    static ~ this ( ) MemberFunctionAttributesopt FunctionBody
SharedStaticConstructor:
    shared static this ( ) MemberFunctionAttributesopt ;
    shared static this ( ) MemberFunctionAttributesopt FunctionBody
SharedStaticDestructor:
    shared static ~ this ( ) MemberFunctionAttributesopt ;
    shared static ~ this ( ) MemberFunctionAttributesopt FunctionBody
ClassInvariant:
    invariant ( ) BlockStatement
    invariant BlockStatement
    invariant ( ContractArguments ) ;
Allocator:
    new Parameters ;
    new Parameters FunctionBody
Deallocator:
    delete Parameters ;
    delete Parameters FunctionBody
AliasThis:
    alias Identifier this ;
NewAnonClassExpression:
    new AllocatorArgumentsopt class ClassArgumentsopt SuperClassopt Interfacesopt AggregateBody
ClassArguments: ( ArgumentListopt )
class Identifier : SuperClass Interfaces AggregateBody
new (ArgumentList) Identifier (ArgumentList);

Interfaces

InterfaceDeclaration:
    interface Identifier ;
    interface Identifier BaseInterfaceListopt AggregateBody
    InterfaceTemplateDeclaration
BaseInterfaceList: : Interfaces

Enums

EnumDeclaration:
    enum Identifier EnumBody
    enum Identifier : EnumBaseType EnumBody
    AnonymousEnumDeclaration
EnumBaseType: Type
EnumBody: { EnumMembers } ;
EnumMembers: EnumMember EnumMember , EnumMember , EnumMembers
EnumMemberAttributes: EnumMemberAttribute EnumMemberAttribute EnumMemberAttributes
EnumMemberAttribute: DeprecatedAttribute UserDefinedAttribute @disable
EnumMember: EnumMemberAttributesopt Identifier EnumMemberAttributesopt Identifier = AssignExpression
AnonymousEnumDeclaration: enum : EnumBaseType { EnumMembers } enum { EnumMembers } enum { AnonymousEnumMembers }
AnonymousEnumMembers: AnonymousEnumMember AnonymousEnumMember , AnonymousEnumMember , AnonymousEnumMembers
AnonymousEnumMember: EnumMember Type Identifier = AssignExpression

Functions

FuncDeclaration:
    StorageClassesopt BasicType FuncDeclarator FunctionBody
    AutoFuncDeclaration
AutoFuncDeclaration: StorageClasses Identifier FuncDeclaratorSuffix FunctionBody
FuncDeclarator: BasicType2opt Identifier FuncDeclaratorSuffix
FuncDeclaratorSuffix: Parameters MemberFunctionAttributesopt TemplateParameters Parameters MemberFunctionAttributesopt Constraintopt
Parameters:
    ( ParameterListopt )
ParameterList: Parameter Parameter , ParameterList ...
Parameter: ParameterAttributesopt BasicType Declarator ParameterAttributesopt BasicType Declarator ... ParameterAttributesopt BasicType Declarator = AssignExpression ParameterAttributesopt Type ParameterAttributesopt Type ...
ParameterAttributes: InOut UserDefinedAttribute ParameterAttributes InOut ParameterAttributes UserDefinedAttribute ParameterAttributes
InOut: auto TypeCtor final in lazy out ref return ref scope
FunctionAttributes:
    FunctionAttribute
    FunctionAttribute FunctionAttributes
FunctionAttribute: nothrow pure Property
MemberFunctionAttributes: MemberFunctionAttribute MemberFunctionAttribute MemberFunctionAttributes
MemberFunctionAttribute: const immutable inout return shared FunctionAttribute
FunctionBody:
    SpecifiedFunctionBody
    MissingFunctionBody
FunctionLiteralBody: SpecifiedFunctionBody
SpecifiedFunctionBody: doopt BlockStatement FunctionContractsopt InOutContractExpression doopt BlockStatement FunctionContractsopt InOutStatement doopt BlockStatement
MissingFunctionBody: ; FunctionContractsopt InOutContractExpression ; FunctionContractsopt InOutStatement
FunctionContracts:
    FunctionContract
    FunctionContract FunctionContracts
FunctionContract: InOutContractExpression InOutStatement
InOutContractExpression: InContractExpression OutContractExpression
InOutStatement: InStatement OutStatement
InContractExpression: in ( ContractArguments )
OutContractExpression: out ( ; ContractArguments ) out ( Identifier ; ContractArguments )
InStatement: in BlockStatement
OutStatement: out BlockStatement out ( Identifier ) BlockStatement

Templates

TemplateDeclaration:
    template Identifier TemplateParameters Constraintopt { DeclDefsopt }
TemplateParameters: ( TemplateParameterListopt )
TemplateParameterList: TemplateParameter TemplateParameter , TemplateParameter , TemplateParameterList
TemplateParameter: TemplateTypeParameter TemplateValueParameter TemplateAliasParameter TemplateSequenceParameter TemplateThisParameter
TemplateInstance:
    Identifier TemplateArguments
TemplateArguments: ! ( TemplateArgumentListopt ) ! TemplateSingleArgument
TemplateArgumentList: TemplateArgument TemplateArgument , TemplateArgument , TemplateArgumentList
TemplateArgument: Type AssignExpression Symbol
Symbol: SymbolTail . SymbolTail
SymbolTail: Identifier Identifier . SymbolTail TemplateInstance TemplateInstance . SymbolTail
TemplateSingleArgument: Identifier BasicTypeX CharacterLiteral StringLiteral IntegerLiteral FloatLiteral true false null this SpecialKeyword
TemplateTypeParameter:
    Identifier
    Identifier TemplateTypeParameterSpecialization
    Identifier TemplateTypeParameterDefault
    Identifier TemplateTypeParameterSpecialization TemplateTypeParameterDefault
TemplateTypeParameterSpecialization: : Type
TemplateTypeParameterDefault: = Type
TemplateThisParameter:
    this TemplateTypeParameter
TemplateValueParameter:
    BasicType Declarator
    BasicType Declarator TemplateValueParameterSpecialization
    BasicType Declarator TemplateValueParameterDefault
    BasicType Declarator TemplateValueParameterSpecialization TemplateValueParameterDefault
TemplateValueParameterSpecialization: : ConditionalExpression
TemplateValueParameterDefault: = AssignExpression = SpecialKeyword
TemplateAliasParameter:
    alias Identifier TemplateAliasParameterSpecializationopt TemplateAliasParameterDefaultopt
    alias BasicType Declarator TemplateAliasParameterSpecializationopt TemplateAliasParameterDefaultopt
TemplateAliasParameterSpecialization: : Type : ConditionalExpression
TemplateAliasParameterDefault: = Type = ConditionalExpression
TemplateSequenceParameter:
    Identifier ...
ConstructorTemplate:
    this TemplateParameters Parameters MemberFunctionAttributesopt Constraintopt :
    this TemplateParameters Parameters MemberFunctionAttributesopt Constraintopt FunctionBody
ClassTemplateDeclaration:
    class Identifier TemplateParameters Constraintopt BaseClassListopt AggregateBody
    class Identifier TemplateParameters BaseClassListopt Constraintopt AggregateBody
InterfaceTemplateDeclaration: interface Identifier TemplateParameters Constraintopt BaseInterfaceListopt AggregateBody interface Identifier TemplateParameters BaseInterfaceList Constraint AggregateBody
StructTemplateDeclaration: struct Identifier TemplateParameters Constraintopt AggregateBody
UnionTemplateDeclaration: union Identifier TemplateParameters Constraintopt AggregateBody
Constraint:
    if ( Expression )

Template Mixins

TemplateMixinDeclaration:
    mixin template Identifier TemplateParameters Constraintopt { DeclDefsopt }
TemplateMixin: mixin MixinTemplateName TemplateArgumentsopt Identifieropt ;
MixinTemplateName: . QualifiedIdentifierList QualifiedIdentifierList Typeof . QualifiedIdentifierList
QualifiedIdentifierList: Identifier Identifier . QualifiedIdentifierList TemplateInstance . QualifiedIdentifierList

Conditional Compilation

ConditionalDeclaration:
    Condition DeclarationBlock
    Condition DeclarationBlock else DeclarationBlock
    Condition : DeclDefsopt
    Condition DeclarationBlock else : DeclDefsopt
ConditionalStatement: Condition NoScopeNonEmptyStatement Condition NoScopeNonEmptyStatement else NoScopeNonEmptyStatement
Condition:
    VersionCondition
    DebugCondition
    StaticIfCondition
VersionCondition:
    version ( IntegerLiteral )
    version ( Identifier )
    version ( unittest )
    version ( assert )
VersionSpecification:
    version = Identifier ;
    version = IntegerLiteral ;
DebugCondition:
    debug
    debug ( IntegerLiteral )
    debug ( Identifier )
DebugSpecification:
    debug = Identifier ;
    debug = IntegerLiteral ;
StaticIfCondition:
    static if ( AssignExpression )
StaticForeach:
    static AggregateForeach
    static RangeForeach
StaticForeachDeclaration: StaticForeach DeclarationBlock StaticForeach : DeclDefsopt
StaticForeachStatement: StaticForeach NoScopeNonEmptyStatement
StaticAssert:
    static assert ( AssignExpression ,opt );
    static assert ( AssignExpression , AssignExpression ,opt );

Traits

TraitsExpression:
    __traits ( TraitsKeyword , TraitsArguments )
TraitsKeyword: isAbstractClass isArithmetic isAssociativeArray isFinalClass isPOD isNested isFuture isDeprecated isFloating isIntegral isScalar isStaticArray isUnsigned isDisabled isVirtualFunction isVirtualMethod isAbstractFunction isFinalFunction isStaticFunction isOverrideFunction isTemplate isRef isOut isLazy isReturnOnStack hasMember identifier getAliasThis getAttributes getFunctionAttributes getFunctionVariadicStyle getLinkage getMember getOverloads getParameterStorageClasses getPointerBitmap getProtection getVirtualFunctions getVirtualMethods getUnitTests parent classInstanceSize getVirtualIndex allMembers derivedMembers isSame compiles
TraitsArguments: TraitsArgument TraitsArgument , TraitsArguments
TraitsArgument: AssignExpression Type

Unit Tests

UnitTest:
    unittest BlockStatement

D x86 Inline Assembler

AsmStatement:
    asm FunctionAttributesopt { AsmInstructionListopt }
AsmInstructionList: AsmInstruction ; AsmInstruction ; AsmInstructionList
AsmInstruction:
    Identifier : AsmInstruction
    align IntegerExpression
    even
    naked
    db Operands
    ds Operands
    di Operands
    dl Operands
    df Operands
    dd Operands
    de Operands
    db StringLiteral
    ds StringLiteral
    di StringLiteral
    dl StringLiteral
    dw StringLiteral
    dq StringLiteral
    Opcode
    Opcode Operands
Operands: Operand Operand , Operands
IntegerExpression:
    IntegerLiteral
    Identifier
Register:
    AL AH AX EAX
    BL BH BX EBX
    CL CH CX ECX
    DL DH DX EDX
    BP EBP
    SP ESP
    DI EDI
    SI ESI
    ES CS SS DS GS FS
    CR0 CR2 CR3 CR4
    DR0 DR1 DR2 DR3 DR6 DR7
    TR3 TR4 TR5 TR6 TR7
    ST
    ST(0) ST(1) ST(2) ST(3) ST(4) ST(5) ST(6) ST(7)
    MM0  MM1  MM2  MM3  MM4  MM5  MM6  MM7
    XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7
Register64:
    RAX  RBX  RCX  RDX
    BPL  RBP
    SPL  RSP
    DIL  RDI
    SIL  RSI
    R8B  R8W  R8D  R8
    R9B  R9W  R9D  R9
    R10B R10W R10D R10
    R11B R11W R11D R11
    R12B R12W R12D R12
    R13B R13W R13D R13
    R14B R14W R14D R14
    R15B R15W R15D R15
    XMM8 XMM9 XMM10 XMM11 XMM12 XMM13 XMM14 XMM15
    YMM0 YMM1 YMM2  YMM3  YMM4  YMM5  YMM6  YMM7
    YMM8 YMM9 YMM10 YMM11 YMM12 YMM13 YMM14 YMM15
Operand:
    AsmExp
AsmExp: AsmLogOrExp AsmLogOrExp ? AsmExp : AsmExp
AsmLogOrExp: AsmLogAndExp AsmLogOrExp || AsmLogAndExp
AsmLogAndExp: AsmOrExp AsmLogAndExp && AsmOrExp
AsmOrExp: AsmXorExp AsmOrExp | AsmXorExp
AsmXorExp: AsmAndExp AsmXorExp ^ AsmAndExp
AsmAndExp: AsmEqualExp AsmAndExp & AsmEqualExp
AsmEqualExp: AsmRelExp AsmEqualExp == AsmRelExp AsmEqualExp != AsmRelExp
AsmRelExp: AsmShiftExp AsmRelExp < AsmShiftExp AsmRelExp <= AsmShiftExp AsmRelExp > AsmShiftExp AsmRelExp >= AsmShiftExp
AsmShiftExp: AsmAddExp AsmShiftExp << AsmAddExp AsmShiftExp >> AsmAddExp AsmShiftExp >>> AsmAddExp
AsmAddExp: AsmMulExp AsmAddExp + AsmMulExp AsmAddExp - AsmMulExp
AsmMulExp: AsmBrExp AsmMulExp * AsmBrExp AsmMulExp / AsmBrExp AsmMulExp % AsmBrExp
AsmBrExp: AsmUnaExp AsmBrExp [ AsmExp ]
AsmUnaExp: AsmTypePrefix AsmExp offsetof AsmExp seg AsmExp + AsmUnaExp - AsmUnaExp ! AsmUnaExp ~ AsmUnaExp AsmPrimaryExp
AsmPrimaryExp: IntegerLiteral FloatLiteral __LOCAL_SIZE $ Register Register : AsmExp Register64 Register64 : AsmExp DotIdentifier this
DotIdentifier: Identifier Identifier . DotIdentifier
AsmTypePrefix:
    near ptr
    far ptr
    byte ptr
    short ptr
    int ptr
    word ptr
    dword ptr
    qword ptr
    float ptr
    double ptr
    real ptr

Named Character Entities

NamedCharacterEntity:
    & Identifier ;

Application Binary Interface

MangledName:
    _D QualifiedName Type
    _D QualifiedName Z        // Internal
QualifiedName:
    SymbolFunctionName
    SymbolFunctionName QualifiedName
SymbolFunctionName: SymbolName SymbolName TypeFunctionNoReturn SymbolName M TypeModifiersopt TypeFunctionNoReturn
SymbolName:
    LName
    TemplateInstanceName
    IdentifierBackRef
    0                         // anonymous symbols
TemplateInstanceName:
    TemplateID LName TemplateArgs Z
TemplateID: __T __U // for symbols declared inside template constraint
TemplateArgs: TemplateArg TemplateArg TemplateArgs
TemplateArg: TemplateArgX H TemplateArgX
TemplateArgX:
    T Type
    V Type Value
    S QualifiedName
    X Number ExternallyMangledName
Value:
    n
    i Number
    N Number
    e HexFloat
    c HexFloat c HexFloat
    CharWidth Number _ HexDigits
    A Number Value...
    S Number Value...
HexFloat: NAN INF NINF N HexDigits P Exponent HexDigits P Exponent
Exponent: N Number Number
HexDigits: HexDigit HexDigit HexDigits
HexDigit: Digit A B C D E F
CharWidth: a w d
Name:
    Namestart
    Namestart Namechars
Namestart: _ Alpha
Namechar: Namestart Digit
Namechars: Namechar Namechar Namechars
LName:
    Number Name
Number: Digit Digit Number
Digit: 0 1 2 3 4 5 6 7 8 9
TypeBackRef:
    Q NumberBackRef
IdentifierBackRef: Q NumberBackRef
NumberBackRef: lower-case-letter upper-case-letter NumberBackRef
Type:
    TypeModifiersopt TypeX
    TypeBackRef
TypeX: TypeArray TypeStaticArray TypeAssocArray TypePointer TypeFunction TypeIdent TypeClass TypeStruct TypeEnum TypeTypedef TypeDelegate TypeVoid TypeByte TypeUbyte TypeShort TypeUshort TypeInt TypeUint TypeLong TypeUlong TypeCent TypeUcent TypeFloat TypeDouble TypeReal TypeIfloat TypeIdouble TypeIreal TypeCfloat TypeCdouble TypeCreal TypeBool TypeChar TypeWchar TypeDchar TypeNull TypeTuple TypeVector
TypeModifiers: Const Wild Wild Const Shared Shared Const Shared Wild Shared Wild Const Immutable
Shared: O
Const: x
Immutable: y
Wild: Ng
TypeArray: A Type
TypeStaticArray: G Number Type
TypeAssocArray: H Type Type
TypePointer: P Type
TypeVector: Nh Type
TypeFunction: TypeFunctionNoReturn Type
TypeFunctionNoReturn: CallConvention FuncAttrsopt Parametersopt ParamClose
CallConvention: F // D U // C W // Windows V // Pascal R // C++ Y // Objective-C
FuncAttrs: FuncAttr FuncAttr FuncAttrs
FuncAttr: FuncAttrPure FuncAttrNothrow FuncAttrRef FuncAttrProperty FuncAttrNogc FuncAttrReturn FuncAttrScope FuncAttrTrusted FuncAttrSafe
FuncAttrPure:
    Na
FuncAttrNogc: Ni
FuncAttrNothrow: Nb
FuncAttrProperty: Nd
FuncAttrRef: Nc
FuncAttrReturn: Nj
FuncAttrScope: Nl
FuncAttrTrusted: Ne
FuncAttrSafe: Nf
Parameters: Parameter Parameter Parameters
Parameter: Parameter2 M Parameter2 // scope
Parameter2: Type J Type // out K Type // ref L Type // lazy
ParamClose X // variadic T t...) style Y // variadic T t,...) style Z // not variadic
TypeIdent: I QualifiedName
TypeClass: C QualifiedName
TypeStruct: S QualifiedName
TypeEnum: E QualifiedName
TypeTypedef: T QualifiedName
TypeDelegate: D TypeModifiersopt TypeFunction
TypeVoid: v
TypeByte: g
TypeUbyte: h
TypeShort: s
TypeUshort: t
TypeInt: i
TypeUint: k
TypeLong: l
TypeUlong: m
TypeCent: zi
TypeUcent: zk
TypeFloat: f
TypeDouble: d
TypeReal: e
TypeIfloat: o
TypeIdouble: p
TypeIreal: j
TypeCfloat: q
TypeCdouble: r
TypeCreal: c
TypeBool: b
TypeChar: a
TypeWchar: u
TypeDchar: w
TypeNull: n
TypeTuple: B Parameters Z
Lexical
Modules