2008-11-05 Francisco Figueiredo Jr. <francisco@npgsql.org>
[mono.git] / mcs / mcs / cs-parser.jay
index c9655baecdfa6ac123c23c4f6a20621d5b11e974..82665c5e9d1b92c107b51f89c22c0e58908ec6ab 100644 (file)
@@ -228,7 +228,6 @@ namespace Mono.CSharp
 %token ARGLIST
 %token PARTIAL
 %token ARROW
-%token QUERY_FIRST_TOKEN
 %token FROM
 %token JOIN
 %token ON
@@ -241,8 +240,13 @@ namespace Mono.CSharp
 %token ASCENDING
 %token DESCENDING
 %token INTO
-%token QUERY_LAST_TOKEN
 %token INTERR_NULLABLE
+%token EXTERN_ALIAS
+
+/* Generics <,> tokens */
+%token OP_GENERICS_LT
+%token OP_GENERICS_LT_DECL
+%token OP_GENERICS_GT
 
 /* C# keywords which are not really keywords */
 %token GET
@@ -257,6 +261,7 @@ namespace Mono.CSharp
 %token CLOSE_BRACKET
 %token OPEN_PARENS
 %token CLOSE_PARENS
+
 %token DOT
 %token COMMA
 %token COLON
@@ -268,10 +273,7 @@ namespace Mono.CSharp
 %token BANG
 %token ASSIGN
 %token OP_LT
-%token OP_GENERICS_LT
-%token OP_GENERICS_LT_DECL
 %token OP_GT
-%token OP_GENERICS_GT
 %token BITWISE_AND
 %token BITWISE_OR
 %token STAR
@@ -279,7 +281,6 @@ namespace Mono.CSharp
 %token DIV
 %token CARRET
 %token INTERR
-%token EXTERN_ALIAS
 
 /* C# multi-character operators. */
 %token DOUBLE_COLON
@@ -316,11 +317,7 @@ namespace Mono.CSharp
 
 %token IDENTIFIER
 %token OPEN_PARENS_LAMBDA
-%token CLOSE_PARENS_CAST
-%token CLOSE_PARENS_NO_CAST
-%token CLOSE_PARENS_OPEN_PARENS
-%token CLOSE_PARENS_MINUS
-%token DEFAULT_OPEN_PARENS
+%token OPEN_PARENS_CAST
 %token GENERIC_DIMENSION
 %token DEFAULT_COLON
 
@@ -1741,7 +1738,7 @@ get_accessor_declaration
          accessor_body
          {
                if (has_get) {
-                       Report.Error (1007, (Location) $3, "Property accessor already defined");
+                       Report.Error (1007, GetLocation ($3), "Property accessor already defined");
                        break;
                }
                Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
@@ -1776,7 +1773,7 @@ set_accessor_declaration
          accessor_body
          {
                if (has_set) {
-                       Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
+                       Report.Error (1007, GetLocation ($3), "Property accessor already defined");
                        break;
                }
                Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
@@ -2043,11 +2040,13 @@ conversion_operator_declarator
          }
        | IMPLICIT error 
          {
-               syntax_error ((Location) $1, "'operator' expected");
+               Error_SyntaxError (yyToken);
+               $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
          }
        | EXPLICIT error 
          {
-               syntax_error ((Location) $1, "'operator' expected");
+               Error_SyntaxError (yyToken);
+               $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
          }
        ;
 
@@ -2520,6 +2519,7 @@ enum_member_declaration
          }
        | opt_attributes IDENTIFIER
          {
+               ++lexer.parsing_block;
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
@@ -2527,6 +2527,7 @@ enum_member_declaration
          }
          ASSIGN constant_expression
          { 
+               --lexer.parsing_block;    
                VariableDeclaration vd = new VariableDeclaration (
                        (LocatedToken) $2, $5, (Attributes) $1);
 
@@ -2843,44 +2844,6 @@ type_expression
          }     
        ;
 
-non_expression_type
-       : builtin_types opt_nullable
-         {
-               if ($2 != null)
-                       $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
-         }
-       | VOID
-         {
-               $$ = TypeManager.system_void_expr;
-         }
-       | non_expression_type rank_specifiers
-         {
-               Location loc = GetLocation ($1);
-               if (loc.IsNull)
-                       loc = lexer.Location;
-               $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, loc);
-         }
-       | non_expression_type STAR
-         {
-               Location loc = GetLocation ($1);
-               if (loc.IsNull)
-                       loc = lexer.Location;
-               $$ = new ComposedCast ((FullNamedExpression) $1, "*", loc);
-         }
-       //
-       // We need this because the parser will happily go and reduce IDENTIFIER STAR
-       // through this different path
-       //
-       | multiplicative_expression STAR 
-         {
-               FullNamedExpression e = $1 as FullNamedExpression;
-               if (e != null)
-                       $$ = new ComposedCast (e, "*");
-               else
-                       Error_TypeExpected (GetLocation ($1));
-         }
-       ;
-
 type_list
        : base_type_name
          {
@@ -2911,7 +2874,7 @@ base_type_name
        
 /*
  * replaces all the productions for isolating the various
- * simple types, but we need this to reuse it easily in local_variable_type
+ * simple types, but we need this to reuse it easily in variable_type
  */
 builtin_types
        : OBJECT        { $$ = TypeManager.system_object_expr; }
@@ -3016,36 +2979,25 @@ boolean_literal
        | FALSE                 { $$ = new BoolLiteral (false, lexer.Location); }
        ;
 
-parenthesized_expression_0
-       : OPEN_PARENS expression CLOSE_PARENS
-         {
-               $$ = $2;
-               lexer.Deambiguate_CloseParens ($$);
-               // After this, the next token returned is one of
-               // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
-               // or CLOSE_PARENS_MINUS.
-         }
-       | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
+
+//
+// Here is the trick, tokenizer may think that parens is a special but
+// parser is interested in open parens only, so we merge them.
+// Consider: if (a)foo ();
+//
+open_parens_any
+       : OPEN_PARENS
+       | OPEN_PARENS_CAST
+       | OPEN_PARENS_LAMBDA
        ;
 
 parenthesized_expression
-       : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
-         {
-               $$ = $1;
-         }  
-       | parenthesized_expression_0 CLOSE_PARENS
-         {
-               $$ = $1;
-         }
-       | parenthesized_expression_0 CLOSE_PARENS_MINUS
+       : OPEN_PARENS expression CLOSE_PARENS
          {
-               // If a parenthesized expression is followed by a minus, we need to wrap
-               // the expression inside a ParenthesizedExpression for the CS0075 check
-               // in Binary.DoResolve().
-               $$ = new ParenthesizedExpression ((Expression) $1);
+               $$ = new ParenthesizedExpression ((Expression) $2);
          }
        ;
-
+       
 member_access
        : primary_expression DOT IDENTIFIER opt_type_argument_list
          {
@@ -3068,30 +3020,10 @@ member_access
        ;
 
 invocation_expression
-       : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
+       : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
          {
                $$ = new Invocation ((Expression) $1, (ArrayList) $3);
          }
-       | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
-         {
-               $$ = new Invocation ((Expression) $1, new ArrayList ());
-         }
-       | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
-         {
-               $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
-         }
-       | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
-         {
-               ArrayList args = new ArrayList (1);
-               args.Add ($4);
-               $$ = new Invocation ((Expression) $1, args);
-         }
-       | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
-         {
-               ArrayList args = ((ArrayList) $4);
-               args.Add ($6);
-               $$ = new Invocation ((Expression) $1, args);
-         }
        ;
 
 opt_object_or_collection_initializer
@@ -3211,7 +3143,7 @@ non_simple_argument
          { 
                $$ = new Argument ((Expression) $2, Argument.AType.Out);
          }
-       | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
+       | ARGLIST open_parens_any argument_list CLOSE_PARENS
          {
                ArrayList list = (ArrayList) $3;
                Argument[] args = new Argument [list.Count];
@@ -3220,7 +3152,7 @@ non_simple_argument
                Expression expr = new Arglist (args, (Location) $1);
                $$ = new Argument (expr, Argument.AType.Expression);
          }
-       | ARGLIST OPEN_PARENS CLOSE_PARENS
+       | ARGLIST open_parens_any CLOSE_PARENS
          {
                $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
          }       
@@ -3312,21 +3244,19 @@ base_access
 post_increment_expression
        : primary_expression OP_INC
          {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
-                                      (Expression) $1, (Location) $2);
+               $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
          }
        ;
 
 post_decrement_expression
        : primary_expression OP_DEC
          {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
-                                      (Expression) $1, (Location) $2);
+               $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
          }
        ;
 
 object_or_delegate_creation_expression
-       : NEW simple_type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
+       : NEW simple_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
          {
                if ($6 != null) {
                        if (RootContext.Version <= LanguageVersion.ISO_2)
@@ -3549,7 +3479,7 @@ typeof_expression
                pushed_current_array_type = current_array_type;
                lexer.TypeOfParsing = true;
          }
-         OPEN_PARENS typeof_type_expression CLOSE_PARENS
+         open_parens_any typeof_type_expression CLOSE_PARENS
          {
                lexer.TypeOfParsing = false;
                Expression type = (Expression)$4;
@@ -3631,20 +3561,20 @@ qualified_alias_member
        ;
 
 sizeof_expression
-       : SIZEOF OPEN_PARENS type CLOSE_PARENS { 
+       : SIZEOF open_parens_any type CLOSE_PARENS { 
                $$ = new SizeOf ((Expression) $3, (Location) $1);
          }
        ;
 
 checked_expression
-       : CHECKED OPEN_PARENS expression CLOSE_PARENS
+       : CHECKED open_parens_any expression CLOSE_PARENS
          {
                $$ = new CheckedExpr ((Expression) $3, (Location) $1);
          }
        ;
 
 unchecked_expression
-       : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
+       : UNCHECKED open_parens_any expression CLOSE_PARENS
          {
                $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
          }
@@ -3668,7 +3598,7 @@ anonymous_method_expression
          }
          block
          {
-               $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
+               $$ = end_anonymous ((ToplevelBlock) $4);
        }
        ;
 
@@ -3690,12 +3620,12 @@ anonymous_method_signature
        ;
 
 default_value_expression
-       : DEFAULT_OPEN_PARENS type CLOSE_PARENS
+       : DEFAULT open_parens_any type CLOSE_PARENS
          {
                if (RootContext.Version < LanguageVersion.ISO_2)
                        Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
 
-               $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
+               $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
          }
        ;
 
@@ -3703,39 +3633,23 @@ unary_expression
        : primary_expression
        | BANG prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
          }
        | TILDE prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
          }
        | cast_expression
        ;
 
-cast_list
-       : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
-         {
-               $$ = new Cast ((Expression) $1, (Expression) $3);
-         }
-       | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
+cast_expression
+       : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
          {
-               $$ = new Cast ((Expression) $1, (Expression) $3);
+               $$ = new Cast ((Expression) $2, (Expression) $4, GetLocation ($1));
          }
-       | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
-         {
-               $$ = new Cast ((Expression) $1, (Expression) $3);
-         }     
-       ;
-
-cast_expression
-       : cast_list
-       | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
+       | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
          {
-               if ($2 == TypeManager.system_void_expr)
-                       Expression.Error_VoidInvalidInTheContext (GetLocation ($2));
-
-               // TODO: wrong location
-               $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
+               $$ = new Cast ((Expression) $2, (Expression) $4, GetLocation ($1));
          }
        ;
 
@@ -3747,29 +3661,27 @@ prefixed_unary_expression
        : unary_expression
        | PLUS prefixed_unary_expression
          { 
-               $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
          } 
        | MINUS prefixed_unary_expression 
          { 
-               $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
          }
        | OP_INC prefixed_unary_expression 
          {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
-                                      (Expression) $2, (Location) $1);
+               $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
          }
        | OP_DEC prefixed_unary_expression 
          {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
-                                      (Expression) $2, (Location) $1);
+               $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
          }
        | STAR prefixed_unary_expression
          {
-               $$ = new Indirection ((Expression) $2, (Location) $1);
+               $$ = new Indirection ((Expression) $2, GetLocation ($1));
          }
        | BITWISE_AND prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
          }
        ;
 
@@ -3801,9 +3713,13 @@ additive_expression
          }
        | additive_expression MINUS multiplicative_expression
          {
-               $$ = new Binary (Binary.Operator.Subtraction, 
-                                (Expression) $1, (Expression) $3);
+               $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
          }
+       | parenthesized_expression MINUS multiplicative_expression
+         {
+               // Shift/Reduce conflict
+               $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
+         }
        | additive_expression AS type
          {
                $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
@@ -4062,19 +3978,19 @@ lambda_expression
          {
                LocatedToken lt = (LocatedToken) $1;
                Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
-               start_anonymous (true, new Parameters (p), (Location) $2);
+               start_anonymous (true, new Parameters (p), GetLocation ($1));
          }
          lambda_expression_body
          {
-               $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
+               $$ = end_anonymous ((ToplevelBlock) $4);
          }
        | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW 
          {
-               start_anonymous (true, (Parameters) $2, (Location) $4);
+               start_anonymous (true, (Parameters) $2, GetLocation ($1));
          }
          lambda_expression_body 
          {
-               $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
+               $$ = end_anonymous ((ToplevelBlock) $6);
          }
        ;
 
@@ -4441,7 +4357,7 @@ declaration_statement
  * > expressions to prevent reduce/reduce errors in the grammar.
  * > The expressions are converted into types during semantic analysis.
  */
-local_variable_type
+variable_type
        : primary_expression_no_array_creation opt_rank_specifier_or_nullable
          { 
                // FIXME: Do something smart here regarding the composition of the type.
@@ -4513,7 +4429,7 @@ local_variable_pointer_type
          }
        | builtin_types STAR
          {
-               $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
+               $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
          }
        | VOID STAR
          {
@@ -4525,6 +4441,23 @@ local_variable_pointer_type
          }
        ;
 
+local_variable_type
+       : variable_type
+       | local_variable_pointer_type opt_rank_specifier
+         {
+               if ($1 != null){
+                       string rank = (string)$2;
+
+                       if (rank == "")
+                               $$ = $1;
+                       else
+                               $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
+               } else {
+                       $$ = null;
+               }
+         }
+       ;
+
 local_variable_declaration
        : local_variable_type local_variable_declarators
          {
@@ -4537,23 +4470,10 @@ local_variable_declaration
                } else
                        $$ = null;
          }
-       | local_variable_pointer_type opt_rank_specifier local_variable_declarators
-         {
-               if ($1 != null){
-                       Expression t;
-
-                       if ((string) $2 == "")
-                               t = (Expression) $1;
-                       else
-                               t = new ComposedCast ((FullNamedExpression) $1, (string) $2);
-                       $$ = new DictionaryEntry (t, $3);
-               } else 
-                       $$ = null;
-         }
        ;
 
 local_constant_declaration
-       : CONST local_variable_type constant_declarators
+       : CONST variable_type constant_declarators
          {
                if ($2 != null)
                        $$ = new DictionaryEntry ($2, $3);
@@ -4584,10 +4504,9 @@ statement_expression
 
                if (s == null) {
                        expr.Error_InvalidExpressionStatement ();
-                       $$ = null;
-               } else {
-                       $$ = new StatementExpression (s);
                }
+
+               $$ = new StatementExpression (s);
          }
        | error
          {
@@ -4618,7 +4537,7 @@ selection_statement
        ; 
 
 if_statement
-       : IF OPEN_PARENS boolean_expression CLOSE_PARENS 
+       : IF open_parens_any boolean_expression CLOSE_PARENS 
          embedded_statement
          { 
                Location l = (Location) $1;
@@ -4630,7 +4549,7 @@ if_statement
                        Report.Warning (642, 3, l, "Possible mistaken empty statement");
 
          }
-       | IF OPEN_PARENS boolean_expression CLOSE_PARENS
+       | IF open_parens_any boolean_expression CLOSE_PARENS
          embedded_statement ELSE embedded_statement
          {
                Location l = (Location) $1;
@@ -4646,7 +4565,7 @@ if_statement
        ;
 
 switch_statement
-       : SWITCH OPEN_PARENS
+       : SWITCH open_parens_any
          { 
                if (switch_stack == null)
                        switch_stack = new Stack (2);
@@ -4742,7 +4661,7 @@ iteration_statement
        ;
 
 while_statement
-       : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
+       : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
          {
                Location l = (Location) $1;
                $$ = new While ((Expression) $3, (Statement) $5, l);
@@ -4751,7 +4670,7 @@ while_statement
 
 do_statement
        : DO embedded_statement 
-         WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
+         WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
          {
                Location l = (Location) $1;
 
@@ -4760,8 +4679,7 @@ do_statement
        ;
 
 for_statement
-       : FOR OPEN_PARENS 
-         opt_for_initializer SEMICOLON
+       : FOR open_parens_any opt_for_initializer SEMICOLON
          {
                Location l = lexer.Location;
                start_block (l);  
@@ -4858,12 +4776,12 @@ statement_expression_list
        ;
 
 foreach_statement
-       : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
+       : FOREACH open_parens_any type IN expression CLOSE_PARENS
          {
                Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
                $$ = null;
          }
-       | FOREACH OPEN_PARENS type IDENTIFIER IN
+       | FOREACH open_parens_any type IDENTIFIER IN
          expression CLOSE_PARENS 
          {
                start_block (lexer.Location);
@@ -5082,11 +5000,11 @@ opt_catch_args
        ;         
 
 catch_args 
-       : OPEN_PARENS type opt_identifier CLOSE_PARENS 
+       : open_parens_any type opt_identifier CLOSE_PARENS 
          {
                $$ = new DictionaryEntry ($2, $3);
          }
-       | OPEN_PARENS CLOSE_PARENS 
+       | open_parens_any CLOSE_PARENS 
          {
                Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
          }
@@ -5116,7 +5034,7 @@ unsafe_statement
        ;
 
 fixed_statement
-       : FIXED OPEN_PARENS 
+       : FIXED open_parens_any 
          type_and_void fixed_pointer_declarators 
          CLOSE_PARENS
          {
@@ -5184,7 +5102,7 @@ fixed_pointer_declarator
        ;
 
 lock_statement
-       : LOCK OPEN_PARENS expression CLOSE_PARENS 
+       : LOCK open_parens_any expression CLOSE_PARENS 
          {
                //
          } 
@@ -5195,7 +5113,7 @@ lock_statement
        ;
 
 using_statement
-       : USING OPEN_PARENS local_variable_declaration CLOSE_PARENS
+       : USING open_parens_any local_variable_declaration CLOSE_PARENS
          {
                start_block (lexer.Location);
                Block assign_block = current_block;
@@ -5250,7 +5168,7 @@ using_statement
                current_block.AddStatement (stmt);
                $$ = end_block (lexer.Location);
          }
-       | USING OPEN_PARENS expression CLOSE_PARENS
+       | USING open_parens_any expression CLOSE_PARENS
          {
                start_block (lexer.Location);
          }
@@ -5983,6 +5901,10 @@ end_block (Location loc)
 void
 start_anonymous (bool lambda, Parameters parameters, Location loc)
 {
+       if (RootContext.Version == LanguageVersion.ISO_1){
+               Report.FeatureIsNotAvailable (loc, "anonymous methods");
+       }
+
        oob_stack.Push (current_anonymous_method);
        oob_stack.Push (current_local_parameters);
 
@@ -6000,17 +5922,12 @@ start_anonymous (bool lambda, Parameters parameters, Location loc)
  * Completes the anonymous method processing, if lambda_expr is null, this
  * means that we have a Statement instead of an Expression embedded 
  */
-AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
+AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
 {
        AnonymousMethodExpression retval;
 
-       if (RootContext.Version == LanguageVersion.ISO_1){
-               Report.FeatureIsNotAvailable (loc, "anonymous methods");
-               retval = null;
-       } else  {
-               current_anonymous_method.Block = anon_block;
-               retval = current_anonymous_method;
-       }
+       current_anonymous_method.Block = anon_block;
+       retval = current_anonymous_method;
 
        current_local_parameters = (Parameters) oob_stack.Pop ();
        current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
@@ -6027,15 +5944,23 @@ public NamespaceEntry CurrentNamespace {
 
 void Error_SyntaxError (int token)
 {
-       Error_SyntaxError (1525, token);
+       Error_SyntaxError (0, token);
 }
 
 void Error_SyntaxError (int error_code, int token)
 {
        string symbol = GetSymbolName (token);
        string expecting = GetExpecting ();
+       
+       if (error_code == 0) {
+               if (expecting == "`)'")
+                       error_code = 1026;
+               else
+                       error_code = 1525;
+       }
+       
        if (expecting != null)
-               Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
+               Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}", 
                        symbol, expecting);       
        else
                Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
@@ -6044,10 +5969,7 @@ void Error_SyntaxError (int error_code, int token)
 string GetExpecting ()
 {
        int [] tokens = yyExpectingTokens (yyExpectingState);
-       if (tokens.Length == 1)
-               return "`" + GetTokenName (tokens [0]) + "'";
-       
-       ArrayList names = new ArrayList ();
+       ArrayList names = new ArrayList (tokens.Length);
        bool has_type = false;
        bool has_identifier = false;
        for (int i = 0; i < tokens.Length; i++){
@@ -6064,7 +5986,7 @@ string GetExpecting ()
                
                names.Add (name);
        }
-       
+
        //
        // Too many tokens to enumerate
        //
@@ -6074,6 +5996,9 @@ string GetExpecting ()
        if (has_type && has_identifier)
                names.Remove ("identifier");
 
+       if (names.Count == 1)
+               return "`" + GetTokenName (tokens [0]) + "'";
+       
        StringBuilder sb = new StringBuilder ();
        names.Sort ();
        int count = names.Count;
@@ -6134,6 +6059,74 @@ string GetSymbolName (int token)
                return "ushort";
        case Token.OBJECT:
                return "object";
+               
+       case Token.PLUS:
+               return "+";
+       case Token.UMINUS:
+       case Token.MINUS:
+               return "-";
+       case Token.BANG:
+               return "!";
+       case Token.BITWISE_AND:
+               return "&";
+       case Token.BITWISE_OR:
+               return "|";
+       case Token.STAR:
+               return "*";
+       case Token.PERCENT:
+               return "%";
+       case Token.DIV:
+               return "/";
+       case Token.CARRET:
+               return "^";
+       case Token.OP_INC:
+               return "++";
+       case Token.OP_DEC:
+               return "--";
+       case Token.OP_SHIFT_LEFT:
+               return "<<";
+       case Token.OP_SHIFT_RIGHT:
+               return ">>";
+       case Token.OP_LT:
+               return "<";
+       case Token.OP_GT:
+               return ">";
+       case Token.OP_LE:
+               return "<=";
+       case Token.OP_GE:
+               return ">=";
+       case Token.OP_EQ:
+               return "==";
+       case Token.OP_NE:
+               return "!=";
+       case Token.OP_AND:
+               return "&&";
+       case Token.OP_OR:
+               return "||";
+       case Token.OP_PTR:
+               return "->";
+       case Token.OP_COALESCING:       
+               return "??";
+       case Token.OP_MULT_ASSIGN:
+               return "*=";
+       case Token.OP_DIV_ASSIGN:
+               return "/=";
+       case Token.OP_MOD_ASSIGN:
+               return "%=";
+       case Token.OP_ADD_ASSIGN:
+               return "+=";
+       case Token.OP_SUB_ASSIGN:
+               return "-=";
+       case Token.OP_SHIFT_LEFT_ASSIGN:
+               return "<<=";
+       case Token.OP_SHIFT_RIGHT_ASSIGN:
+               return ">>=";
+       case Token.OP_AND_ASSIGN:
+               return "&=";
+       case Token.OP_XOR_ASSIGN:
+               return "^=";
+       case Token.OP_OR_ASSIGN:
+               return "|=";
        }
 
        return GetTokenName (token);
@@ -6312,14 +6305,10 @@ static string GetTokenName (int token)
                return "[";
        case Token.CLOSE_BRACKET:
                return "]";
-       case Token.DEFAULT_OPEN_PARENS:
+       case Token.OPEN_PARENS_CAST:
        case Token.OPEN_PARENS_LAMBDA:
        case Token.OPEN_PARENS:
                return "(";
-       case Token.CLOSE_PARENS_CAST:
-       case Token.CLOSE_PARENS_NO_CAST:
-       case Token.CLOSE_PARENS_OPEN_PARENS:
-       case Token.CLOSE_PARENS_MINUS:
        case Token.CLOSE_PARENS:
                return ")";
        case Token.DOT:
@@ -6359,8 +6348,6 @@ static string GetTokenName (int token)
        case Token.OP_OR:
        case Token.OP_PTR:
        case Token.OP_COALESCING:       
-               return "<operator>";
-       
        case Token.OP_MULT_ASSIGN:
        case Token.OP_DIV_ASSIGN:
        case Token.OP_MOD_ASSIGN:
@@ -6422,8 +6409,6 @@ static string GetTokenName (int token)
        case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
        case Token.EVAL_STATEMENT_PARSER:
        case Token.LOWPREC:
-       case Token.QUERY_LAST_TOKEN:
-       case Token.QUERY_FIRST_TOKEN:
        case Token.LAST_KEYWORD:        
                return "<internal>";