using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using ICSharpCode.NRefactory.Parser; using ICSharpCode.NRefactory.Ast; using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute; using Types = ICSharpCode.NRefactory.Ast.ClassType; COMPILER CS /* AW 2002-12-30 renamed from CompilationUnit to CS */ /*------------------------------------------------------------------------* *----- LEXER TOKEN LIST ------------------------------------------------* *------------------------------------------------------------------------*/ /* START AUTOGENERATED TOKENS SECTION */ TOKENS /* ----- terminal classes ----- */ /* EOF is 0 */ ident Literal /* ----- special character ----- */ "=" "+" "-" "*" "/" "%" ":" "::" ";" "?" "??" "," "." "{" "}" "[" "]" "(" ")" ">" "<" "!" "&&" "||" "~" "&" "|" "^" "++" "--" "==" "!=" ">=" "<=" "<<" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" "->" "=>" /* ----- keywords ----- */ "abstract" "as" "base" "bool" "break" "byte" "case" "catch" "char" "checked" "class" "const" "continue" "decimal" "default" "delegate" "do" "double" "else" "enum" "event" "explicit" "extern" "false" "finally" "fixed" "float" "for" "foreach" "goto" "if" "implicit" "in" "int" "interface" "internal" "is" "lock" "long" "namespace" "new" "null" "object" "operator" "out" "override" "params" "private" "protected" "public" "readonly" "ref" "return" "sbyte" "sealed" "short" "sizeof" "stackalloc" "static" "string" "struct" "switch" "this" "throw" "true" "try" "typeof" "uint" "ulong" "unchecked" "unsafe" "ushort" "using" "virtual" "void" "volatile" "while" "partial" "where" "get" "set" "add" "remove" "yield" "select" "group" "by" "into" "from" "ascending" "descending" "orderby" "let" "join" "on" "equals" /* END AUTOGENERATED TOKENS SECTION */ /*------------------------------------------------------------------------* *----- PARSER -----------------------------------------------------------* *------------------------------------------------------------------------*/ PRODUCTIONS /*--- compilation unit: */ CS (. lexer.NextToken(); /* get the first token */ .) = { UsingDirective } { IF (IsGlobalAttrTarget()) GlobalAttributeSection } { NamespaceMemberDecl } EOF . UsingDirective (. string qualident = null; TypeReference aliasedType = null; .) = "using" (. Location startPos = t.Location; .) Qualident [ "=" NonArrayType ] ";" (. if (qualident != null && qualident.Length > 0) { INode node; if (aliasedType != null) { node = new UsingDeclaration(qualident, aliasedType); } else { node = new UsingDeclaration(qualident); } node.StartLocation = startPos; node.EndLocation = t.EndLocation; compilationUnit.AddChild(node); } .) . GlobalAttributeSection = "[" (. Location startPos = t.Location; .) Identifier (. if (t.val != "assembly" && t.val != "module") Error("global attribute target specifier (assembly or module) expected"); string attributeTarget = t.val; List attributes = new List(); ASTAttribute attribute; .) ":" Attribute (. attributes.Add(attribute); .) { IF (NotFinalComma()) "," Attribute (. attributes.Add(attribute); .)} [ "," ] "]" (. AttributeSection section = new AttributeSection { AttributeTarget = attributeTarget, Attributes = attributes, StartLocation = startPos, EndLocation = t.EndLocation }; compilationUnit.AddChild(section); .) . Attribute (. string qualident; string alias = null; .) = (. Location startPos = la.Location; .) [ IF (IdentAndDoubleColon()) Identifier (. alias = t.val; .) "::" ] Qualident (. List positional = new List(); List named = new List(); string name = (alias != null && alias != "global") ? alias + "." + qualident : qualident; .) [ AttributeArguments ] (. attribute = new ASTAttribute(name, positional, named); attribute.StartLocation = startPos; attribute.EndLocation = t.EndLocation; .) . AttributeArguments positional, List named> (. bool nameFound = false; string name = ""; Expression expr; .) = "(" [ [ IF (IsAssignment()) (. nameFound = true; .) Identifier (. name = t.val; .) "=" ] Expr (. if (expr != null) {if(name == "") positional.Add(expr); else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } } .) { "," ( IF (IsAssignment()) (. nameFound = true; .) Identifier (. name = t.val; .) "=" | /*Empty*/ (. if (nameFound) Error("no positional argument after named argument"); .) ) Expr (. if (expr != null) { if(name == "") positional.Add(expr); else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } } .) } ] ")" . AttributeSection (. string attributeTarget = ""; List attributes = new List(); ASTAttribute attribute; .) = "[" (. Location startPos = t.Location; .) /*--- attribute target specifier: */ [ IF (IsLocalAttrTarget()) ( "event" (. attributeTarget = "event";.) | "return" (. attributeTarget = "return";.) | Identifier (. if (t.val != "field" && t.val != "method" && t.val != "param" && t.val != "property" && t.val != "type") Error("attribute target specifier (field, event, method, param, property, return or type) expected"); attributeTarget = t.val; .) ) ":" ] /*--- attribute list: */ Attribute (. attributes.Add(attribute); .) { IF (NotFinalComma()) "," Attribute (. attributes.Add(attribute); .)} [ "," ] "]" (. section = new AttributeSection { AttributeTarget = attributeTarget, Attributes = attributes, StartLocation = startPos, EndLocation = t.EndLocation }; .) . NamespaceMemberDecl (. AttributeSection section; List attributes = new List(); ModifierList m = new ModifierList(); string qualident; .) = /*--- namespace declaration: */ "namespace" (. Location startPos = t.Location; .) Qualident (. INode node = new NamespaceDeclaration(qualident); node.StartLocation = startPos; compilationUnit.AddChild(node); compilationUnit.BlockStart(node); .) "{" { UsingDirective } { NamespaceMemberDecl } "}" [ ";" ] (. node.EndLocation = t.EndLocation; compilationUnit.BlockEnd(); .) /*--- type declaration: */ | { AttributeSection (. attributes.Add(section); .) } { TypeModifier } TypeDecl . TypeDecl attributes> (. TypeReference type; List names; List p = new List(); string name; List templates; .) = /*--- class declaration: */ (. m.Check(Modifiers.Classes); .) "class" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); templates = newType.Templates; compilationUnit.AddChild(newType); compilationUnit.BlockStart(newType); newType.StartLocation = m.GetDeclarationLocation(t.Location); newType.Type = Types.Class; .) Identifier (. newType.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] [ ClassBase (. newType.BaseTypes = names; .) ] /* .NET 2.0 */ { TypeParameterConstraintsClause } (. newType.BodyStartLocation = t.EndLocation; .) "{" ClassBody "}" [ ";" ] (. newType.EndLocation = t.Location; compilationUnit.BlockEnd(); .) | /*--- struct declaration: */ (. m.Check(Modifiers.StructsInterfacesEnumsDelegates); .) ( "struct" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); templates = newType.Templates; newType.StartLocation = m.GetDeclarationLocation(t.Location); compilationUnit.AddChild(newType); compilationUnit.BlockStart(newType); newType.Type = Types.Struct; .) Identifier (. newType.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] [ StructInterfaces (. newType.BaseTypes = names; .) ] /* .NET 2.0 */ { TypeParameterConstraintsClause } (. newType.BodyStartLocation = t.EndLocation; .) StructBody [ ";" ] (. newType.EndLocation = t.Location; compilationUnit.BlockEnd(); .) | /*--- interface declaration: */ "interface" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); templates = newType.Templates; compilationUnit.AddChild(newType); compilationUnit.BlockStart(newType); newType.StartLocation = m.GetDeclarationLocation(t.Location); newType.Type = Types.Interface; .) Identifier (. newType.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] [ InterfaceBase (. newType.BaseTypes = names; .) ] /* .NET 2.0 */ { TypeParameterConstraintsClause } (. newType.BodyStartLocation = t.EndLocation; .) InterfaceBody [ ";" ] (. newType.EndLocation = t.Location; compilationUnit.BlockEnd(); .) | /*--- enumeration declaration: */ "enum" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); compilationUnit.AddChild(newType); compilationUnit.BlockStart(newType); newType.StartLocation = m.GetDeclarationLocation(t.Location); newType.Type = Types.Enum; .) Identifier (. newType.Name = t.val; .) [ ":" IntegralType (. newType.BaseTypes.Add(new TypeReference(name)); .) ] (. newType.BodyStartLocation = t.EndLocation; .) EnumBody [ ";" ] (. newType.EndLocation = t.Location; compilationUnit.BlockEnd(); .) | /*--- delegate declaration: */ "delegate" (. DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes); templates = delegateDeclr.Templates; delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location); .) ( IF (NotVoidPointer()) "void" (. delegateDeclr.ReturnType = new TypeReference("void", 0, null); .) | Type (. delegateDeclr.ReturnType = type; .) ) Identifier (. delegateDeclr.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] "(" [ FormalParameterList

(. delegateDeclr.Parameters = p; .) ] ")" /* .NET 2.0 */ { TypeParameterConstraintsClause } ";" (. delegateDeclr.EndLocation = t.Location; compilationUnit.AddChild(delegateDeclr); .) ) . Qualident = Identifier (. qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); .) { IF (DotAndIdent()) "." Identifier (. qualidentBuilder.Append('.'); qualidentBuilder.Append(t.val); .) } (. qualident = qualidentBuilder.ToString(); .) . ClassBase names> (. TypeReference typeRef; names = new List(); .) = ":" ClassType (. if (typeRef != null) { names.Add(typeRef); } .) { "," TypeName (. if (typeRef != null) { names.Add(typeRef); } .) } . ClassBody (. AttributeSection section; .) = { (.List attributes = new List(); ModifierList m = new ModifierList(); .) SYNC { AttributeSection (. attributes.Add(section); .) } MemberModifiers ClassMemberDecl } . StructInterfaces names> (. TypeReference typeRef; names = new List(); .) = ":" TypeName (. if (typeRef != null) { names.Add(typeRef); } .) { "," TypeName (. if (typeRef != null) { names.Add(typeRef); } .) } . StructBody (. AttributeSection section; .) = "{" { (.List attributes = new List(); ModifierList m = new ModifierList(); .) { AttributeSection (. attributes.Add(section); .) } MemberModifiers StructMemberDecl } "}" . InterfaceBase names> (. TypeReference typeRef; names = new List(); .) = ":" TypeName (. if (typeRef != null) { names.Add(typeRef); } .) { "," TypeName (. if (typeRef != null) { names.Add(typeRef); } .) } . InterfaceBody = "{" { SYNC InterfaceMemberDecl } "}" . EnumBody (. FieldDeclaration f; .) = "{" [ EnumMemberDecl (. compilationUnit.AddChild(f); .) { IF (NotFinalComma()) "," EnumMemberDecl (. compilationUnit.AddChild(f); .) } [","] ] "}" . Type = TypeWithRestriction . TypeWithRestriction (. string name; int pointer = 0; type = null; .) = ( ClassType | SimpleType (. type = new TypeReference(name); .) | "void" "*" (. pointer = 1; type = new TypeReference("void"); .) ) (. List r = new List(); .) [ IF (allowNullable && la.kind == Tokens.Question) NullableQuestionMark ] { IF (IsPointerOrDims()) (. int i = 0; .) ( "*" (. ++pointer; .) | "[" { "," (. ++i; .) } "]" (. r.Add(i); .) ) } (. if (type != null) { type.RankSpecifier = r.ToArray(); type.PointerNestingLevel = pointer; } .) . NonArrayType (. string name; int pointer = 0; type = null; .) = ( ClassType | SimpleType (. type = new TypeReference(name); .) | "void" "*" (. pointer = 1; type = new TypeReference("void"); .) ) [ NullableQuestionMark ] { IF (IsPointer()) "*" (. ++pointer; .) } (. if (type != null) { type.PointerNestingLevel = pointer; } .) . SimpleType (. name = String.Empty; .) = IntegralType | "float" (. name = "float"; .) | "double" (. name = "double"; .) | "decimal" (. name = "decimal"; .) | "bool" (. name = "bool"; .) . FormalParameterList parameter> (. ParameterDeclarationExpression p; AttributeSection section; List attributes = new List(); .) = { AttributeSection (.attributes.Add(section); .) } ( FixedParameter (. bool paramsFound = false; p.Attributes = attributes; parameter.Add(p); .) { "," (. attributes = new List(); if (paramsFound) Error("params array must be at end of parameter list"); .) { AttributeSection (.attributes.Add(section); .) } ( FixedParameter (. p.Attributes = attributes; parameter.Add(p); .) | ParameterArray (. paramsFound = true; p.Attributes = attributes; parameter.Add(p); .) ) } | ParameterArray (. p.Attributes = attributes; parameter.Add(p); .) ) . FixedParameter (. TypeReference type; ParameterModifiers mod = ParameterModifiers.In; Location start = t.Location; .) = [ "ref" (. mod = ParameterModifiers.Ref; .) | "out" (. mod = ParameterModifiers.Out; .) ] Type Identifier (. p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .) . ParameterArray (. TypeReference type; .) = "params" Type Identifier (. p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); .) . AccessorModifiers (. m = new ModifierList(); .) = "private" (. m.Add(Modifiers.Private, t.Location); .) | "protected" (. m.Add(Modifiers.Protected, t.Location); .) ["internal" (. m.Add(Modifiers.Internal, t.Location); .)] | "internal" (. m.Add(Modifiers.Internal, t.Location); .) ["protected" (. m.Add(Modifiers.Protected, t.Location); .)] . TypeModifier = "new" (. m.Add(Modifiers.New, t.Location); .) | "public" (. m.Add(Modifiers.Public, t.Location); .) | "protected" (. m.Add(Modifiers.Protected, t.Location); .) | "internal" (. m.Add(Modifiers.Internal, t.Location); .) | "private" (. m.Add(Modifiers.Private, t.Location); .) | "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .) | "abstract" (. m.Add(Modifiers.Abstract, t.Location); .) | "sealed" (. m.Add(Modifiers.Sealed, t.Location); .) | "static" (. m.Add(Modifiers.Static, t.Location); .) | "partial" (. m.Add(Modifiers.Partial, t.Location); .) . ClassType (. TypeReference r; typeRef = null; .) = TypeName (. typeRef = r; .) | "object" (. typeRef = new TypeReference("object"); .) | "string" (. typeRef = new TypeReference("string"); .) . IntegralType (. name = ""; .) = "sbyte" (. name = "sbyte"; .) | "byte" (. name = "byte"; .) | "short" (. name = "short"; .) | "ushort" (. name = "ushort"; .) | "int" (. name = "int"; .) | "uint" (. name = "uint"; .) | "long" (. name = "long"; .) | "ulong" (. name = "ulong"; .) | "char" (. name = "char"; .) . MemberModifiers = { "abstract" (. m.Add(Modifiers.Abstract, t.Location); .) | "extern" (. m.Add(Modifiers.Extern, t.Location); .) | "internal" (. m.Add(Modifiers.Internal, t.Location); .) | "new" (. m.Add(Modifiers.New, t.Location); .) | "override" (. m.Add(Modifiers.Override, t.Location); .) | "private" (. m.Add(Modifiers.Private, t.Location); .) | "protected" (. m.Add(Modifiers.Protected, t.Location); .) | "public" (. m.Add(Modifiers.Public, t.Location); .) | "readonly" (. m.Add(Modifiers.ReadOnly, t.Location); .) | "sealed" (. m.Add(Modifiers.Sealed, t.Location); .) | "static" (. m.Add(Modifiers.Static, t.Location); .) | "fixed" (. m.Add(Modifiers.Fixed, t.Location); .) | "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .) | "virtual" (. m.Add(Modifiers.Virtual, t.Location); .) | "volatile" (. m.Add(Modifiers.Volatile, t.Location); .) | "partial" (. m.Add(Modifiers.Partial, t.Location); .) } . StructMemberDecl attributes> (. string qualident = null; TypeReference type; Expression expr; List p = new List(); Statement stmt = null; List variableDeclarators = new List(); List templates = new List(); TypeReference explicitInterface = null; bool isExtensionMethod = false; .) = /*--- constant declaration: */ (. m.Check(Modifiers.Constants); .) "const" (.Location startPos = t.Location; .) Type Identifier (. FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifiers.Const); fd.StartLocation = m.GetDeclarationLocation(startPos); VariableDeclaration f = new VariableDeclaration(t.val); fd.Fields.Add(f); .) "=" Expr (. f.Initializer = expr; .) { "," Identifier (. f = new VariableDeclaration(t.val); fd.Fields.Add(f); .) "=" Expr (. f.Initializer = expr; .) } ";" (. fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); .) | /*--- void method (procedure) declaration: */ IF (NotVoidPointer()) (. m.Check(Modifiers.PropertysEventsMethods); .) "void" (. Location startPos = t.Location; .) ( IF (IsExplicitInterfaceImplementation()) TypeName (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); } .) | Identifier (. qualident = t.val; .) ) /* .NET 2.0 */ [ TypeParameterList ] "(" [ "this" (. isExtensionMethod = true; /* C# 3.0 */ .) ] [ FormalParameterList

] ")" (. MethodDeclaration methodDeclaration = new MethodDeclaration { Name = qualident, Modifier = m.Modifier, TypeReference = new TypeReference("void"), Parameters = p, Attributes = attributes, StartLocation = m.GetDeclarationLocation(startPos), EndLocation = t.EndLocation, Templates = templates, IsExtensionMethod = isExtensionMethod }; if (explicitInterface != null) methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); compilationUnit.AddChild(methodDeclaration); compilationUnit.BlockStart(methodDeclaration); .) /* .NET 2.0 */ { TypeParameterConstraintsClause } ( Block | ";" ) (. compilationUnit.BlockEnd(); methodDeclaration.Body = (BlockStatement)stmt; .) | /*--- event declaration: */ (. m.Check(Modifiers.PropertysEventsMethods); .) "event" (. EventDeclaration eventDecl = new EventDeclaration { Modifier = m.Modifier, Attributes = attributes, StartLocation = t.Location }; compilationUnit.AddChild(eventDecl); compilationUnit.BlockStart(eventDecl); EventAddRegion addBlock = null; EventRemoveRegion removeBlock = null; .) Type (. eventDecl.TypeReference = type; .) ( IF (IsExplicitInterfaceImplementation()) TypeName (. qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); .) (. eventDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); .) | Identifier (. qualident = t.val; .) ) (. eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; .) [ "=" Expr (. eventDecl.Initializer = expr; .) ] [ "{" (. eventDecl.BodyStart = t.Location; .) EventAccessorDecls "}" (. eventDecl.BodyEnd = t.EndLocation; .) ] [ ";" ] (. compilationUnit.BlockEnd(); eventDecl.AddRegion = addBlock; eventDecl.RemoveRegion = removeBlock; .) | /*--- constructor or static contructor declaration: */ IF (IdentAndLPar()) (. m.Check(Modifiers.Constructors | Modifiers.StaticConstructors); .) Identifier (. string name = t.val; Location startPos = t.Location; .) "(" [ (. m.Check(Modifiers.Constructors); .) FormalParameterList

] ")" (.ConstructorInitializer init = null; .) [ (. m.Check(Modifiers.Constructors); .) ConstructorInitializer ] (. ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, init, attributes); cd.StartLocation = startPos; cd.EndLocation = t.EndLocation; .) ( Block | ";" ) (. cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); .) | /*--- conversion operator declaration: */ (. m.Check(Modifiers.Operators); if (m.isNone) Error("at least one modifier must be set"); bool isImplicit = true; Location startPos = Location.Empty; .) ( "implicit" (. startPos = t.Location; .) | "explicit" (. isImplicit = false; startPos = t.Location; .) ) "operator" Type (. TypeReference operatorType = type; .) "(" Type Identifier (. string varName = t.val; .) ")" (. Location endPos = t.Location; .) ( Block | ";" (. stmt = null; .) ) (. List parameters = new List(); parameters.Add(new ParameterDeclarationExpression(type, varName)); OperatorDeclaration operatorDeclaration = new OperatorDeclaration { Modifier = m.Modifier, Attributes = attributes, Parameters = parameters, TypeReference = operatorType, ConversionType = isImplicit ? ConversionType.Implicit : ConversionType.Explicit, Body = (BlockStatement)stmt, StartLocation = m.GetDeclarationLocation(startPos), EndLocation = endPos }; compilationUnit.AddChild(operatorDeclaration); .) | /*--- inner type declaration: */ TypeDecl | Type (. Location startPos = t.Location; .) ( /*--- operator declaration: */ (. OverloadableOperatorType op; m.Check(Modifiers.Operators); if (m.isNone) Error("at least one modifier must be set"); .) "operator" OverloadableOperator (. TypeReference firstType, secondType = null; string secondName = null; .) "(" Type Identifier (. string firstName = t.val; .) ( "," Type Identifier (. secondName = t.val; .) /* (. if (Tokens.OverloadableUnaryOp[op.kind] && !Tokens.OverloadableBinaryOp[op.kind]) Error("too many operands for unary operator"); .)*/ | /* empty */ /*(. if (Tokens.OverloadableBinaryOp[op.kind]){ Error("too few operands for binary operator"); } .)*/ ) (. Location endPos = t.Location; .) ")" ( Block | ";" ) (. List parameters = new List(); parameters.Add(new ParameterDeclarationExpression(firstType, firstName)); if (secondType != null) { parameters.Add(new ParameterDeclarationExpression(secondType, secondName)); } OperatorDeclaration operatorDeclaration = new OperatorDeclaration { Modifier = m.Modifier, Attributes = attributes, Parameters = parameters, TypeReference = type, OverloadableOperator = op, Body = (BlockStatement)stmt, StartLocation = m.GetDeclarationLocation(startPos), EndLocation = endPos }; compilationUnit.AddChild(operatorDeclaration); .) /*--- field declaration: */ | IF (IsVarDecl()) (. m.Check(Modifiers.Fields); FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier); fd.StartLocation = m.GetDeclarationLocation(startPos); .) ( IF (m.Contains(Modifiers.Fixed)) VariableDeclarator "[" Expr (. if (variableDeclarators.Count > 0) variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; .) "]" { "," VariableDeclarator "[" Expr (. if (variableDeclarators.Count > 0) variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; .) "]" } | /* non-fixed field */ VariableDeclarator { "," VariableDeclarator } ) ";" (. fd.EndLocation = t.EndLocation; fd.Fields = variableDeclarators; compilationUnit.AddChild(fd); .) /*--- unqualified indexer declaration (without interface name): */ | (. m.Check(Modifiers.Indexers); .) "this" "[" FormalParameterList

"]" (. Location endLocation = t.EndLocation; .) "{" (. IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes); indexer.StartLocation = startPos; indexer.EndLocation = endLocation; indexer.BodyStart = t.Location; PropertyGetRegion getRegion; PropertySetRegion setRegion; .) AccessorDecls "}" (. indexer.BodyEnd = t.EndLocation; indexer.GetRegion = getRegion; indexer.SetRegion = setRegion; compilationUnit.AddChild(indexer); .) | IF (IsIdentifierToken(la)) ( IF (IsExplicitInterfaceImplementation()) TypeName (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); } .) | Identifier (. qualident = t.val; .) ) (. Location qualIdentEndLocation = t.EndLocation; .) ( /*--- "not void" method (function) declaration: */ ( (. m.Check(Modifiers.PropertysEventsMethods); .) /* .NET 2.0 */ [ TypeParameterList ] "(" [ "this" (. isExtensionMethod = true; .) ] [ FormalParameterList

] ")" (. MethodDeclaration methodDeclaration = new MethodDeclaration { Name = qualident, Modifier = m.Modifier, TypeReference = type, Parameters = p, Attributes = attributes }; if (explicitInterface != null) methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos); methodDeclaration.EndLocation = t.EndLocation; methodDeclaration.IsExtensionMethod = isExtensionMethod; methodDeclaration.Templates = templates; compilationUnit.AddChild(methodDeclaration); .) { TypeParameterConstraintsClause } ( Block | ";" ) (. methodDeclaration.Body = (BlockStatement)stmt; .) /*--- property declaration: */ | "{" (. PropertyDeclaration pDecl = new PropertyDeclaration(qualident, type, m.Modifier, attributes); if (explicitInterface != null) pDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); pDecl.StartLocation = m.GetDeclarationLocation(startPos); pDecl.EndLocation = qualIdentEndLocation; pDecl.BodyStart = t.Location; PropertyGetRegion getRegion; PropertySetRegion setRegion; .) AccessorDecls "}" (. pDecl.GetRegion = getRegion; pDecl.SetRegion = setRegion; pDecl.BodyEnd = t.EndLocation; compilationUnit.AddChild(pDecl); .) ) /*--- qualified indexer declaration (with interface name): */ | (. m.Check(Modifiers.Indexers); .) "." "this" "[" FormalParameterList

"]" (. IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes); indexer.StartLocation = m.GetDeclarationLocation(startPos); indexer.EndLocation = t.EndLocation; if (explicitInterface != null) indexer.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, "this")); PropertyGetRegion getRegion; PropertySetRegion setRegion; .) "{" (. Location bodyStart = t.Location; .) AccessorDecls "}" (. indexer.BodyStart = bodyStart; indexer.BodyEnd = t.EndLocation; indexer.GetRegion = getRegion; indexer.SetRegion = setRegion; compilationUnit.AddChild(indexer); .) ) ) . ClassMemberDecl attributes> (. Statement stmt = null; .) = StructMemberDecl | /*--- destructor declaration: */ (. m.Check(Modifiers.Destructors); Location startPos = t.Location; .) "~" Identifier (. DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes); d.Modifier = m.Modifier; d.StartLocation = m.GetDeclarationLocation(startPos); .) "(" ")" (. d.EndLocation = t.EndLocation; .) ( Block | ";" ) (. d.Body = (BlockStatement)stmt; compilationUnit.AddChild(d); .) . InterfaceMemberDecl (. TypeReference type; AttributeSection section; Modifiers mod = Modifiers.None; List attributes = new List(); List parameters = new List(); string name; PropertyGetRegion getBlock; PropertySetRegion setBlock; Location startLocation = new Location(-1, -1); List templates = new List(); .) = { AttributeSection (. attributes.Add(section); .)} [ "new" (. mod = Modifiers.New; startLocation = t.Location; .) ] ( /*--- interface void method (procedure) declaration: */ IF (NotVoidPointer()) "void" (. if (startLocation.X == -1) startLocation = t.Location; .) Identifier (. name = t.val; .) [ TypeParameterList ] "(" [ FormalParameterList ] ")" { TypeParameterConstraintsClause } ";" (. MethodDeclaration md = new MethodDeclaration { Name = name, Modifier = mod, TypeReference = new TypeReference("void"), Parameters = parameters, Attributes = attributes, Templates = templates, StartLocation = startLocation, EndLocation = t.EndLocation }; compilationUnit.AddChild(md); .) | ( Type (. if (startLocation.X == -1) startLocation = t.Location; .) ( Identifier (. name = t.val; Location qualIdentEndLocation = t.EndLocation; .) ( /*--- interface "not void" method (function) declaration: */ /* .NET 2.0 */ [ TypeParameterList ] "(" [ FormalParameterList ] ")" /* .NET 2.0 */ { TypeParameterConstraintsClause } ";" (. MethodDeclaration md = new MethodDeclaration { Name = name, Modifier = mod, TypeReference = type, Parameters = parameters, Attributes = attributes, Templates = templates, StartLocation = startLocation, EndLocation = t.EndLocation }; compilationUnit.AddChild(md); .) /*--- interface property declaration: */ | (. PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes); compilationUnit.AddChild(pd); .) "{" (. Location bodyStart = t.Location;.) InterfaceAccessors "}" (. pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; .) ) /*--- interface indexer declaration: */ | "this" "[" FormalParameterList "]" (.Location bracketEndLocation = t.EndLocation; .) (. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes); compilationUnit.AddChild(id); .) "{" (. Location bodyStart = t.Location;.) InterfaceAccessors "}" (. id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation;.) ) /*--- interface event declaration: */ | "event" (. if (startLocation.X == -1) startLocation = t.Location; .) Type Identifier (. EventDeclaration ed = new EventDeclaration { TypeReference = type, Name = t.val, Modifier = mod, Attributes = attributes }; compilationUnit.AddChild(ed); .) ";" (. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .) ) ) . EnumMemberDecl (. Expression expr = null; List attributes = new List(); AttributeSection section = null; VariableDeclaration varDecl = null; .) = { AttributeSection (. attributes.Add(section); .) } Identifier (. f = new FieldDeclaration(attributes); varDecl = new VariableDeclaration(t.val); f.Fields.Add(varDecl); f.StartLocation = t.Location; .) [ "=" Expr (. varDecl.Initializer = expr; .) ] . AccessorDecls (. List attributes = new List(); AttributeSection section; getBlock = null; setBlock = null; ModifierList modifiers = null; .) = { AttributeSection (. attributes.Add(section); .) } [ AccessorModifiers ] ( GetAccessorDecl (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .) [ (. attributes = new List(); modifiers = null; .) { AttributeSection (. attributes.Add(section); .) } [ AccessorModifiers ] SetAccessorDecl (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .) ] | SetAccessorDecl (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .) [ (. attributes = new List(); modifiers = null; .) { AttributeSection (. attributes.Add(section); .) } [ AccessorModifiers ] GetAccessorDecl (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .) ] | Identifier (. Error("get or set accessor declaration expected"); .) ) . GetAccessorDecl attributes> (. Statement stmt = null; .) = "get" (. Location startLocation = t.Location; .) ( Block | ";" ) (. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .) (. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .) . SetAccessorDecl attributes> (. Statement stmt = null; .) = "set" (. Location startLocation = t.Location; .) ( Block | ";" ) (. setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); .) (. setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; .) . EventAccessorDecls (. AttributeSection section; List attributes = new List(); Statement stmt; addBlock = null; removeBlock = null; .) = { AttributeSection (. attributes.Add(section); .) } ( (. addBlock = new EventAddRegion(attributes); .) AddAccessorDecl (. attributes = new List(); addBlock.Block = (BlockStatement)stmt; .) { AttributeSection (. attributes.Add(section); .)} RemoveAccessorDecl (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; .) | RemoveAccessorDecl (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; attributes = new List(); .) { AttributeSection (. attributes.Add(section); .) } AddAccessorDecl (. addBlock = new EventAddRegion(attributes); addBlock.Block = (BlockStatement)stmt; .) ) . InterfaceAccessors (. AttributeSection section; List attributes = new List(); getBlock = null; setBlock = null; PropertyGetSetRegion lastBlock = null; .) = { AttributeSection (. attributes.Add(section); .) } (. Location startLocation = la.Location; .) ( "get" (. getBlock = new PropertyGetRegion(null, attributes); .) | "set" (. setBlock = new PropertySetRegion(null, attributes); .) ) ";" (. if (getBlock != null) { getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; } if (setBlock != null) { setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; } attributes = new List(); .) [ { AttributeSection (. attributes.Add(section); .) } (. startLocation = la.Location; .) ( "get" (. if (getBlock != null) Error("get already declared"); else { getBlock = new PropertyGetRegion(null, attributes); lastBlock = getBlock; } .) | "set" (. if (setBlock != null) Error("set already declared"); else { setBlock = new PropertySetRegion(null, attributes); lastBlock = setBlock; } .) ) ";" (. if (lastBlock != null) { lastBlock.StartLocation = startLocation; lastBlock.EndLocation = t.EndLocation; } .) ] . VariableDeclarator fieldDeclaration> (. Expression expr = null; .) = Identifier (. VariableDeclaration f = new VariableDeclaration(t.val); .) [ "=" VariableInitializer (. f.Initializer = expr; .) ] (. fieldDeclaration.Add(f); .) . Block /* not BlockStatement because of EmbeddedStatement */ = "{" (. BlockStatement blockStmt = new BlockStatement(); blockStmt.StartLocation = t.Location; compilationUnit.BlockStart(blockStmt); if (!ParseMethodBodies) lexer.SkipCurrentBlock(0); .) { Statement } "}" (. stmt = blockStmt; blockStmt.EndLocation = t.EndLocation; compilationUnit.BlockEnd(); .) . AddAccessorDecl (.stmt = null;.) = "add" Block . RemoveAccessorDecl (.stmt = null;.) = "remove" Block . ConstructorInitializer (. Expression expr; ci = new ConstructorInitializer(); .) = ":" ( "base" (. ci.ConstructorInitializerType = ConstructorInitializerType.Base; .) | "this" (. ci.ConstructorInitializerType = ConstructorInitializerType.This; .) ) "(" [ Argument (. if (expr != null) { ci.Arguments.Add(expr); } .) { "," Argument (. if (expr != null) { ci.Arguments.Add(expr); } .) } ] ")" . VariableInitializer (. TypeReference type = null; Expression expr = null; initializerExpression = null; .) = Expr | CollectionInitializer | "stackalloc" Type "[" Expr "]" (. initializerExpression = new StackAllocExpression(type, expr); .) . OverloadableOperator (. op = OverloadableOperatorType.None; .) = "+" (. op = OverloadableOperatorType.Add; .) | "-" (. op = OverloadableOperatorType.Subtract; .) | "!" (. op = OverloadableOperatorType.Not; .) | "~" (. op = OverloadableOperatorType.BitNot; .) | "++" (. op = OverloadableOperatorType.Increment; .) | "--" (. op = OverloadableOperatorType.Decrement; .) | "true" (. op = OverloadableOperatorType.IsTrue; .) | "false" (. op = OverloadableOperatorType.IsFalse; .) | "*" (. op = OverloadableOperatorType.Multiply; .) | "/" (. op = OverloadableOperatorType.Divide; .) | "%" (. op = OverloadableOperatorType.Modulus; .) | "&" (. op = OverloadableOperatorType.BitwiseAnd; .) | "|" (. op = OverloadableOperatorType.BitwiseOr; .) | "^" (. op = OverloadableOperatorType.ExclusiveOr; .) | "<<" (. op = OverloadableOperatorType.ShiftLeft; .) | "==" (. op = OverloadableOperatorType.Equality; .) | "!=" (. op = OverloadableOperatorType.InEquality; .) | "<" (. op = OverloadableOperatorType.LessThan; .) | ">=" (. op = OverloadableOperatorType.GreaterThanOrEqual; .) | "<=" (. op = OverloadableOperatorType.LessThanOrEqual; .) | ">" (. op = OverloadableOperatorType.GreaterThan; .) [ ">" (. op = OverloadableOperatorType.ShiftRight; .) ] . Argument (. Expression expr; FieldDirection fd = FieldDirection.None; .) = [ "ref" (. fd = FieldDirection.Ref; .) | "out" (. fd = FieldDirection.Out; .) ] Expr (. argumentexpr = fd != FieldDirection.None ? argumentexpr = new DirectionExpression(fd, expr) : expr; .) . AssignmentOperator (. op = AssignmentOperatorType.None; .) = "=" (. op = AssignmentOperatorType.Assign; .) | "+=" (. op = AssignmentOperatorType.Add; .) | "-=" (. op = AssignmentOperatorType.Subtract; .) | "*=" (. op = AssignmentOperatorType.Multiply; .) | "/=" (. op = AssignmentOperatorType.Divide; .) | "%=" (. op = AssignmentOperatorType.Modulus; .) | "&=" (. op = AssignmentOperatorType.BitwiseAnd; .) | "|=" (. op = AssignmentOperatorType.BitwiseOr; .) | "^=" (. op = AssignmentOperatorType.ExclusiveOr; .) | "<<=" (. op = AssignmentOperatorType.ShiftLeft; .) | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) ">" ">=" (. op = AssignmentOperatorType.ShiftRight; .) . CollectionInitializer (. Expression expr = null; CollectionInitializerExpression initializer = new CollectionInitializerExpression(); .) = "{" (. initializer.StartLocation = t.Location; .) [ VariableInitializer (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) { IF (NotFinalComma()) "," VariableInitializer (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) } [ "," ] ] "}" (. initializer.EndLocation = t.Location; outExpr = initializer; .) . CollectionOrObjectInitializer (. Expression expr = null; CollectionInitializerExpression initializer = new CollectionInitializerExpression(); .) = "{" (. initializer.StartLocation = t.Location; .) [ ObjectPropertyInitializerOrVariableInitializer (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) { IF (NotFinalComma()) "," ObjectPropertyInitializerOrVariableInitializer (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) } [ "," ] ] "}" (. initializer.EndLocation = t.Location; outExpr = initializer; .) . ObjectPropertyInitializerOrVariableInitializer (. expr = null; .) = ( IF (IdentAndAsgn()) Identifier (. NamedArgumentExpression nae = new NamedArgumentExpression(t.val, null); nae.StartLocation = t.Location; Expression r = null; .) "=" ( CollectionOrObjectInitializer | VariableInitializer ) (. nae.Expression = r; nae.EndLocation = t.EndLocation; expr = nae; .) | VariableInitializer ) . LocalVariableDecl (. TypeReference type; VariableDeclaration var = null; LocalVariableDeclaration localVariableDeclaration; .) = Type (. localVariableDeclaration = new LocalVariableDeclaration(type); localVariableDeclaration.StartLocation = t.Location; .) LocalVariableDeclarator (. localVariableDeclaration.Variables.Add(var); .) { "," LocalVariableDeclarator (. localVariableDeclaration.Variables.Add(var); .) } (. stmt = localVariableDeclaration; .) . LocalVariableDeclarator (. Expression expr = null; .) = Identifier (. var = new VariableDeclaration(t.val); .) [ "=" VariableInitializer (. var.Initializer = expr; .) ] . Statement (. TypeReference type; Expression expr; Statement stmt = null; Location startPos = la.Location; .) = SYNC ( /*--- labeled statement: */ IF (IsLabel()) Identifier (. compilationUnit.AddChild(new LabelStatement(t.val)); .) ":" Statement /*--- local constant declaration: */ | "const" Type (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.Const); string ident = null; var.StartLocation = t.Location; .) Identifier (. ident = t.val; .) "=" Expr (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) { "," Identifier (. ident = t.val; .) "=" Expr (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) } ";" (. compilationUnit.AddChild(var); .) /*--- local variable declaration: */ | IF (IsLocalVarDecl()) LocalVariableDecl ";" (. compilationUnit.AddChild(stmt); .) | EmbeddedStatement (. compilationUnit.AddChild(stmt); .) /* LL(1) confict: LocalVariableDecl * * <-> StatementExpr * * ident {"." ident} { "[" Expr ... */ ) (. if (stmt != null) { stmt.StartLocation = startPos; stmt.EndLocation = t.EndLocation; } .) . EmbeddedStatement (. TypeReference type = null; Expression expr = null; Statement embeddedStatement = null; statement = null; .) = (. Location startLocation = la.Location; .) ( Block /*--- empty statement: */ | ";" (. statement = new EmptyStatement(); .) /*--- checked / unchecked statement: */ | IF (UnCheckedAndLBrace()) (. Statement block; bool isChecked = true; .) ("checked" | "unchecked" (. isChecked = false;.) ) Block (. statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); .) /*--- selection statements (if, switch): */ | IfStatement | "switch" (. List switchSections = new List(); .) "(" Expr ")" "{" SwitchSections "}" (. statement = new SwitchStatement(expr, switchSections); .) /*--- iteration statements (while, do, for, foreach): */ | "while" "(" Expr ")" EmbeddedStatement (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);.) | "do" EmbeddedStatement "while" "(" Expr ")" ";" (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); .) | "for" (. List initializer = null; List iterator = null; .) "(" [ ForInitializer ] ";" [ Expr ] ";" [ ForIterator ] ")" EmbeddedStatement (. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .) | "foreach" "(" Type Identifier (. string varName = t.val; .) "in" Expr ")" EmbeddedStatement (. statement = new ForeachStatement(type, varName , expr, embeddedStatement); .) /*--- jump statements (break, contine, goto, return, throw): */ | "break" ";" (. statement = new BreakStatement(); .) | "continue" ";" (. statement = new ContinueStatement(); .) | GotoStatement | IF (IsYieldStatement()) "yield" ( "return" Expr (. statement = new YieldStatement(new ReturnStatement(expr)); .) | "break" (. statement = new YieldStatement(new BreakStatement()); .) ) ";" | "return" [ Expr ] ";" (. statement = new ReturnStatement(expr); .) | "throw" [ Expr ] ";" (. statement = new ThrowStatement(expr); .) /*--- expression statement: */ | StatementExpr SYNC ";" /*--- try statement: */ | TryStatement /*--- lock satement: */ | "lock" "(" Expr ")" EmbeddedStatement (. statement = new LockStatement(expr, embeddedStatement); .) /*--- using statement: */ | (.Statement resourceAcquisitionStmt = null; .) "using" "(" ResourceAcquisition ")" EmbeddedStatement (. statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); .) /*--- unsafe statement: */ | "unsafe" Block (. statement = new UnsafeStatement(embeddedStatement); .) /*--- fixed statement: */ | "fixed" "(" Type (. if (type == null || type.PointerNestingLevel == 0) Error("can only fix pointer types"); List pointerDeclarators = new List(1); .) Identifier (. string identifier = t.val; .) "=" Expr (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .) { "," Identifier (. identifier = t.val; .) "=" Expr (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .) } ")" EmbeddedStatement (. statement = new FixedStatement(type, pointerDeclarators, embeddedStatement); .) ) (. if (statement != null) { statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } .) . IfStatement (. Expression expr = null; Statement embeddedStatement = null; statement = null; .) = "if" "(" Expr ")" EmbeddedStatement (. Statement elseStatement = null; .) [ "else" EmbeddedStatement ] (. statement = elseStatement != null ? new IfElseStatement(expr, embeddedStatement, elseStatement) : new IfElseStatement(expr, embeddedStatement); .) (. if (elseStatement is IfElseStatement && (elseStatement as IfElseStatement).TrueStatement.Count == 1) { /* else if-section (otherwise we would have a BlockStatment) */ (statement as IfElseStatement).ElseIfSections.Add( new ElseIfSection((elseStatement as IfElseStatement).Condition, (elseStatement as IfElseStatement).TrueStatement[0])); (statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections); (statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement; } .) . ForInitializer initializer> (. Statement stmt; initializer = new List(); .) = IF (IsLocalVarDecl()) LocalVariableDecl (. initializer.Add(stmt);.) | StatementExpr (.initializer.Add(stmt);.) { "," StatementExpr (. initializer.Add(stmt);.) } . ForIterator iterator> (. Statement stmt; iterator = new List(); .) = StatementExpr (. iterator.Add(stmt);.) { "," StatementExpr (. iterator.Add(stmt); .) } . SwitchSections switchSections> (. SwitchSection switchSection = new SwitchSection(); CaseLabel label; .) = SwitchLabel (. if (label != null) { switchSection.SwitchLabels.Add(label); } .) (. compilationUnit.BlockStart(switchSection); .) { ( SwitchLabel (. if (label != null) { if (switchSection.Children.Count > 0) { // open new section compilationUnit.BlockEnd(); switchSections.Add(switchSection); switchSection = new SwitchSection(); compilationUnit.BlockStart(switchSection); } switchSection.SwitchLabels.Add(label); } .) | Statement) } (. compilationUnit.BlockEnd(); switchSections.Add(switchSection); .) . SwitchLabel (. Expression expr = null; label = null; .) = "case" Expr ":" (. label = new CaseLabel(expr); .) | "default" ":" (. label = new CaseLabel(); .) . TryStatement (. Statement blockStmt = null, finallyStmt = null; List catchClauses = null; .) = "try" Block ( CatchClauses [ "finally" Block ] | "finally" Block ) (. tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt); .) . CatchClauses catchClauses> (. catchClauses = new List(); .) = "catch" (. string identifier; Statement stmt; TypeReference typeRef; .) /*--- general catch clause (as only catch clause) */ ( Block (. catchClauses.Add(new CatchClause(stmt)); .) /*--- specific catch clause */ | "(" ClassType (. identifier = null; .) [ Identifier (. identifier = t.val; .) ] ")" Block (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) { IF (IsTypedCatch()) "catch" "(" ClassType (. identifier = null; .) [ Identifier (. identifier = t.val; .) ] ")" Block (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) } /*--- general catch clause (after specific catch clauses, optional) */ [ "catch" Block (. catchClauses.Add(new CatchClause(stmt)); .) ] ) . GotoStatement (. Expression expr; stmt = null; .) = "goto" ( Identifier (. stmt = new GotoStatement(t.val); .) ";" | "case" Expr ";" (. stmt = new GotoCaseStatement(expr); .) | "default" ";" (. stmt = new GotoCaseStatement(null); .) ) . ResourceAcquisition (. stmt = null; Expression expr; .) = ( IF (IsLocalVarDecl()) LocalVariableDecl | Expr /* LL(1) conflict resoltion: * * check if next is Qualident followed by ident * * ==> LocalVariableDecl * * new problem: first set of ResourceAcquisition changes */ (. stmt = new ExpressionStatement(expr); .) ) . StatementExpr (. Expression expr; .) = Expr /* The grammar allows only assignments or method invocations here, */ /* but we don't enforce that here */ (. stmt = new ExpressionStatement(expr); .) . Expr (. expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; .) = (. Location startLocation = la.Location; .) UnaryExpr /*--- conditional expression: */ ( ( AssignmentOperator Expr (. expr = new AssignmentExpression(expr, op, expr1); .) ) | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) ( AssignmentOperator Expr (. expr = new AssignmentExpression(expr, op, expr1); .) ) | ( ConditionalOrExpr [ "??" Expr (. expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); .) ] [ "?" Expr ":" Expr (. expr = new ConditionalExpression(expr, expr1, expr2); .) ] ) ) (. if (expr != null) { expr.StartLocation = startLocation; expr.EndLocation = t.EndLocation; } .) . UnaryExpr (. TypeReference type = null; Expression expr = null; ArrayList expressions = new ArrayList(); uExpr = null; .) = { /* IF (Tokens.UnaryOp[la.kind] || IsTypeCast()) */ ( "+" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); .) | "-" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); .) | "!" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); .) | "~" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); .) | "*" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Star)); .) | "++" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); .) | "--" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Decrement)); .) | "&" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitWiseAnd)); .) /*--- cast expression: */ /* Problem: "(" Type ")" from here and * * "(" Expr ")" from PrimaryExpr * * Solution: (in IsTypeCast()) */ | IF (IsTypeCast()) "(" Type ")" (. expressions.Add(new CastExpression(type)); .) ) } /* special rule (2.4.4.2) to allow writing int.MinValue and long.MinValue */ ( IF (LastExpressionIsUnaryMinus(expressions) && IsMostNegativeIntegerWithoutTypeSuffix()) Literal (. expressions.RemoveAt(expressions.Count - 1); if (t.literalValue is uint) { expr = new PrimitiveExpression(int.MinValue, int.MinValue.ToString()); } else if (t.literalValue is ulong) { expr = new PrimitiveExpression(long.MinValue, long.MinValue.ToString()); } else { throw new Exception("t.literalValue must be uint or ulong"); } .) | PrimaryExpr ) (. for (int i = 0; i < expressions.Count; ++i) { Expression nextExpression = i + 1 < expressions.Count ? (Expression)expressions[i + 1] : expr; if (expressions[i] is CastExpression) { ((CastExpression)expressions[i]).Expression = nextExpression; } else { ((UnaryOperatorExpression)expressions[i]).Expression = nextExpression; } } if (expressions.Count > 0) { uExpr = (Expression)expressions[0]; } else { uExpr = expr; } .) . PrimaryExpr (. TypeReference type = null; Expression expr; pexpr = null; .) = (. Location startLocation = la.Location; .) ( "true" (.pexpr = new PrimitiveExpression(true, "true"); .) | "false" (.pexpr = new PrimitiveExpression(false, "false"); .) | "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */ | Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .) | IF (StartOfQueryExpression()) QueryExpression | IF (IdentAndDoubleColon()) Identifier (. type = new TypeReference(t.val); .) "::" (. pexpr = new TypeReferenceExpression(type); .) Identifier (. if (type.Type == "global") { type.IsGlobal = true; type.Type = (t.val ?? "?"); } else type.Type += "." + (t.val ?? "?"); .) /*--- simple name (IdentifierExpression): */ | Identifier (. pexpr = new IdentifierExpression(t.val); .) [ ShortedLambdaExpression<(IdentifierExpression)pexpr, out pexpr> | IF (IsGenericInSimpleNameOrMemberAccess()) (. List typeList; .) TypeArgumentList (. ((IdentifierExpression)pexpr).TypeArguments = typeList; .) ] | IF (IsLambdaExpression()) /* Lambda expression */ LambdaExpression /*--- parenthesized expression: */ | "(" Expr ")" (. pexpr = new ParenthesizedExpression(expr); .) | /*--- predefined type member access: */ (. string val = null; .) ( "bool" (. val = "bool"; .) | "byte" (. val = "byte"; .) | "char" (. val = "char"; .) | "decimal" (. val = "decimal"; .) | "double" (. val = "double"; .) | "float" (. val = "float"; .) | "int" (. val = "int"; .) | "long" (. val = "long"; .) | "object" (. val = "object"; .) | "sbyte" (. val = "sbyte"; .) | "short" (. val = "short"; .) | "string" (. val = "string"; .) | "uint" (. val = "uint"; .) | "ulong" (. val = "ulong"; .) | "ushort" (. val = "ushort"; .) ) MemberAccess /*--- this access: */ | "this" (. pexpr = new ThisReferenceExpression(); .) /*--- base access: */ | "base" (. pexpr = new BaseReferenceExpression(); .) /* new ... - ObjectCreationExpression or ArrayCreateExpression */ | NewExpression | "typeof" "(" ( IF (NotVoidPointer()) "void" (. type = new TypeReference("void"); .) | TypeWithRestriction ) ")" (. pexpr = new TypeOfExpression(type); .) | "default" "(" Type ")" (. pexpr = new DefaultValueExpression(type); .) | "sizeof" "(" Type ")" (. pexpr = new SizeOfExpression(type); .) | "checked" "(" Expr ")" (. pexpr = new CheckedExpression(expr); .) | "unchecked" "(" Expr ")" (. pexpr = new UncheckedExpression(expr); .) | "delegate" AnonymousMethodExpr (. pexpr = expr; .) ) (. if (pexpr != null) { pexpr.StartLocation = startLocation; pexpr.EndLocation = t.EndLocation; } .) { (. startLocation = la.Location; .) ( "++" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); .) | "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .) ) /*--- member access */ | PointerMemberAccess | MemberAccess /*--- invocation expression: */ | "(" (. List parameters = new List(); .) [ Argument (. if (expr != null) {parameters.Add(expr);} .) { "," Argument (. if (expr != null) {parameters.Add(expr);} .) } ] ")" (. pexpr = new InvocationExpression(pexpr, parameters); .) /*--- element access */ | (. /*if (isArrayCreation) Error("element access not allow on array creation");*/ List indices = new List(); .) "[" Expr (. if (expr != null) { indices.Add(expr); } .) { "," Expr (. if (expr != null) { indices.Add(expr); } .) } "]" (. pexpr = new IndexerExpression(pexpr, indices); .) (. if (pexpr != null) { pexpr.StartLocation = startLocation; pexpr.EndLocation = t.EndLocation; } .) } . MemberAccess (. List typeList; .) = (. if (ShouldConvertTargetExpressionToTypeReference(target)) { TypeReference type = GetTypeReferenceFromExpression(target); if (type != null) { target = new TypeReferenceExpression(type) { StartLocation = t.Location, EndLocation = t.EndLocation }; } } t.val = ""; // required for TypeReferenceExpressionTests.StandaloneIntReferenceExpression hack .) "." Identifier (. expr = new MemberReferenceExpression(target, t.val); .) [ IF (IsGenericInSimpleNameOrMemberAccess()) TypeArgumentList (. ((MemberReferenceExpression)expr).TypeArguments = typeList; .) ] . PointerMemberAccess (. List typeList; .) = "->" Identifier (. expr = new PointerReferenceExpression(target, t.val); .) [ IF (IsGenericInSimpleNameOrMemberAccess()) TypeArgumentList (. ((MemberReferenceExpression)expr).TypeArguments = typeList; .) ] . NewExpression (. pexpr = null; List parameters = new List(); TypeReference type = null; Expression expr; .) = "new" [ NonArrayType ] /* optional since .NET 3.0 */ /*--- delegate / object creation expression: */ /* Note: a delegate creation expression allow only a single Expr */ /* not an argument list, but this is not distinguished here */ ( ( (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .) "(" (. if (type == null) Error("Cannot use an anonymous type with arguments for the constructor"); .) [ Argument (. if (expr != null) { parameters.Add(expr); } .) { "," Argument (. if (expr != null) { parameters.Add(expr); } .) } ] ")" (. pexpr = oce; .) [ CollectionOrObjectInitializer (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .) ] | (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .) CollectionOrObjectInitializer (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .) (. pexpr = oce; .) ) /*--- array creation expression: */ | "[" (. ArrayCreateExpression ace = new ArrayCreateExpression(type); /* we must not change RankSpecifier on the null type reference*/ if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); } pexpr = ace; int dims = 0; List ranks = new List(); .) ( { "," (. dims += 1; .) } "]" (. ranks.Add(dims); dims = 0; .) { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) } (. ace.CreateType.RankSpecifier = ranks.ToArray(); .) CollectionInitializer (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .) | Expr (. if (expr != null) parameters.Add(expr); .) { "," (. dims += 1; .) Expr (. if (expr != null) parameters.Add(expr); .) } "]" (. ranks.Add(dims); ace.Arguments = parameters; dims = 0; .) { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) } (. ace.CreateType.RankSpecifier = ranks.ToArray(); .) [ CollectionInitializer (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .) ] ) ) . /* Lambda expression with parameter list */ LambdaExpression (. LambdaExpression lambda = new LambdaExpression(); lambda.StartLocation = la.Location; ParameterDeclarationExpression p; outExpr = lambda; .) = "(" [ LambdaExpressionParameter (. if (p != null) lambda.Parameters.Add(p); .) { "," LambdaExpressionParameter (. if (p != null) lambda.Parameters.Add(p); .) } ] ")" "=>" LambdaExpressionBody . ShortedLambdaExpression (. LambdaExpression lambda = new LambdaExpression(); pexpr = lambda; .) = "=>" /* not an IdentifierExpression, but a short lambda expression*/ (. lambda.StartLocation = ident.StartLocation; lambda.Parameters.Add(new ParameterDeclarationExpression(null, ident.Identifier)); lambda.Parameters[0].StartLocation = ident.StartLocation; lambda.Parameters[0].EndLocation = ident.EndLocation; .) LambdaExpressionBody . LambdaExpressionParameter (. Location start = la.Location; p = null; TypeReference type; .) = ( IF (Peek(1).kind == Tokens.Comma || Peek(1).kind == Tokens.CloseParenthesis) Identifier (. p = new ParameterDeclarationExpression(null, t.val); p.StartLocation = start; p.EndLocation = t.EndLocation; .) | Type Identifier (. p = new ParameterDeclarationExpression(type, t.val); p.StartLocation = start; p.EndLocation = t.EndLocation; .) ) . LambdaExpressionBody (. Expression expr; BlockStatement stmt; .) = ( BlockInsideExpression (. lambda.StatementBody = stmt; .) | Expr (. lambda.ExpressionBody = expr; .) ) (. lambda.EndLocation = t.EndLocation; .) . AnonymousMethodExpr (. AnonymousMethodExpression expr = new AnonymousMethodExpression(); expr.StartLocation = t.Location; BlockStatement stmt; List p = new List(); outExpr = expr; .) = [ "(" [ FormalParameterList

(. expr.Parameters = p; .) ] ")" (. expr.HasParameterList = true; .) ] BlockInsideExpression (. expr.Body = stmt; .) (. expr.EndLocation = t.Location; .) . BlockInsideExpression (. Statement stmt = null; outStmt = null; .) = /*--- ParseExpression doesn't set a compilation unit, */ /*--- so we can't use block then -> skip body of anonymous method */ (. if (compilationUnit != null) { .) Block (. outStmt = (BlockStatement)stmt; .) (. } else { .) "{" (. lexer.SkipCurrentBlock(0); .) "}" (. } .) . ConditionalOrExpr (. Expression expr; .) = ConditionalAndExpr { "||" UnaryExpr ConditionalAndExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr); .) } . ConditionalAndExpr (. Expression expr; .) = InclusiveOrExpr { "&&" UnaryExpr InclusiveOrExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr); .) } . InclusiveOrExpr (. Expression expr; .) = ExclusiveOrExpr { "|" UnaryExpr ExclusiveOrExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr); .) } . ExclusiveOrExpr (. Expression expr; .) = AndExpr { "^" UnaryExpr AndExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr); .) } . AndExpr (. Expression expr; .) = EqualityExpr { "&" UnaryExpr EqualityExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr); .) } . EqualityExpr (. Expression expr; BinaryOperatorType op = BinaryOperatorType.None; .) = RelationalExpr { ( "!=" (. op = BinaryOperatorType.InEquality; .) | "==" (. op = BinaryOperatorType.Equality; .) ) UnaryExpr RelationalExpr (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) } . RelationalExpr (. TypeReference type; Expression expr; BinaryOperatorType op = BinaryOperatorType.None; .) = ShiftExpr { ( "<" (. op = BinaryOperatorType.LessThan; .) | ">" (. op = BinaryOperatorType.GreaterThan; .) | "<=" (. op = BinaryOperatorType.LessThanOrEqual; .) | ">=" (. op = BinaryOperatorType.GreaterThanOrEqual; .) ) UnaryExpr ShiftExpr (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) | ( "is" TypeWithRestriction [ IF (la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) NullableQuestionMark ] (. outExpr = new TypeOfIsExpression(outExpr, type); .) | "as" TypeWithRestriction [ IF (la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) NullableQuestionMark ] (. outExpr = new CastExpression(type, outExpr, CastType.TryCast); .) ) } . ShiftExpr (. Expression expr; BinaryOperatorType op = BinaryOperatorType.None; .) = AdditiveExpr { ( "<<" (. op = BinaryOperatorType.ShiftLeft; .) | IF (IsShiftRight()) ( ">" ">" (. op = BinaryOperatorType.ShiftRight; .) ) ) UnaryExpr AdditiveExpr (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) } . AdditiveExpr (. Expression expr; BinaryOperatorType op = BinaryOperatorType.None; .) = MultiplicativeExpr { ( "+" (. op = BinaryOperatorType.Add; .) | "-" (. op = BinaryOperatorType.Subtract; .) ) UnaryExpr MultiplicativeExpr (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) } . MultiplicativeExpr (. Expression expr; BinaryOperatorType op = BinaryOperatorType.None; .) = { ( "*" (. op = BinaryOperatorType.Multiply; .) | "/" (. op = BinaryOperatorType.Divide; .) | "%" (. op = BinaryOperatorType.Modulus; .) ) UnaryExpr (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) } . /* .NET 2.0 rules */ TypeName (. List typeArguments = null; string alias = null; string qualident; .) = [ IF (IdentAndDoubleColon()) Identifier (. alias = t.val; .) "::" ] Qualident [TypeArgumentList] (. if (alias == null) { typeRef = new TypeReference(qualident, typeArguments); } else if (alias == "global") { typeRef = new TypeReference(qualident, typeArguments); typeRef.IsGlobal = true; } else { typeRef = new TypeReference(alias + "." + qualident, typeArguments); } .) { IF (DotAndIdent()) "." (. typeArguments = null; .) Qualident [TypeArgumentList] (. typeRef = new InnerClassTypeReference(typeRef, qualident, typeArguments); .) } . NullableQuestionMark (. List typeArguments = new List(1); .) = "?" (. if (typeRef != null) typeArguments.Add(typeRef); typeRef = new TypeReference("System.Nullable", typeArguments); .) . TypeArgumentList types, bool canBeUnbound> (. types = new List(); TypeReference type = null; .) = "<" ( IF (canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma)) (. types.Add(TypeReference.Null); .) { "," (. types.Add(TypeReference.Null); .) } | Type (. if (type != null) { types.Add(type); } .) { "," Type (. if (type != null) { types.Add(type); } .) } ) ">" . TypeParameterList templates> (. AttributeSection section; List attributes = new List(); .) = "<" { AttributeSection (. attributes.Add(section); .) } Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .) { "," { AttributeSection (. attributes.Add(section); .) } Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .)} ">" . TypeParameterConstraintsClause templates> (. string name = ""; TypeReference type; .) = "where" Identifier (. name = t.val; .) ":" TypeParameterConstraintsClauseBase (. TemplateDefinition td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { td = d; break; } } if ( td != null && type != null) { td.Bases.Add(type); } .) { "," TypeParameterConstraintsClauseBase (. td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { td = d; break; } } if ( td != null && type != null) { td.Bases.Add(type); } .) } . TypeParameterConstraintsClauseBase (. TypeReference t; type = null; .) = "struct" (. type = TypeReference.StructConstraint; .) | "class" (. type = TypeReference.ClassConstraint; .) | "new" "(" ")" (. type = TypeReference.NewConstraint; .) | Type (. type = t; .) . QueryExpression (. QueryExpression q = new QueryExpression(); outExpr = q; q.StartLocation = la.Location; QueryExpressionFromClause fromClause; .) = QueryExpressionFromClause (. q.FromClause = fromClause; .) QueryExpressionBody (. q.EndLocation = t.EndLocation; .) . QueryExpressionFromClause (. fc = new QueryExpressionFromClause(); fc.StartLocation = la.Location; .) = "from" QueryExpressionFromOrJoinClause (. fc.EndLocation = t.EndLocation; .) . QueryExpressionJoinClause (. jc = new QueryExpressionJoinClause(); jc.StartLocation = la.Location; Expression expr; .) = "join" QueryExpressionFromOrJoinClause "on" Expr (. jc.OnExpression = expr; .) "equals" Expr (. jc.EqualsExpression = expr; .) [ "into" Identifier (. jc.IntoIdentifier = t.val; .) ] (. jc.EndLocation = t.EndLocation; .) . QueryExpressionFromOrJoinClause (. TypeReference type; Expression expr; .) = (. fjc.Type = null; .) [ IF (IsLocalVarDecl()) Type (. fjc.Type = type; .) ] Identifier (. fjc.Identifier = t.val; .) "in" Expr (. fjc.InExpression = expr; .) . QueryExpressionBody (. QueryExpressionFromClause fromClause; QueryExpressionWhereClause whereClause; QueryExpressionLetClause letClause; QueryExpressionJoinClause joinClause; QueryExpressionSelectClause selectClause; QueryExpressionGroupClause groupClause; QueryExpressionIntoClause intoClause; .) = { ( QueryExpressionFromClause (. SafeAdd(q, q.FromLetWhereClauses, fromClause); .) | QueryExpressionWhereClause (. SafeAdd(q, q.FromLetWhereClauses, whereClause); .) | QueryExpressionLetClause (. SafeAdd(q, q.FromLetWhereClauses, letClause); .) | QueryExpressionJoinClause (. SafeAdd(q, q.FromLetWhereClauses, joinClause); .) ) } [ QueryExpressionOrderByClause ] ( QueryExpressionSelectClause (. q.SelectOrGroupClause = selectClause; .) | QueryExpressionGroupClause (. q.SelectOrGroupClause = groupClause; .) ) [ QueryExpressionIntoClause (. q.IntoClause = intoClause; .) ] . QueryExpressionWhereClause (. Expression expr; wc = new QueryExpressionWhereClause(); wc.StartLocation = la.Location; .) = "where" Expr (. wc.Condition = expr; .) (. wc.EndLocation = t.EndLocation; .) . QueryExpressionLetClause (. Expression expr; wc = new QueryExpressionLetClause(); wc.StartLocation = la.Location; .) = "let" Identifier (. wc.Identifier = t.val; .) "=" Expr (. wc.Expression = expr; .) (. wc.EndLocation = t.EndLocation; .) . QueryExpressionOrderByClause (. QueryExpressionOrdering ordering; .) = "orderby" QueryExpressionOrderingClause (. SafeAdd(q, q.Orderings, ordering); .) { "," QueryExpressionOrderingClause (. SafeAdd(q, q.Orderings, ordering); .) } . QueryExpressionOrderingClause (. Expression expr; ordering = new QueryExpressionOrdering(); ordering.StartLocation = la.Location; .) = Expr (. ordering.Criteria = expr; .) [ "ascending" (. ordering.Direction = QueryExpressionOrderingDirection.Ascending; .) | "descending" (. ordering.Direction = QueryExpressionOrderingDirection.Descending; .) ] (. ordering.EndLocation = t.EndLocation; .) . QueryExpressionSelectClause (. Expression expr; sc = new QueryExpressionSelectClause(); sc.StartLocation = la.Location; .) = "select" Expr (. sc.Projection = expr; .) (. sc.EndLocation = t.EndLocation; .) . QueryExpressionGroupClause (. Expression expr; gc = new QueryExpressionGroupClause(); gc.StartLocation = la.Location; .) = "group" Expr (. gc.Projection = expr; .) "by" Expr (. gc.GroupBy = expr; .) (. gc.EndLocation = t.EndLocation; .) . QueryExpressionIntoClause (. ic = new QueryExpressionIntoClause(); ic.StartLocation = la.Location; .) = "into" Identifier (. ic.IntoIdentifier = t.val; .) (. ic.ContinuedQuery = new QueryExpression(); .) (. ic.ContinuedQuery.StartLocation = la.Location; .) QueryExpressionBody (. ic.ContinuedQuery.EndLocation = t.EndLocation; .) (. ic.EndLocation = t.EndLocation; .) . /* allow usage of context sensitive keywords as identifiers */ Identifier = /* when updating this list, ensure you also change KeywordList.IdentifierTokens*/ ident | "partial" | "where" | "get" | "set" | "add" | "remove" | "yield" | "select" | "group" | "by" | "into" | "from" | "ascending" | "descending" | "orderby" | "let" | "join" | "on" | "equals" . END CS.