2008-11-05 Francisco Figueiredo Jr. <francisco@npgsql.org>
[mono.git] / mcs / mcs / cs-parser.jay
index ac4633b6c7c2c823f3c2b90d01e9557bf6b5f503..82665c5e9d1b92c107b51f89c22c0e58908ec6ab 100644 (file)
@@ -19,7 +19,8 @@
 // Possible optimization:
 //   Run memory profiler with parsing only, and consider dropping 
 //   arraylists where not needed.   Some pieces can use linked lists.
-//
+
+
 using System.Text;
 using System.IO;
 using System;
@@ -88,8 +89,17 @@ namespace Mono.CSharp
                ///
                Stack switch_stack;
 
+               ///
+               /// Controls the verbosity of the errors produced by the parser
+               ///
                static public int yacc_verbose_flag;
 
+               /// 
+               /// Used by the interactive shell, flags whether EOF was reached
+               /// and an error was produced
+               ///
+               public bool UnexpectedEOF;
+
                ///
                /// The current file.
                ///
@@ -112,6 +122,18 @@ namespace Mono.CSharp
                bool params_modifiers_not_allowed;
                bool arglist_allowed;
 
+
+               /// When using the interactive parser, this holds the
+               /// resulting expression
+               public object InteractiveResult;
+
+               //
+               // Keeps track of global data changes to undo on parser error
+               //
+               public Undo undo;
+
+               // A counter to create new class names in interactive mode
+               static int class_count;
 %}
 
 %token EOF
@@ -126,7 +148,6 @@ namespace Mono.CSharp
 %token ABSTRACT        
 %token AS
 %token ADD
-%token ASSEMBLY
 %token BASE    
 %token BOOL    
 %token BREAK   
@@ -207,7 +228,6 @@ namespace Mono.CSharp
 %token ARGLIST
 %token PARTIAL
 %token ARROW
-%token QUERY_FIRST_TOKEN
 %token FROM
 %token JOIN
 %token ON
@@ -220,86 +240,92 @@ 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           "get"
-%token SET           "set"
+%token GET
+%token SET
 
 %left LAST_KEYWORD
 
 /* C# single character operators/punctuation. */
-%token OPEN_BRACE    "{"
-%token CLOSE_BRACE   "}"
-%token OPEN_BRACKET  "["
-%token CLOSE_BRACKET "]"
-%token OPEN_PARENS   "("
-%token CLOSE_PARENS  ")"
-%token DOT           "."
-%token COMMA         ","
-%token COLON         ":"
-%token SEMICOLON     ";"
-%token TILDE         "~"
-
-%token PLUS           "+"
-%token MINUS          "-"
-%token BANG           "!"
-%token ASSIGN         "="
-%token OP_LT          "<"
-%token OP_GENERICS_LT "<"
-%token OP_GT          ">"
-%token OP_GENERICS_GT ">"
-%token BITWISE_AND    "&"
-%token BITWISE_OR     "|"
-%token STAR           "*"
-%token PERCENT        "%"
-%token DIV            "/"
-%token CARRET         "^"
-%token INTERR         "?"
+%token OPEN_BRACE
+%token CLOSE_BRACE
+%token OPEN_BRACKET
+%token CLOSE_BRACKET
+%token OPEN_PARENS
+%token CLOSE_PARENS
+
+%token DOT
+%token COMMA
+%token COLON
+%token SEMICOLON
+%token TILDE
+
+%token PLUS
+%token MINUS
+%token BANG
+%token ASSIGN
+%token OP_LT
+%token OP_GT
+%token BITWISE_AND
+%token BITWISE_OR
+%token STAR
+%token PERCENT
+%token DIV
+%token CARRET
+%token INTERR
 
 /* C# multi-character operators. */
-%token DOUBLE_COLON          "::"
-%token OP_INC                 "++"
-%token OP_DEC                 "--"
-%token OP_SHIFT_LEFT          "<<"
-%token OP_SHIFT_RIGHT         ">>"
-%token OP_LE                  "<="
-%token OP_GE                  ">="
-%token OP_EQ                  "=="
-%token OP_NE                  "!="
-%token OP_AND                 "&&"
-%token OP_OR                  "||"
-%token OP_MULT_ASSIGN         "*="
-%token OP_DIV_ASSIGN          "/="
-%token OP_MOD_ASSIGN          "%="
-%token OP_ADD_ASSIGN          "+="
-%token OP_SUB_ASSIGN          "-="
-%token OP_SHIFT_LEFT_ASSIGN   "<<="
-%token OP_SHIFT_RIGHT_ASSIGN  ">>="
-%token OP_AND_ASSIGN          "&="
-%token OP_XOR_ASSIGN          "^="
-%token OP_OR_ASSIGN           "|="
-%token OP_PTR                 "->"
-%token OP_COALESCING          "??"
+%token DOUBLE_COLON
+%token OP_INC
+%token OP_DEC
+%token OP_SHIFT_LEFT
+%token OP_SHIFT_RIGHT
+%token OP_LE
+%token OP_GE
+%token OP_EQ
+%token OP_NE
+%token OP_AND
+%token OP_OR
+%token OP_MULT_ASSIGN
+%token OP_DIV_ASSIGN
+%token OP_MOD_ASSIGN
+%token OP_ADD_ASSIGN
+%token OP_SUB_ASSIGN
+%token OP_SHIFT_LEFT_ASSIGN
+%token OP_SHIFT_RIGHT_ASSIGN
+%token OP_AND_ASSIGN
+%token OP_XOR_ASSIGN
+%token OP_OR_ASSIGN
+%token OP_PTR
+%token OP_COALESCING
 
 /* Numbers */
-%token LITERAL_INTEGER           "int literal"
-%token LITERAL_FLOAT             "float literal"
-%token LITERAL_DOUBLE            "double literal"
-%token LITERAL_DECIMAL           "decimal literal"
-%token LITERAL_CHARACTER         "character literal"
-%token LITERAL_STRING            "string literal"
+%token LITERAL_INTEGER
+%token LITERAL_FLOAT
+%token LITERAL_DOUBLE
+%token LITERAL_DECIMAL
+%token LITERAL_CHARACTER
+%token LITERAL_STRING
 
 %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
 
+// Make the parser go into eval mode parsing (statements and compilation units).
+%token EVAL_STATEMENT_PARSER
+%token EVAL_COMPILATION_UNIT_PARSER
+%token EVAL_USING_DECLARATIONS_UNIT_PARSER
+
 /* Add precedence rules to solve dangling else s/r conflict */
 %nonassoc LOWPREC
 %nonassoc IF
@@ -327,8 +353,9 @@ compilation_unit
         | outer_declarations global_attributes opt_EOF
         | global_attributes opt_EOF
        | opt_EOF /* allow empty files */
-        ;
-       
+       | interactive_parsing opt_EOF
+       ;
+
 opt_EOF
        : /* empty */
          {
@@ -341,27 +368,28 @@ opt_EOF
        ;
 
 outer_declarations
-        : outer_declaration
-        | outer_declarations outer_declaration
-        ;
+       : outer_declaration
+       | outer_declarations outer_declaration
+       ;
  
 outer_declaration
        : extern_alias_directive
-        | using_directive 
-        | namespace_member_declaration
-        ;
+       | using_directive 
+       | namespace_member_declaration
+       ;
 
 extern_alias_directives
        : extern_alias_directive
-       | extern_alias_directives extern_alias_directive;
+       | extern_alias_directives extern_alias_directive
+       ;
 
 extern_alias_directive
-       : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
+       : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
          {
                LocatedToken lt = (LocatedToken) $2;
                string s = lt.Value;
                if (s != "alias"){
-                       Report.Error (1003, lt.Location, "'alias' expected");
+                       syntax_error (lt.Location, "`alias' expected");
                } else if (RootContext.Version == LanguageVersion.ISO_1) {
                        Report.FeatureIsNotAvailable (lt.Location, "external alias");
                } else {
@@ -369,6 +397,10 @@ extern_alias_directive
                        current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
                }
          }
+       | EXTERN_ALIAS error
+         {
+               syntax_error (GetLocation ($1), "`alias' expected");   // TODO: better
+         }
        ;
  
 using_directives
@@ -390,14 +422,14 @@ using_directive
        ;
 
 using_alias_directive
-       : USING IDENTIFIER ASSIGN 
-         namespace_or_type_name SEMICOLON
+       : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
          {
                LocatedToken lt = (LocatedToken) $2;
                current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
          }
        | USING error {
                CheckIdentifierToken (yyToken, GetLocation ($2));
+               $$ = null;
          }
        ;
 
@@ -463,7 +495,8 @@ opt_comma
        ;
 
 namespace_name
-       : namespace_or_type_name {
+       : namespace_or_type_name
+        {
                MemberName name = (MemberName) $1;
 
                if (name.TypeArguments != null)
@@ -497,7 +530,7 @@ namespace_body_body
          opt_namespace_member_declarations
          EOF
          {
-               Report.Error (1513, lexer.Location, "} expected");
+               Report.Error (1513, lexer.Location, "Expected `}'");
          }
        ;
 
@@ -548,8 +581,8 @@ namespace_member_declaration
 
 type_declaration
        : class_declaration             
-       | struct_declaration            
-       | interface_declaration         
+       | struct_declaration
+       | interface_declaration
        | enum_declaration              
        | delegate_declaration
 //
@@ -567,20 +600,20 @@ type_declaration
 
 global_attributes
        : attribute_sections
-{
-       if ($1 != null) {
-               Attributes attrs = (Attributes)$1;
-               if (global_attrs_enabled) {
-                       CodeGen.Assembly.AddAttributes (attrs.Attrs);
-               } else {
-                       foreach (Attribute a in attrs.Attrs) {
-                               Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
+         {
+               if ($1 != null) {
+                       Attributes attrs = (Attributes)$1;
+                       if (global_attrs_enabled) {
+                               CodeGen.Assembly.AddAttributes (attrs.Attrs);
+                       } else {
+                               foreach (Attribute a in attrs.Attrs) {
+                                       Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
+                               }
                        }
                }
-       }
-
-       $$ = $1;
-}
+               $$ = $1;
+         }
+       ;
 
 opt_attributes
        : /* empty */ 
@@ -665,7 +698,7 @@ attribute_section
          {
                $$ = $3;
          }
-        | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
+       | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
          {
                $$ = $2;
          }
@@ -689,7 +722,7 @@ attribute_target
        | RETURN { $$ = "return"; }
        | error
          {
-               string name = yyNames [yyToken].ToLower ();
+               string name = GetTokenName (yyToken);
                $$ = CheckAttributeTarget (name, GetLocation ($1));
          }
        ;
@@ -713,15 +746,20 @@ attribute_list
        ;
 
 attribute
-       : attribute_name opt_attribute_arguments
+       : attribute_name
+         {
+               ++lexer.parsing_block;
+         }
+        opt_attribute_arguments
          {
+               --lexer.parsing_block;
                MemberName mname = (MemberName) $1;
                if (mname.IsGeneric) {
                        Report.Error (404, lexer.Location,
                                      "'<' unexpected: attributes cannot be generic");
                }
 
-               object [] arguments = (object []) $2;
+               object [] arguments = (object []) $3;
                MemberName left = mname.Left;
                string identifier = mname.Name;
 
@@ -808,12 +846,12 @@ named_argument_list
 
                $$ = args;
          }
-         | named_argument_list COMMA expression
-           {
-                 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
-                 $$ = null;
-               }
-        ;
+       | named_argument_list COMMA expression
+         {
+               Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
+               $$ = null;
+         }
+       ;
 
 named_argument
        : IDENTIFIER ASSIGN expression
@@ -852,6 +890,12 @@ class_member_declaration
        | constructor_declaration               // done
        | destructor_declaration                // done
        | type_declaration
+       | error
+         {
+               Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
+                       GetSymbolName (yyToken));
+               $$ = null;
+         }
        ;
 
 struct_declaration
@@ -862,7 +906,7 @@ struct_declaration
          {
                lexer.ConstraintsParsing = true;
          }
-         type_name
+         type_declaration_name
          { 
                MemberName name = MakeName ((MemberName) $6);
                push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
@@ -879,6 +923,7 @@ struct_declaration
          }
          struct_body
          {
+               --lexer.parsing_declaration;      
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
@@ -976,9 +1021,14 @@ constant_declarators
        ;
 
 constant_declarator
-       : IDENTIFIER ASSIGN constant_expression
+       : IDENTIFIER ASSIGN
          {
-               $$ = new VariableDeclaration ((LocatedToken) $1, $3);
+               ++lexer.parsing_block;
+         }     
+         constant_initializer
+         {
+               --lexer.parsing_block;
+               $$ = new VariableDeclaration ((LocatedToken) $1, $4);
          }
        | IDENTIFIER
          {
@@ -987,22 +1037,29 @@ constant_declarator
                $$ = null;
          }
        ;
+       
+constant_initializer
+       : constant_expression
+       | array_initializer
+       ;
 
 field_declaration
        : opt_attributes
          opt_modifiers
-         type 
+         member_type
          variable_declarators
          SEMICOLON
          { 
                FullNamedExpression type = (FullNamedExpression) $3;
+               if (type == TypeManager.system_void_expr)
+                       Report.Error (670, GetLocation ($3), "Fields cannot have void type");
+               
                int mod = (int) $2;
 
                current_array_type = null;
 
-               foreach (VariableDeclaration var in (ArrayList) $4){
-                       Field field = new Field (current_class, type, mod, var.identifier, 
-                                                (Attributes) $1, var.Location);
+               foreach (VariableMemberDeclaration var in (ArrayList) $4){
+                       Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
 
                        field.Initializer = var.expression_or_array_initializer;
 
@@ -1017,11 +1074,12 @@ field_declaration
        | opt_attributes
          opt_modifiers
          FIXED
-         type 
+         member_type
          fixed_variable_declarators
          SEMICOLON
          { 
                        FullNamedExpression type = (FullNamedExpression) $4;
+                       
                        int mod = (int) $2;
 
                        current_array_type = null;
@@ -1041,19 +1099,11 @@ field_declaration
        | opt_attributes
          opt_modifiers
          FIXED
-         type 
+         member_type
          error
          {
                Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
          }
-       | opt_attributes
-         opt_modifiers
-         VOID  
-         variable_declarators
-         SEMICOLON {
-               current_array_type = null;
-               Report.Error (670, (Location) $3, "Fields cannot have void type");
-         }
        ;
 
 fixed_variable_declarators
@@ -1082,25 +1132,26 @@ fixed_variable_declarator
                $$ = new VariableDeclaration ((LocatedToken) $1, null);
          }
        ;
-
-variable_declarators
-       : variable_declarator 
+       
+       
+local_variable_declarators     
+       : local_variable_declarator 
          {
                ArrayList decl = new ArrayList (4);
                if ($1 != null)
                        decl.Add ($1);
                $$ = decl;
          }
-       | variable_declarators COMMA variable_declarator
+       | local_variable_declarators COMMA local_variable_declarator
          {
                ArrayList decls = (ArrayList) $1;
                decls.Add ($3);
                $$ = $1;
          }
        ;
-
-variable_declarator
-       : IDENTIFIER ASSIGN variable_initializer
+       
+local_variable_declarator
+       : IDENTIFIER ASSIGN local_variable_initializer
          {
                $$ = new VariableDeclaration ((LocatedToken) $1, $3);
          }
@@ -1108,24 +1159,16 @@ variable_declarator
          {
                $$ = new VariableDeclaration ((LocatedToken) $1, null);
          }
-       | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
+       | IDENTIFIER variable_bad_array
          {
-               Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
-                       "To declare a fixed size buffer field, use the fixed keyword before the field type");
                $$ = null;
          }
        ;
 
-variable_initializer
+local_variable_initializer
        : expression
-         {
-               $$ = $1;
-         }
        | array_initializer
-         {
-               $$ = $1;
-         }
-       | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
+       | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
          {
                $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
          }
@@ -1133,13 +1176,65 @@ variable_initializer
          {
                $$ = new ArglistAccess ((Location) $1);
          }
-       | STACKALLOC type
+       | STACKALLOC simple_type
          {
                Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
-                $$ = null;
+               $$ = new StackAlloc ((Expression) $2, null, (Location) $1);             
+         }
+       ;
+
+variable_declarators
+       : variable_declarator 
+         {
+               ArrayList decl = new ArrayList (4);
+               if ($1 != null)
+                       decl.Add ($1);
+               $$ = decl;
+         }
+       | variable_declarators COMMA variable_declarator
+         {
+               ArrayList decls = (ArrayList) $1;
+               decls.Add ($3);
+               $$ = $1;
+         }
+       ;
+
+variable_declarator
+       : member_declaration_name ASSIGN
+         {
+               ++lexer.parsing_block;
+               lexer.parsing_generic_declaration = false;
+         }
+         variable_initializer
+         {
+               --lexer.parsing_block;
+               $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
+         }
+       | member_declaration_name
+         {
+               lexer.parsing_generic_declaration = false;
+               $$ = new VariableMemberDeclaration ((MemberName) $1, null);
+         }
+       | member_declaration_name variable_bad_array
+         {
+               lexer.parsing_generic_declaration = false;        
+               $$ = null;
+         }
+       ;
+       
+variable_bad_array
+       : OPEN_BRACKET opt_expression CLOSE_BRACKET
+         {
+               Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
+                       "To declare a fixed size buffer field, use the fixed keyword before the field type");
          }
        ;
 
+variable_initializer
+       : expression
+       | array_initializer
+       ;
+
 method_declaration
        : method_header {
                if (RootContext.Documentation != null)
@@ -1150,6 +1245,10 @@ method_declaration
                Method method = (Method) $1;
                method.Block = (ToplevelBlock) $3;
                current_container.AddMethod (method);
+               
+               if (current_container.Kind == Kind.Interface && method.Block != null) {
+                       Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
+               }
 
                current_generic_method = null;
                current_local_parameters = null;
@@ -1159,30 +1258,11 @@ method_declaration
          }
        ;
 
-opt_error_modifier
-       : /* empty */
-       | modifiers 
-         {
-               int m = (int) $1;
-               int i = 1;
-
-               while (m != 0){
-                       if ((i & m) != 0){
-                               Report.Error (1585, lexer.Location,
-                                       "Member modifier `{0}' must precede the member type and name",
-                                       Modifiers.Name (i));
-                       }
-                       m &= ~i;
-                       i = i << 1;
-               }
-         }
-       ;
-
 method_header
        : opt_attributes
          opt_modifiers
-         type member_name
-         OPEN_PARENS
+         member_type
+         method_declaration_name OPEN_PARENS
          {
                arglist_allowed = true;
          }
@@ -1211,7 +1291,7 @@ method_header
                        generic.SetParameterInfo ((ArrayList) $10);
                }
 
-               method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2, false,
+               method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
                                     name, current_local_parameters, (Attributes) $1);
 
                current_generic_method = generic;
@@ -1221,52 +1301,10 @@ method_header
 
                $$ = method;
          }
-       | opt_attributes
-         opt_modifiers
-         VOID member_name
-         OPEN_PARENS
-         {
-               arglist_allowed = true;
-         }       
-         opt_formal_parameter_list CLOSE_PARENS
-         {
-               lexer.ConstraintsParsing = true;
-         }
-         opt_type_parameter_constraints_clauses
-         {
-               lexer.ConstraintsParsing = false;
-               arglist_allowed = false;
-
-               MemberName name = (MemberName) $4;
-               current_local_parameters = (Parameters) $7;
-
-               if ($10 != null && name.TypeArguments == null)
-                       Report.Error (80, lexer.Location,
-                                     "Constraints are not allowed on non-generic declarations");
-
-               Method method;
-               GenericMethod generic = null;
-               if (name.TypeArguments != null) {
-                       generic = new GenericMethod (current_namespace, current_class, name,
-                                                    TypeManager.system_void_expr, current_local_parameters);
-
-                       generic.SetParameterInfo ((ArrayList) $10);
-               }
-
-               method = new Method (current_class, generic, TypeManager.system_void_expr,
-                                    (int) $2, false, name, current_local_parameters, (Attributes) $1);
-
-               current_generic_method = generic;
-
-               if (RootContext.Documentation != null)
-                       method.DocComment = Lexer.consume_doc_comment ();
-
-               $$ = method;
-       }
        | opt_attributes
          opt_modifiers
          PARTIAL
-         VOID member_name
+         VOID method_declaration_name
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
          {
                lexer.ConstraintsParsing = true;
@@ -1311,7 +1349,7 @@ method_header
                modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
                
                method = new Method (current_class, generic, TypeManager.system_void_expr,
-                                    modifiers, false, name, current_local_parameters, (Attributes) $1);
+                                    modifiers, name, current_local_parameters, (Attributes) $1);
 
                current_generic_method = generic;
 
@@ -1322,15 +1360,15 @@ method_header
          }
        | opt_attributes
          opt_modifiers
-         type 
-         modifiers member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+         member_type
+         modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
                MemberName name = (MemberName) $5;
                Report.Error (1585, name.Location, 
                        "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
 
                Method method = new Method (current_class, null, TypeManager.system_void_expr,
-                                           0, false, name, (Parameters) $7, (Attributes) $1);
+                                           0, name, (Parameters) $7, (Attributes) $1);
 
                current_local_parameters = (Parameters) $7;
 
@@ -1387,7 +1425,7 @@ formal_parameter_list
        | fixed_parameters COMMA arglist_modifier
          {
                ArrayList pars_list = (ArrayList) $1;
-               //pars_list.Add (new ArglistParameter (GetLocation ($3)));
+               pars_list.Add (new ArglistParameter (GetLocation ($3)));
 
                Parameter [] pars = new Parameter [pars_list.Count];
                pars_list.CopyTo (pars);
@@ -1422,7 +1460,7 @@ formal_parameter_list
          }
        | arglist_modifier
          {
-               $$ = new Parameters (new Parameter[0], true);
+               $$ = new Parameters (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
          }
        ;
 
@@ -1470,7 +1508,7 @@ fixed_parameter
          type
          {
                Report.Error (1001, GetLocation ($3), "Identifier expected");
-               $$ = null;
+               $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, lexer.Location);               
          }
        | opt_attributes
          opt_parameter_modifier
@@ -1592,12 +1630,12 @@ arglist_modifier
                        Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
          }
        ;
-
+       
 property_declaration
        : opt_attributes
          opt_modifiers
-         type
-         namespace_or_type_name
+         member_type
+         member_declaration_name
          {
                if (RootContext.Documentation != null)
                        tmpComment = Lexer.consume_doc_comment ();
@@ -1605,7 +1643,6 @@ property_declaration
          OPEN_BRACE 
          {
                implicit_value_parameter_type = (FullNamedExpression) $3;
-
                lexer.PropertyParsing = true;
          }
          accessor_declarations 
@@ -1615,21 +1652,31 @@ property_declaration
          }
          CLOSE_BRACE
          { 
-               if ($8 == null)
-                       break;
-
                Property prop;
                Accessors accessors = (Accessors) $8;
-               Accessor get_block = accessors.get_or_add;
-               Accessor set_block = accessors.set_or_remove;
+               Accessor get_block = accessors != null ? accessors.get_or_add : null;
+               Accessor set_block = accessors != null ? accessors.set_or_remove : null;
+               bool order = accessors != null ? accessors.declared_in_reverse : false;
 
                MemberName name = (MemberName) $4;
+               FullNamedExpression ptype = (FullNamedExpression) $3;
 
-               if (name.TypeArguments != null)
-                       syntax_error (lexer.Location, "a property can't have type arguments");
+               prop = new Property (current_class, ptype, (int) $2,
+                                    name, (Attributes) $1, get_block, set_block, order, current_block);
+
+               if (ptype == TypeManager.system_void_expr)
+                       Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
+                       
+               if (accessors == null)
+                       Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
+
+               if (current_container.Kind == Kind.Interface) {
+                       if (prop.Get.Block != null)
+                               Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
 
-               prop = new Property (current_class, (FullNamedExpression) $3, (int) $2, false,
-                                    name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse, current_block);
+                       if (prop.Set.Block != null)
+                               Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
+               }
 
                current_container.AddProperty (prop);
                implicit_value_parameter_type = null;
@@ -1664,8 +1711,16 @@ accessor_declarations
         }
        | error
          {
-               Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
-               $$ = null;
+               if (yyToken == Token.CLOSE_BRACE) {
+                       $$ = null;
+               } else {
+                       if (yyToken == Token.SEMICOLON)
+                               Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
+                       else
+                               Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
+
+                       $$ = new Accessors (null, null);
+               }
          }
        ;
 
@@ -1680,13 +1735,13 @@ get_accessor_declaration
                        current_local_parameters = indexer_parameters;
                lexer.PropertyParsing = false;
          }
-          accessor_body
+         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, (Location) $3);
+               Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
                has_get = true;
                current_local_parameters = null;
                lexer.PropertyParsing = true;
@@ -1702,28 +1757,15 @@ get_accessor_declaration
 set_accessor_declaration
        : opt_attributes opt_modifiers SET 
          {
-               Parameter [] args;
                Parameter implicit_value_parameter = new Parameter (
                        implicit_value_parameter_type, "value", 
                        Parameter.Modifier.NONE, null, (Location) $3);
 
-               if (parsing_indexer == false) {
-                       args  = new Parameter [1];
-                       args [0] = implicit_value_parameter;
-                       current_local_parameters = new Parameters (args);
+               if (!parsing_indexer) {
+                       current_local_parameters = new Parameters (new Parameter [] { implicit_value_parameter });
                } else {
-                       Parameter [] fpars = indexer_parameters.FixedParameters;
-
-                       if (fpars != null){
-                               int count = fpars.Length;
-
-                               args = new Parameter [count + 1];
-                               fpars.CopyTo (args, 0);
-                               args [count] = implicit_value_parameter;
-                       } else 
-                               args = null;
-                       current_local_parameters = new Parameters (
-                               args);
+                       current_local_parameters = Parameters.MergeGenerated (
+                               indexer_parameters, true, implicit_value_parameter, null);
                }
                
                lexer.PropertyParsing = false;
@@ -1731,10 +1773,10 @@ 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, (Location) $3);
+               Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
                has_set = true;
                current_local_parameters = null;
                lexer.PropertyParsing = true;
@@ -1749,7 +1791,15 @@ set_accessor_declaration
 
 accessor_body
        : block 
-       | SEMICOLON             { $$ = null; }
+       | SEMICOLON
+         {
+               $$ = null;
+         }
+       | error
+         {
+               Error_SyntaxError (1043, yyToken);
+               $$ = null;
+         }
        ;
 
 interface_declaration
@@ -1760,7 +1810,7 @@ interface_declaration
          {
                lexer.ConstraintsParsing = true;
          }
-         type_name
+         type_declaration_name
          {
                MemberName name = MakeName ((MemberName) $6);
                push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
@@ -1779,6 +1829,7 @@ interface_declaration
          }
          interface_body
          {
+               --lexer.parsing_declaration;      
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
@@ -1808,392 +1859,75 @@ interface_member_declarations
        ;
 
 interface_member_declaration
-       : interface_method_declaration          
-         { 
-               if ($1 == null)
-                       break;
-
-               Method m = (Method) $1;
-
-               if (m.IsExplicitImpl)
-                       Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
-                               m.GetSignatureForError ());
-
-               current_container.AddMethod (m);
+       : constant_declaration
+         {
+               Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
+         }
+       | field_declaration
+         {
+               Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
+         }
+       | method_declaration
+       | property_declaration
+       | event_declaration
+       | indexer_declaration
+       | operator_declaration
+         {
+               Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
+         }
+       | constructor_declaration
+         {
+               Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
+         }
+       | type_declaration
+         {
+               Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
+         }
+       ;
 
-               if (RootContext.Documentation != null)
-                       Lexer.doc_state = XmlCommentState.Allowed;
+operator_declaration
+       : opt_attributes opt_modifiers operator_declarator 
+         {
          }
-       | interface_property_declaration        
-         { 
-               if ($1 == null)
+         operator_body
+         {
+               if ($3 == null)
                        break;
 
-               Property p = (Property) $1;
+               OperatorDeclaration decl = (OperatorDeclaration) $3;
+               Operator op = new Operator (
+                       current_class, decl.optype, decl.ret_type, (int) $2, 
+                       current_local_parameters,
+                       (ToplevelBlock) $5, (Attributes) $1, decl.location);
 
-               if (p.IsExplicitImpl)
-                       Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
-                               p.GetSignatureForError ());
+               if (RootContext.Documentation != null) {
+                       op.DocComment = tmpComment;
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
 
-               current_container.AddProperty (p);
+               // Note again, checking is done in semantic analysis
+               current_container.AddOperator (op);
 
-               if (RootContext.Documentation != null)
-                       Lexer.doc_state = XmlCommentState.Allowed;
+               current_local_parameters = null;
          }
-       | interface_event_declaration 
-          { 
-               if ($1 != null){
-                       Event e = (Event) $1;
-
-                       if (e.IsExplicitImpl)
-                       Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
-                               e.GetSignatureForError ());
-                       
-                       current_container.AddEvent (e);
-               }
-
-               if (RootContext.Documentation != null)
-                       Lexer.doc_state = XmlCommentState.Allowed;
-         }
-       | interface_indexer_declaration
-         { 
-               if ($1 == null)
-                       break;
-
-               Indexer i = (Indexer) $1;
-
-               if (i.IsExplicitImpl)
-                       Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
-                               i.GetSignatureForError ());
-
-               current_container.AddIndexer (i);
-
-               if (RootContext.Documentation != null)
-                       Lexer.doc_state = XmlCommentState.Allowed;
-         }
-       | delegate_declaration
-         {
-               if ($1 != null) {
-                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
-                               ((MemberCore)$1).GetSignatureForError ());
-               }
-         }
-       | class_declaration
-         {
-               if ($1 != null) {
-                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
-                               ((MemberCore)$1).GetSignatureForError ());
-               }
-         }
-       | struct_declaration
-         {
-               if ($1 != null) {
-                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
-                               ((MemberCore)$1).GetSignatureForError ());
-               }
-         }
-       | enum_declaration 
-         {
-               if ($1 != null) {
-                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
-                               ((MemberCore)$1).GetSignatureForError ());
-               }
-         }
-       | interface_declaration 
-         {
-               if ($1 != null) {
-                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
-                               ((MemberCore)$1).GetSignatureForError ());
-               }
-         } 
-       | constant_declaration
-         {
-               Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
-         }
-       ;
-
-opt_new
-       : opt_modifiers 
-         {
-               int val = (int) $1;
-               val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
-               $$ = val;
-         }
-       ;
-
-interface_method_declaration_body
-       : OPEN_BRACE 
-         {
-               Report.Error (531, (Location)$1,
-                             "`{0}.{1}{2}': interface members cannot have a definition",
-                             current_class.GetSignatureForError (),
-                             ((MemberName) $-0).GetSignatureForError (),
-                             ((Parameters)$-4).GetSignatureForError ());
-         
-               lexer.ConstraintsParsing = false;
-         }
-         opt_statement_list CLOSE_BRACE
-         {
-               $$ = null;
-         }
-       | SEMICOLON
-       ;
-
-interface_method_declaration
-       : opt_attributes opt_new type namespace_or_type_name
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
-         {
-               lexer.ConstraintsParsing = true;
-         }
-         opt_type_parameter_constraints_clauses
-         {
-               // Refer to the name as $-1 in interface_method_declaration_body          
-               $$ = $4;
-         }
-         interface_method_declaration_body
-         {
-               lexer.ConstraintsParsing = false;
-
-               MemberName name = (MemberName) $4;
-
-               if ($9 != null && name.TypeArguments == null)
-                       Report.Error (80, lexer.Location,
-                                     "Constraints are not allowed on non-generic declarations");
-
-               GenericMethod generic = null;
-               if (name.TypeArguments != null) {
-                       generic = new GenericMethod (current_namespace, current_class, name,
-                                                    (FullNamedExpression) $3, (Parameters) $6);
-
-                       generic.SetParameterInfo ((ArrayList) $9);
-               }
-
-               $$ = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2, true, name,
-                                (Parameters) $6, (Attributes) $1);
-               if (RootContext.Documentation != null)
-                       ((Method) $$).DocComment = Lexer.consume_doc_comment ();
-         }
-       | opt_attributes opt_new VOID namespace_or_type_name
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
-         {
-               lexer.ConstraintsParsing = true;
-         }
-         opt_type_parameter_constraints_clauses
-         {
-               $$ = $4;
-         }
-         interface_method_declaration_body
-         {
-               lexer.ConstraintsParsing = false;
-
-               MemberName name = (MemberName) $4;
-
-               if ($9 != null && name.TypeArguments == null)
-                       Report.Error (80, lexer.Location,
-                                     "Constraints are not allowed on non-generic declarations");
-
-               GenericMethod generic = null;
-               if (name.TypeArguments != null) {
-                       generic = new GenericMethod (current_namespace, current_class, name,
-                                                    TypeManager.system_void_expr, (Parameters) $6);
-
-                       generic.SetParameterInfo ((ArrayList) $9);
-               }
-
-               $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
-                                true, name, (Parameters) $6, (Attributes) $1);
-               if (RootContext.Documentation != null)
-                       ((Method) $$).DocComment = Lexer.consume_doc_comment ();
-         }
-       ;
-
-interface_property_declaration
-       : opt_attributes
-         opt_new
-         type IDENTIFIER 
-         OPEN_BRACE 
-         {
-               lexer.PropertyParsing = true;
-               implicit_value_parameter_type = (FullNamedExpression)$3;
-         }
-         accessor_declarations 
-         {
-               has_get = has_set = false; 
-               lexer.PropertyParsing = false;
-               implicit_value_parameter_type = null;
-         }
-         CLOSE_BRACE
-         {
-               LocatedToken lt = (LocatedToken) $4;
-               MemberName name = new MemberName (lt.Value, lt.Location);
-
-               if ($3 == TypeManager.system_void_expr) {
-                       Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
-                       break;
-               }
-
-               Property p = null;
-               if ($7 == null) {
-                       p = new Property (current_class, (FullNamedExpression) $3, (int) $2, true,
-                                  name, (Attributes) $1,
-                                  null, null, false);
-
-                       Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
-                       break;
-               }
-
-               Accessors accessor = (Accessors) $7;
-               p = new Property (current_class, (FullNamedExpression) $3, (int) $2, true,
-                                  name, (Attributes) $1,
-                                  accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
-
-               if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
-                       Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
-                       $$ = null;
-                       break;
-               }
-
-               if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
-                       Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
-                       $$ = null;
-                       break;
-               }
-
-               if (RootContext.Documentation != null)
-                       p.DocComment = Lexer.consume_doc_comment ();
-
-               $$ = p;
-         }
-       | opt_attributes
-         opt_new
-         type error {
-               CheckIdentifierToken (yyToken, GetLocation ($4));
-               $$ = null;
-         }
-       ;
-
-
-interface_event_declaration
-       : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
-         {
-               LocatedToken lt = (LocatedToken) $5;
-               $$ = new EventField (current_class, (FullNamedExpression) $4, (int) $2, true,
-                                    new MemberName (lt.Value, lt.Location),
-                                    (Attributes) $1);
-               if (RootContext.Documentation != null)
-                       ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
-         }
-       | opt_attributes opt_new EVENT type error {
-               CheckIdentifierToken (yyToken, GetLocation ($5));
-               $$ = null;
-         }
-       | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN  {
-               LocatedToken lt = (LocatedToken) $5;
-               Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
-               $$ = null;
-         }
-       | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
-         {
-               implicit_value_parameter_type = (FullNamedExpression) $4;
-               lexer.EventParsing = true;
-         }
-         event_accessor_declarations
-         {
-               lexer.EventParsing = false;
-               implicit_value_parameter_type = null;
-         }
-         CLOSE_BRACE {
-               Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
-               $$ = null;
-         }
-       ;
-
-interface_indexer_declaration 
-       : opt_attributes opt_new type THIS 
-         OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
-         OPEN_BRACE
-         {
-               lexer.PropertyParsing = true;
-               implicit_value_parameter_type = (FullNamedExpression)$3;
-         }
-         accessor_declarations 
-         { 
-               has_get = has_set = false;
-               lexer.PropertyParsing = false;
-               implicit_value_parameter_type = null;
-         }
-         CLOSE_BRACE
-         {
-               Indexer i = null;
-               if ($10 == null) {
-                       i = new Indexer (current_class, (FullNamedExpression) $3,
-                                 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
-                                 (int) $2, true, (Parameters) $6, (Attributes) $1,
-                                 null, null, false);
-
-                       Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
-                       break;
-               }
-
-               Accessors accessors = (Accessors) $10;
-               i = new Indexer (current_class, (FullNamedExpression) $3,
-                                 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
-                                 (int) $2, true, (Parameters) $6, (Attributes) $1,
-                                  accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
-
-               if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
-                       Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
-                       $$ = null;
-                       break;
-               }
-
-               if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
-                       Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
-                       $$ = null;
-                       break;
-               }
-
-               if (RootContext.Documentation != null)
-                       i.DocComment = ConsumeStoredComment ();
-
-               $$ = i;
-         }
-       ;
-
-operator_declaration
-       : opt_attributes opt_modifiers operator_declarator 
-         {
-         }
-         operator_body
-         {
-               if ($3 == null)
-                       break;
-
-               OperatorDeclaration decl = (OperatorDeclaration) $3;
-               Operator op = new Operator (
-                       current_class, decl.optype, decl.ret_type, (int) $2, 
-                       current_local_parameters,
-                       (ToplevelBlock) $5, (Attributes) $1, decl.location);
-
-               if (RootContext.Documentation != null) {
-                       op.DocComment = tmpComment;
-                       Lexer.doc_state = XmlCommentState.Allowed;
-               }
-
-               // Note again, checking is done in semantic analysis
-               current_container.AddOperator (op);
-
-               current_local_parameters = null;
-         }
-       ;
+       ;
 
 operator_body 
        : block
        | SEMICOLON { $$ = null; }
        ; 
 
+operator_type
+       : type_expression_or_array
+       | VOID
+         {
+               Report.Error (590, lexer.Location, "User-defined operators cannot return void");
+               $$ = TypeManager.system_void_expr;              
+         }
+       ;
+
 operator_declarator
-       : type OPERATOR overloadable_operator OPEN_PARENS
+       : operator_type OPERATOR overloadable_operator OPEN_PARENS
          {
                params_modifiers_not_allowed = true;
          }
@@ -2306,43 +2040,26 @@ 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));
          }
        ;
 
 constructor_declaration
-       : opt_attributes
-         opt_modifiers
-         constructor_declarator
+       : constructor_declarator
          constructor_body
          { 
-               Constructor c = (Constructor) $3;
-               c.Block = (ToplevelBlock) $4;
-               c.OptAttributes = (Attributes) $1;
-               int mods = (int) $2;
+               Constructor c = (Constructor) $1;
+               c.Block = (ToplevelBlock) $2;
                
                if (RootContext.Documentation != null)
                        c.DocComment = ConsumeStoredComment ();
 
-               if ((mods & Modifiers.STATIC) != 0 && c.Name == current_container.MemberName.Name) {
-                       if ((mods & Modifiers.Accessibility) != 0){
-                               Report.Error (515, c.Location,
-                                       "`{0}': static constructor cannot have an access modifier",
-                                       c.GetSignatureForError ());
-                       }
-       
-                       if (c.Initializer != null){
-                               Report.Error (514, c.Location,
-                                       "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
-                                       c.GetSignatureForError ());
-                       }
-               }
-
-               c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, mods, Modifiers.PRIVATE, c.Location);
                current_container.AddConstructor (c);
 
                current_local_parameters = null;
@@ -2352,19 +2069,9 @@ constructor_declaration
        ;
 
 constructor_declarator
-       : constructor_header
-         {
-               $$ = $1;
-         }
-       | constructor_header constructor_initializer
-         {
-               ((Constructor)$1).Initializer = (ConstructorInitializer) $2;
-               $$ = $1;
-         }
-       ;
-
-constructor_header
-       : IDENTIFIER
+       : opt_attributes
+         opt_modifiers
+         IDENTIFIER
          {
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -2373,12 +2080,40 @@ constructor_header
          }
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
-               LocatedToken lt = (LocatedToken) $1;
-               current_local_parameters = (Parameters) $4;
-               current_block = new ToplevelBlock (null, current_local_parameters, null, lt.Location);
+               current_local_parameters = (Parameters) $6;  
+               
+               //
+               // start block here, so possible anonymous methods inside
+               // constructor initializer can get correct parent block
+               //
+               start_block (lexer.Location);
+         }
+         opt_constructor_initializer
+         {
+               LocatedToken lt = (LocatedToken) $3;
+               int mods = (int) $2;
+               ConstructorInitializer ci = (ConstructorInitializer) $9;
 
-               $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
-                                     null, lt.Location);
+               Constructor c = new Constructor (current_class, lt.Value, mods,
+                       (Attributes) $1, current_local_parameters, ci, lt.Location);
+               
+               if (lt.Value != current_container.MemberName.Name) {
+                       Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
+               } else if ((mods & Modifiers.STATIC) != 0) {
+                       if ((mods & Modifiers.Accessibility) != 0){
+                               Report.Error (515, c.Location,
+                                       "`{0}': static constructor cannot have an access modifier",
+                                       c.GetSignatureForError ());
+                       }
+                       if (ci != null) {
+                               Report.Error (514, c.Location,
+                                       "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
+                                       c.GetSignatureForError ());
+                       
+                       }
+               }
+               
+               $$ = c;
          }
        ;
 
@@ -2387,14 +2122,29 @@ constructor_body
        | SEMICOLON             { current_block = null; $$ = null; }
        ;
 
+opt_constructor_initializer
+       : /* Empty */
+       | constructor_initializer
+       ;
+
 constructor_initializer
-       : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
+       : COLON BASE OPEN_PARENS
          {
-               $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
+               ++lexer.parsing_block;
          }
-       | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
+         opt_argument_list CLOSE_PARENS
          {
-               $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
+               --lexer.parsing_block;
+               $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2);
+         }
+       | COLON THIS OPEN_PARENS
+         {
+               ++lexer.parsing_block;
+         }
+         opt_argument_list CLOSE_PARENS
+         {
+               --lexer.parsing_block;
+               $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2);
          }
        | COLON error {
                Report.Error (1018, (Location) $1, "Keyword this or base expected");
@@ -2402,14 +2152,8 @@ constructor_initializer
          }
        ;
 
-opt_finalizer
-        : /* EMPTY */           { $$ = 0; }
-        | UNSAFE               { $$ = Modifiers.UNSAFE; }
-       | EXTERN                { $$ = Modifiers.EXTERN; }
-        ;
-        
 destructor_declaration
-       : opt_attributes opt_finalizer TILDE 
+       : opt_attributes opt_modifiers TILDE 
          {
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -2424,17 +2168,9 @@ destructor_declaration
                } else if (current_container.Kind != Kind.Class){
                        Report.Error (575, lt.Location, "Only class types can contain destructor");
                } else {
-                       Location l = lt.Location;
-
-                       int m = (int) $2;
-                       if (!RootContext.StdLib && current_container.Name == "System.Object")
-                               m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
-                       else
-                               m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
-                        
                        Method d = new Destructor (
-                               current_class, TypeManager.system_void_expr, m, "Finalize", 
-                               Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
+                               current_class, TypeManager.system_void_expr, (int) $2, "Finalize", 
+                               Parameters.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
                        if (RootContext.Documentation != null)
                                d.DocComment = ConsumeStoredComment ();
                  
@@ -2450,16 +2186,24 @@ event_declaration
          EVENT type variable_declarators SEMICOLON
          {
                current_array_type = null;
-               foreach (VariableDeclaration var in (ArrayList) $5) {
-
-                       MemberName name = new MemberName (var.identifier,
-                               var.Location);
+               foreach (VariableMemberDeclaration var in (ArrayList) $5) {
 
                        EventField e = new EventField (
-                               current_class, (FullNamedExpression) $4, (int) $2, false, name,
-                               (Attributes) $1);
+                               current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
+                               
+                       if (var.expression_or_array_initializer != null) {
+                               if (current_container.Kind == Kind.Interface) {
+                                       Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
+                               }
 
-                       e.Initializer = var.expression_or_array_initializer;
+                               e.Initializer = var.expression_or_array_initializer;
+                       }
+                       
+                       if (var.MemberName.Left != null) {
+                               Report.Error (71, e.Location,
+                                       "`{0}': An explicit interface implementation of an event must use property syntax",
+                                       e.GetSignatureForError ());
+                       }
 
                        current_container.AddEvent (e);
 
@@ -2471,10 +2215,14 @@ event_declaration
          }
        | opt_attributes
          opt_modifiers
-         EVENT type namespace_or_type_name
+         EVENT type member_declaration_name
          OPEN_BRACE
          {
                implicit_value_parameter_type = (FullNamedExpression) $4;  
+               current_local_parameters = new Parameters (
+                       new Parameter (implicit_value_parameter_type, "value", 
+                       Parameter.Modifier.NONE, null, GetLocation ($3)));
+
                lexer.EventParsing = true;
          }
          event_accessor_declarations
@@ -2484,6 +2232,10 @@ event_declaration
          CLOSE_BRACE
          {
                MemberName name = (MemberName) $5;
+               
+               if (current_container.Kind == Kind.Interface) {
+                       Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
+               }
 
                if ($8 == null){
                        Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
@@ -2492,15 +2244,12 @@ event_declaration
                } else {
                        Accessors accessors = (Accessors) $8;
                        
-                       if (name.TypeArguments != null)
-                               syntax_error (lexer.Location, "an event can't have type arguments");
-
                        if (accessors.get_or_add == null || accessors.set_or_remove == null)
                                // CS0073 is already reported, so no CS0065 here.
                                $$ = null;
                        else {
                                Event e = new EventProperty (
-                                       current_class, (FullNamedExpression) $4, (int) $2, false, name,
+                                       current_class, (FullNamedExpression) $4, (int) $2, name,
                                        (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
                                if (RootContext.Documentation != null) {
                                        e.DocComment = Lexer.consume_doc_comment ();
@@ -2511,17 +2260,19 @@ event_declaration
                                implicit_value_parameter_type = null;
                        }
                }
+               current_local_parameters = null;
          }
-       | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
+       | opt_attributes opt_modifiers EVENT type member_declaration_name error
+         {
                MemberName mn = (MemberName) $5;
-
                if (mn.Left != null)
                        Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
-               else 
-                       Report.Error (71, mn.Location, "Event declaration should use property syntax");
 
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
+
+               Error_SyntaxError (yyToken);
+               $$ = null;
          }
        ;
 
@@ -2547,24 +2298,14 @@ event_accessor_declarations
        ;
 
 add_accessor_declaration
-       : opt_attributes ADD
-         {
-               Parameter [] args = new Parameter [1];
-               Parameter implicit_value_parameter = new Parameter (
-                       implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null, (Location) $2);
-
-               args [0] = implicit_value_parameter;
-               
-               current_local_parameters = new Parameters (args);  
+       : opt_attributes ADD
+         {
                lexer.EventParsing = false;
          }
          block
          {
-               Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
+               Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
                lexer.EventParsing = true;
-               
-               current_local_parameters = null;
                $$ = accessor;
          }
        | opt_attributes ADD error {
@@ -2580,21 +2321,12 @@ add_accessor_declaration
 remove_accessor_declaration
        : opt_attributes REMOVE
          {
-               Parameter [] args = new Parameter [1];
-               Parameter implicit_value_parameter = new Parameter (
-                       implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null, (Location) $2);
-
-               args [0] = implicit_value_parameter;
-               
-               current_local_parameters = new Parameters (args);  
                lexer.EventParsing = false;
          }
          block
          {
-               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
+               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
                lexer.EventParsing = true;
-               current_local_parameters = null;
          }
        | opt_attributes REMOVE error {
                Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
@@ -2607,19 +2339,26 @@ remove_accessor_declaration
        ;
 
 indexer_declaration
-       : opt_attributes opt_modifiers indexer_declarator 
+       : opt_attributes opt_modifiers
+         member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
          OPEN_BRACE
          {
-               IndexerDeclaration decl = (IndexerDeclaration) $3;
-
-               implicit_value_parameter_type = decl.type;
+               implicit_value_parameter_type = (FullNamedExpression) $3;
+               indexer_parameters = (Parameters) $6;
                
+               if (indexer_parameters.IsEmpty)
+                       Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
+
+               if (RootContext.Documentation != null) {
+                       tmpComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
+
                lexer.PropertyParsing = true;
                parsing_indexer  = true;
                
-               indexer_parameters = decl.param_list;
          }
-          accessor_declarations 
+         accessor_declarations 
          {
                  lexer.PropertyParsing = false;
                  has_get = has_set = false;
@@ -2627,27 +2366,28 @@ indexer_declaration
          }
          CLOSE_BRACE
          { 
-               if ($6 == null)
-                       break;
+               Accessors accessors = (Accessors) $10;
+               Accessor get_block = accessors != null ? accessors.get_or_add : null;
+               Accessor set_block = accessors != null ? accessors.set_or_remove : null;
+               bool order = accessors != null ? accessors.declared_in_reverse : false;
+
+               Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
+                       (MemberName)$4, (int) $2, (Parameters) $6, (Attributes) $1,
+                       get_block, set_block, order);
+                                      
+               if ($3 == TypeManager.system_void_expr)
+                       Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
+                       
+               if (accessors == null)
+                       Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
 
-               // The signature is computed from the signature of the indexer.  Look
-               // at section 3.6 on the spec
-               Indexer indexer;
-               IndexerDeclaration decl = (IndexerDeclaration) $3;
-               Location loc = decl.location;
-               Accessors accessors = (Accessors) $6;
-               Accessor get_block = accessors.get_or_add;
-               Accessor set_block = accessors.set_or_remove;
-
-               MemberName name;
-               if (decl.interface_type != null)
-                       name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);
-               else
-                       name = new MemberName (TypeContainer.DefaultIndexerName, loc);
+               if (current_container.Kind == Kind.Interface) {
+                       if (indexer.Get.Block != null)
+                               Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
 
-               indexer = new Indexer (current_class, decl.type, name,
-                                      (int) $2, false, decl.param_list, (Attributes) $1,
-                                      get_block, set_block, accessors.declared_in_reverse);
+                       if (indexer.Set.Block != null)
+                               Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
+               }
 
                if (RootContext.Documentation != null)
                        indexer.DocComment = ConsumeStoredComment ();
@@ -2660,41 +2400,10 @@ indexer_declaration
          }
        ;
 
-indexer_declarator
-       : type THIS OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
-         {
-               Parameters pars = (Parameters) $4;
-               if (pars.Empty){
-                       Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
-               }
-               if (RootContext.Documentation != null) {
-                       tmpComment = Lexer.consume_doc_comment ();
-                       Lexer.doc_state = XmlCommentState.Allowed;
-               }
-
-               $$ = new IndexerDeclaration ((FullNamedExpression) $1, null, pars, (Location) $2);
-         }
-       | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
-         {
-               Parameters pars = (Parameters) $6;
-               if (pars.Empty){
-                       Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
-               }
-
-               MemberName name = (MemberName) $2;
-               $$ = new IndexerDeclaration ((FullNamedExpression) $1, name, pars, (Location) $4);
-
-               if (RootContext.Documentation != null) {
-                       tmpComment = Lexer.consume_doc_comment ();
-                       Lexer.doc_state = XmlCommentState.Allowed;
-               }
-         }
-       ;
-
 enum_declaration
        : opt_attributes
          opt_modifiers
-         ENUM IDENTIFIER 
+         ENUM type_declaration_name
          opt_enum_base {
                if (RootContext.Documentation != null)
                        enumTypeComment = Lexer.consume_doc_comment ();
@@ -2702,11 +2411,13 @@ enum_declaration
          enum_body
          opt_semicolon
          {
-               LocatedToken lt = (LocatedToken) $4;
-               Location enum_location = lt.Location;
+               MemberName name = (MemberName) $4;
+               if (name.IsGeneric) {
+                       Report.Error (1675, name.Location, "Enums cannot have type parameters");
+               }
 
-               MemberName name = MakeName (new MemberName (lt.Value, enum_location));
-               Enum e = new Enum (current_namespace, current_class, (FullNamedExpression) $5, (int) $2,
+               name = MakeName (name);
+               Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
                                   name, (Attributes) $1);
                
                if (RootContext.Documentation != null)
@@ -2724,8 +2435,11 @@ enum_declaration
 
                        e.AddEnumMember (em);
                }
+               if (RootContext.EvalMode)
+                       undo.AddTypeContainer (current_container, e);
 
                current_container.AddTypeContainer (e);
+
                $$ = e;
 
          }
@@ -2733,7 +2447,20 @@ enum_declaration
 
 opt_enum_base
        : /* empty */           { $$ = TypeManager.system_int32_expr; }
-       | COLON type            { $$ = $2;   }
+       | COLON type
+        {
+               if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
+                       $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
+                       $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
+                       $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
+                       Enum.Error_1008 (GetLocation ($2));
+        
+               $$ = $2;
+        }
+       | COLON error
+        {
+               Error_TypeExpected (lexer.Location);
+        }
        ;
 
 enum_body
@@ -2792,13 +2519,15 @@ enum_member_declaration
          }
        | opt_attributes IDENTIFIER
          {
+               ++lexer.parsing_block;
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
          }
-          ASSIGN expression
+         ASSIGN constant_expression
          { 
+               --lexer.parsing_block;    
                VariableDeclaration vd = new VariableDeclaration (
                        (LocatedToken) $2, $5, (Attributes) $1);
 
@@ -2813,7 +2542,7 @@ delegate_declaration
        : opt_attributes
          opt_modifiers
          DELEGATE
-         type type_name
+         member_type type_declaration_name
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
                MemberName name = MakeName ((MemberName) $5);
@@ -2847,47 +2576,31 @@ delegate_declaration
 opt_nullable
        : /* empty */
          {
-               lexer.CheckNullable (false);
-               $$ = false;
+               $$ = null;
          }
-       | INTERR
+       | INTERR_NULLABLE
          {
-               // FIXME: A hack with parsing conditional operator as nullable type
-               //if (RootContext.Version < LanguageVersion.ISO_2)
-               //      Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
-                       
-               lexer.CheckNullable (true);
-               $$ = true;
+               if (RootContext.Version < LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
+         
+               $$ = this;
          }
        ;
 
 namespace_or_type_name
-       : IDENTIFIER opt_type_argument_list
+       : member_name
+       | qualified_alias_member IDENTIFIER opt_type_argument_list
          {
-               LocatedToken lt = (LocatedToken) $1;
-               $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
-         }
-       | IDENTIFIER DOUBLE_COLON IDENTIFIER opt_type_argument_list {
                LocatedToken lt1 = (LocatedToken) $1;
-               LocatedToken lt2 = (LocatedToken) $3;
-               if (RootContext.Version == LanguageVersion.ISO_1)
-                       Report.FeatureIsNotAvailable (lt1.Location, "namespace alias qualifier");
+               LocatedToken lt2 = (LocatedToken) $2;
                
-               $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $4, lt1.Location);
-         }
-       | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
-               LocatedToken lt = (LocatedToken) $3;
-               $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
+               $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
          }
        ;
 
 member_name
-       : IDENTIFIER opt_type_parameter_list
-         {
-               LocatedToken lt = (LocatedToken) $1;
-               $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
-         }
-       | namespace_or_type_name DOT IDENTIFIER opt_type_parameter_list 
+       : type_name
+       | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
          {
                LocatedToken lt = (LocatedToken) $3;
                $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
@@ -2895,17 +2608,16 @@ member_name
        ;
 
 type_name
-       : IDENTIFIER opt_type_parameter_list
+       : IDENTIFIER opt_type_argument_list
          {
                LocatedToken lt = (LocatedToken) $1;
                $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);   
          }
        ;
-
+       
 //
 // Generics arguments  (any type, without attributes)
 //
-
 opt_type_argument_list
        : /* empty */                { $$ = null; } 
        | OP_GENERICS_LT type_arguments OP_GENERICS_GT
@@ -2915,15 +2627,100 @@ opt_type_argument_list
          
                $$ = $2;
          }
+       | OP_GENERICS_LT error
+         {
+               Error_TypeExpected (lexer.Location);
+               $$ = new TypeArguments (lexer.Location);
+         }
+       ;
+
+type_arguments
+       : type
+         {
+               TypeArguments type_args = new TypeArguments (lexer.Location);
+               type_args.Add ((Expression) $1);
+               $$ = type_args;
+         }
+       | type_arguments COMMA type
+         {
+               TypeArguments type_args = (TypeArguments) $1;
+               type_args.Add ((Expression) $3);
+               $$ = type_args;
+         }       
        ;
 
 //
-// Generics parameters (identifiers only, with attributes), used in type, method declarations
+// Generics parameters (identifiers only, with attributes), used in type or method declarations
 //
+type_declaration_name
+       : IDENTIFIER
+         {
+               lexer.parsing_generic_declaration = true;
+         }
+         opt_type_parameter_list
+         {
+               lexer.parsing_generic_declaration = false;
+               LocatedToken lt = (LocatedToken) $1;
+               $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);   
+         }
+       ;
+
+member_declaration_name
+       : method_declaration_name
+         {
+               MemberName mn = (MemberName)$1;
+               if (mn.TypeArguments != null)
+                       syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
+                               mn.GetSignatureForError ()));
+         }
+       ;
+
+method_declaration_name
+       : type_declaration_name
+       | explicit_interface IDENTIFIER opt_type_parameter_list
+         {
+               lexer.parsing_generic_declaration = false;        
+               LocatedToken lt = (LocatedToken) $2;
+               $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
+         }
+       ;
+       
+indexer_declaration_name
+       : THIS
+         {
+               lexer.parsing_generic_declaration = false;        
+               $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
+         }
+       | explicit_interface THIS
+         {
+               lexer.parsing_generic_declaration = false;
+               $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
+         }
+       ;
 
+explicit_interface
+       : IDENTIFIER opt_type_argument_list DOT
+         {
+               LocatedToken lt = (LocatedToken) $1;
+               $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
+         }
+       | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
+         {
+               LocatedToken lt1 = (LocatedToken) $1;
+               LocatedToken lt2 = (LocatedToken) $2;
+               
+               $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
+         }
+       | explicit_interface IDENTIFIER opt_type_argument_list DOT
+         {
+               LocatedToken lt = (LocatedToken) $2;
+               $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
+         }
+       ;
+       
 opt_type_parameter_list
        : /* empty */                { $$ = null; } 
-       | OP_GENERICS_LT type_arguments OP_GENERICS_GT
+       | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
          {
                if (RootContext.Version < LanguageVersion.ISO_2)
                        Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
@@ -2932,68 +2729,107 @@ opt_type_parameter_list
          }
        ;
 
-type_arguments
-       : type_argument
+type_parameters
+       : type_parameter
          {
                TypeArguments type_args = new TypeArguments (lexer.Location);
-               type_args.Add ((Expression) $1);
+               type_args.Add ((Expression)$1);
                $$ = type_args;
          }
-       | type_arguments COMMA type_argument
+       | type_parameters COMMA type_parameter
          {
                TypeArguments type_args = (TypeArguments) $1;
-               type_args.Add ((Expression) $3);
+               type_args.Add ((Expression)$3);
                $$ = type_args;
          }       
        ;
 
-type_argument
-       : type
+type_parameter
+       : opt_attributes IDENTIFIER
          {
-               $$ = $1;
+               LocatedToken lt = (LocatedToken)$2;
+               $$ = new TypeParameterName (lt.Value, (Attributes)$1, lt.Location);
          }
-       | attribute_sections type
+       | error
          {
-               SimpleName sn = $2 as SimpleName;
-               if (sn == null)
-                       Error_TypeExpected (GetLocation ($2));
+               if (GetTokenName (yyToken) == "type")
+                       Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
                else
-                       $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
-               $$ = $2;          
+                       Error_SyntaxError (yyToken);
+                       
+               $$ = new TypeParameterName ("", null, lexer.Location);
          }
        ;
+
+//
+// All types where void is allowed
+//
+type_and_void
+       : type_expression_or_array
+       | VOID
+         {
+               $$ = TypeManager.system_void_expr;
+         }
+       ;
        
-/* 
- * Before you think of adding a return_type, notice that we have been
- * using two rules in the places where it matters (one rule using type
- * and another identical one that uses VOID as the return type).  This
- * gets rid of a shift/reduce couple
- */
+member_type
+       : type_and_void
+         {
+               lexer.parsing_generic_declaration = true;
+         }
+       ;
+
+//
+// A type which does not allow `void' to be used
+//
 type
+       : type_expression_or_array
+       | VOID
+         {
+               Expression.Error_VoidInvalidInTheContext (lexer.Location);
+               $$ = TypeManager.system_void_expr;
+         }     
+       ;
+       
+simple_type
+       : type_expression
+       | VOID
+         {
+               Expression.Error_VoidInvalidInTheContext (lexer.Location);
+               $$ = TypeManager.system_void_expr;
+         }     
+       ;               
+
+type_expression_or_array
+       : type_expression
+       | type_expression rank_specifiers
+         {
+               string rank_specifiers = (string) $2;
+               $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
+         }
+       ;
+       
+type_expression
        : namespace_or_type_name opt_nullable
          {
                MemberName name = (MemberName) $1;
 
-               if ((bool) $2) {
+               if ($2 != null) {
                        $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
                } else {
-                       if (RootContext.Version > LanguageVersion.ISO_2 && name.Left == null && name.Name == "var")
-                               $$ = new VarExpr (name.Location);
+                       if (name.Left == null && name.Name == "var" &&
+                           (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
+                               $$ = current_array_type = new VarExpr (name.Location);
                        else
                                $$ = name.GetTypeExpression ();
                }
          }
        | builtin_types opt_nullable
          {
-               if ((bool) $2)
+               if ($2 != null)
                        $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
          }
-       | array_type
-       | pointer_type
-       ;
-
-pointer_type
-       : type STAR
+       | type_expression STAR
          {
                //
                // Note that here only unmanaged types are allowed but we
@@ -3005,42 +2841,7 @@ pointer_type
        | VOID STAR
          {
                $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
-         }
-       ;
-
-non_expression_type
-       : builtin_types opt_nullable
-         {
-               if ((bool) $2)
-                       $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
-         }
-       | non_expression_type rank_specifier
-         {
-               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
@@ -3065,11 +2866,15 @@ base_type_name
                        Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
                $$ = $1;
          }
+       | error
+         {
+               Error_TypeExpected (lexer.Location);
+         }
        ;
        
 /*
  * 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; }
@@ -3091,38 +2896,32 @@ integral_type
        | LONG          { $$ = TypeManager.system_int64_expr; }
        | ULONG         { $$ = TypeManager.system_uint64_expr; }
        | CHAR          { $$ = TypeManager.system_char_expr; }
-       | VOID          { $$ = TypeManager.system_void_expr; }
        ;
 
-array_type
-       : type rank_specifiers
+predefined_type
+       : builtin_types
+       | VOID
          {
-               string rank_specifiers = (string) $2;
-               $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
+               $$ = TypeManager.system_void_expr;      
          }
        ;
 
 //
 // Expressions, section 7.5
 //
+
+
 primary_expression
+       : primary_expression_no_array_creation
+       | array_creation_expression
+       ;
+
+primary_expression_no_array_creation
        : literal
+       | IDENTIFIER opt_type_argument_list
          {
-               // 7.5.1: Literals
-         }
-       | type_name
-         {
-               MemberName mn = (MemberName) $1;
-               $$ = mn.GetTypeExpression ();
-         }
-       | IDENTIFIER DOUBLE_COLON IDENTIFIER opt_type_argument_list
-         {
-               LocatedToken lt1 = (LocatedToken) $1;
-               LocatedToken lt2 = (LocatedToken) $3;
-               if (RootContext.Version == LanguageVersion.ISO_1)
-                       Report.FeatureIsNotAvailable (lt1.Location, "namespace alias qualifier");
-
-               $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $4, lt1.Location);
+               LocatedToken lt = (LocatedToken) $1;
+               $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);          
          }
        | parenthesized_expression
        | default_value_expression
@@ -3133,7 +2932,8 @@ primary_expression
        | base_access
        | post_increment_expression
        | post_decrement_expression
-       | new_expression
+       | object_or_delegate_creation_expression
+       | anonymous_type_expression
        | typeof_expression
        | sizeof_expression
        | checked_expression
@@ -3179,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
          {
@@ -3221,39 +3010,19 @@ member_access
                // TODO: Location is wrong as some predefined types doesn't hold a location
                $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
          }
-       ;
+       | qualified_alias_member IDENTIFIER opt_type_argument_list
+         {
+               LocatedToken lt1 = (LocatedToken) $1;
+               LocatedToken lt2 = (LocatedToken) $2;
 
-predefined_type
-       : builtin_types
+               $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
+         }
        ;
 
 invocation_expression
-       : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
-         {
-               if ($1 == null)
-                       Report.Error (1, (Location) $2, "Parse error");
-               else
-                       $$ = 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
+       : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
          {
-               ArrayList args = ((ArrayList) $4);
-               args.Add ($6);
-               $$ = new Invocation ((Expression) $1, args);
+               $$ = new Invocation ((Expression) $1, (ArrayList) $3);
          }
        ;
 
@@ -3342,9 +3111,15 @@ argument_list
                list.Add ($3);
                $$ = list;
          }
-       | argument_list error {
-               CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
-               $$ = null;
+       | argument_list COMMA
+         {
+               Report.Error (839, GetLocation ($2), "An argument is missing");
+               $$ = null;
+         }
+       | COMMA argument
+         {
+               Report.Error (839, GetLocation ($1), "An argument is missing");
+               $$ = null;
          }
        ;
 
@@ -3368,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];
@@ -3377,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);
          }       
@@ -3392,11 +3167,16 @@ variable_reference
        ;
 
 element_access
-       : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET 
+       : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET       
          {
                $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
          }
-       | primary_expression rank_specifiers
+       | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
+         {
+               // LAMESPEC: Not allowed according to specification
+               $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
+         }     
+       | primary_expression_no_array_creation rank_specifiers
          {
                // So the super-trick is that primary_expression
                // can only be either a SimpleName or a MemberAccess. 
@@ -3464,27 +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);
          }
        ;
 
-new_expression
-       : object_or_delegate_creation_expression
-       | array_creation_expression
-       | anonymous_type_expression
-       ;
-
 object_or_delegate_creation_expression
-       : NEW 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)
@@ -3495,7 +3267,7 @@ object_or_delegate_creation_expression
                else
                        $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
          }
-       | NEW type object_or_collection_initializer
+       | NEW simple_type object_or_collection_initializer
          {
                if (RootContext.Version <= LanguageVersion.ISO_2)
                        Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
@@ -3504,27 +3276,26 @@ object_or_delegate_creation_expression
          }
        ;
 
+
 array_creation_expression
-       : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET 
-         opt_rank_specifier
+       : NEW simple_type OPEN_BRACKET expression_list CLOSE_BRACKET 
+         opt_rank_specifier    // shift/reduce on OPEN_BRACE
          opt_array_initializer
          {
                $$ = new ArrayCreation ((FullNamedExpression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
          }
-       | NEW type rank_specifiers array_initializer
+       | NEW simple_type rank_specifiers opt_array_initializer
          {
+               if ($4 == null)
+                       Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
+
                $$ = new ArrayCreation ((FullNamedExpression) $2, (string) $3, (ArrayList) $4, (Location) $1);
          }
        | NEW rank_specifiers array_initializer
          {
                $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
          }
-       | NEW error
-         {
-               Report.Error (1031, (Location) $1, "Type expected");
-                $$ = null;
-         }          
-       | NEW type error 
+       | NEW simple_type error
          {
                Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
                $$ = null;
@@ -3599,58 +3370,53 @@ anonymous_type_parameter
 opt_rank_specifier
        : /* empty */
          {
-                 $$ = "";
+               $$ = "";
          }
        | rank_specifiers
          {
-                       $$ = $1;
+               $$ = $1;
          }
        ;
 
 opt_rank_specifier_or_nullable
-       : /* empty */
-         {
-               $$ = string.Empty;
-         }
-       | INTERR
+       : opt_nullable
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
-
-               $$ = "?";
+               if ($1 != null)
+                       $$ = "?";
+               else
+                       $$ = string.Empty;
          }
        | opt_nullable rank_specifiers
          {
-               if ((bool) $1)
-                       $$ = "?" + $2;
+               if ($1 != null)
+                       $$ = "?" + (string) $2;
                else
                        $$ = $2;
          }
        ;
 
 rank_specifiers
-       : rank_specifier opt_rank_specifier
+       : rank_specifier
+       | rank_specifier rank_specifiers
          {
-                 $$ = (string) $2 + (string) $1;
+               $$ = (string) $2 + (string) $1;
          }
-        ;
+       ;
 
 rank_specifier
-       : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
+       : OPEN_BRACKET CLOSE_BRACKET
          {
-               $$ = "[" + (string) $2 + "]";
+               $$ = "[]";
          }
-       ;
-
-opt_dim_separators
-       : /* empty */
+       | OPEN_BRACKET dim_separators CLOSE_BRACKET
          {
-               $$ = "";
+               $$ = "[" + (string) $2 + "]";
          }
-       | dim_separators
+       | OPEN_BRACKET error CLOSE_BRACKET
          {
-                 $$ = $1;
-         }               
+               ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1));
+               $$ = "[]";
+         }
        ;
 
 dim_separators
@@ -3669,7 +3435,7 @@ opt_array_initializer
          {
                $$ = null;
          }
-        | array_initializer
+       | array_initializer
          {
                $$ = $1;
          }
@@ -3700,6 +3466,11 @@ variable_initializer_list
                list.Add ($3);
                $$ = list;
          }
+       | error
+         {
+               Error_SyntaxError (yyToken);
+               $$ = new ArrayList ();
+         }
        ;
 
 typeof_expression
@@ -3708,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;
@@ -3721,7 +3492,7 @@ typeof_expression
        ;
        
 typeof_type_expression
-       : type
+       : type_and_void
          {
                $$ = $1;
          }
@@ -3729,63 +3500,81 @@ typeof_type_expression
          {
                $$ = new UnboundTypeExpression ((MemberName)$1, lexer.Location);
          }
+       | error
+        {
+               Error_TypeExpected (lexer.Location);
+               $$ = null;
+        }
        ;
        
 unbound_type_name
-       : IDENTIFIER GENERIC_DIMENSION
-         {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (lexer.Location, "generics");
-         
+       : IDENTIFIER generic_dimension
+         {  
                LocatedToken lt = (LocatedToken) $1;
-               TypeArguments ta = new TypeArguments ((int)$2, lt.Location);
+               TypeArguments ta = (TypeArguments)$2;
 
                $$ = new MemberName (lt.Value, ta, lt.Location);
          }
-       | IDENTIFIER DOUBLE_COLON IDENTIFIER GENERIC_DIMENSION
+       | qualified_alias_member IDENTIFIER generic_dimension
          {
-               LocatedToken lt = (LocatedToken) $1;
-               MemberName left = new MemberName (lt.Value, lt.Location);
-               lt = (LocatedToken) $3;
-               TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
-               
-               if (RootContext.Version == LanguageVersion.ISO_1)
-                       Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
-               
-               $$ = new MemberName (left, lt.Value, ta, lt.Location);
+               LocatedToken lt1 = (LocatedToken) $1;
+               LocatedToken lt2 = (LocatedToken) $2;
+               TypeArguments ta = (TypeArguments)$3;
+
+               $$ = new MemberName (new MemberName (lt1.Value, lt1.Location), lt2.Value, ta, lt2.Location);
          }
-       | unbound_type_name DOT IDENTIFIER GENERIC_DIMENSION
+       | unbound_type_name DOT IDENTIFIER generic_dimension
          {
                LocatedToken lt = (LocatedToken) $3;
-               TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
+               TypeArguments ta = (TypeArguments)$4;
                
                $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
          }
-       | namespace_or_type_name DOT IDENTIFIER GENERIC_DIMENSION
+       | namespace_or_type_name DOT IDENTIFIER generic_dimension
          {
                LocatedToken lt = (LocatedToken) $3;
-               TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
+               TypeArguments ta = (TypeArguments)$4;
                
-               $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
+               $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);                
+         }
+       ;
+       
+generic_dimension
+       : GENERIC_DIMENSION
+         {
+               if (RootContext.Version < LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (lexer.Location, "generics");
+
+               $$ = new TypeArguments ((int)$1, lexer.Location);
          }
        ;
+       
+qualified_alias_member
+       : IDENTIFIER DOUBLE_COLON
+         {
+               LocatedToken lt = (LocatedToken) $1;
+               if (RootContext.Version == LanguageVersion.ISO_1)
+                       Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
 
+               $$ = lt;                
+         }
+       ;
 
 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);
          }
@@ -3809,7 +3598,7 @@ anonymous_method_expression
          }
          block
          {
-               $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
+               $$ = end_anonymous ((ToplevelBlock) $4);
        }
        ;
 
@@ -3831,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));
          }
        ;
 
@@ -3844,36 +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
+       | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
          {
-               $$ = new Cast ((Expression) $1, (Expression) $3);
-         }     
-       ;
-
-cast_expression
-       : cast_list
-       | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
-         {
-               // TODO: wrong location
-               $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
+               $$ = new Cast ((Expression) $2, (Expression) $4, GetLocation ($1));
          }
        ;
 
@@ -3885,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);
          }
        ;
 
@@ -3939,9 +3713,21 @@ 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);
          }
+       | additive_expression IS type
+         {
+               $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
+         }       
        ;
 
 shift_expression
@@ -3958,28 +3744,6 @@ shift_expression
          }
        ; 
 
-opt_error
-       : /* empty */
-         {
-               $$ = false;
-         }
-       | error
-         {
-               lexer.PutbackNullable ();
-               $$ = true;
-         }
-       ;
-
-nullable_type_or_conditional
-       : type opt_error
-         {
-               if (((bool) $2) && ($1 is ComposedCast))
-                       $$ = ((ComposedCast) $1).RemoveNullable ();
-               else
-                       $$ = $1;
-         }
-       ;
-
 relational_expression
        : shift_expression
        | relational_expression OP_LT shift_expression
@@ -4002,20 +3766,6 @@ relational_expression
                $$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
                                 (Expression) $1, (Expression) $3);
          }
-       | relational_expression IS
-         {
-               yyErrorFlag = 3;
-         } nullable_type_or_conditional
-         {
-               $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
-         }
-       | relational_expression AS
-         {
-               yyErrorFlag = 3;
-         } nullable_type_or_conditional
-         {
-               $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
-         }
        ;
 
 equality_expression
@@ -4090,11 +3840,15 @@ conditional_expression
                        
                $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
          }
-       // We'll be resolved into a `parenthesized_expression_0' later on.
-       | conditional_or_expression INTERR CLOSE_PARENS
+       | primary_expression INTERR_NULLABLE opt_rank_specifier
          {
-               $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
-               lexer.PutbackCloseParens ();
+               //
+               // TODO: Is this the best place to handle `= (foo?)a;' ?
+               //
+               if (RootContext.Version < LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
+               
+               $$ = new ComposedCast ((FullNamedExpression) $1, "?" + (string)$3, lexer.Location);
          }
        ;
 
@@ -4224,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);
          }
        ;
 
@@ -4270,7 +4024,7 @@ class_declaration
          {
                lexer.ConstraintsParsing = true;
          }
-         type_name
+         type_declaration_name
          {
                MemberName name = MakeName ((MemberName) $6);
                push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
@@ -4289,6 +4043,7 @@ class_declaration
          }
          class_body
          {
+               --lexer.parsing_declaration;      
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
@@ -4326,7 +4081,12 @@ modifiers
        ;
 
 modifier
-       : NEW                   { $$ = Modifiers.NEW; }
+       : NEW
+         {
+               $$ = Modifiers.NEW;
+               if (current_container == RootContext.ToplevelTypes)
+                       Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
+         }
        | PUBLIC                { $$ = Modifiers.PUBLIC; }
        | PROTECTED             { $$ = Modifiers.PROTECTED; }
        | INTERNAL              { $$ = Modifiers.INTERNAL; }
@@ -4443,6 +4203,7 @@ block_prepared
        : OPEN_BRACE
          {
                ++lexer.parsing_block;
+               current_block.StartLocation = GetLocation ($1);
          }
          opt_statement_list CLOSE_BRACE 
          {
@@ -4476,6 +4237,32 @@ statement
        | labeled_statement
        ;
 
+//
+// The interactive_statement and its derivatives are only 
+// used to provide a special version of `expression_statement'
+// that has a side effect of assigning the expression to
+// $retval
+//
+interactive_statement_list
+       : interactive_statement
+       | interactive_statement_list interactive_statement
+       ;
+
+interactive_statement
+       : declaration_statement
+         {
+               if ($1 != null && (Block) $1 != current_block){
+                       current_block.AddStatement ((Statement) $1);
+                       current_block = (Block) $1;
+               }
+         }
+       | interactive_valid_declaration_statement
+         {
+               current_block.AddStatement ((Statement) $1);
+         }
+       | labeled_statement
+       ;
+
 valid_declaration_statement
        : block
        | empty_statement
@@ -4492,6 +4279,22 @@ valid_declaration_statement
        | fixed_statement
        ;
 
+interactive_valid_declaration_statement
+       : block
+       | empty_statement
+        | interactive_expression_statement
+       | selection_statement
+       | iteration_statement
+       | jump_statement                  
+       | try_statement
+       | checked_statement
+       | unchecked_statement
+       | lock_statement
+       | using_statement
+       | unsafe_statement
+       | fixed_statement
+       ;
+
 embedded_statement
        : valid_declaration_statement
        | declaration_statement
@@ -4554,8 +4357,8 @@ declaration_statement
  * > expressions to prevent reduce/reduce errors in the grammar.
  * > The expressions are converted into types during semantic analysis.
  */
-local_variable_type
-       : primary_expression opt_rank_specifier_or_nullable
+variable_type
+       : primary_expression_no_array_creation opt_rank_specifier_or_nullable
          { 
                // FIXME: Do something smart here regarding the composition of the type.
 
@@ -4585,8 +4388,9 @@ local_variable_type
                        //
                        if (rank_or_nullable.Length == 0) {
                                SimpleName sn = expr as SimpleName;
-                               if (sn != null && RootContext.Version > LanguageVersion.ISO_2 && sn.Name == "var")
-                                       $$ = new VarExpr (sn.Location);
+                               if (sn != null && sn.Name == "var" &&
+                                   (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
+                                       $$ = current_array_type = new VarExpr (sn.Location);
                                else
                                        $$ = $1;
                        } else {
@@ -4604,10 +4408,15 @@ local_variable_type
                else
                        $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
          }
-        ;
+       | VOID opt_rank_specifier
+         {
+               Expression.Error_VoidInvalidInTheContext (lexer.Location);
+               $$ = TypeManager.system_void_expr;
+         }
+       ;
 
 local_variable_pointer_type
-       : primary_expression STAR
+       : primary_expression_no_array_creation STAR
          {
                ATypeNameExpression expr = $1 as ATypeNameExpression;
 
@@ -4618,22 +4427,39 @@ local_variable_pointer_type
                        $$ = expr;
                }
          }
-        | builtin_types STAR
+       | builtin_types STAR
          {
-               $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
+               $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
          }
-        | VOID STAR
+       | VOID STAR
          {
                $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
          }
        | local_variable_pointer_type STAR
-          {
+         {
                $$ = new ComposedCast ((FullNamedExpression) $1, "*");
          }
-        ;
+       ;
+
+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 variable_declarators
+       : local_variable_type local_variable_declarators
          {
                if ($1 != null) {
                        VarExpr ve = $1 as VarExpr;
@@ -4644,23 +4470,10 @@ local_variable_declaration
                } else
                        $$ = null;
          }
-       | local_variable_pointer_type opt_rank_specifier_or_nullable 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);
@@ -4673,6 +4486,10 @@ expression_statement
        : statement_expression SEMICOLON { $$ = $1; }
        ;
 
+interactive_expression_statement
+       : interactive_statement_expression SEMICOLON { $$ = $1; }
+       ;
+
        //
        // We have to do the wrapping here and not in the case above,
        // because statement_expression is used for example in for_statement
@@ -4681,27 +4498,46 @@ statement_expression
        : expression
          {
                Expression expr = (Expression) $1;
-               ExpressionStatement s = expr as ExpressionStatement;
+               ExpressionStatement s;
+
+               s = expr as ExpressionStatement;
+
                if (s == null) {
                        expr.Error_InvalidExpressionStatement ();
-                       $$ = null;
                }
+
                $$ = new StatementExpression (s);
          }
        | error
          {
-               Report.Error (1002, GetLocation ($1), "Expecting `;'");
+               Error_SyntaxError (yyToken);
                $$ = null;
          }
        ;
 
+interactive_statement_expression
+       : expression
+         {
+               Expression expr = (Expression) $1;
+               ExpressionStatement s;
+
+               s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
+               $$ = new StatementExpression (s);
+         }
+       | error
+         {
+               Error_SyntaxError (yyToken);
+               $$ = null;
+         }
+       ;
+       
 selection_statement
        : if_statement
        | switch_statement
        ; 
 
 if_statement
-       : IF OPEN_PARENS boolean_expression CLOSE_PARENS 
+       : IF open_parens_any boolean_expression CLOSE_PARENS 
          embedded_statement
          { 
                Location l = (Location) $1;
@@ -4713,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;
@@ -4729,7 +4565,7 @@ if_statement
        ;
 
 switch_statement
-       : SWITCH OPEN_PARENS
+       : SWITCH open_parens_any
          { 
                if (switch_stack == null)
                        switch_stack = new Stack (2);
@@ -4807,12 +4643,13 @@ switch_labels
        ;
 
 switch_label
-       : CASE constant_expression COLON        { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
-       | DEFAULT_COLON                         { $$ = new SwitchLabel (null, (Location) $1); }
-       | error {
-               Report.Error (
-                       1523, GetLocation ($1), 
-                       "The keyword case or default must precede code in switch block");
+       : CASE constant_expression COLON
+        {
+               $$ = new SwitchLabel ((Expression) $2, (Location) $1);
+        }
+       | DEFAULT_COLON
+         {
+               $$ = new SwitchLabel (null, (Location) $1);
          }
        ;
 
@@ -4824,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);
@@ -4833,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;
 
@@ -4842,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);  
@@ -4940,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);
@@ -5164,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");
          }
@@ -5198,8 +5034,8 @@ unsafe_statement
        ;
 
 fixed_statement
-       : FIXED OPEN_PARENS 
-         type fixed_pointer_declarators 
+       : FIXED open_parens_any 
+         type_and_void fixed_pointer_declarators 
          CLOSE_PARENS
          {
                ArrayList list = (ArrayList) $4;
@@ -5266,7 +5102,7 @@ fixed_pointer_declarator
        ;
 
 lock_statement
-       : LOCK OPEN_PARENS expression CLOSE_PARENS 
+       : LOCK open_parens_any expression CLOSE_PARENS 
          {
                //
          } 
@@ -5277,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;
@@ -5332,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);
          }
@@ -5599,6 +5435,75 @@ opt_query_continuation
          }
        ;
        
+//
+// Support for using the compiler as an interactive parser
+//
+// The INTERACTIVE_PARSER token is first sent to parse our
+// productions;  If the result is a Statement, the parsing
+// is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
+// to setup the blocks in advance.
+//
+// This setup is here so that in the future we can add 
+// support for other constructs (type parsing, namespaces, etc)
+// that do not require a block to be setup in advance
+//
+
+interactive_parsing
+       : EVAL_STATEMENT_PARSER EOF 
+       | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives 
+       | EVAL_STATEMENT_PARSER { 
+               Evaluator.LoadAliases (current_namespace);
+
+               push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
+                       Modifiers.PUBLIC, null), null);
+
+               ArrayList baseclass_list = new ArrayList ();
+               baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
+               current_container.AddBasesForPart (current_class, baseclass_list);
+
+               // (ref object retval)
+               Parameter [] mpar = new Parameter [1];
+               mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
+
+               Parameters pars = new Parameters (mpar);
+               current_local_parameters = pars;
+               Method method = new Method (
+                       current_class,
+                       null, // generic
+                       TypeManager.system_void_expr,
+                       Modifiers.PUBLIC | Modifiers.STATIC,
+                       new MemberName ("Host"),
+                       pars,
+                       null /* attributes */);
+
+               oob_stack.Push (method);
+               ++lexer.parsing_block;
+               start_block (lexer.Location);
+         }             
+         interactive_statement_list
+         {
+               --lexer.parsing_block;
+               Method method = (Method) oob_stack.Pop ();
+
+               method.Block = (ToplevelBlock) end_block(lexer.Location);
+               current_container.AddMethod (method);
+
+               --lexer.parsing_declaration;
+               InteractiveResult = pop_current_class ();
+               current_local_parameters = null;
+         } 
+       | EVAL_COMPILATION_UNIT_PARSER {
+               Evaluator.LoadAliases (current_namespace);
+         }
+         interactive_compilation_unit
+       ;
+
+interactive_compilation_unit
+       : outer_declarations 
+       | outer_declarations global_attributes 
+       | global_attributes 
+       | /* nothing */
+       ;
 %%
 
 // <summary>
@@ -5628,25 +5533,24 @@ public class VariableDeclaration {
        }
 }
 
-// <summary>
-//   A class used to hold info about an indexer declarator
-// </summary>
-public class IndexerDeclaration {
-       public FullNamedExpression type;
-       public MemberName interface_type;
-       public Parameters param_list;
-       public Location location;
-
-       public IndexerDeclaration (FullNamedExpression type, MemberName interface_type,
-                                  Parameters param_list, Location loc)
+class VariableMemberDeclaration
+{
+       public readonly MemberName MemberName;
+       public Expression expression_or_array_initializer;
+       
+       public VariableMemberDeclaration (MemberName mn, object initializer)
        {
-               this.type = type;
-               this.interface_type = interface_type;
-               this.param_list = param_list;
-               this.location = loc;
+               MemberName = mn;
+               
+               if (initializer is ArrayList) {
+                       this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
+               } else {
+                       this.expression_or_array_initializer = (Expression)initializer;
+               }
        }
 }
 
+
 // <summary>
 //  A class used to hold info about an operator declarator
 // </summary>
@@ -5691,10 +5595,17 @@ static void Error_TypeExpected (Location loc)
 
 void push_current_class (TypeContainer tc, object partial_token)
 {
+       if (RootContext.EvalMode){
+               tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
+               undo.AddTypeContainer (current_container, tc);
+       }
+
        if (partial_token != null)
                current_container = current_container.AddPartial (tc);
        else
                current_container = current_container.AddTypeContainer (tc);
+
+       ++lexer.parsing_declaration;
        current_class = tc;
 }
 
@@ -5717,7 +5628,7 @@ MakeName (MemberName class_name)
 {
        Namespace ns = current_namespace.NS;
 
-       if (current_container.Name.Length == 0){
+       if (current_container == RootContext.ToplevelTypes) {
                if (ns.Name.Length != 0)
                        return new MemberName (ns.MemberName, class_name);
                else
@@ -5732,6 +5643,52 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
        Block implicit_block;
        ArrayList inits = null;
 
+       //
+       // If we are doing interactive editing, we want variable declarations
+       // that are in the top block to be added instead to the class as 
+       // static variables
+       //
+       if (RootContext.StatementMode){
+               bool hoist = true;
+
+               for (Block b = current_block; b != null; b = b.Parent){
+                       if (b is ExplicitBlock && !(b is ToplevelBlock)){
+                               // There has been an explicit block, we cant add to the class
+                               hoist = false;
+                               break;
+                       }
+               }               
+               if (hoist){
+                       //
+                       // We can use "current_block" since we know there are no explicit blocks
+                       //
+                       foreach (VariableDeclaration decl in variable_declarators){
+                               // We can not use the super-handy f.Initializer, because
+                               // multiple lines would force code to be executed out of sync
+                               if (decl.expression_or_array_initializer != null){
+                                       string id = "$" + decl.identifier;
+                                       current_block.AddVariable (type, id, decl.Location);                                    
+
+                                       LocalVariableReference var;
+                                       var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
+                                       Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
+                                       current_block.AddStatement (new StatementExpression (assign));
+                                       assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
+                                       current_block.AddStatement (new StatementExpression (assign));
+                               } else {
+                                       Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
+                                               new MemberName (decl.identifier, loc), null);
+                                       current_container.AddField (f);
+
+                                       // Register the field to be visible later as a global variable
+                                       Evaluator.QueueField (f);
+                               }
+                       }
+
+                       return current_block;
+               }
+       }
+
        //
        // We use the `Used' property to check whether statements
        // have been added to the current block.  If so, we need
@@ -5748,7 +5705,7 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
        // int j = 1;  int k = j + 1;
        //
        if (current_block.Used)
-               implicit_block = new Block (current_block, loc, Location.Null);
+               implicit_block = new Block (current_block, loc, lexer.Location);
        else
                implicit_block = current_block;
 
@@ -5849,36 +5806,40 @@ static CSharpParser ()
        oob_stack = new Stack ();
 }
 
-public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ArrayList defines)
+public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
 {
+       if (RootContext.EvalMode)
+               undo = new Undo ();
+
        this.file = file;
        current_namespace = new NamespaceEntry (null, file, null);
        current_class = current_namespace.SlaveDeclSpace;
        current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
        oob_stack.Clear ();
-       lexer = new Tokenizer (reader, file, defines);
+       lexer = new Tokenizer (reader, file);
 }
 
 public void parse ()
 {
-       int errors = Report.Errors;
+       eof_token = Token.EOF;
+
        try {
                if (yacc_verbose_flag > 1)
                        yyparse (lexer, new yydebug.yyDebugSimple ());
                else
                        yyparse (lexer);
-               Tokenizer tokenizer = lexer as Tokenizer;
-               tokenizer.cleanup ();
        } catch (Exception e){
-               //
-               // Removed for production use, use parser verbose to get the output.
-               //
-               // Console.WriteLine (e);
-               if (Report.Errors == errors)
+               if (e is yyParser.yyUnexpectedEof)
+                       UnexpectedEOF = true;
+               else if (yacc_verbose_flag > 0)
+                       Console.WriteLine (e);
+               if (e is yyParser.yyException)
                        Report.Error (-25, lexer.Location, "Parsing error");
-               if (yacc_verbose_flag > 0)
-                       Console.WriteLine (e);
+               else 
+                       Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
        }
+       Tokenizer tokenizer = lexer as Tokenizer;
+       tokenizer.cleanup ();
 
        if (RootContext.ToplevelTypes.NamespaceEntry != null)
                throw new InternalErrorException ("who set it?");
@@ -5887,7 +5848,7 @@ public void parse ()
 static void CheckToken (int error, int yyToken, string msg, Location loc)
 {
        if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
-               Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
+               Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
        else
                Report.Error (error, loc, msg);
 }
@@ -5940,14 +5901,18 @@ 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);
 
        current_local_parameters = parameters;
 
        current_anonymous_method = lambda 
-               ? new LambdaExpression (current_container, parameters, loc) 
-               : new AnonymousMethodExpression (current_container, parameters, loc);
+               ? new LambdaExpression (parameters, loc) 
+               : new AnonymousMethodExpression (parameters, loc);
 
        // Force the next block to be created as a ToplevelBlock
        parsing_anonymous_method = true;
@@ -5957,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 ();
@@ -5975,5 +5935,488 @@ AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
        return retval;
 }
 
+public NamespaceEntry CurrentNamespace {
+       get { 
+                  return current_namespace;
+       }
+}
+
+
+void Error_SyntaxError (int 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}", 
+                       symbol, expecting);       
+       else
+               Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
+}
+
+string GetExpecting ()
+{
+       int [] tokens = yyExpectingTokens (yyExpectingState);
+       ArrayList names = new ArrayList (tokens.Length);
+       bool has_type = false;
+       bool has_identifier = false;
+       for (int i = 0; i < tokens.Length; i++){
+               int token = tokens [i];
+               has_identifier |= token == Token.IDENTIFIER;
+               
+               string name = GetTokenName (token);
+               if (name == "<internal>")
+                       continue;
+                       
+               has_type |= name == "type";
+               if (names.Contains (name))
+                       continue;
+               
+               names.Add (name);
+       }
+
+       //
+       // Too many tokens to enumerate
+       //
+       if (names.Count > 8)
+               return null;
+
+       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;
+       for (int i = 0; i < count; i++){
+               bool last = i + 1 == count;
+               if (last)
+                       sb.Append ("or ");
+               sb.Append ('`');
+               sb.Append (names [i]);
+               sb.Append (last ? "'" : "', ");
+       }
+       return sb.ToString ();
+}
+
+
+string GetSymbolName (int token)
+{
+       switch (token){
+       case Token.LITERAL_FLOAT:
+       case Token.LITERAL_INTEGER:
+       case Token.LITERAL_DOUBLE:
+       case Token.LITERAL_DECIMAL:
+       case Token.LITERAL_CHARACTER:
+       case Token.LITERAL_STRING:
+               return lexer.Value.ToString ();
+       case Token.IDENTIFIER:
+               return ((LocatedToken)lexer.Value).Value;
+
+       case Token.BOOL:
+               return "bool";
+       case Token.BYTE:
+               return "byte";
+       case Token.CHAR:
+               return "char";
+       case Token.VOID:
+               return "void";
+       case Token.DECIMAL:
+               return "decimal";
+       case Token.DOUBLE:
+               return "double";
+       case Token.FLOAT:
+               return "float";
+       case Token.INT:
+               return "int";
+       case Token.LONG:
+               return "long";
+       case Token.SBYTE:
+               return "sbyte";
+       case Token.SHORT:
+               return "short";
+       case Token.STRING:
+               return "string";
+       case Token.UINT:
+               return "uint";
+       case Token.ULONG:
+               return "ulong";
+       case Token.USHORT:
+               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);
+}
+
+static string GetTokenName (int token)
+{
+       switch (token){
+       case Token.ABSTRACT:
+               return "abstract";
+       case Token.AS:
+               return "as";
+       case Token.ADD:
+               return "add";
+       case Token.BASE:
+               return "base";
+       case Token.BREAK:
+               return "break";
+       case Token.CASE:
+               return "case";
+       case Token.CATCH:
+               return "catch";
+       case Token.CHECKED:
+               return "checked";
+       case Token.CLASS:
+               return "class";
+       case Token.CONST:
+               return "const";
+       case Token.CONTINUE:
+               return "continue";
+       case Token.DEFAULT:
+               return "default";
+       case Token.DELEGATE:
+               return "delegate";
+       case Token.DO:
+               return "do";
+       case Token.ELSE:
+               return "else";
+       case Token.ENUM:
+               return "enum";
+       case Token.EVENT:
+               return "event";
+       case Token.EXPLICIT:
+               return "explicit";
+       case Token.EXTERN:
+               return "extern";
+       case Token.FALSE:
+               return "false";
+       case Token.FINALLY:
+               return "finally";
+       case Token.FIXED:
+               return "fixed";
+       case Token.FOR:
+               return "for";
+       case Token.FOREACH:
+               return "foreach";
+       case Token.GOTO:
+               return "goto";
+       case Token.IF:
+               return "if";
+       case Token.IMPLICIT:
+               return "implicit";
+       case Token.IN:
+               return "in";
+       case Token.INTERFACE:
+               return "interface";
+       case Token.INTERNAL:
+               return "internal";
+       case Token.IS:
+               return "is";
+       case Token.LOCK:
+               return "lock";
+       case Token.NAMESPACE:
+               return "namespace";
+       case Token.NEW:
+               return "new";
+       case Token.NULL:
+               return "null";
+       case Token.OPERATOR:
+               return "operator";
+       case Token.OUT:
+               return "out";
+       case Token.OVERRIDE:
+               return "override";
+       case Token.PARAMS:
+               return "params";
+       case Token.PRIVATE:
+               return "private";
+       case Token.PROTECTED:
+               return "protected";
+       case Token.PUBLIC:
+               return "public";
+       case Token.READONLY:
+               return "readonly";
+       case Token.REF:
+               return "ref";
+       case Token.RETURN:
+               return "return";
+       case Token.REMOVE:
+               return "remove";
+       case Token.SEALED:
+               return "sealed";
+       case Token.SIZEOF:
+               return "sizeof";
+       case Token.STACKALLOC:
+               return "stackalloc";
+       case Token.STATIC:
+               return "static";
+       case Token.STRUCT:
+               return "struct";
+       case Token.SWITCH:
+               return "switch";
+       case Token.THIS:
+               return "this";
+       case Token.THROW:
+               return "throw";
+       case Token.TRUE:
+               return "true";
+       case Token.TRY:
+               return "try";
+       case Token.TYPEOF:
+               return "typeof";
+       case Token.UNCHECKED:
+               return "unchecked";
+       case Token.UNSAFE:
+               return "unsafe";
+       case Token.USING:
+               return "using";
+       case Token.VIRTUAL:
+               return "virtual";
+       case Token.VOLATILE:
+               return "volatile";
+       case Token.WHERE:
+               return "where";
+       case Token.WHILE:
+               return "while";
+       case Token.ARGLIST:
+               return "arglist";
+       case Token.PARTIAL:
+               return "partial";
+       case Token.ARROW:
+               return "=>";
+       case Token.FROM:
+               return "from";
+       case Token.JOIN:
+               return "join";
+       case Token.ON:
+               return "on";
+       case Token.EQUALS:
+               return "equals";
+       case Token.SELECT:
+               return "select";
+       case Token.GROUP:
+               return "group";
+       case Token.BY:
+               return "by";
+       case Token.LET:
+               return "let";
+       case Token.ORDERBY:
+               return "orderby";
+       case Token.ASCENDING:
+               return "ascending";
+       case Token.DESCENDING:
+               return "descending";
+       case Token.INTO:
+               return "into";
+       case Token.GET:
+               return "get";
+       case Token.SET:
+               return "set";
+       case Token.OPEN_BRACE:
+               return "{";
+       case Token.CLOSE_BRACE:
+               return "}";
+       case Token.OPEN_BRACKET:
+               return "[";
+       case Token.CLOSE_BRACKET:
+               return "]";
+       case Token.OPEN_PARENS_CAST:
+       case Token.OPEN_PARENS_LAMBDA:
+       case Token.OPEN_PARENS:
+               return "(";
+       case Token.CLOSE_PARENS:
+               return ")";
+       case Token.DOT:
+               return ".";
+       case Token.COMMA:
+               return ",";
+       case Token.DEFAULT_COLON:
+               return "default:";
+       case Token.COLON:
+               return ":";
+       case Token.SEMICOLON:
+               return ";";
+       case Token.TILDE:
+               return "~";
+               
+       case Token.PLUS:
+       case Token.UMINUS:
+       case Token.MINUS:
+       case Token.BANG:
+       case Token.OP_LT:
+       case Token.OP_GT:
+       case Token.BITWISE_AND:
+       case Token.BITWISE_OR:
+       case Token.STAR:
+       case Token.PERCENT:
+       case Token.DIV:
+       case Token.CARRET:
+       case Token.OP_INC:
+       case Token.OP_DEC:
+       case Token.OP_SHIFT_LEFT:
+       case Token.OP_SHIFT_RIGHT:
+       case Token.OP_LE:
+       case Token.OP_GE:
+       case Token.OP_EQ:
+       case Token.OP_NE:
+       case Token.OP_AND:
+       case Token.OP_OR:
+       case Token.OP_PTR:
+       case Token.OP_COALESCING:       
+       case Token.OP_MULT_ASSIGN:
+       case Token.OP_DIV_ASSIGN:
+       case Token.OP_MOD_ASSIGN:
+       case Token.OP_ADD_ASSIGN:
+       case Token.OP_SUB_ASSIGN:
+       case Token.OP_SHIFT_LEFT_ASSIGN:
+       case Token.OP_SHIFT_RIGHT_ASSIGN:
+       case Token.OP_AND_ASSIGN:
+       case Token.OP_XOR_ASSIGN:
+       case Token.OP_OR_ASSIGN:
+               return "<operator>";
+
+       case Token.BOOL:
+       case Token.BYTE:
+       case Token.CHAR:
+       case Token.VOID:
+       case Token.DECIMAL:
+       case Token.DOUBLE:
+       case Token.FLOAT:
+       case Token.INT:
+       case Token.LONG:
+       case Token.SBYTE:
+       case Token.SHORT:
+       case Token.STRING:
+       case Token.UINT:
+       case Token.ULONG:
+       case Token.USHORT:
+       case Token.OBJECT:
+               return "type";
+       
+       case Token.ASSIGN:
+               return "=";
+       case Token.OP_GENERICS_LT:
+       case Token.GENERIC_DIMENSION:
+               return "<";
+       case Token.OP_GENERICS_GT:
+               return ">";
+       case Token.INTERR:
+       case Token.INTERR_NULLABLE:
+               return "?";
+       case Token.DOUBLE_COLON:
+               return "::";
+       case Token.LITERAL_FLOAT:
+       case Token.LITERAL_INTEGER:
+       case Token.LITERAL_DOUBLE:
+       case Token.LITERAL_DECIMAL:
+       case Token.LITERAL_CHARACTER:
+       case Token.LITERAL_STRING:
+               return "value";
+       case Token.IDENTIFIER:
+               return "identifier";
+
+               // All of these are internal.
+       case Token.NONE:
+       case Token.ERROR:
+       case Token.FIRST_KEYWORD:
+       case Token.EOF:
+       case Token.EVAL_COMPILATION_UNIT_PARSER:
+       case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
+       case Token.EVAL_STATEMENT_PARSER:
+       case Token.LOWPREC:
+       case Token.LAST_KEYWORD:        
+               return "<internal>";
+
+               // A bit more robust.
+       default:
+               return yyNames [token];
+        }
+}
+
 /* end end end */
 }