2008-10-08 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / cs-parser.jay
index 356460811ee1cd002d4fc70cc1ba7dc4a605ae38..e62e03d1f8e71c5c10ffde2c2301016e3549c708 100644 (file)
@@ -270,6 +270,7 @@ namespace Mono.CSharp
 %token ASSIGN
 %token OP_LT
 %token OP_GENERICS_LT
+%token OP_GENERICS_LT_DECL
 %token OP_GT
 %token OP_GENERICS_GT
 %token BITWISE_AND
@@ -370,19 +371,20 @@ 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
@@ -419,8 +421,7 @@ 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);
@@ -493,7 +494,8 @@ opt_comma
        ;
 
 namespace_name
-       : namespace_or_type_name {
+       : namespace_or_type_name
+        {
                MemberName name = (MemberName) $1;
 
                if (name.TypeArguments != null)
@@ -597,20 +599,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 */ 
@@ -897,7 +899,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);
@@ -1015,7 +1017,7 @@ constant_declarator
          {
                ++lexer.parsing_block;
          }     
-         constant_expression
+         constant_initializer
          {
                --lexer.parsing_block;
                $$ = new VariableDeclaration ((LocatedToken) $1, $4);
@@ -1027,22 +1029,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;
 
@@ -1057,11 +1066,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;
@@ -1081,19 +1091,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
@@ -1122,32 +1124,28 @@ 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
-         {
-               ++lexer.parsing_block;
-         }
-         variable_initializer
+       
+local_variable_declarator
+       : IDENTIFIER ASSIGN local_variable_initializer
          {
-               --lexer.parsing_block;
-               $$ = new VariableDeclaration ((LocatedToken) $1, $4);
+               $$ = new VariableDeclaration ((LocatedToken) $1, $3);
          }
        | IDENTIFIER
          {
@@ -1161,16 +1159,10 @@ variable_declarator
          }
        ;
 
-variable_initializer
+local_variable_initializer
        : expression
-         {
-               $$ = $1;
-         }
        | array_initializer
-         {
-               $$ = $1;
-         }
-       | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
+       | STACKALLOC type_expression OPEN_BRACKET expression CLOSE_BRACKET
          {
                $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
          }
@@ -1185,6 +1177,53 @@ variable_initializer
          }
        ;
 
+
+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 OPEN_BRACKET opt_expression CLOSE_BRACKET
+         {
+               lexer.parsing_generic_declaration = false;        
+               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
+       : expression
+       | array_initializer
+       ;
+
 method_declaration
        : method_header {
                if (RootContext.Documentation != null)
@@ -1208,30 +1247,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;
          }
@@ -1270,52 +1290,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, 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;
@@ -1371,8 +1349,8 @@ 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, 
@@ -1645,8 +1623,8 @@ arglist_modifier
 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 ();
@@ -1654,7 +1632,6 @@ property_declaration
          OPEN_BRACE 
          {
                implicit_value_parameter_type = (FullNamedExpression) $3;
-
                lexer.PropertyParsing = true;
          }
          accessor_declarations 
@@ -1673,14 +1650,11 @@ property_declaration
                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, ptype.Location, "`{0}': property return type cannot be `void'", prop.GetSignatureForError ());
+                       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 ());
@@ -1701,7 +1675,7 @@ property_declaration
 
          }
        ;
-       
+
 accessor_declarations
        : get_accessor_declaration
         {
@@ -1809,7 +1783,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);
@@ -1915,8 +1889,17 @@ operator_body
        | 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;
          }
@@ -2038,34 +2021,15 @@ conversion_operator_declarator
        ;
 
 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;
@@ -2075,19 +2039,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 ();
@@ -2096,12 +2050,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;
          }
        ;
 
@@ -2110,6 +2092,11 @@ constructor_body
        | SEMICOLON             { current_block = null; $$ = null; }
        ;
 
+opt_constructor_initializer
+       : /* Empty */
+       | constructor_initializer
+       ;
+
 constructor_initializer
        : COLON BASE OPEN_PARENS
          {
@@ -2169,14 +2156,10 @@ 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, 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) {
@@ -2185,6 +2168,12 @@ event_declaration
 
                                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);
 
@@ -2196,7 +2185,7 @@ 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;  
@@ -2225,9 +2214,6 @@ 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;
@@ -2246,16 +2232,17 @@ event_declaration
                }
                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;
+
+               Report.Error (1002, GetLocation ($6), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
+               $$ = null;
          }
        ;
 
@@ -2322,19 +2309,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;
@@ -2342,28 +2336,17 @@ indexer_declaration
          }
          CLOSE_BRACE
          { 
-               // 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;
+               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;
 
-               MemberName name;
-               if (decl.interface_type != null)
-                       name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);
-               else
-                       name = new MemberName (TypeContainer.DefaultIndexerName, loc);
-
-               indexer = new Indexer (current_class, decl.type, name,
-                                      (int) $2, decl.param_list, (Attributes) $1,
-                                      get_block, set_block, order);
+               Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
+                       (MemberName)$4, (int) $2, (Parameters) $6, (Attributes) $1,
+                       get_block, set_block, order);
                                       
-               if (decl.type == TypeManager.system_void_expr)
-                       Report.Error (620, loc, "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
+               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 ());
@@ -2387,41 +2370,10 @@ indexer_declaration
          }
        ;
 
-indexer_declarator
-       : type THIS OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
-         {
-               Parameters pars = (Parameters) $4;
-               if (pars.IsEmpty){
-                       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.IsEmpty){
-                       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 type_name
+         ENUM type_declaration_name
          opt_enum_base {
                if (RootContext.Documentation != null)
                        enumTypeComment = Lexer.consume_doc_comment ();
@@ -2558,7 +2510,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);
@@ -2604,32 +2556,19 @@ opt_nullable
        ;
 
 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);
@@ -2637,17 +2576,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
@@ -2660,66 +2598,173 @@ opt_type_argument_list
        | OP_GENERICS_LT error
          {
                Error_TypeExpected (lexer.Location);
+               $$ = new TypeParameterName ("", null, 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");
          
                $$ = $2;
          }
-       | OP_GENERICS_LT error
-         {
-               Error_TypeExpected (lexer.Location);
-         }
        ;
 
-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;          
+                       Report.Error (1002, GetLocation ($1), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (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;
+         }     
+       ;
+
+type_expression_or_array
+       : type_expression
+       | array_type
+       ;
+       
+type_expression
        : namespace_or_type_name opt_nullable
          {
                MemberName name = (MemberName) $1;
@@ -2739,12 +2784,7 @@ type
                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
@@ -2756,7 +2796,7 @@ pointer_type
        | VOID STAR
          {
                $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
-         }
+         }     
        ;
 
 non_expression_type
@@ -2765,7 +2805,11 @@ non_expression_type
                if ($2 != null)
                        $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
          }
-       | non_expression_type rank_specifier
+       | VOID
+         {
+               $$ = TypeManager.system_void_expr;
+         }
+       | non_expression_type rank_specifiers
          {
                Location loc = GetLocation ($1);
                if (loc.IsNull)
@@ -2832,7 +2876,6 @@ builtin_types
        | DECIMAL       { $$ = TypeManager.system_decimal_expr; }
        | FLOAT         { $$ = TypeManager.system_single_expr; }
        | DOUBLE        { $$ = TypeManager.system_double_expr; }
-       | VOID          { $$ = TypeManager.system_void_expr; }  
        | integral_type
        ;
 
@@ -2849,34 +2892,37 @@ integral_type
        ;
 
 array_type
-       : type rank_specifiers
+       : type_expression rank_specifiers
          {
                string rank_specifiers = (string) $2;
                $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
          }
        ;
 
+predefined_type
+       : builtin_types
+       | VOID
+         {
+               $$ = 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
@@ -2887,7 +2933,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
@@ -2975,10 +3022,13 @@ 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
@@ -3106,10 +3156,6 @@ argument_list
                Report.Error (839, GetLocation ($1), "An argument is missing");
                $$ = null;
          }
-       | argument_list error {
-               CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
-               $$ = null;
-         }
        ;
 
 argument
@@ -3156,11 +3202,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. 
@@ -3241,12 +3292,6 @@ post_decrement_expression
          }
        ;
 
-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
          {
@@ -3269,13 +3314,13 @@ object_or_delegate_creation_expression
        ;
 
 array_creation_expression
-       : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET 
+       : NEW type_expression OPEN_BRACKET expression_list CLOSE_BRACKET 
          opt_rank_specifier
          opt_array_initializer
          {
                $$ = new ArrayCreation ((FullNamedExpression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
          }
-       | NEW type rank_specifiers array_initializer
+       | NEW type_expression rank_specifiers array_initializer
          {
                $$ = new ArrayCreation ((FullNamedExpression) $2, (string) $3, (ArrayList) $4, (Location) $1);
          }
@@ -3286,9 +3331,9 @@ array_creation_expression
        | NEW error
          {
                Report.Error (1031, (Location) $1, "Type expected");
-                $$ = null;
+               $$ = null;
          }          
-       | NEW type error 
+       | NEW type_expression error
          {
                Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
                $$ = null;
@@ -3391,9 +3436,9 @@ opt_rank_specifier_or_nullable
 rank_specifiers
        : rank_specifier opt_rank_specifier
          {
-                 $$ = (string) $2 + (string) $1;
+               $$ = (string) $2 + (string) $1;
          }
-        ;
+       ;
 
 rank_specifier
        : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
@@ -3429,7 +3474,7 @@ opt_array_initializer
          {
                $$ = null;
          }
-        | array_initializer
+       | array_initializer
          {
                $$ = $1;
          }
@@ -3481,7 +3526,7 @@ typeof_expression
        ;
        
 typeof_type_expression
-       : type
+       : type_and_void
          {
                $$ = $1;
          }
@@ -3492,48 +3537,62 @@ typeof_type_expression
        | 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 { 
@@ -3636,6 +3695,9 @@ cast_expression
        : cast_list
        | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
          {
+               if ($2 == TypeManager.system_void_expr)
+                       Expression.Error_VoidInvalidInTheContext (GetLocation ($2));
+
                // TODO: wrong location
                $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
          }
@@ -3706,6 +3768,14 @@ additive_expression
                $$ = 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
@@ -3744,14 +3814,6 @@ relational_expression
                $$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
                                 (Expression) $1, (Expression) $3);
          }
-       | relational_expression IS type
-         {
-               $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
-         }
-       | relational_expression AS type
-         {
-               $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
-         }
        ;
 
 equality_expression
@@ -4010,7 +4072,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);
@@ -4066,7 +4128,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; }
@@ -4183,6 +4250,7 @@ block_prepared
        : OPEN_BRACE
          {
                ++lexer.parsing_block;
+               current_block.StartLocation = GetLocation ($1);
          }
          opt_statement_list CLOSE_BRACE 
          {
@@ -4337,7 +4405,7 @@ declaration_statement
  * > The expressions are converted into types during semantic analysis.
  */
 local_variable_type
-       : primary_expression opt_rank_specifier_or_nullable
+       : primary_expression_no_array_creation opt_rank_specifier_or_nullable
          { 
                // FIXME: Do something smart here regarding the composition of the type.
 
@@ -4387,10 +4455,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;
 
@@ -4401,22 +4474,22 @@ local_variable_pointer_type
                        $$ = expr;
                }
          }
-        | builtin_types STAR
+       | builtin_types STAR
          {
                $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
          }
-        | VOID STAR
+       | VOID STAR
          {
                $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
          }
        | local_variable_pointer_type STAR
-          {
+         {
                $$ = new ComposedCast ((FullNamedExpression) $1, "*");
          }
-        ;
+       ;
 
 local_variable_declaration
-       : local_variable_type variable_declarators
+       : local_variable_type local_variable_declarators
          {
                if ($1 != null) {
                        VarExpr ve = $1 as VarExpr;
@@ -4427,7 +4500,7 @@ local_variable_declaration
                } else
                        $$ = null;
          }
-       | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
+       | local_variable_pointer_type opt_rank_specifier local_variable_declarators
          {
                if ($1 != null){
                        Expression t;
@@ -4475,8 +4548,9 @@ statement_expression
                if (s == null) {
                        expr.Error_InvalidExpressionStatement ();
                        $$ = null;
-               } 
-               $$ = new StatementExpression (s);
+               } else {
+                       $$ = new StatementExpression (s);
+               }
          }
        | error
          {
@@ -4613,12 +4687,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);
          }
        ;
 
@@ -5005,7 +5080,7 @@ unsafe_statement
 
 fixed_statement
        : FIXED OPEN_PARENS 
-         type fixed_pointer_declarators 
+         type_and_void fixed_pointer_declarators 
          CLOSE_PARENS
          {
                ArrayList list = (ArrayList) $4;
@@ -5422,13 +5497,13 @@ interactive_parsing
        : EVAL_STATEMENT_PARSER EOF 
        | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives 
        | EVAL_STATEMENT_PARSER { 
-               CSharpEvaluator.LoadAliases (current_namespace);
+               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 (CSharpEvaluator.InteractiveBaseClass, lexer.Location));
+               baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
                current_container.AddBasesForPart (current_class, baseclass_list);
 
                // (ref object retval)
@@ -5462,7 +5537,7 @@ interactive_parsing
                current_local_parameters = null;
          } 
        | EVAL_COMPILATION_UNIT_PARSER {
-               CSharpEvaluator.LoadAliases (current_namespace);
+               Evaluator.LoadAliases (current_namespace);
          }
          interactive_compilation_unit
        ;
@@ -5502,25 +5577,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>
@@ -5598,7 +5672,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
@@ -5646,11 +5720,12 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
                                        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, decl.identifier, null, loc);
+                                       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
-                                       CSharpEvaluator.QueueField (f);
+                                       Evaluator.QueueField (f);
                                }
                        }
 
@@ -6134,6 +6209,7 @@ static public string GetTokenName (int token)
        case Token.COMMA:
                return ",";
        case Token.DEFAULT_COLON:
+               return "default:";
        case Token.COLON:
                return ":";
        case Token.SEMICOLON: