using System.Drawing; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using ICSharpCode.NRefactory.Parser; using ICSharpCode.NRefactory.Parser.AST; using ASTAttribute = ICSharpCode.NRefactory.Parser.AST.Attribute; using Types = ICSharpCode.NRefactory.Parser.AST.ClassType; COMPILER CS /* AW 2002-12-30 renamed from CompilationUnit to CS */ /*----------------------------- token sets -------------------------------*/ string assemblyName = null; StringBuilder qualidentBuilder = new StringBuilder(); public string ContainingAssembly { set { assemblyName = value; } } Token t { [System.Diagnostics.DebuggerStepThrough] get { return lexer.Token; } } Token la { [System.Diagnostics.DebuggerStepThrough] get { return lexer.LookAhead; } } public void Error(string s) { if (errDist >= minErrDist) { errors.Error(la.line, la.col, s); } errDist = 0; } public override Expression ParseExpression() { lexer.NextToken(); Expression expr; Expr(out expr); return expr; } // Begin ISTypeCast bool IsTypeCast() { if (la.kind != Tokens.OpenParenthesis) { return false; } if (IsSimpleTypeCast()) { return true; } return GuessTypeCast(); } // "(" ( typeKW [ "[" {","} "]" | "*" ] | void ( "[" {","} "]" | "*" ) ) ")" // only for built-in types, all others use GuessTypeCast! bool IsSimpleTypeCast () { // assert: la.kind == _lpar lexer.StartPeek(); Token pt = lexer.Peek(); if (!IsTypeKWForTypeCast(ref pt)) { return false; } if (pt.kind == Tokens.Question) pt = lexer.Peek(); return pt.kind == Tokens.CloseParenthesis; } /* !!! Proceeds from current peek position !!! */ bool IsTypeKWForTypeCast(ref Token pt) { if (Tokens.TypeKW[pt.kind]) { pt = lexer.Peek(); if (pt.kind == Tokens.Times || pt.kind == Tokens.OpenSquareBracket) { return IsPointerOrDims(ref pt); } else { return true; } } else if (pt.kind == Tokens.Void) { pt = lexer.Peek(); return IsPointerOrDims(ref pt); } return false; } /* !!! Proceeds from current peek position !!! */ bool IsTypeNameOrKWForTypeCast(ref Token pt) { if (IsTypeKWForTypeCast(ref pt)) return true; else return IsTypeNameForTypeCast(ref pt); } // TypeName = ident [ "::" ident ] { "." ident } ["<" TypeNameOrKW { "," TypeNameOrKW } ">" ] PointerOrDims /* !!! Proceeds from current peek position !!! */ bool IsTypeNameForTypeCast(ref Token pt) { // ident if (pt.kind != Tokens.Identifier) { return false; } pt = Peek(); // "::" ident if (pt.kind == Tokens.DoubleColon) { pt = Peek(); if (pt.kind != Tokens.Identifier) { return false; } pt = Peek(); } // { "." ident } while (pt.kind == Tokens.Dot) { pt = Peek(); if (pt.kind != Tokens.Identifier) { return false; } pt = Peek(); } if (pt.kind == Tokens.LessThan) { do { pt = Peek(); if (!IsTypeNameOrKWForTypeCast(ref pt)) { return false; } } while (pt.kind == Tokens.Comma); if (pt.kind != Tokens.GreaterThan) { return false; } pt = Peek(); } if (pt.kind == Tokens.Times || pt.kind == Tokens.OpenSquareBracket) { return IsPointerOrDims(ref pt); } return true; } // "(" TypeName ")" castFollower bool GuessTypeCast () { // assert: la.kind == _lpar StartPeek(); Token pt = Peek(); if (!IsTypeNameForTypeCast(ref pt)) { return false; } // ")" if (pt.kind != Tokens.CloseParenthesis) { return false; } // check successor pt = Peek(); return Tokens.CastFollower[pt.kind] || (Tokens.TypeKW[pt.kind] && lexer.Peek().kind == Tokens.Dot); } // END IsTypeCast /* Checks whether the next sequences of tokens is a qualident * * and returns the qualident string */ /* !!! Proceeds from current peek position !!! */ bool IsQualident(ref Token pt, out string qualident) { if (pt.kind == Tokens.Identifier) { qualidentBuilder.Length = 0; qualidentBuilder.Append(pt.val); pt = Peek(); while (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) { pt = Peek(); if (pt.kind != Tokens.Identifier) { qualident = String.Empty; return false; } qualidentBuilder.Append('.'); qualidentBuilder.Append(pt.val); pt = Peek(); } qualident = qualidentBuilder.ToString(); return true; } qualident = String.Empty; return false; } /* Skips generic type extensions */ /* !!! Proceeds from current peek position !!! */ /* skip: { "*" | "[" { "," } "]" } */ /* !!! Proceeds from current peek position !!! */ bool IsPointerOrDims (ref Token pt) { for (;;) { if (pt.kind == Tokens.OpenSquareBracket) { do pt = Peek(); while (pt.kind == Tokens.Comma); if (pt.kind != Tokens.CloseSquareBracket) return false; } else if (pt.kind != Tokens.Times) break; pt = Peek(); } return true; } /* Return the n-th token after the current lookahead token */ void StartPeek() { lexer.StartPeek(); } Token Peek() { return lexer.Peek(); } Token Peek (int n) { lexer.StartPeek(); Token x = la; while (n > 0) { x = lexer.Peek(); n--; } return x; } /*-----------------------------------------------------------------* * Resolver routines to resolve LL(1) conflicts: * * * These resolution routine return a boolean value that indicates * * whether the alternative at hand shall be choosen or not. * * They are used in IF ( ... ) expressions. * *-----------------------------------------------------------------*/ /* True, if ident is followed by "=" */ bool IdentAndAsgn () { return la.kind == Tokens.Identifier && Peek(1).kind == Tokens.Assign; } bool IsAssignment () { return IdentAndAsgn(); } /* True, if ident is followed by ",", "=", or ";" */ bool IdentAndCommaOrAsgnOrSColon () { int peek = Peek(1).kind; return la.kind == Tokens.Identifier && (peek == Tokens.Comma || peek == Tokens.Assign || peek == Tokens.Semicolon); } bool IsVarDecl () { return IdentAndCommaOrAsgnOrSColon(); } /* True, if the comma is not a trailing one, * * like the last one in: a, b, c, */ bool NotFinalComma () { int peek = Peek(1).kind; return la.kind == Tokens.Comma && peek != Tokens.CloseCurlyBrace && peek != Tokens.CloseSquareBracket; } /* True, if "void" is followed by "*" */ bool NotVoidPointer () { return la.kind == Tokens.Void && Peek(1).kind != Tokens.Times; } /* True, if "checked" or "unchecked" are followed by "{" */ bool UnCheckedAndLBrace () { return la.kind == Tokens.Checked || la.kind == Tokens.Unchecked && Peek(1).kind == Tokens.OpenCurlyBrace; } /* True, if "." is followed by an ident */ bool DotAndIdent () { return la.kind == Tokens.Dot && Peek(1).kind == Tokens.Identifier; } /* True, if ident is followed by ":" */ bool IdentAndColon () { return la.kind == Tokens.Identifier && Peek(1).kind == Tokens.Colon; } bool IsLabel () { return IdentAndColon(); } /* True, if ident is followed by "(" */ bool IdentAndLPar () { return la.kind == Tokens.Identifier && Peek(1).kind == Tokens.OpenParenthesis; } /* True, if "catch" is followed by "(" */ bool CatchAndLPar () { return la.kind == Tokens.Catch && Peek(1).kind == Tokens.OpenParenthesis; } bool IsTypedCatch () { return CatchAndLPar(); } /* True, if "[" is followed by the ident "assembly" */ bool IsGlobalAttrTarget () { Token pt = Peek(1); return la.kind == Tokens.OpenSquareBracket && pt.kind == Tokens.Identifier && pt.val == "assembly"; } /* True, if "[" is followed by "," or "]" */ bool LBrackAndCommaOrRBrack () { int peek = Peek(1).kind; return la.kind == Tokens.OpenSquareBracket && (peek == Tokens.Comma || peek == Tokens.CloseSquareBracket); } bool IsDims () { return LBrackAndCommaOrRBrack(); } /* True, if "[" is followed by "," or "]" */ /* or if the current token is "*" */ bool TimesOrLBrackAndCommaOrRBrack () { return la.kind == Tokens.Times || LBrackAndCommaOrRBrack(); } bool IsPointerOrDims () { return TimesOrLBrackAndCommaOrRBrack(); } bool IsPointer () { return la.kind == Tokens.Times; } bool SkipGeneric(ref Token pt) { if (pt.kind == Tokens.LessThan) { int braces = 1; while (braces != 0) { pt = Peek(); if (pt.kind == Tokens.GreaterThan) { --braces; } else if (pt.kind == Tokens.LessThan) { ++braces; } else if (pt.kind == Tokens.Semicolon || pt.kind == Tokens.OpenCurlyBrace || pt.kind == Tokens.CloseCurlyBrace || pt.kind == Tokens.EOF) { return false; } } pt = Peek(); } return true; } bool SkipQuestionMark(ref Token pt) { if (pt.kind == Tokens.Question) { pt = Peek(); } return true; } /* True, if lookahead is a primitive type keyword, or */ /* if it is a type declaration followed by an ident */ bool IsLocalVarDecl () { if (IsYieldStatement()) { return false; } if ((Tokens.TypeKW[la.kind] && Peek(1).kind != Tokens.Dot) || la.kind == Tokens.Void) { return true; } StartPeek(); Token pt = la ; string ignore; if (!IsQualident(ref pt, out ignore)) return false; if (!SkipGeneric(ref pt)) return false; while (pt.kind == Tokens.Dot) { pt = Peek(); if (!IsQualident(ref pt, out ignore)) return false; if (!SkipGeneric(ref pt)) return false; } return SkipQuestionMark(ref pt) && IsPointerOrDims(ref pt) && pt.kind == Tokens.Identifier; } /* True if lookahead is type parameters (<...>) followed by the specified token */ bool IsGenericFollowedBy(int token) { Token t = la; if (t.kind != Tokens.LessThan) return false; StartPeek(); return SkipGeneric(ref t) && t.kind == token; } bool IsExplicitInterfaceImplementation() { StartPeek(); Token pt = la; pt = Peek(); if (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) return true; if (pt.kind == Tokens.LessThan) { if (SkipGeneric(ref pt)) return pt.kind == Tokens.Dot; } return false; } /* True, if lookahead ident is "where" */ bool IdentIsWhere () { return la.kind == Tokens.Identifier && la.val == "where"; } /* True, if lookahead ident is "get" */ bool IdentIsGet () { return la.kind == Tokens.Identifier && la.val == "get"; } /* True, if lookahead ident is "set" */ bool IdentIsSet () { return la.kind == Tokens.Identifier && la.val == "set"; } /* True, if lookahead ident is "add" */ bool IdentIsAdd () { return la.kind == Tokens.Identifier && la.val == "add"; } /* True, if lookahead ident is "remove" */ bool IdentIsRemove () { return la.kind == Tokens.Identifier && la.val == "remove"; } bool IsNotYieldStatement () { return !IsYieldStatement(); } /* True, if lookahead ident is "yield" and than follows a break or return */ bool IsYieldStatement () { return la.kind == Tokens.Identifier && la.val == "yield" && (Peek(1).kind == Tokens.Return || Peek(1).kind == Tokens.Break); } /* True, if lookahead is a local attribute target specifier, * * i.e. one of "event", "return", "field", "method", * * "module", "param", "property", or "type" */ bool IsLocalAttrTarget () { int cur = la.kind; string val = la.val; return (cur == Tokens.Event || cur == Tokens.Return || (cur == Tokens.Identifier && (val == "field" || val == "method" || val == "module" || val == "param" || val == "property" || val == "type"))) && Peek(1).kind == Tokens.Colon; } bool IsShiftRight() { Token next = Peek(1); // TODO : Add col test (seems not to work, lexer bug...) : && la.col == next.col - 1 return (la.kind == Tokens.GreaterThan && next.kind == Tokens.GreaterThan); } bool IsTypeReferenceExpression(Expression expr) { if (expr is TypeReferenceExpression) return ((TypeReferenceExpression)expr).TypeReference.GenericTypes.Count == 0; while (expr is FieldReferenceExpression) { expr = ((FieldReferenceExpression)expr).TargetObject; if (expr is TypeReferenceExpression) return true; } return expr is IdentifierExpression; } TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List genericTypes) { TypeReferenceExpression tre = expr as TypeReferenceExpression; if (tre != null) { return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes)); } StringBuilder b = new StringBuilder(); if (!WriteFullTypeName(b, expr)) { // there is some TypeReferenceExpression hidden in the expression while (expr is FieldReferenceExpression) { expr = ((FieldReferenceExpression)expr).TargetObject; } tre = expr as TypeReferenceExpression; if (tre != null) { TypeReference typeRef = tre.TypeReference; if (typeRef.GenericTypes.Count == 0) { typeRef = typeRef.Clone(); typeRef.Type += "." + b.ToString(); typeRef.GenericTypes.AddRange(genericTypes); } else { typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes); } return new TypeReferenceExpression(typeRef); } } return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes)); } /* Writes the type name represented through the expression into the string builder. */ /* Returns true when the expression was converted successfully, returns false when */ /* There was an unknown expression (e.g. TypeReferenceExpression) in it */ bool WriteFullTypeName(StringBuilder b, Expression expr) { FieldReferenceExpression fre = expr as FieldReferenceExpression; if (fre != null) { bool result = WriteFullTypeName(b, fre.TargetObject); if (b.Length > 0) b.Append('.'); b.Append(fre.FieldName); return result; } else if (expr is IdentifierExpression) { b.Append(((IdentifierExpression)expr).Identifier); return true; } else { return false; } } /*------------------------------------------------------------------------* *----- 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" /* END AUTOGENERATED TOKENS SECTION */ /*------------------------------------------------------------------------* *----- PARSER -----------------------------------------------------------* *------------------------------------------------------------------------*/ PRODUCTIONS /*--- compilation unit: */ CS (. lexer.NextToken(); /* get the first token */ compilationUnit = new CompilationUnit(); .) = { UsingDirective } { IF (IsGlobalAttrTarget()) GlobalAttributeSection } { NamespaceMemberDecl } EOF . UsingDirective (. string qualident = null; TypeReference aliasedType = null; .) = "using" (. Point 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 = "[" (. Point startPos = t.Location; .) ident (. if (t.val != "assembly") Error("global attribute target specifier (\"assembly\") 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, attributes); section.StartLocation = startPos; section.EndLocation = t.EndLocation; compilationUnit.AddChild(section); .) . Attribute (. string qualident; string alias = null; .) = [ IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) ident (. alias = t.val; .) "::" ] Qualident (. List positional = new List(); List named = new List(); string name = (alias != null && alias != "global") ? alias + "." + qualident : qualident; .) [ AttributeArguments ] (. attribute = new ICSharpCode.NRefactory.Parser.AST.Attribute(name, positional, named);.) . AttributeArguments positional, List named> (. bool nameFound = false; string name = ""; Expression expr; .) = "(" [ [ IF (IsAssignment()) (. nameFound = true; .) ident (. name = t.val; .) "=" ] Expr (. if (expr != null) {if(name == "") positional.Add(expr); else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } } .) { "," ( IF (IsAssignment()) (. nameFound = true; .) ident (. 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; .) = "[" (. Point startPos = t.Location; .) /*--- attribute target specifier: */ [ IF (IsLocalAttrTarget()) ( "event" (. attributeTarget = "event";.) | "return" (. attributeTarget = "return";.) | ident (. if (t.val != "field" || t.val != "method" || t.val != "module" || t.val != "param" || t.val != "property" || t.val != "type") Error("attribute target specifier (event, return, field," + "method, module, param, property, or type) expected"); attributeTarget = t.val; .) ) ":" ] /*--- attribute list: */ Attribute (. attributes.Add(attribute); .) { IF (NotFinalComma()) "," Attribute (. attributes.Add(attribute); .)} [ "," ] "]" (. section = new AttributeSection(attributeTarget, attributes); section.StartLocation = startPos; section.EndLocation = t.EndLocation; .) . NamespaceMemberDecl (. AttributeSection section; List attributes = new List(); Modifiers m = new Modifiers(); string qualident; .) = /*--- namespace declaration: */ "namespace" (. Point 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(Modifier.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; .) ident (. newType.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] [ ClassBase (. newType.BaseTypes = names; .) ] /* .NET 2.0 */ { IF (IdentIsWhere()) TypeParameterConstraintsClause } ClassBody [ ";" ] (. newType.EndLocation = t.Location; compilationUnit.BlockEnd(); .) | /*--- struct declaration: */ (. m.Check(Modifier.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; .) ident (. newType.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] [ StructInterfaces (. newType.BaseTypes = names; .) ] /* .NET 2.0 */ { IF (IdentIsWhere()) TypeParameterConstraintsClause } 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; .) ident (. newType.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] [ InterfaceBase (. newType.BaseTypes = names; .) ] /* .NET 2.0 */ { IF (IdentIsWhere()) TypeParameterConstraintsClause } 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; .) ident (. newType.Name = t.val; .) [ ":" IntegralType (. newType.BaseTypes.Add(new TypeReference(name)); .) ] 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; .) ) ident (. delegateDeclr.Name = t.val; .) /* .NET 2.0 */ [ TypeParameterList ] "(" [ FormalParameterList

(. delegateDeclr.Parameters = p; .) ] ")" /* .NET 2.0 */ { IF (IdentIsWhere()) TypeParameterConstraintsClause } ";" (. delegateDeclr.EndLocation = t.Location; compilationUnit.AddChild(delegateDeclr); .) ) . Qualident = ident (. qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); .) { IF (DotAndIdent()) "." ident (. 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(); Modifiers m = new Modifiers(); .) { AttributeSection (. attributes.Add(section); .) } { MemberModifier } 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(); Modifiers m = new Modifiers(); .) { AttributeSection (. attributes.Add(section); .) } { MemberModifier } StructMemberDecl } "}" . InterfaceBase names> (. TypeReference typeRef; names = new List(); .) = ":" TypeName (. if (typeRef != null) { names.Add(typeRef); } .) { "," TypeName (. if (typeRef != null) { names.Add(typeRef); } .) } . InterfaceBody = "{" { 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; ParamModifier mod = ParamModifier.In; System.Drawing.Point start = t.Location; .) = [ "ref" (. mod = ParamModifier.Ref; .) | "out" (. mod = ParamModifier.Out; .) ] Type ident (. p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .) . ParameterArray (. TypeReference type; .) = "params" Type ident (. p = new ParameterDeclarationExpression(type, t.val, ParamModifier.Params); .) . AccessorModifiers (. m = new Modifiers(); .) = "private" (. m.Add(Modifier.Private, t.Location); .) | "protected" (. m.Add(Modifier.Protected, t.Location); .) ["internal" (. m.Add(Modifier.Internal, t.Location); .)] | "internal" (. m.Add(Modifier.Internal, t.Location); .) ["protected" (. m.Add(Modifier.Protected, t.Location); .)] . TypeModifier = "new" (. m.Add(Modifier.New, t.Location); .) | "public" (. m.Add(Modifier.Public, t.Location); .) | "protected" (. m.Add(Modifier.Protected, t.Location); .) | "internal" (. m.Add(Modifier.Internal, t.Location); .) | "private" (. m.Add(Modifier.Private, t.Location); .) | "unsafe" (. m.Add(Modifier.Unsafe, t.Location); .) | "abstract" (. m.Add(Modifier.Abstract, t.Location); .) | "sealed" (. m.Add(Modifier.Sealed, t.Location); .) | "static" (. m.Add(Modifier.Static, t.Location); .) | ident (. if (t.val == "partial") { m.Add(Modifier.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"; .) . MemberModifier = "abstract" (. m.Add(Modifier.Abstract, t.Location); .) | "extern" (. m.Add(Modifier.Extern, t.Location); .) | "internal" (. m.Add(Modifier.Internal, t.Location); .) | "new" (. m.Add(Modifier.New, t.Location); .) | "override" (. m.Add(Modifier.Override, t.Location); .) | "private" (. m.Add(Modifier.Private, t.Location); .) | "protected" (. m.Add(Modifier.Protected, t.Location); .) | "public" (. m.Add(Modifier.Public, t.Location); .) | "readonly" (. m.Add(Modifier.ReadOnly, t.Location); .) | "sealed" (. m.Add(Modifier.Sealed, t.Location); .) | "static" (. m.Add(Modifier.Static, t.Location); .) | "unsafe" (. m.Add(Modifier.Unsafe, t.Location); .) | "virtual" (. m.Add(Modifier.Virtual, t.Location); .) | "volatile" (. m.Add(Modifier.Volatile, 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; .) = /*--- constant declaration: */ (. m.Check(Modifier.Constants); .) "const" (.Point startPos = t.Location; .) Type ident (. FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifier.Const); fd.StartLocation = m.GetDeclarationLocation(startPos); VariableDeclaration f = new VariableDeclaration(t.val); fd.Fields.Add(f); .) "=" Expr (. f.Initializer = expr; .) { "," ident (. 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(Modifier.PropertysEventsMethods); .) "void" (. Point startPos = t.Location; .) ( IF (IsExplicitInterfaceImplementation()) TypeName (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); } .) | ident (. qualident = t.val; .) ) /* .NET 2.0 */ [ TypeParameterList ] "(" [ FormalParameterList

] ")" (. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident, m.Modifier, new TypeReference("void"), p, attributes); methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos); methodDeclaration.EndLocation = t.EndLocation; methodDeclaration.Templates = templates; if (explicitInterface != null) methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); compilationUnit.AddChild(methodDeclaration); compilationUnit.BlockStart(methodDeclaration); .) /* .NET 2.0 */ { IF (IdentIsWhere()) TypeParameterConstraintsClause } ( Block | ";" ) (. compilationUnit.BlockEnd(); methodDeclaration.Body = (BlockStatement)stmt; .) | /*--- event declaration: */ (. m.Check(Modifier.PropertysEventsMethods); .) "event" (. EventDeclaration eventDecl = new EventDeclaration(null, null, m.Modifier, attributes, null); eventDecl.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)); .) | ident (. qualident = t.val; .) ) (. eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; .) [ "{" (. 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(Modifier.Constructors | Modifier.StaticConstructors); .) ident (. string name = t.val; Point startPos = t.Location; .) "(" [ (. m.Check(Modifier.Constructors); .) FormalParameterList

] ")" (.ConstructorInitializer init = null; .) [ (. m.Check(Modifier.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(Modifier.Operators); if (m.isNone) Error("at least one modifier must be set"); bool isImplicit = true; Point startPos = Point.Empty; .) ( "implicit" (. startPos = t.Location; .) | "explicit" (. isImplicit = false; startPos = t.Location; .) ) "operator" Type (. TypeReference operatorType = type; .) "(" Type ident (. string varName = t.val; .) ")" (. Point endPos = t.Location; .) ( Block | ";" (. stmt = null; .) ) (. List parameters = new List(); parameters.Add(new ParameterDeclarationExpression(type, varName)); OperatorDeclaration operatorDeclaration = new OperatorDeclaration(m.Modifier, attributes, parameters, operatorType, isImplicit ? ConversionType.Implicit : ConversionType.Explicit ); operatorDeclaration.Body = (BlockStatement)stmt; operatorDeclaration.StartLocation = m.GetDeclarationLocation(startPos); operatorDeclaration.EndLocation = endPos; compilationUnit.AddChild(operatorDeclaration); .) /*--- inner type declaration: */ | TypeDecl | Type (. Point startPos = t.Location; .) ( /*--- operator declaration: */ (. OverloadableOperatorType op; m.Check(Modifier.Operators); if (m.isNone) Error("at least one modifier must be set"); .) "operator" OverloadableOperator (. TypeReference firstType, secondType = null; string secondName = null; .) "(" Type ident (. string firstName = t.val; .) ( "," Type ident (. 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"); } .)*/ ) (. Point 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(m.Modifier, attributes, parameters, type, op); operatorDeclaration.Body = (BlockStatement)stmt; operatorDeclaration.StartLocation = m.GetDeclarationLocation(startPos); operatorDeclaration.EndLocation = endPos; compilationUnit.AddChild(operatorDeclaration); .) /*--- field declaration: */ | IF (IsVarDecl()) (. m.Check(Modifier.Fields); FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier); fd.StartLocation = m.GetDeclarationLocation(startPos); .) VariableDeclarator { "," VariableDeclarator } ";" (. fd.EndLocation = t.EndLocation; fd.Fields = variableDeclarators; compilationUnit.AddChild(fd); .) /*--- unqualified indexer declaration (without interface name): */ | (. m.Check(Modifier.Indexers); .) "this" "[" FormalParameterList

"]" (. Point 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 (la.kind == Tokens.Identifier) ( IF (IsExplicitInterfaceImplementation()) TypeName (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); } .) | ident (. qualident = t.val; .) ) (. Point qualIdentEndLocation = t.EndLocation; .) ( /*--- "not void" method (function) declaration: */ ( (. m.Check(Modifier.PropertysEventsMethods); .) /* .NET 2.0 */ [ TypeParameterList ] "(" [ FormalParameterList

] ")" (. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident, m.Modifier, type, p, attributes); if (explicitInterface != null) methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos); methodDeclaration.EndLocation = t.EndLocation; methodDeclaration.Templates = templates; compilationUnit.AddChild(methodDeclaration); .) { IF (IdentIsWhere()) 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(Modifier.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; .) "{" (. Point 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(Modifier.Destructors); Point startPos = t.Location; .) "~" ident (. 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; Modifier mod = Modifier.None; List attributes = new List(); List parameters = new List(); string name; PropertyGetRegion getBlock; PropertySetRegion setBlock; Point startLocation = new Point(-1, -1); List templates = new List(); .) = { AttributeSection (. attributes.Add(section); .)} [ "new" (. mod = Modifier.New; startLocation = t.Location; .) ] ( /*--- interface void method (procedure) declaration: */ IF (NotVoidPointer()) "void" (. if (startLocation.X == -1) startLocation = t.Location; .) ident (. name = t.val; .) [ TypeParameterList ] "(" [ FormalParameterList ] ")" { IF (IdentIsWhere()) TypeParameterConstraintsClause } ";" (. MethodDeclaration md = new MethodDeclaration(name, mod, new TypeReference("void"), parameters, attributes); md.StartLocation = startLocation; md.EndLocation = t.EndLocation; md.Templates = templates; compilationUnit.AddChild(md); .) | ( Type (. if (startLocation.X == -1) startLocation = t.Location; .) ( ident (. name = t.val; Point qualIdentEndLocation = t.EndLocation; .) ( /*--- interface "not void" method (function) declaration: */ /* .NET 2.0 */ [ TypeParameterList ] "(" [ FormalParameterList ] ")" /* .NET 2.0 */ { IF (IdentIsWhere()) TypeParameterConstraintsClause } ";" (. MethodDeclaration md = new MethodDeclaration(name, mod, type, parameters, attributes); md.StartLocation = startLocation; md.EndLocation = t.EndLocation; md.Templates = templates; compilationUnit.AddChild(md); .) /*--- interface property declaration: */ | (. PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes); compilationUnit.AddChild(pd); .) "{" (. Point 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 "]" (.Point bracketEndLocation = t.EndLocation; .) (. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes); compilationUnit.AddChild(id); .) "{" (. Point 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 ident (. EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes, null); 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); .) } ident (. 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; Modifiers modifiers = null; .) = { AttributeSection (. attributes.Add(section); .) } [ AccessorModifiers ] ( IF (IdentIsGet()) 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; } .) ] | IF (IdentIsSet()) 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; } .) ] | ident (. Error("get or set accessor declaration expected"); .) ) . GetAccessorDecl attributes> (. Statement stmt = null; .) = ident /* "get" is not a keyword! */ (. if (t.val != "get") Error("get expected"); .) (. Point startLocation = t.Location; .) ( Block | ";" ) (. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .) (. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .) . SetAccessorDecl attributes> (. Statement stmt = null; .) = ident /* "set" is not a keyword! */ (. if (t.val != "set") Error("set expected"); .) (. Point 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); .) } ( IF (IdentIsAdd()) (. 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; .) | IF (IdentIsRemove()) 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; .) | ident (. Error("add or remove accessor declaration expected"); .) ) . InterfaceAccessors (. AttributeSection section; List attributes = new List(); getBlock = null; setBlock = null; PropertyGetSetRegion lastBlock = null; .) = { AttributeSection (. attributes.Add(section); .) } (. Point startLocation = la.Location; .) ( IF (IdentIsGet()) ident (. getBlock = new PropertyGetRegion(null, attributes); .) | IF (IdentIsSet()) ident (. setBlock = new PropertySetRegion(null, attributes); .) | ident (. Error("set or get expected"); .) ) ";" (. 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; .) ( IF (IdentIsGet()) ident (. if (getBlock != null) Error("get already declared"); else { getBlock = new PropertyGetRegion(null, attributes); lastBlock = getBlock; } .) | IF (IdentIsSet()) ident (. if (setBlock != null) Error("set already declared"); else { setBlock = new PropertySetRegion(null, attributes); lastBlock = setBlock; } .) | ident (. Error("set or get expected"); .) ) ";" (. if (lastBlock != null) { lastBlock.StartLocation = startLocation; lastBlock.EndLocation = t.EndLocation; } .) ] . VariableDeclarator fieldDeclaration> (. Expression expr = null; .) = ident (. 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.EndLocation; compilationUnit.BlockStart(blockStmt); if (!parseMethodContents) lexer.SkipCurrentBlock(); .) { Statement } "}" (. stmt = blockStmt; blockStmt.EndLocation = t.EndLocation; compilationUnit.BlockEnd(); .) . AddAccessorDecl (.stmt = null;.) = /* "add" is not a keyword!? */ ident (. if (t.val != "add") Error("add expected"); .) Block . RemoveAccessorDecl (.stmt = null;.) = /* "remove" is not a keyword!? */ ident (. if (t.val != "remove") Error("remove expected"); .) 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 | ArrayInitializer | "stackalloc" Type "[" Expr "]" (. initializerExpression = new StackAllocExpression(type, expr); .) | /* workaround for coco bug? doesn't work in Expr production in this case. */ "default" "(" Type ")" (. initializerExpression = new DefaultValueExpression(type); .) . 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.True; .) | "false" (. op = OverloadableOperatorType.False; .) | "*" (. 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; .) . ArrayInitializer (. Expression expr = null; ArrayInitializerExpression initializer = new ArrayInitializerExpression(); .) = "{" [ VariableInitializer (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) { IF (NotFinalComma()) "," VariableInitializer (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) } [ "," ] ] "}" (. outExpr = initializer; .) . 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; .) = /* ident (. var = new VariableDeclaration(t.val); .) [ "=" LocalVariableInitializer (. var.Initializer = expr; .) ]*/ ident (. var = new VariableDeclaration(t.val); .) [ "=" VariableInitializer (. var.Initializer = expr; .) ] . /* LocalVariableInitializer (. expr = null; .) = Expr | ArrayInitializer . */ Statement (. TypeReference type; Expression expr; Statement stmt = null; Point startPos = la.Location; .) = ( /*--- labeled statement: */ IF (IsLabel()) ident (. compilationUnit.AddChild(new LabelStatement(t.val)); .) ":" Statement /*--- local constant declaration: */ | "const" Type (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifier.Const); string ident = null; var.StartLocation = t.Location; .) ident (. ident = t.val; .) "=" Expr (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) { "," ident (. 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; .) = 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): */ | "if" (. Statement elseStatement = null; .) "(" Expr ")" EmbeddedStatement [ "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; } .) | "switch" (. List switchSections = new List(); SwitchSection switchSection; .) "(" Expr ")" "{" { SwitchSection (. switchSections.Add(switchSection); .) } "}" (. 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 ident (. string varName = t.val; Point start = t.Location;.) "in" Expr ")" EmbeddedStatement (. statement = new ForeachStatement(type, varName , expr, embeddedStatement); statement.EndLocation = t.EndLocation; .) /*--- jump statements (break, contine, goto, return, throw): */ | "break" ";" (. statement = new BreakStatement(); .) | "continue" ";" (. statement = new ContinueStatement(); .) | GotoStatement | IF (IsYieldStatement()) ident ( "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 ";" /*--- 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.PointerNestingLevel == 0) Error("can only fix pointer types"); List pointerDeclarators = new List(1); .) ident (. string identifier = t.val; .) "=" Expr (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .) { "," ident (. identifier = t.val; .) "=" Expr (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .) } ")" EmbeddedStatement (. statement = new FixedStatement(type, pointerDeclarators, embeddedStatement); .) . 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); .) } . SwitchSection (. SwitchSection switchSection = new SwitchSection(); CaseLabel label; .) = SwitchLabel (. switchSection.SwitchLabels.Add(label); .) { SwitchLabel (. switchSection.SwitchLabels.Add(label); .) } (. compilationUnit.BlockStart(switchSection); .) Statement { Statement } (. compilationUnit.BlockEnd(); stmt = 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; .) [ ident (. identifier = t.val; .) ] ")" Block (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) { IF (IsTypedCatch()) "catch" "(" ClassType (. identifier = null; .) [ ident (. 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" ( ident (. 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 StatementExpression(expr); .) ) . StatementExpr (. Expression expr; .) = Expr /* The grammar allows only assignments or method invocations here, */ /* but we don't enforce that here */ (. stmt = new StatementExpression(expr); .) . Expr (. expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; .) = 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); .) ] ) ) . UnaryExpr (. TypeReference type = null; Expression expr; 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)); .) ) } 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; List typeList = null; bool isArrayCreation = false; Expression expr; pexpr = null; .) = ( "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 (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) ident (. type = new TypeReference(t.val); .) "::" (. pexpr = new TypeReferenceExpression(type); .) ident (. if (type.Type == "global") { type.IsGlobal = true; type.Type = t.val; } else type.Type += "." + t.val; .) /*--- simple name: */ | ident (. pexpr = new IdentifierExpression(t.val); .) /*--- 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"; .) ) (. t.val = ""; .) "." ident (. pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); .) /*--- this access: */ | "this" (. pexpr = new ThisReferenceExpression(); .) /*--- base access: */ | "base" (. Expression retExpr = new BaseReferenceExpression(); .) ( "." ident (. retExpr = new FieldReferenceExpression(retExpr, t.val); .) | "[" Expr (. List indices = new List(); if (expr != null) { indices.Add(expr); } .) { "," Expr (. if (expr != null) { indices.Add(expr); } .) } "]" (. retExpr = new IndexerExpression(retExpr, indices); .) ) (. pexpr = retExpr; .) | "new" NonArrayType (. List parameters = new List(); .) /*--- 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); .) [ Argument (. if (expr != null) { parameters.Add(expr); } .) { "," Argument (. if (expr != null) { parameters.Add(expr); } .) } ] ")" (. pexpr = oce; .) | "[" /*--- array creation expression: */ (. isArrayCreation = true; ArrayCreateExpression ace = new ArrayCreateExpression(type); 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(); .) ArrayInitializer (. ace.ArrayInitializer = (ArrayInitializerExpression)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(); .) [ ArrayInitializer (. ace.ArrayInitializer = (ArrayInitializerExpression)expr; .) ] ) ) | "typeof" "(" ( IF (NotVoidPointer()) "void" (. type = new TypeReference("void"); .) | TypeWithRestriction ) ")" (. pexpr = new TypeOfExpression(type); .) | IF (la.kind == Tokens.Default && Peek(1).kind == Tokens.OpenParenthesis) /* possible conflict with switch's default */ "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; .) ) { ( "++" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); .) | "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .) ) /*--- member access */ | "->" ident (. pexpr = new PointerReferenceExpression(pexpr, t.val); .) | "." ident (. pexpr = new FieldReferenceExpression(pexpr, t.val);.) /* member access on generic type */ | ( IF (IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr)) TypeArgumentList ) "." ident (. pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeList), t.val);.) /*--- 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); .) | ( IF (IsGenericFollowedBy(Tokens.OpenParenthesis)) TypeArgumentList ) "(" (. List parameters = new List(); .) [ Argument (. if (expr != null) {parameters.Add(expr);} .) { "," Argument (. if (expr != null) {parameters.Add(expr);} .) } ] ")" (. pexpr = new InvocationExpression(pexpr, parameters, typeList); .) /*--- 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); .) } . AnonymousMethodExpr (. AnonymousMethodExpression expr = new AnonymousMethodExpression(); expr.StartLocation = t.Location; Statement stmt; List p = new List(); outExpr = expr; .) = [ "(" [ FormalParameterList

(. expr.Parameters = p; .) ] ")" ] /*--- ParseExpression doesn't set a compilation unit, */ /*--- so we can't use block then -> skip body of anonymous method */ (. if (compilationUnit != null) { .) Block (. expr.Body = (BlockStatement)stmt; .) (. } else { .) "{" (. lexer.SkipCurrentBlock(); .) "}" (. } .) (. expr.EndLocation = t.Location; .) . 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 && Tokens.CastFollower[Peek(1).kind] == false) NullableQuestionMark ] (. outExpr = new TypeOfIsExpression(outExpr, type); .) | "as" TypeWithRestriction [ IF (la.kind == Tokens.Question && Tokens.CastFollower[Peek(1).kind] == false) 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 (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) ident (. 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 (. types.Add(type); .) { "," Type (. types.Add(type); .) } ) ">" . TypeParameterList templates> (. AttributeSection section; List attributes = new List(); .) = "<" { AttributeSection (. attributes.Add(section); .) } ident (. templates.Add(new TemplateDefinition(t.val, attributes)); .) { "," { AttributeSection (. attributes.Add(section); .) } ident (. templates.Add(new TemplateDefinition(t.val, attributes)); .)} ">" . TypeParameterConstraintsClause templates> (. string name = ""; TypeReference type; .) = ident (. if (t.val != "where") Error("where expected"); .) ident (. name = t.val; .) ":" TypeParameterConstraintsClauseBase (. TemplateDefinition td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { td = d; break; } } if ( td != null) { td.Bases.Add(type); } .) { "," TypeParameterConstraintsClauseBase (. td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { td = d; break; } } if ( td != null) { td.Bases.Add(type); } .) } . TypeParameterConstraintsClauseBase (. TypeReference t; type = null; .) = "struct" (. type = new TypeReference("struct"); .) | "class" (. type = new TypeReference("struct"); .) | "new" "(" ")" (. type = new TypeReference("struct"); .) | Type (. type = t; .) . END CS.