D Programming Language
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 local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

# D Grammar

### Lexical Syntax

Refer to the page for lexical syntax.

### Type

    Type:
        TypeCtorsopt BasicType
        TypeCtorsopt BasicType Declarator2

    BasicType:
        BasicTypeX
        . IdentifierList
        IdentifierList
        Typeof
        Typeof . IdentifierList
        TypeCtor ( Type )

    BasicTypeX:
        bool
        byte
        ubyte
        short
        ushort
        int
        uint
        long
        ulong
        char
        wchar
        dchar
        float
        double
        real
        ifloat
        idouble
        ireal
        cfloat
        cdouble
        creal
        void

    BasicType2:
        *
        [ ]
        [ AssignExpression ]
        [ AssignExpression .. AssignExpression ]
        [ Type ]
        delegate Parameters MemberFunctionAttributesopt
        function Parameters FunctionAttributesopt

    IdentifierList:
        Identifier
        Identifier . IdentifierList
        TemplateInstance
        TemplateInstance . IdentifierList

    TypeCtors:
        TypeCtor
        TypeCtor TypeCtors

    TypeCtor:
        const
        immutable
        inout
        shared

    Typeof:
        typeof ( Expression )
        typeof ( return )

### Expression

    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
        CmpExpression
        AndAndExpression && CmpExpression

    OrExpression:
        XorExpression
        OrExpression | XorExpression

    XorExpression:
        AndExpression
        XorExpression ^ AndExpression

    AndExpression:
        ShiftExpression
        AndExpression & ShiftExpression

    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
        ShiftExpression !<>= ShiftExpression
        ShiftExpression !<> ShiftExpression
        ShiftExpression <> ShiftExpression
        ShiftExpression <>= ShiftExpression
        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

    NewAnonClassExpression:
        new AllocatorArgumentsopt class ClassArgumentsopt SuperClassopt Interfacesopt AggregateBody

    ClassArguments:
        ( ArgumentListopt )

    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 [ AssignExpression .. AssignExpression ]

    PrimaryExpression:
        Identifier
        . Identifier
        TemplateInstance
        . TemplateInstance
        this
        super
        null
        true
        false
        $
        IntegerLiteral
        FloatLiteral
        CharacterLiteral
        StringLiterals
        ArrayLiteral
        AssocArrayLiteral
        FunctionLiteral
        AssertExpression
        MixinExpression
        ImportExpression
        NewExpressionWithArgs
        BasicTypeX . Identifier
        Typeof
        TypeidExpression
        IsExpression
        ( Expression )
        TraitsExpression
        SpecialKeyword

    StringLiterals:
        StringLiteral
        StringLiterals StringLiteral

    ArrayLiteral:
        [ ArgumentListopt ]

    AssocArrayLiteral:
        [ KeyValuePairs ]

    KeyValuePairs:
        KeyValuePair
        KeyValuePair , KeyValuePairs

    KeyValuePair:
        KeyExpression : ValueExpression

    KeyExpression:
        AssignExpression

    ValueExpression:
        AssignExpression

    FunctionLiteral:
        function Typeopt ParameterAttributes opt FunctionBody
        delegate Typeopt ParameterAttributes opt FunctionBody
        ParameterAttributes FunctionBody
        FunctionBody
        Lambda

    ParameterAttributes:
        Parameters
        Parameters FunctionAttributes

    Lambda:
        Identifier => AssignExpression
        functionopt ParameterAttributes => AssignExpression
        delegateopt ParameterAttributes => AssignExpression

    AssertExpression:
        assert ( AssignExpression )
        assert ( AssignExpression , AssignExpression )

    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

    TraitsExpression:
        __traits ( TraitsKeyword , TraitsArguments )

    TraitsKeyword:
        isAbstractClass
        isArithmetic
        isAssociativeArray
        isFinalClass
        isPOD
        isNested
        isFloating
        isIntegral
        isScalar
        isStaticArray
        isUnsigned
        isVirtualFunction
        isVirtualMethod
        isAbstractFunction
        isFinalFunction
        isStaticFunction
        isOverrideFunction
        isRef
        isOut
        isLazy
        hasMember
        identifier
        getAliasThis
        getAttributes
        getMember
        getOverloads
        getProtection
        getVirtualFunctions
        getVirtualMethods
        getUnitTests
        parent
        classInstanceSize
        getVirtualIndex
        allMembers
        derivedMembers
        isSame
        compiles

    TraitsArguments:
        TraitsArgument
        TraitsArgument , TraitsArguments

    TraitsArgument:
        AssignExpression
        Type

    SpecialKeyword:
        __FILE__
        __MODULE__
        __LINE__
        __FUNCTION__
        __PRETTY_FUNCTION__

### Statement

    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
        StaticAssert
        TemplateMixin
        ImportDeclaration

    ScopeStatement:
        NonEmptyStatement
        BlockStatement

    ScopeBlockStatement:
        BlockStatement

    LabeledStatement:
        Identifier :
        Identifier : NoScopeStatement
        Identifier : Statement

    BlockStatement:
        { }
        { StatementList }

    StatementList:
        Statement
        Statement StatementList

    ExpressionStatement:
        Expression ;

    DeclarationStatement:
        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

    ForeachStatement:
        Foreach ( ForeachTypeList ; ForeachAggregate ) NoScopeNonEmptyStatement

    Foreach:
        foreach
        foreach_reverse

    ForeachTypeList:
        ForeachType
        ForeachType , ForeachTypeList

    ForeachType:
        refopt TypeCtorsopt BasicType Declarator
        refopt TypeCtorsopt Identifier

    ForeachAggregate:
        Expression

    ForeachRangeStatement:
        Foreach ( ForeachType ; LwrExpression .. UprExpression ) ScopeStatement

    LwrExpression:
        Expression

    UprExpression:
        Expression

    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:
        LastCatch
        Catch
        Catch Catches

    LastCatch:
        catch NoScopeNonEmptyStatement

    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 { AsmInstructionListopt }

    AsmInstructionList:
        AsmInstruction ;
        AsmInstruction ; AsmInstructionList

    PragmaStatement:
        Pragma NoScopeStatement

    MixinStatement:
        mixin ( AssignExpression ) ;

### Iasm

    AsmInstruction:
        Identifier : AsmInstruction
        align IntegerExpression
        even
        naked
        db Operands
        ds Operands
        di Operands
        dl Operands
        df Operands
        dd Operands
        de Operands
        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
        AsmLogAndExp || AsmLogAndExp

    AsmLogAndExp:
        AsmOrExp
        AsmOrExp && AsmOrExp

    AsmOrExp:
        AsmXorExp
        AsmXorExp | AsmXorExp

    AsmXorExp:
        AsmAndExp
        AsmAndExp ^ AsmAndExp

    AsmAndExp:
        AsmEqualExp
        AsmEqualExp & AsmEqualExp

    AsmEqualExp:
        AsmRelExp
        AsmRelExp == AsmRelExp
        AsmRelExp != AsmRelExp

    AsmRelExp:
        AsmShiftExp
        AsmShiftExp < AsmShiftExp
        AsmShiftExp <= AsmShiftExp
        AsmShiftExp > AsmShiftExp
        AsmShiftExp >= AsmShiftExp

    AsmShiftExp:
        AsmAddExp
        AsmAddExp << AsmAddExp
        AsmAddExp >> AsmAddExp
        AsmAddExp >>> AsmAddExp

    AsmAddExp:
        AsmMulExp
        AsmMulExp + AsmMulExp
        AsmMulExp - AsmMulExp

    AsmMulExp:
        AsmBrExp
        AsmBrExp * AsmBrExp
        AsmBrExp / AsmBrExp
        AsmBrExp % AsmBrExp

    AsmBrExp:
        AsmUnaExp
        AsmBrExp [ AsmExp ]

    AsmUnaExp:
        AsmTypePrefix AsmExp
        offsetof AsmExp
        seg AsmExp
        + AsmUnaExp
        - AsmUnaExp
        ! AsmUnaExp
        ~ AsmUnaExp
        AsmPrimaryExp

    AsmPrimaryExp:
        IntegerLiteral
        FloatLiteral
        __LOCAL_SIZE
        $
        Register
        Register64
        DotIdentifier

    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

### Declaration

    Declaration:
        AliasDeclaration
        AggregateDeclaration
        EnumDeclaration
        ImportDeclaration
        Decl

    AliasDeclaration:
        alias StorageClassesopt BasicType Declarator
        alias AliasDeclarationX ;

    AliasDeclarationX:
        Identifier TemplateParametersopt = StorageClassesopt Type
        AliasDeclarationX , Identifier TemplateParametersopt = StorageClassesopt Type

    AutoDeclaration:
        StorageClasses AutoDeclarationX ;

    AutoDeclarationX:
        Identifier TemplateParametersopt = Initializer
        AutoDeclarationX , Identifier TemplateParametersopt = Initializer

    Decl:
        StorageClassesopt BasicType Declarators ;
        StorageClassesopt BasicType Declarator FunctionBody
        AutoDeclaration

    Declarators:
        DeclaratorInitializer
        DeclaratorInitializer , DeclaratorIdentifierList

    DeclaratorInitializer:
        Declarator
        Declarator = Initializer

    DeclaratorIdentifierList:
        DeclaratorIdentifier
        DeclaratorIdentifier , DeclaratorIdentifierList

    DeclaratorIdentifier:
        Identifier
        Identifier = Initializer

    Declarator:
        BasicType2opt ( Declarator ) DeclaratorSuffixesopt
        BasicType2opt Identifier DeclaratorSuffixesopt

    Declarator2:
        BasicType2opt DeclaratorSuffixesopt
        BasicType2opt ( Declarator2 ) DeclaratorSuffixesopt

    DeclaratorSuffixes:
        DeclaratorSuffix
        DeclaratorSuffix DeclaratorSuffixes

    DeclaratorSuffix:
        [ ]
        [ AssignExpression ]
        [ Type ]
        Parameters MemberFunctionAttributesopt
        TemplateParameters Parameters MemberFunctionAttributesopt Constraintopt

    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

    VoidInitializer:
        void

    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

### Function

    Parameters:
        ( ParameterListopt )

    ParameterList:
        Parameter
        Parameter , ParameterList
        ...

    Parameter:
        InOutopt BasicType Declarator
        InOutopt BasicType Declarator ...
        InOutopt BasicType Declarator = DefaultInitializerExpression
        InOutopt Type
        InOutopt Type ...

    InOut:
        InOutX
        InOut InOutX

    InOutX:
        auto
        TypeCtor
        final
        in
        lazy
        out
        ref
        scope

    FunctionAttributes:
        FunctionAttribute
        FunctionAttribute FunctionAttributes

    FunctionAttribute:
        nothrow
        pure
        Property

    MemberFunctionAttributes:
        MemberFunctionAttribute
        MemberFunctionAttribute MemberFunctionAttributes

    MemberFunctionAttribute:
        const
        immutable
        inout
        shared
        FunctionAttribute

    DefaultInitializerExpression:
        AssignExpression
        SpecialKeyword

    FunctionBody:
        BlockStatement
        BodyStatement
        InStatement BodyStatement
        OutStatement BodyStatement
        InStatement OutStatement BodyStatement
        OutStatement InStatement BodyStatement

    InStatement:
        in BlockStatement

    OutStatement:
        out BlockStatement
        out ( Identifier ) BlockStatement

    BodyStatement:
        body BlockStatement

    Constructor:
        this Parameters MemberFunctionAttributesopt ;
        this Parameters MemberFunctionAttributesopt FunctionBody
        ConstructorTemplate

    ConstructorTemplate:
        this TemplateParameters Parameters MemberFunctionAttributesopt Constraintopt ;
        this TemplateParameters Parameters MemberFunctionAttributesopt Constraintopt FunctionBody

    Destructor:
        ~ this ( ) MemberFunctionAttributesopt ;
        ~ this ( ) MemberFunctionAttributesopt FunctionBody

    Postblit:
        this ( this ) MemberFunctionAttributesopt ;
        this ( this ) MemberFunctionAttributesopt FunctionBody

    Allocator:
        new Parameters ;
        new Parameters FunctionBody

    Deallocator:
        delete Parameters ;
        delete Parameters FunctionBody

    Invariant:
        invariant ( ) BlockStatement

    UnitTest:
        unittest FunctionBody

    StaticConstructor:
        static this ( ) ;
        static this ( ) FunctionBody

    StaticDestructor:
        static ~ this ( ) MemberFunctionAttributesopt ;
        static ~ this ( ) MemberFunctionAttributesopt FunctionBody

    SharedStaticConstructor:
        shared static this ( ) ;
        shared static this ( ) FunctionBody

    SharedStaticDestructor:
        shared static ~ this ( ) MemberFunctionAttributesopt ;
        shared static ~ this ( ) MemberFunctionAttributesopt FunctionBody

### Aggregate

    AggregateDeclaration:
        ClassDeclaration
        InterfaceDeclaration
        StructDeclaration
        UnionDeclaration

    ClassDeclaration:
        class Identifier ;
        class Identifier BaseClassListopt AggregateBody
        ClassTemplateDeclaration

    ClassTemplateDeclaration:
        class Identifier TemplateParameters Constraintopt BaseClassListopt AggregateBody
        class Identifier TemplateParameters BaseClassList Constraint AggregateBody

    InterfaceDeclaration:
        interface Identifier ;
        interface Identifier BaseInterfaceListopt AggregateBody
        InterfaceTemplateDeclaration

    InterfaceTemplateDeclaration:
        interface Identifier TemplateParameters Constraintopt BaseInterfaceListopt AggregateBody
        interface Identifier TemplateParameters BaseInterfaceList Constraint AggregateBody

    StructDeclaration:
        struct Identifier ;
        struct Identifier AggregateBody
        StructTemplateDeclaration
        AnonStructDeclaration

    StructTemplateDeclaration:
        struct Identifier TemplateParameters Constraintopt AggregateBody

    AnonStructDeclaration:
        struct AggregateBody

    UnionDeclaration:
        union Identifier ;
        union Identifier AggregateBody
        UnionTemplateDeclaration
        AnonUnionDeclaration

    UnionTemplateDeclaration:
        union Identifier TemplateParameters Constraintopt AggregateBody

    AnonUnionDeclaration:
        union AggregateBody

    AggregateBody:
        { DeclDefsopt }

    BaseClassList:
        : SuperClass
        : SuperClass , Interfaces
        : Interfaces

    BaseInterfaceList:
        : Interfaces

    SuperClass:
        Identifier

    Interfaces:
        Interface
        Interface , Interfaces

    Interface:
        Identifier

    AliasThis:
        alias Identifier this ;

### Enum

    EnumDeclaration:
        enum EnumTag EnumBody
        enum EnumBody
        enum EnumTag : EnumBaseType EnumBody
        enum : EnumBaseType EnumBody

    EnumTag:
        Identifier

    EnumBaseType:
        Type

    EnumBody:
        EmptyEnumBody
        EnumMembersBody

    EmptyEnumBody:
        ;

    EnumMembersBody:
        { EnumMembers }

    EnumMembers:
        EnumMember
        EnumMember ,
        EnumMember , EnumMembers

    EnumMember:
        Identifier
        Identifier = AssignExpression
        Type Identifier = AssignExpression

### Template

    TemplateDeclaration:
        template Identifier TemplateParameters Constraintopt { DeclDefsopt }

    TemplateParameters:
        ( TemplateParameterListopt )

    TemplateParameterList:
        TemplateParameter
        TemplateParameter ,
        TemplateParameter , TemplateParameterList

    TemplateParameter:
        TemplateTypeParameter
        TemplateValueParameter
        TemplateAliasParameter
        TemplateTupleParameter
        TemplateThisParameter

    Constraint:
        if ( Expression )

    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

    TemplateTupleParameter:
        Identifier ...

    TemplateMixinDeclaration:
        mixin template Identifier TemplateParameters Constraintopt { DeclDefsopt }

    TemplateMixin:
        mixin MixinTemplateName TemplateArgumentsopt Identifieropt ;

    MixinTemplateName:
        . QualifiedIdentifierList
        QualifiedIdentifierList
        Typeof . QualifiedIdentifierList

    QualifiedIdentifierList:
        Identifier
        Identifier . QualifiedIdentifierList
        TemplateInstance . QualifiedIdentifierList

### Attribute

    AttributeSpecifier:
        Attribute :
        Attribute DeclarationBlock

    Attribute:
        LinkageAttribute
        AlignAttribute
        DeprecatedAttribute
        ProtectionAttribute
        Pragma
        static
        extern
        abstract
        final
        override
        synchronized
        auto
        scope
        const
        immutable
        inout
        shared
        __gshared
        Property
        nothrow
        pure
        ref

    DeclarationBlock:
        DeclDef
        { DeclDefsopt }

    LinkageAttribute:
        extern ( LinkageType )
        extern ( C++, IdentifierList )

    LinkageType:
        C
        C++
        D
        Windows
        Pascal
        System

    AlignAttribute:
        align
        align ( IntegerLiteral )

    DeprecatedAttribute:
        deprecated
        deprecated ( StringLiteral )

    ProtectionAttribute:
        private
        package
        protected
        public
        export

    Property:
        @ PropertyIdentifier
        UserDefinedAttribute

    PropertyIdentifier:
        property
        safe
        trusted
        system
        disable
        nogc

    UserDefinedAttribute:
        @ ( ArgumentList )
        @ Identifier
        @ Identifier ( ArgumentListopt )

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

### Conditional

    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 )

    DebugCondition:
        debug
        debug ( IntegerLiteral )
        debug ( Identifier )

    StaticIfCondition:
        static if ( AssignExpression )

    VersionSpecification:
        version = Identifier ;
        version = IntegerLiteral ;

    DebugSpecification:
        debug = Identifier ;
        debug = IntegerLiteral ;

    StaticAssert:
        static assert ( AssignExpression );
        static assert ( AssignExpression , AssignExpression );

### Module

    Module:
        ModuleDeclaration DeclDefs
        DeclDefs

    DeclDefs:
        DeclDef
        DeclDef DeclDefs

    DeclDef:
        AttributeSpecifier
        Declaration
        Constructor
        Destructor
        Postblit
        Allocator
        Deallocator
        Invariant
        UnitTest
        AliasThis
        StaticConstructor
        StaticDestructor
        SharedStaticConstructor
        SharedStaticDestructor
        ConditionalDeclaration
        DebugSpecification
        VersionSpecification
        StaticAssert
        TemplateDeclaration
        TemplateMixinDeclaration
        TemplateMixin
        MixinDeclaration
        ;

    ModuleDeclaration:
        module ModuleFullyQualifiedName ;

    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 ) ;

Forums | Comments | Search | Downloads | Home
Copyright © 1999-2014 by Digital Mars ®, All Rights Reserved | Page generated by Ddoc on Wed Oct 15 12:09:37 2014