Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar CS;
- import Unicode;
- start: namespaceOrTypeName EOF;
- /**********
- *
- * Basic Concepts
- *
- **********/
- namespaceName
- : namespaceOrTypeName
- ;
- typeName
- : namespaceOrTypeName
- ;
- namespaceOrTypeName
- : Identifier typeArgumentList?
- | namespaceOrTypeName '.' Identifier typeArgumentList?
- | qualifiedAliasMember
- ;
- /**********
- *
- * Types
- *
- **********/
- type
- : (typeName
- | simpleType
- | enumType
- | classType
- | interfaceType
- | delegateType
- | typeParameter
- | 'void' '*'
- ) ('?' | rankSpecifiers | '*')*
- ;
- valueType
- : structType
- | enumType
- ;
- structType
- : typeName
- | simpleType
- | nullableType
- ;
- simpleType
- : numericType
- | 'bool'
- ;
- numericType
- : integralType
- | floatingPointType
- | 'decimal'
- ;
- integralType
- : 'sbyte'
- | 'byte'
- | 'short'
- | 'ushort'
- | 'int'
- | 'uint'
- | 'long'
- | 'ulong'
- | 'char'
- ;
- floatingPointType
- : 'float'
- | 'double'
- ;
- nullableType
- : nonNullableValueType '?'
- ;
- nonNullableValueType
- : type
- ;
- enumType
- : typeName
- ;
- referenceType
- : classType
- | interfaceType
- | arrayType
- | delegateType
- ;
- classType
- : typeName
- | 'object'
- | 'dynamic'
- | 'string'
- ;
- interfaceType
- : typeName
- ;
- rankSpecifiers
- : rankSpecifier
- | rankSpecifiers rankSpecifier
- ;
- rankSpecifier
- : '[' dimSeparators? ']'
- ;
- dimSeparators
- : ','
- | dimSeparators ','
- ;
- delegateType
- : typeName
- ;
- typeArgumentList
- : '<' typeArguments '>'
- ;
- typeArguments
- : typeArgument
- | typeArguments ',' typeArgument
- ;
- typeArgument
- : type
- ;
- typeParameter
- : Identifier
- ;
- pointerType
- : unmanagedType '*'
- | 'void' '*'
- ;
- unmanagedType
- : type
- ;
- /**********
- *
- * Variable
- *
- **********/
- variableReference
- : expression
- ;
- /**********
- *
- * Expressions
- *
- **********/
- argumentList
- : argument
- | argumentList ',' argument
- ;
- argument
- : argumentName? argumentValue
- ;
- argumentName
- : Identifier ':'
- ;
- argumentValue
- : expression
- | 'ref' variableReference
- | 'out' variableReference
- ;
- primaryExpression
- : (literal
- | simpleName
- | parenthesizedExpression
- | predefinedType '.' Identifier typeArgumentList?
- | qualifiedAliasMember '.' Identifier
- | thisAccess
- | baseAccess
- | objectCreationExpression
- | delegateCreationExpression
- | anonymousObjectCreationExpression
- | typeofExpression
- | checkedExpression
- | uncheckedExpression
- | defaultValueExpression
- | anonymousMethodExpression
- | sizeofExpression
- ) ('[' argumentList ']' | '[' expression ']')* ( ('.' Identifier typeArgumentList? | '(' argumentList? ')' | '++' | '--' | '->' Identifier typeArgumentList?) ('[' argumentList ']' | '[' expression ']')*)*
- | arrayCreationExpression
- ;
- primaryNoArrayCreationExpression
- : (literal
- | simpleName
- | parenthesizedExpression
- | memberAccess
- | invocationExpression
- | thisAccess
- | baseAccess
- | postIncrementExpression
- | postDecrementExpression
- | objectCreationExpression
- | delegateCreationExpression
- | anonymousObjectCreationExpression
- | typeofExpression
- | checkedExpression
- | uncheckedExpression
- | defaultValueExpression
- | anonymousMethodExpression
- | pointerMemberAccess
- | sizeofExpression
- ) ('[' argumentList ']' | '[' expression ']')*
- ;
- simpleName
- : Identifier typeArgumentList?
- ;
- parenthesizedExpression
- : '(' expression ')'
- ;
- memberAccess
- : primaryExpression '.' Identifier typeArgumentList?
- | predefinedType '.' Identifier typeArgumentList?
- | qualifiedAliasMember '.' Identifier
- ;
- predefinedType
- : 'bool'
- | 'byte'
- | 'char'
- | 'decimal'
- | 'double'
- | 'float'
- | 'int'
- | 'long'
- | 'object'
- | 'sbyte'
- | 'short'
- | 'string'
- | 'uint'
- | 'ulong'
- | 'ushort'
- ;
- invocationExpression
- : primaryExpression '(' argumentList? ')'
- ;
- elementAccess
- : primaryNoArrayCreationExpression '[' argumentList ']'
- ;
- thisAccess
- : 'this'
- ;
- baseAccess
- : 'base' '.' Identifier
- | 'base' '[' argumentList ']'
- ;
- postIncrementExpression
- : primaryExpression '++'
- ;
- postDecrementExpression
- : primaryExpression '--'
- ;
- objectCreationExpression
- : 'new' type '(' argumentList? ')' objectOrCollectionInitializer?
- | 'new' type objectOrCollectionInitializer
- ;
- objectOrCollectionInitializer
- : objectInitializer
- | collectionInitializer
- ;
- objectInitializer
- : '{' memberInitializerList? '}'
- | '{' memberInitializerList ',' '}'
- ;
- memberInitializerList
- : memberInitializer
- | memberInitializer ',' memberInitializer
- ;
- memberInitializer
- : Identifier '=' initializerValue
- ;
- initializerValue
- : expression
- | objectOrCollectionInitializer
- ;
- collectionInitializer
- : '{' elementInitializerList '}'
- | '{' elementInitializerList ',' '}'
- ;
- elementInitializerList
- : elementInitializer
- | elementInitializerList ',' elementInitializer
- ;
- elementInitializer
- : nonAssignmentExpression
- | '{' expressionList '}'
- ;
- expressionList
- : expression
- | expressionList ',' expression
- ;
- arrayCreationExpression
- : 'new' nonArrayType '[' expressionList ']' rankSpecifiers? arrayInitializer?
- | 'new' arrayType arrayInitializer
- | 'new' rankSpecifier arrayInitializer
- ;
- delegateCreationExpression
- : 'new' delegateType '(' expression ')'
- ;
- anonymousObjectCreationExpression
- : 'new' anonymousObjectInitializer
- ;
- anonymousObjectInitializer
- : '{' memberDeclaratorList? '}'
- | '{' memberDeclaratorList ',' '}'
- ;
- memberDeclaratorList
- : memberDeclarator
- | memberDeclaratorList ',' memberDeclarator
- ;
- memberDeclarator
- : simpleName
- | memberAccess
- | Identifier '=' expression
- ;
- typeofExpression
- : 'typeof' '(' type ')'
- | 'typeof' '(' unboundTypeName ')'
- | 'typeof' '(' 'void' ')'
- ;
- unboundTypeName
- : Identifier genericDimensionSpecifier?
- | Identifier '::' Identifier genericDimensionSpecifier?
- | unboundTypeName '.' Identifier genericDimensionSpecifier?
- ;
- genericDimensionSpecifier
- : '<' commas? '>'
- ;
- commas
- : ','
- | commas ','
- ;
- checkedExpression
- : 'checked' '(' expression ')'
- ;
- uncheckedExpression
- : 'unchecked' '(' expression ')'
- ;
- defaultValueExpression
- : 'default' '(' type ')'
- ;
- unaryExpression
- : primaryExpression
- | '+' unaryExpression
- | '-' unaryExpression
- | '!' unaryExpression
- | '~' unaryExpression
- | preIncrementExpression
- | preDecrementExpression
- | castExpression
- | pointerIndirectionExpression
- | addressofExpression
- ;
- pointerIndirectionExpression
- : '*' unaryExpression
- ;
- pointerMemberAccess
- : primaryExpression '->' Identifier typeArgumentList?
- ;
- pointerElementAccess
- : primaryNoArrayCreationExpression '[' expression ']'
- ;
- addressofExpression
- : '&' unaryExpression
- ;
- sizeofExpression
- : 'sizeof' '(' unmanagedType ')'
- ;
- fixedStatement
- : 'fixed' '(' pointerType fixedPointerDeclarators ')' embeddedStatement
- ;
- fixedPointerDeclarators
- : fixedPointerDeclarator
- | fixedPointerDeclarators ',' fixedPointerDeclarator
- ;
- fixedPointerDeclarator
- : Identifier '=' fixedPointerInitializer
- ;
- fixedPointerInitializer
- : '&' variableReference
- | expression
- ;
- preIncrementExpression
- : '++' unaryExpression
- ;
- preDecrementExpression
- : '--' unaryExpression
- ;
- castExpression
- : '(' type ')' unaryExpression
- ;
- multiplicativeExpression
- : unaryExpression
- | multiplicativeExpression '*' unaryExpression
- | multiplicativeExpression '/' unaryExpression
- | multiplicativeExpression '%' unaryExpression
- ;
- additiveExpression
- : multiplicativeExpression
- | additiveExpression '+' multiplicativeExpression
- | additiveExpression '-' multiplicativeExpression
- ;
- shiftExpression
- : additiveExpression
- | shiftExpression '<<' additiveExpression
- | shiftExpression '>>' additiveExpression
- ;
- relationalExpression
- : shiftExpression
- | relationalExpression '<' shiftExpression
- | relationalExpression '>' shiftExpression
- | relationalExpression '<=' shiftExpression
- | relationalExpression '>=' shiftExpression
- | relationalExpression 'is' type
- | relationalExpression 'as' type
- ;
- equalityExpression
- : relationalExpression
- | equalityExpression '==' relationalExpression
- | equalityExpression '!=' relationalExpression
- ;
- andExpression
- : equalityExpression
- | andExpression '&' equalityExpression
- ;
- exclusiveOrExpression
- : andExpression
- | exclusiveOrExpression '^' andExpression
- ;
- inclusiveOrExpression
- : exclusiveOrExpression
- | inclusiveOrExpression '|' exclusiveOrExpression
- ;
- conditionalAndExpression
- : inclusiveOrExpression
- | conditionalAndExpression '&&' inclusiveOrExpression
- ;
- conditionalOrExpression
- : conditionalAndExpression
- | conditionalOrExpression '||' conditionalAndExpression
- ;
- nullCoalescingExpression
- : conditionalOrExpression
- | conditionalOrExpression '??' nullCoalescingExpression
- ;
- conditionalExpression
- : nullCoalescingExpression
- | nullCoalescingExpression '?' expression ':' expression
- ;
- lambdaExpression
- : anonymousFunctionSignature '=>' anonymousFunctionBody
- ;
- anonymousMethodExpression
- : 'delegate' explicitAnonymousFunctionSignature? block
- ;
- anonymousFunctionSignature
- : explicitAnonymousFunctionSignature
- | implicitAnonymousFunctionSignature
- ;
- explicitAnonymousFunctionSignature
- : '(' explicitAnonymousFunctionParameterList? ')'
- ;
- explicitAnonymousFunctionParameterList
- : explicitAnonymousFunctionParameter
- | explicitAnonymousFunctionParameterList ',' explicitAnonymousFunctionParameter
- ;
- explicitAnonymousFunctionParameter
- : anonymousFunctionParameterModifier? type Identifier
- ;
- anonymousFunctionParameterModifier
- : 'ref'
- | 'out'
- ;
- implicitAnonymousFunctionSignature
- : '(' implicitAnonymousFunctionParameterList? ')'
- | implicitAnonymousFunctionParameter
- ;
- implicitAnonymousFunctionParameterList
- : implicitAnonymousFunctionParameter
- | implicitAnonymousFunctionParameterList ',' implicitAnonymousFunctionParameter
- ;
- implicitAnonymousFunctionParameter
- : Identifier
- ;
- anonymousFunctionBody
- : expression
- | block
- ;
- queryExpression
- : fromClause queryBody
- ;
- fromClause
- : 'from' type? Identifier 'in' expression
- ;
- queryBody
- : queryBodyClauses? selectOrGroupClause queryContinuation?
- ;
- queryBodyClauses
- : queryBodyClause
- | queryBodyClauses queryBodyClause
- ;
- queryBodyClause
- : fromClause
- | letClause
- | whereClause
- | joinClause
- | joinIntoClause
- | orderbyClause
- ;
- letClause
- : 'let' Identifier '=' expression
- ;
- whereClause
- : 'where' booleanExpression
- ;
- joinClause
- : 'join' type? Identifier 'in' expression 'on' expression 'equals' expression
- ;
- joinIntoClause
- : 'join' type? Identifier 'in' expression 'on' expression 'equals' expression 'into' Identifier
- ;
- orderbyClause
- : 'orderby' orderings
- ;
- orderings
- : ordering
- | orderings ',' ordering
- ;
- ordering
- : expression orderingDirection?
- ;
- orderingDirection
- : 'ascending'
- | 'descending'
- ;
- selectOrGroupClause
- : selectClause
- | groupClause
- ;
- selectClause
- : 'select' expression
- ;
- groupClause
- : 'group' expression 'by' expression
- ;
- queryContinuation
- : 'into' Identifier queryBody
- ;
- assignment
- : unaryExpression assignmentOperator expression
- ;
- assignmentOperator
- : '='
- | '+='
- | '-='
- | '*='
- | '/='
- | '%='
- | '&='
- | '|='
- | '^='
- | '<<='
- | '>>='
- ;
- expression
- : nonAssignmentExpression
- | assignment
- ;
- nonAssignmentExpression
- : conditionalExpression
- | lambdaExpression
- | queryExpression
- ;
- constantExpression
- : expression
- ;
- booleanExpression
- : expression
- ;
- /**********
- *
- * Statements
- *
- **********/
- statement
- : labeledStatement
- | declarationStatement
- | embeddedStatement
- ;
- embeddedStatement
- : block
- | emptyStatement
- | expressionStatement
- | selectionStatement
- | iterationStatement
- | jumpStatement
- | tryStatement
- | checkedStatement
- | uncheckedStatement
- | lockStatement
- | usingStatement
- | yieldStatement
- | unsafeStatement
- | fixedStatement
- ;
- unsafeStatement
- : 'unsafe' block
- ;
- block
- : '{' statementList? '}'
- ;
- statementList
- : statement
- | statementList statement
- ;
- emptyStatement
- : ';'
- ;
- labeledStatement
- : Identifier ':' statement
- ;
- declarationStatement
- : localVariableDeclaration ';'
- | localConstantDeclaration ';'
- ;
- localVariableDeclaration
- : localVariableType localVariableDeclarators
- ;
- localVariableType
- : type
- | 'var'
- ;
- localVariableDeclarators
- : localVariableDeclarator
- | localVariableDeclarators ',' localVariableDeclarator
- ;
- localVariableDeclarator
- : Identifier
- | Identifier '=' localVariableInitializer
- ;
- localVariableInitializer
- : expression
- | arrayInitializer
- | stackallocInitializer
- ;
- stackallocInitializer
- : 'stackalloc' unmanagedType '[' expression ']'
- ;
- localConstantDeclaration
- : 'const' type constantDeclarators
- ;
- constantDeclarators
- : constantDeclarator
- | constantDeclarators ',' constantDeclarator
- ;
- constantDeclarator
- : Identifier '=' constantExpression
- ;
- expressionStatement
- : statementExpression ';'
- ;
- statementExpression
- : invocationExpression
- | objectCreationExpression
- | assignment
- | postIncrementExpression
- | postDecrementExpression
- | preIncrementExpression
- | preDecrementExpression
- ;
- selectionStatement
- : ifStatement
- | switchStatement
- ;
- ifStatement
- : 'if' '(' booleanExpression ')' embeddedStatement
- | 'if' '(' booleanExpression ')' embeddedStatement 'else' embeddedStatement
- ;
- switchStatement
- : 'switch' '(' expression ')' switchBlock
- ;
- switchBlock
- : '{' switchSections? '}'
- ;
- switchSections
- : switchSection
- | switchSections switchSection
- ;
- switchSection
- : switchLabels statementList
- ;
- switchLabels
- : switchLabel
- | switchLabels switchLabel
- ;
- switchLabel
- : 'case' constantExpression ':'
- | 'default' ':'
- ;
- iterationStatement
- : whileStatement
- | doStatement
- | forStatement
- | foreachStatement
- ;
- whileStatement
- : 'while' '(' booleanExpression ')' embeddedStatement
- ;
- doStatement
- : 'do' embeddedStatement 'while' '(' booleanExpression ')' ';'
- ;
- forStatement
- : 'for' '(' forInitializer? ';' forCondition? ';' forIterator? ')' embeddedStatement
- ;
- forInitializer
- : localVariableDeclaration
- | statementExpressionList
- ;
- forCondition
- : booleanExpression
- ;
- forIterator
- : statementExpressionList
- ;
- statementExpressionList
- : statementExpression
- | statementExpressionList ',' statementExpression
- ;
- foreachStatement
- : 'foreach' '(' localVariableType Identifier 'in' expression ')' embeddedStatement
- ;
- jumpStatement
- : breakStatement
- | continueStatement
- | gotoStatement
- | returnStatement
- | throwStatement
- ;
- breakStatement
- : 'break' ';'
- ;
- continueStatement
- : 'continue' ';'
- ;
- gotoStatement
- : 'goto' Identifier ';'
- | 'goto' 'case' constantExpression ';'
- | 'goto' 'default' ';'
- ;
- returnStatement
- : 'return' expression? ';'
- ;
- throwStatement
- : 'throw' expression? ';'
- ;
- tryStatement
- : 'try' block catchClauses
- | 'try' block finallyClause
- | 'try' block catchClauses finallyClause
- ;
- catchClauses
- : specificCatchClauses generalCatchClause?
- | specificCatchClauses? generalCatchClause
- ;
- specificCatchClauses
- : specificCatchClause
- | specificCatchClauses specificCatchClause
- ;
- specificCatchClause
- : 'catch' '(' classType Identifier? ')' block
- ;
- generalCatchClause
- : 'catch' block
- ;
- finallyClause
- : 'finally' block
- ;
- checkedStatement
- : 'checked' block
- ;
- uncheckedStatement
- : 'unchecked' block
- ;
- lockStatement
- : 'lock' '(' expression ')' embeddedStatement
- ;
- usingStatement
- : 'using' '(' resourceAcquisition ')' embeddedStatement
- ;
- resourceAcquisition
- : localVariableDeclaration
- | expression
- ;
- yieldStatement
- : 'yield' 'return' expression ';'
- | 'yield' 'break' ';'
- ;
- /**********
- *
- * Namespaces
- *
- **********/
- compilationUnit
- : externAliasDirectives? usingDirectives? globalAttributes? namespaceMemberDeclarations?
- ;
- namespaceDeclaration
- : 'namespace' qualifiedIdentifier namespaceBody ';'?
- ;
- qualifiedIdentifier
- : Identifier
- | qualifiedIdentifier '.' Identifier
- ;
- namespaceBody
- : '{' externAliasDirectives? usingDirectives? namespaceMemberDeclarations? '}'
- ;
- externAliasDirectives
- : externAliasDirective
- | externAliasDirectives externAliasDirective
- ;
- externAliasDirective
- : 'extern' 'alias' Identifier ';'
- ;
- usingDirectives
- : usingDirective
- | usingDirectives usingDirective
- ;
- usingDirective
- : usingAliasDirective
- | usingNamespaceDirective
- ;
- usingAliasDirective
- : 'using' Identifier '=' namespaceOrTypeName ';'
- ;
- usingNamespaceDirective
- : 'using' namespaceName ';'
- ;
- namespaceMemberDeclarations
- : namespaceMemberDeclaration
- | namespaceMemberDeclarations namespaceMemberDeclaration
- ;
- namespaceMemberDeclaration
- : namespaceDeclaration
- | typeDeclaration
- ;
- typeDeclaration
- : classDeclaration
- | structDeclaration
- | interfaceDeclaration
- | enumDeclaration
- | delegateDeclaration
- ;
- qualifiedAliasMember
- : Identifier '::' Identifier typeArgumentList?
- ;
- /**********
- *
- * Classes
- *
- **********/
- classDeclaration
- : attributes? classModifiers? 'partial'? 'class' Identifier typeParameterList? classBase? typeParameterConstraintsClauses? classBody ';'?
- ;
- classModifiers
- : classModifier
- | classModifiers classModifier
- ;
- classModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'abstract'
- | 'sealed'
- | 'static'
- | 'unsafe'
- ;
- typeParameterList
- : '<' typeParameters '>'
- ;
- typeParameters
- : attributes? typeParameter
- | typeParameters ',' attributes? typeParameter
- ;
- classBase
- : ':' classType
- | ':' interfaceTypeList
- | ':' classType ',' interfaceTypeList
- ;
- interfaceTypeList
- : interfaceType
- | interfaceTypeList ',' interfaceType
- ;
- typeParameterConstraintsClauses
- : typeParameterConstraintsClause
- | typeParameterConstraintsClauses typeParameterConstraintsClause
- ;
- typeParameterConstraintsClause
- : 'where' typeParameter ':' typeParameterConstraints
- ;
- typeParameterConstraints
- : primaryConstraint
- | secondaryConstraints
- | constructorConstraint
- | primaryConstraint ',' secondaryConstraints
- | primaryConstraint ',' constructorConstraint
- | secondaryConstraints ',' constructorConstraint
- | primaryConstraint ',' secondaryConstraints ',' constructorConstraint
- ;
- primaryConstraint
- : classType
- | 'class'
- | 'struct'
- ;
- secondaryConstraints
- : interfaceType
- | typeParameter
- | secondaryConstraints ',' interfaceType
- | secondaryConstraints ',' typeParameter
- ;
- constructorConstraint
- : 'new' '(' ')'
- ;
- classBody
- : '{' classMemberDeclarations? '}'
- ;
- classMemberDeclarations
- : classMemberDeclaration
- | classMemberDeclarations classMemberDeclaration
- ;
- classMemberDeclaration
- : constantDeclaration
- | fieldDeclaration
- | methodDeclaration
- | propertyDeclaration
- | eventDeclaration
- | indexerDeclaration
- | operatorDeclaration
- | constructorDeclaration
- | destructorDeclaration
- | staticConstructorDeclaration
- | typeDeclaration
- ;
- constantDeclaration
- : attributes? constantModifiers? 'const' type constantDeclarators ';'
- ;
- constantModifiers
- : constantModifier
- | constantModifiers constantModifier
- ;
- constantModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- ;
- fieldDeclaration
- : attributes? fieldModifiers? type variableDeclarators ';'
- ;
- fieldModifiers
- : fieldModifier
- | fieldModifiers fieldModifier
- ;
- fieldModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'static'
- | 'readonly'
- | 'volatile'
- | 'unsafe'
- ;
- variableDeclarators
- : variableDeclarator
- | variableDeclarators ',' variableDeclarator
- ;
- variableDeclarator
- : Identifier
- | Identifier '=' variableInitializer
- ;
- variableInitializer
- : expression
- | arrayInitializer
- ;
- methodDeclaration
- : methodHeader methodBody
- ;
- methodHeader
- : attributes? methodModifiers? 'partial'? returnType memberName typeParameterList? '(' formalParameterList? ')' typeParameterConstraintsClauses?
- ;
- methodModifiers
- : methodModifier
- | methodModifiers methodModifier
- ;
- methodModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'static'
- | 'virtual'
- | 'sealed'
- | 'override'
- | 'abstract'
- | 'extern'
- | 'unsafe'
- ;
- returnType
- : type
- | 'void'
- ;
- memberName
- : Identifier
- | interfaceType '.' Identifier
- ;
- methodBody
- : block
- | ';'
- ;
- formalParameterList
- : fixedParameters
- | fixedParameters ',' parameterArray
- | parameterArray
- ;
- fixedParameters
- : fixedParameter
- | fixedParameters ',' fixedParameter
- ;
- fixedParameter
- : attributes? parameterModifier? type Identifier defaultArgument?
- ;
- defaultArgument
- : '=' expression
- ;
- parameterModifier
- : 'ref'
- | 'out'
- | 'this'
- ;
- parameterArray
- : attributes? 'params' arrayType Identifier
- ;
- propertyDeclaration
- : attributes? propertyModifiers? type memberName '{' accessorDeclarations '}'
- ;
- propertyModifiers
- : propertyModifier
- | propertyModifiers propertyModifier
- ;
- propertyModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'static'
- | 'virtual'
- | 'sealed'
- | 'override'
- | 'abstract'
- | 'extern'
- | 'unsafe'
- ;
- accessorDeclarations
- : getAccessorDeclaration setAccessorDeclaration?
- | setAccessorDeclaration getAccessorDeclaration?
- ;
- getAccessorDeclaration
- : attributes? accessorModifier? 'get' accessorBody
- ;
- setAccessorDeclaration
- : attributes? accessorModifier? 'set' accessorBody
- ;
- accessorModifier
- : 'protected'
- | 'internal'
- | 'private'
- | 'protected' 'internal'
- | 'internal' 'protected'
- ;
- accessorBody
- : block
- | ';'
- ;
- eventDeclaration
- : attributes? eventModifiers? 'event' type variableDeclarators ';'
- | attributes? eventModifiers? 'event' type memberName '{' eventAccessorDeclarations '}'
- ;
- eventModifiers
- : eventModifier
- | eventModifiers eventModifier
- ;
- eventModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'static'
- | 'virtual'
- | 'sealed'
- | 'override'
- | 'abstract'
- | 'extern'
- | 'unsafe'
- ;
- eventAccessorDeclarations
- : addAccessorDeclaration removeAccessorDeclaration
- | removeAccessorDeclaration addAccessorDeclaration
- ;
- addAccessorDeclaration
- : attributes? 'add' block
- ;
- removeAccessorDeclaration
- : attributes? 'remove' block
- ;
- indexerDeclaration
- : attributes? indexerModifiers? indexerDeclarator '{' accessorDeclarations '}'
- ;
- indexerModifiers
- : indexerModifier
- | indexerModifiers indexerModifier
- ;
- indexerModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'virtual'
- | 'sealed'
- | 'override'
- | 'abstract'
- | 'extern'
- | 'unsafe'
- ;
- indexerDeclarator
- : type 'this' '[' formalParameterList ']'
- | type interfaceType '.' 'this' '[' formalParameterList ']'
- ;
- operatorDeclaration
- : attributes? operatorModifiers operatorDeclarator operatorBody
- ;
- operatorModifiers
- : operatorModifier
- | operatorModifiers operatorModifier
- ;
- operatorModifier
- : 'public'
- | 'static'
- | 'extern'
- | 'unsafe'
- ;
- operatorDeclarator
- : unaryOperatorDeclarator
- | binaryOperatorDeclarator
- | conversionOperatorDeclarator
- ;
- unaryOperatorDeclarator
- : type 'operator' overloadableUnaryOperator '(' type Identifier ')'
- ;
- overloadableUnaryOperator
- : '+'
- | '-'
- | '!'
- | '~'
- | '++'
- | '--'
- | 'true'
- | 'false'
- ;
- binaryOperatorDeclarator
- : type 'operator' overloadableBinaryOperator '(' type Identifier ',' type Identifier ')'
- ;
- overloadableBinaryOperator
- : '+'
- | '-'
- | '*'
- | '/'
- | '%'
- | '&'
- | '|'
- | '^'
- | '<<'
- | '>>'
- | '=='
- | '!='
- | '>'
- | '<'
- | '>='
- | '<='
- ;
- conversionOperatorDeclarator
- : 'implicit' 'operator' type '(' type Identifier ')'
- | 'explicit' 'operator' type '(' type Identifier ')'
- ;
- operatorBody
- : block
- | ';'
- ;
- constructorDeclaration
- : attributes? constructorModifiers? constructorDeclarator constructorBody
- ;
- constructorModifiers
- : constructorModifier
- | constructorModifiers constructorModifier
- ;
- constructorModifier
- : 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'extern'
- | 'unsafe'
- ;
- constructorDeclarator
- : Identifier '(' formalParameterList? ')' constructorInitializer?
- ;
- constructorInitializer
- : ':' 'base' '(' argumentList? ')'
- | ':' 'this' '(' argumentList? ')'
- ;
- constructorBody
- : block
- | ';'
- ;
- staticConstructorDeclaration
- : attributes? staticConstructorModifiers Identifier '(' ')' staticConstructorBody
- ;
- staticConstructorModifiers
- : 'extern'? 'unsafe'? 'static'
- | 'unsafe'? 'extern'? 'static'
- | 'extern'? 'static' 'unsafe'?
- | 'unsafe'? 'static' 'extern'?
- | 'static' 'extern'? 'unsafe'?
- | 'static' 'unsafe'? 'extern'?
- ;
- staticConstructorBody
- : block
- | ';'
- ;
- destructorDeclaration
- : attributes? 'extern'? 'unsafe'? '~' Identifier '(' ')' destructorBody
- | attributes? 'unsafe'? 'extern'? '~' Identifier '(' ')' destructorBody
- ;
- destructorBody
- : block
- | ';'
- ;
- /**********
- *
- * Structs
- *
- **********/
- structDeclaration
- : attributes? structModifiers? 'partial'? 'struct' Identifier typeParameterList? structInterfaces? typeParameterConstraintsClauses? structBody ';'?
- ;
- structModifiers
- : structModifier
- | structModifiers structModifier
- ;
- structModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'unsafe'
- ;
- structInterfaces
- : ':' interfaceTypeList
- ;
- structBody
- : '{' structMemberDeclarations? '}'
- ;
- structMemberDeclarations
- : structMemberDeclaration
- | structMemberDeclarations structMemberDeclaration
- ;
- structMemberDeclaration
- : constantDeclaration
- | fieldDeclaration
- | methodDeclaration
- | propertyDeclaration
- | eventDeclaration
- | indexerDeclaration
- | operatorDeclaration
- | constructorDeclaration
- | staticConstructorDeclaration
- | typeDeclaration
- | fixedSizeBufferDeclaration
- ;
- fixedSizeBufferDeclaration
- : attributes? fixedSizeBufferModifiers? 'fixed' bufferElementType fixedSizeBufferDeclarators ';'
- ;
- fixedSizeBufferModifiers
- : fixedSizeBufferModifier
- | fixedSizeBufferModifier fixedSizeBufferModifiers
- ;
- fixedSizeBufferModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'unsafe'
- ;
- bufferElementType
- : type
- ;
- fixedSizeBufferDeclarators
- : fixedSizeBufferDeclarator
- | fixedSizeBufferDeclarator fixedSizeBufferDeclarators
- ;
- fixedSizeBufferDeclarator
- : Identifier '[' constantExpression ']'
- ;
- /**********
- *
- * Arrays
- *
- **********/
- arrayType
- : nonArrayType rankSpecifiers
- ;
- nonArrayType
- : type
- ;
- arrayInitializer
- : '{' variableInitializerList? '}'
- | '{' variableInitializerList ',' '}'
- ;
- variableInitializerList
- : variableInitializer
- | variableInitializerList ',' variableInitializer
- ;
- /**********
- *
- * Interfaces
- *
- **********/
- interfaceDeclaration
- : attributes? interfaceModifiers? 'partial'? 'interface' Identifier variantTypeParameterList? interfaceBase? typeParameterConstraintsClauses? interfaceBody ';'?
- ;
- interfaceModifiers
- : interfaceModifier
- | interfaceModifiers interfaceModifier
- ;
- interfaceModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'unsafe'
- ;
- variantTypeParameterList
- : '<' variantTypeParameters '>'
- ;
- variantTypeParameters
- : attributes? varianceAnnotation? typeParameter
- | variantTypeParameters ',' attributes? varianceAnnotation? typeParameter
- ;
- varianceAnnotation
- : 'in'
- | 'out'
- ;
- interfaceBase
- : ':' interfaceTypeList
- ;
- interfaceBody
- : '{' interfaceMemberDeclarations? '}'
- ;
- interfaceMemberDeclarations
- : interfaceMemberDeclaration
- | interfaceMemberDeclarations interfaceMemberDeclaration
- ;
- interfaceMemberDeclaration
- : interfaceMethodDeclaration
- | interfacePropertyDeclaration
- | interfaceEventDeclaration
- | interfaceIndexerDeclaration
- ;
- interfaceMethodDeclaration
- : attributes? 'new'? returnType Identifier typeParameterList? '(' formalParameterList? ')' typeParameterConstraintsClauses? ';'
- ;
- interfacePropertyDeclaration
- : attributes? 'new'? type Identifier '{' interfaceAccessors '}'
- ;
- interfaceAccessors
- : attributes? 'get' ';'
- | attributes? 'set' ';'
- | attributes? 'get' ';' attributes? 'set' ';'
- | attributes? 'set' ';' attributes? 'get' ';'
- ;
- interfaceEventDeclaration
- : attributes? 'new'? 'event' type Identifier ';'
- ;
- interfaceIndexerDeclaration
- : attributes? 'new'? type 'this' '[' formalParameterList ']' '{' interfaceAccessors '}'
- ;
- /**********
- *
- * Enums
- *
- **********/
- enumDeclaration
- : attributes? enumModifiers? 'enum' Identifier enumBase? enumBody ';'?
- ;
- enumBase
- : ':' integralType
- ;
- enumBody
- : '{' enumMemberDeclarations? '}'
- | '{' enumMemberDeclarations ',' '}'
- ;
- enumModifiers
- : enumModifier
- | enumModifiers enumModifier
- ;
- enumModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- ;
- enumMemberDeclarations
- : enumMemberDeclaration
- | enumMemberDeclarations ',' enumMemberDeclaration
- ;
- enumMemberDeclaration
- : attributes? Identifier
- | attributes? Identifier '=' constantExpression
- ;
- /**********
- *
- * Delegates
- *
- **********/
- delegateDeclaration
- : attributes? delegateModifiers? 'delegate' returnType Identifier variantTypeParameterList? '(' formalParameterList? ')' typeParameterConstraintsClauses? ';'
- ;
- delegateModifiers
- : delegateModifier
- | delegateModifiers delegateModifier
- ;
- delegateModifier
- : 'new'
- | 'public'
- | 'protected'
- | 'internal'
- | 'private'
- | 'unsafe'
- ;
- /**********
- *
- * Attributes
- *
- **********/
- globalAttributes
- : globalAttributeSections
- ;
- globalAttributeSections
- : globalAttributeSection
- | globalAttributeSections globalAttributeSection
- ;
- globalAttributeSection
- : '[' globalAttributeTargetSpecifier attributeList ']'
- | '[' globalAttributeTargetSpecifier attributeList ',' ']'
- ;
- globalAttributeTargetSpecifier
- : globalAttributeTarget ':'
- ;
- globalAttributeTarget
- : 'assembly'
- | 'module'
- ;
- attributes
- : attributeSections
- ;
- attributeSections
- : attributeSection
- | attributeSections attributeSection
- ;
- attributeSection
- : '[' attributeTargetSpecifier? attributeList ']'
- | '[' attributeTargetSpecifier? attributeList ',' ']'
- ;
- attributeTargetSpecifier
- : attributeTarget ':'
- ;
- attributeTarget
- : 'field'
- | 'event'
- | 'method'
- | 'param'
- | 'property'
- | 'return'
- | 'type'
- ;
- attributeList
- : attribute
- | attributeList ',' attribute
- ;
- attribute
- : attributeName attributeArguments?
- ;
- attributeName
- : typeName
- ;
- attributeArguments
- : '(' positionalArgumentList? ')'
- | '(' positionalArgumentList ',' namedArgumentList ')'
- | '(' namedArgumentList ')'
- ;
- positionalArgumentList
- : positionalArgument
- | positionalArgumentList ',' positionalArgument
- ;
- positionalArgument
- : argumentName? attributeArgumentExpression
- ;
- namedArgumentList
- : namedArgument
- | namedArgumentList ',' namedArgument
- ;
- namedArgument
- : Identifier '=' attributeArgumentExpression
- ;
- attributeArgumentExpression
- : expression
- ;
- /**********
- *
- * Literals
- *
- **********/
- literal
- : booleanLiteral
- | IntegerLiteral
- | RealLiteral
- | CharacterLiteral
- | StringLiteral
- | NullLiteral
- ;
- booleanLiteral
- : 'true'
- | 'false'
- ;
- IntegerLiteral
- : DecimalIntegerLiteral
- | HexadecimalIntegerLiteral
- ;
- DecimalIntegerLiteral
- : DecimalDigits IntegerTypeSuffix?
- ;
- fragment
- DecimalDigits
- : DecimalDigit+
- ;
- fragment
- DecimalDigit
- : [0-9]
- ;
- fragment
- IntegerTypeSuffix
- : 'U'
- | 'u'
- | 'L'
- | 'l'
- | 'UL'
- | 'Ul'
- | 'uL'
- | 'ul'
- | 'LU'
- | 'Lu'
- | 'lU'
- | 'lu'
- ;
- HexadecimalIntegerLiteral
- : ('0x' | '0X') HexDigits IntegerTypeSuffix?
- ;
- fragment
- HexDigits
- : HexDigit+
- ;
- fragment
- HexDigit
- : [0-9A-Fa-f]
- ;
- RealLiteral
- : DecimalDigits '.' DecimalDigits ExponentPart? RealTypeSuffix?
- | '.' DecimalDigits ExponentPart? RealTypeSuffix?
- | DecimalDigits ExponentPart RealTypeSuffix?
- | DecimalDigits RealTypeSuffix
- ;
- fragment
- ExponentPart
- : ('e' | 'E') Sign? DecimalDigits
- ;
- fragment
- Sign
- : '+'
- | '-'
- ;
- fragment
- RealTypeSuffix
- : 'F'
- | 'f'
- | 'D'
- | 'd'
- | 'M'
- | 'm'
- ;
- CharacterLiteral
- : '\'' Character '\''
- ;
- fragment
- Character
- : SingleCharacter
- | SimpleEscapeSequence
- | HexadecimalEscapeSequence
- | UnicodeEscapeSequence
- ;
- fragment
- UnicodeEscapeSequence
- : '\\' 'u' HexDigit HexDigit HexDigit HexDigit
- | '\\' 'U' HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit
- ;
- fragment
- SingleCharacter
- : ~[\u0027\u005C\u000D\u000A\u0085\u2028\u2029]
- ;
- fragment
- SimpleEscapeSequence
- : '\\\''
- | '\\"'
- | '\\\\'
- | '\\0'
- | '\\a'
- | '\\b'
- | '\\f'
- | '\\n'
- | '\\r'
- | '\\t'
- | '\\v'
- ;
- fragment
- HexadecimalEscapeSequence
- : '\\x' HexDigit HexDigit? HexDigit? HexDigit?
- ;
- StringLiteral
- : RegularStringLiteral
- | VerbatimStringLiteral
- ;
- RegularStringLiteral
- : '"' RegularStringLiteralCharacters? '"'
- ;
- fragment
- RegularStringLiteralCharacters
- : RegularStringLiteralCharacter+
- ;
- fragment
- RegularStringLiteralCharacter
- : SingleRegularStringLiteralCharacter
- | SimpleEscapeSequence
- | HexadecimalEscapeSequence
- | UnicodeEscapeSequence
- ;
- fragment
- SingleRegularStringLiteralCharacter
- : ~["\\\u000D\u000A\u0085\u2028\u2029]
- ;
- VerbatimStringLiteral
- : '@"' VerbatimStringLiteralCharacters? '"'
- ;
- fragment
- VerbatimStringLiteralCharacters
- : VerbatimStringLiteralCharacter+
- ;
- fragment
- VerbatimStringLiteralCharacter
- : SingleVerbatimStringLiteralCharacter
- | QuoteEscapeSequence
- ;
- fragment
- SingleVerbatimStringLiteralCharacter
- : ~["]
- ;
- fragment
- QuoteEscapeSequence
- : '""'
- ;
- NullLiteral
- : 'null'
- ;
- /**********
- *
- * Identifiers
- *
- **********/
- Identifier
- : AvailableIdentifier
- | '@' IdentifierOrKeyword
- ;
- AvailableIdentifier
- : IdentifierOrKeyword
- ;
- IdentifierOrKeyword
- : IdentifierStartCharacter IdentifierPartCharacter*
- ;
- IdentifierStartCharacter
- : LetterCharacter
- | '_'
- ;
- fragment
- IdentifierPartCharacter
- : LetterCharacter
- | DecimalDigitCharacter
- | ConnectingCharacter
- | CombiningCharacter
- | FormattingCharacter
- ;
- fragment
- LetterCharacter
- : UNICODE_CLASS_LU
- | UNICODE_CLASS_LL
- | UNICODE_CLASS_LT
- | UNICODE_CLASS_LM
- | UNICODE_CLASS_LO
- | UNICODE_CLASS_NL
- ;
- fragment
- CombiningCharacter
- : UNICODE_CLASS_MN
- | UNICODE_CLASS_MC
- ;
- fragment
- DecimalDigitCharacter
- : UNICODE_CLASS_ND
- ;
- fragment
- ConnectingCharacter
- : UNICODE_CLASS_PC
- ;
- fragment
- FormattingCharacter
- : UNICODE_CLASS_CF
- ;
- /**********
- *
- * Whitespace and comments
- *
- **********/
- WS : [ \t\r\n\u000C]+ -> skip
- ;
- COMMENT
- : '/*' .*? '*/' -> skip
- ;
- LINE_COMMENT
- : '//' ~[\r\n]* -> skip
- ;
- DIRECTIVE
- : '#' ~[\r\n]* -> skip
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement