[672969] Delay type parameter constrain import until its declaring type is ready
[mono.git] / mcs / mcs / cs-parser.jay
index 1be926db00f131b7ecde7d26432b7a8e5518bbf7..dd7fac0a49d8d3ca06b396a9e1f566984702f2b4 100644 (file)
@@ -115,7 +115,7 @@ namespace Mono.CSharp
 
                /// When using the interactive parser, this holds the
                /// resulting expression
-               public object InteractiveResult;
+               public Class InteractiveResult;
 
                //
                // Keeps track of global data changes to undo on parser error
@@ -124,10 +124,12 @@ namespace Mono.CSharp
                
                Stack<Linq.QueryBlock> linq_clause_blocks;
 
-               // A counter to create new class names in interactive mode
-               static int class_count;
+               ModuleContainer module;
                
-               CompilerContext compiler;
+               readonly CompilerContext compiler;
+               readonly LanguageVersion lang_version;
+               readonly bool doc_support;
+               readonly CompilerSettings settings;
                
                //
                // Instead of allocating carrier array everytime we
@@ -250,6 +252,7 @@ namespace Mono.CSharp
 %token INTO
 %token INTERR_NULLABLE
 %token EXTERN_ALIAS
+%token ASYNC
 
 /* C# keywords which are not really keywords */
 %token GET
@@ -406,8 +409,8 @@ extern_alias_directive
                string s = lt.Value;
                if (s != "alias"){
                        syntax_error (lt.Location, "`alias' expected");
-               } else if (RootContext.Version == LanguageVersion.ISO_1) {
-                       Report.FeatureIsNotAvailable (lt.Location, "external alias");
+               } else if (lang_version == LanguageVersion.ISO_1) {
+                       FeatureIsNotAvailable (lt.Location, "external alias");
                } else {
                        lt = (Tokenizer.LocatedToken) $3; 
                        current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
@@ -427,12 +430,12 @@ using_directives
 using_directive
        : using_alias_directive
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
        | using_namespace_directive
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
@@ -441,6 +444,11 @@ using_alias_directive
        : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
          {
                var lt = (Tokenizer.LocatedToken) $2;
+               if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
+                       Report.Warning (440, 2, lt.Location,
+                        "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
+               }
+
                current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
          }
        | USING error
@@ -471,7 +479,7 @@ namespace_declaration
                        Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
                }
 
-               current_namespace = new NamespaceEntry (compiler,
+               current_namespace = new NamespaceEntry (module,
                        current_namespace, file, name.GetName ());
                current_class = current_namespace.SlaveDeclSpace;
                current_container = current_class.PartialContainer;
@@ -497,7 +505,7 @@ qualified_identifier
          }
        | error
          {
-               syntax_error (lexer.Location, "`.' expected");
+               Error_SyntaxError (yyToken);
                $$ = new MemberName ("<invalid>", lexer.Location);
          }
        ;
@@ -527,28 +535,13 @@ namespace_name
 namespace_body
        : OPEN_BRACE
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
-         namespace_body_body
-       ;
-       
-namespace_body_body
-       : opt_extern_alias_directives
+         opt_extern_alias_directives
          opt_using_directives
          opt_namespace_member_declarations
          CLOSE_BRACE
-       | error
-         {
-               Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
-         }
-       | opt_extern_alias_directives
-         opt_using_directives
-         opt_namespace_member_declarations
-         EOF
-         {
-               Report.Error (1513, lexer.Location, "Expected `}'");
-         }
        ;
 
 opt_using_directives
@@ -584,16 +577,14 @@ namespace_member_declaration
                }
                current_namespace.DeclarationFound = true;
          }
-       | namespace_declaration {
+       | namespace_declaration
+         {
                current_namespace.DeclarationFound = true;
          }
-
-       | field_declaration {
-               Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
-         }
-       | method_declaration {
-               Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
-         }
+       | error
+        {
+               Error_SyntaxError (yyToken);
+        }
        ;
 
 type_declaration
@@ -621,7 +612,7 @@ global_attributes
                if ($1 != null) {
                        Attributes attrs = (Attributes)$1;
                        if (global_attrs_enabled) {
-                               CodeGen.Assembly.AddAttributes (attrs.Attrs, current_namespace);
+                               module.AddAttributes (attrs.Attrs, current_namespace);
                        } 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");
@@ -653,17 +644,14 @@ attribute_sections
                        var sect = (List<Attribute>) $1;
 
                        if (global_attrs_enabled) {
-                               if (current_attr_target == "module") {
-                                       current_container.Module.Compiled.AddAttributes (sect);
-                                       $$ = null;
-                               } else if (current_attr_target != null && current_attr_target.Length > 0) {
-                                       CodeGen.Assembly.AddAttributes (sect, current_namespace);
+                               if (!string.IsNullOrEmpty (current_attr_target)) {
+                                       module.AddAttributes (sect, current_namespace);
                                        $$ = null;
                                } else {
                                        $$ = new Attributes (sect);
                                }
                                if ($$ == null) {
-                                       if (RootContext.Documentation != null) {
+                                       if (doc_support) {
                                                Lexer.check_incorrect_doc_comment ();
                                                Lexer.doc_state =
                                                        XmlCommentState.Allowed;
@@ -684,11 +672,8 @@ attribute_sections
                        var sect = (List<Attribute>) $2;
 
                        if (global_attrs_enabled) {
-                               if (current_attr_target == "module") {
-                                       current_container.Module.Compiled.AddAttributes (sect);
-                                       $$ = null;
-                               } else if (current_attr_target == "assembly") {
-                                       CodeGen.Assembly.AddAttributes (sect, current_namespace);
+                               if (!string.IsNullOrEmpty (current_attr_target)) {
+                                       module.AddAttributes (sect);
                                        $$ = null;
                                } else {
                                        if (attrs == null)
@@ -862,8 +847,8 @@ named_attribute_argument
 named_argument
        : IDENTIFIER COLON opt_named_modifier expression
          {
-               if (RootContext.Version <= LanguageVersion.V_3)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
+               if (lang_version <= LanguageVersion.V_3)
+                       FeatureIsNotAvailable (GetLocation ($1), "named argument");
                        
                // Avoid boxing in common case (no modifier)
                var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
@@ -936,7 +921,7 @@ struct_declaration
 
                current_class.SetParameterInfo ((List<Constraints>) $9);
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        current_container.DocComment = Lexer.consume_doc_comment ();
 
                lbag.AddMember (current_class, mod_locations, GetLocation ($4));
@@ -944,7 +929,7 @@ struct_declaration
          struct_body
          {
                --lexer.parsing_declaration;      
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          opt_semicolon
@@ -961,7 +946,7 @@ struct_declaration
 struct_body
        : OPEN_BRACE
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          opt_struct_member_declarations CLOSE_BRACE
@@ -1016,7 +1001,7 @@ constant_declaration
          }
          constant_initializer opt_constant_declarators SEMICOLON
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_field.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -1094,7 +1079,7 @@ field_declaration
          opt_field_declarators
          SEMICOLON
          { 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_field.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -1107,8 +1092,8 @@ field_declaration
          opt_modifiers
          FIXED simple_type IDENTIFIER
          { 
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
 
                var lt = (Tokenizer.LocatedToken) $5;
                current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
@@ -1118,7 +1103,7 @@ field_declaration
          }
          fixed_field_size opt_fixed_field_declarators SEMICOLON
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_field.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
            }
@@ -1245,15 +1230,18 @@ variable_initializer
        ;
 
 method_declaration
-       : method_header {
-               if (RootContext.Documentation != null)
+       : method_header
+         {
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.NotAllowed;
+
+               // Add it early in the case of body being eof for full aot
+               current_container.AddMethod ((Method) $1);
          }
          method_body
          {
                Method method = (Method) $1;
                method.Block = (ToplevelBlock) $3;
-               current_container.AddMethod (method);
                
                if (current_container.Kind == MemberKind.Interface && method.Block != null) {
                        Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
@@ -1261,7 +1249,7 @@ method_declaration
 
                current_local_parameters = null;
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
@@ -1305,7 +1293,7 @@ method_header
                                method.GetSignatureForError ());
                }
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        method.DocComment = Lexer.consume_doc_comment ();
 
                lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
@@ -1367,7 +1355,7 @@ method_header
                method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
                                     modifiers, name, current_local_parameters, (Attributes) $1);
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        method.DocComment = Lexer.consume_doc_comment ();
 
                // TODO: lbag, push void
@@ -1389,7 +1377,7 @@ method_header
 
                current_local_parameters = (ParametersCompiled) $7;
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        method.DocComment = Lexer.consume_doc_comment ();
 
                $$ = method;
@@ -1540,8 +1528,8 @@ fixed_parameter
          constant_expression
          {
                --lexer.parsing_block;
-               if (RootContext.Version <= LanguageVersion.V_3) {
-                       Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
+               if (lang_version <= LanguageVersion.V_3) {
+                       FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
                }
                
                Parameter.Modifier mod = (Parameter.Modifier) $2;
@@ -1572,7 +1560,7 @@ fixed_parameter
                lbag.AddLocation ($$, GetLocation ($5));
                
                if ($7 != null)
-                       ((Parameter) $$).DefaultValue = (Expression) $7;
+                       ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
          }
        ;
 
@@ -1629,8 +1617,8 @@ parameter_modifier
                if ((valid_param_mod & ParameterModifierType.This) == 0)
                        Error_ParameterModifierNotValid ("this", GetLocation ($1));
 
-               if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "extension methods");
                                
                $$ = Parameter.Modifier.This;
          }
@@ -1691,7 +1679,7 @@ property_declaration
          member_type
          member_declaration_name
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        tmpComment = Lexer.consume_doc_comment ();
          }
          OPEN_BRACE
@@ -1711,7 +1699,7 @@ property_declaration
          {
                lexer.PropertyParsing = false;
                
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        current_property.DocComment = ConsumeStoredComment ();                          
          }
          CLOSE_BRACE
@@ -1747,7 +1735,7 @@ indexer_declaration
                        Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
                }
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -1760,7 +1748,7 @@ indexer_declaration
          }
          CLOSE_BRACE
          { 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        current_property.DocComment = ConsumeStoredComment ();
                        
                lbag.AppendToMember (current_property, GetLocation ($12));
@@ -1790,8 +1778,8 @@ accessor_declarations
 get_accessor_declaration
        : opt_attributes opt_modifiers GET
          {
-               if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
-                       Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
+               if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
+                       FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
                }
          
                if (current_property.Get != null) {
@@ -1824,7 +1812,7 @@ get_accessor_declaration
                current_local_parameters = null;
                lexer.PropertyParsing = true;
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        if (Lexer.doc_state == XmlCommentState.Error)
                                Lexer.doc_state = XmlCommentState.NotAllowed;
          }
@@ -1833,8 +1821,8 @@ get_accessor_declaration
 set_accessor_declaration
        : opt_attributes opt_modifiers SET 
          {
-               if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
-                       Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
+               if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
+                       FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
                }
                
                if (current_property.Set != null) {
@@ -1872,7 +1860,7 @@ set_accessor_declaration
                current_local_parameters = null;
                lexer.PropertyParsing = true;
 
-               if (RootContext.Documentation != null
+               if (doc_support
                        && Lexer.doc_state == XmlCommentState.Error)
                        Lexer.doc_state = XmlCommentState.NotAllowed;
          }
@@ -1913,7 +1901,7 @@ interface_declaration
 
                current_class.SetParameterInfo ((List<Constraints>) $9);
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_container.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -1921,7 +1909,7 @@ interface_declaration
          OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
          {
                --lexer.parsing_declaration;      
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          opt_semicolon 
@@ -1985,7 +1973,7 @@ operator_declaration
                                current_local_parameters,
                                (ToplevelBlock) $5, (Attributes) $1, decl.location);
 
-                       if (RootContext.Documentation != null) {
+                       if (doc_support) {
                                op.DocComment = tmpComment;
                                Lexer.doc_state = XmlCommentState.Allowed;
                        }
@@ -2051,7 +2039,7 @@ operator_declarator
                        }
                }
                
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2102,7 +2090,7 @@ conversion_operator_declarator
                Location loc = GetLocation ($2);
                current_local_parameters = (ParametersCompiled)$6;  
                  
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2121,7 +2109,7 @@ conversion_operator_declarator
                Location loc = GetLocation ($2);
                current_local_parameters = (ParametersCompiled)$6;  
                  
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2150,13 +2138,13 @@ constructor_declaration
                Constructor c = (Constructor) $1;
                c.Block = (ToplevelBlock) $2;
                
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        c.DocComment = ConsumeStoredComment ();
 
                current_container.AddConstructor (c);
 
                current_local_parameters = null;
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
@@ -2166,7 +2154,7 @@ constructor_declarator
          opt_modifiers
          IDENTIFIER
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2245,8 +2233,9 @@ constructor_initializer
                $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
                lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
          }
-       | COLON error {
-               Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
+       | error
+         {
+               Error_SyntaxError (yyToken);
                $$ = null;
          }
        ;
@@ -2254,7 +2243,7 @@ constructor_initializer
 destructor_declaration
        : opt_attributes opt_modifiers TILDE 
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2272,7 +2261,7 @@ destructor_declaration
                
                Destructor d = new Destructor (current_class, (Modifiers) $2,
                        ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        d.DocComment = ConsumeStoredComment ();
                  
                d.Block = (ToplevelBlock) $8;
@@ -2302,7 +2291,7 @@ event_declaration
          opt_event_declarators
          SEMICOLON
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_event_field.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2330,7 +2319,7 @@ event_declaration
          }
          CLOSE_BRACE
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_event.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2499,12 +2488,12 @@ enum_declaration
          ENUM type_declaration_name
          opt_enum_base
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        enumTypeComment = Lexer.consume_doc_comment ();
          }
          OPEN_BRACE
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
 
                MemberName name = (MemberName) $4;
@@ -2517,17 +2506,17 @@ enum_declaration
          opt_enum_member_declarations
          {
                // here will be evaluated after CLOSE_BLACE is consumed.
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          CLOSE_BRACE opt_semicolon
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        current_class.DocComment = enumTypeComment;
                        
                --lexer.parsing_declaration;
 
-//                     if (RootContext.Documentation != null)
+//                     if (doc_support)
 //                             em.DocComment = ev.DocComment;
 
                lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
@@ -2583,7 +2572,7 @@ enum_member_declaration
                var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
                ((Enum) current_class).AddEnumMember (em);
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        em.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2593,7 +2582,7 @@ enum_member_declaration
        | opt_attributes IDENTIFIER
          {
                ++lexer.parsing_block;
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2607,7 +2596,7 @@ enum_member_declaration
                em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
                ((Enum) current_class).AddEnumMember (em);
                
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        em.DocComment = ConsumeStoredComment ();
 
                $$ = em;
@@ -2633,7 +2622,7 @@ delegate_declaration
                Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
                                             (Modifiers) $2, name, p, (Attributes) $1);
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        del.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2661,10 +2650,8 @@ opt_nullable
        : /* empty */
        | INTERR_NULLABLE
          {
-               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
-                       Report.FeatureIsNotSupported (GetLocation ($1), "nullable types");
-               else if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "nullable types");
          
                $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
          }
@@ -2706,10 +2693,8 @@ opt_type_argument_list
        : /* empty */
        | OP_GENERICS_LT type_arguments OP_GENERICS_GT
          {
-               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
-                       Report.FeatureIsNotSupported (GetLocation ($1), "generics");
-               else if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "generics");      
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "generics");     
          
                $$ = $2;
          }
@@ -2811,10 +2796,8 @@ opt_type_parameter_list
        : /* empty */
        | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
          {
-               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
-                       Report.FeatureIsNotSupported (GetLocation ($1), "generics");
-               else if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "generics");
          
                $$ = $2;
                lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
@@ -3345,6 +3328,9 @@ expression_list_arguments
        | expression_list_arguments COMMA expression_list_argument
          {
                Arguments args = (Arguments) $1;
+               if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
+                       Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
+         
                args.Add ((Argument) $3);
                $$ = args;        
          }
@@ -3396,8 +3382,8 @@ object_or_delegate_creation_expression
        : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
          {
                if ($6 != null) {
-                       if (RootContext.Version <= LanguageVersion.ISO_2)
-                               Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
+                       if (lang_version <= LanguageVersion.ISO_2)
+                               FeatureIsNotAvailable (GetLocation ($1), "object initializers");
                                
                        $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
                } else {
@@ -3408,8 +3394,8 @@ object_or_delegate_creation_expression
          }
        | NEW new_expr_type object_or_collection_initializer
          {
-               if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
          
                $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
          }
@@ -3433,10 +3419,10 @@ array_creation_expression
 
                $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
          }
-       | NEW rank_specifiers array_initializer
+       | NEW rank_specifier array_initializer
          {
-               if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
          
                $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
          }
@@ -3466,10 +3452,8 @@ new_expr_type
 anonymous_type_expression
        : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
          {
-               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
-                       Report.FeatureIsNotSupported (GetLocation ($1), "anonymous types");
-               else if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
 
                $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
                
@@ -3547,10 +3531,12 @@ rank_specifier
        : OPEN_BRACKET CLOSE_BRACKET
          {
                $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
+               lbag.AddLocation ($$, GetLocation ($2));
          }
        | OPEN_BRACKET dim_separators CLOSE_BRACKET
          {
                $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
+               lbag.AddLocation ($$, GetLocation ($3));
          }
        ;
 
@@ -3588,7 +3574,11 @@ array_initializer
          {
                var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
                ai.VariableDeclaration = current_variable;
-               lbag.AddLocation (ai, GetLocation ($3));
+               if ($3 != null) {
+                       lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
+               } else {
+                       lbag.AddLocation (ai, GetLocation ($4));
+               }
                $$ = ai;
          }
        ;
@@ -3671,10 +3661,8 @@ unbound_type_name
 generic_dimension
        : GENERIC_DIMENSION
          {
-               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
-                       Report.FeatureIsNotSupported (GetLocation ($1), "generics");
-               else if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "generics");
 
                $$ = $1;
          }
@@ -3684,8 +3672,8 @@ qualified_alias_member
        : IDENTIFIER DOUBLE_COLON
          {
                var lt = (Tokenizer.LocatedToken) $1;
-               if (RootContext.Version == LanguageVersion.ISO_1)
-                       Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
+               if (lang_version == LanguageVersion.ISO_1)
+                       FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
 
                $$ = lt;                
          }
@@ -3757,8 +3745,8 @@ anonymous_method_signature
 default_value_expression
        : DEFAULT open_parens_any type CLOSE_PARENS
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "default value expression");
 
                $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
                lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
@@ -3964,8 +3952,8 @@ null_coalescing_expression
        : conditional_or_expression
        | conditional_or_expression OP_COALESCING null_coalescing_expression
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
                        
                $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
          }
@@ -4087,19 +4075,29 @@ opt_lambda_parameter_list
        ;
 
 lambda_expression_body
+       : lambda_expression_body_simple
+       | block
+       ;
+       
+lambda_expression_body_simple
        : {
                start_block (lexer.Location);
          }
-         expression 
+         expression_or_error   // Have to close block when error occurs
          {
                Block b = end_block (lexer.Location);
                b.AddStatement (new ContextualReturn ((Expression) $2));
                $$ = b;
          } 
-       | block
-         { 
-               $$ = $1; 
-         } 
+       ;
+       
+expression_or_error
+       : expression
+       | error
+         {
+               Error_SyntaxError (yyToken);    
+               $$ = EmptyExpression.Null;
+         }
        ;
 
 lambda_expression
@@ -4116,8 +4114,8 @@ lambda_expression
          }
        | OPEN_PARENS_LAMBDA
          {
-               if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
          
                valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
          }
@@ -4129,7 +4127,7 @@ lambda_expression
          lambda_expression_body 
          {
                $$ = end_anonymous ((ParametersBlock) $7);
-               lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
+               lbag.AddLocation ($$, GetLocation ($4), GetLocation ($5));
          }
        ;
 
@@ -4173,7 +4171,12 @@ class_declaration
          type_declaration_name
          {
                MemberName name = MakeName ((MemberName) $6);
-               push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
+               Class c = new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1);
+               if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
+                       FeatureIsNotAvailable (c.Location, "static classes");
+               }
+                       
+               push_current_class (c, $3);
          }
          opt_class_base
          opt_type_parameter_constraints_clauses
@@ -4183,7 +4186,7 @@ class_declaration
                current_class.SetParameterInfo ((List<Constraints>) $9);
                lbag.AddMember (current_class, mod_locations, GetLocation ($4));
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_container.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -4191,7 +4194,7 @@ class_declaration
          OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
          {
                --lexer.parsing_declaration;
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          opt_semicolon 
@@ -4310,9 +4313,14 @@ modifier
          {
                $$ = Modifiers.UNSAFE;
                StoreModifierLocation ($$, GetLocation ($1));
-               if (!RootContext.Unsafe)
+               if (!settings.Unsafe)
                        Error_UnsafeCodeNotAllowed (GetLocation ($1));
          }
+       | ASYNC
+         {
+               $$ = Modifiers.ASYNC;
+               StoreModifierLocation ($$, GetLocation ($1));
+         }
        ;
 
 opt_class_base
@@ -4329,6 +4337,11 @@ opt_type_parameter_constraints_clauses
          {
                $$ = $1;
          }
+       | error
+        {
+               Error_SyntaxError (yyToken);
+               $$ = null;
+        }
        ;
 
 type_parameter_constraints_clauses
@@ -4426,10 +4439,8 @@ opt_type_parameter_variance
          }
        | type_parameter_variance
          {
-               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
-                       Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
-               else if (RootContext.Version <= LanguageVersion.V_3)
-                       Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
+               if (lang_version <= LanguageVersion.V_3)
+                       FeatureIsNotAvailable (lexer.Location, "generic type variance");
 
                $$ = $1;
          }
@@ -4602,7 +4613,8 @@ embedded_statement
 empty_statement
        : SEMICOLON
          {
-               $$ = new EmptyStatement (GetLocation ($1));
+               // Uses lexer.Location because semicolon location is not kept in quick mode
+               $$ = new EmptyStatement (lexer.Location);
          }
        ;
 
@@ -5032,20 +5044,33 @@ for_statement
                start_block (GetLocation ($2));
                current_block.IsCompilerGenerated = true;
          }
-         opt_for_initializer SEMICOLON
+         for_statement_cont
+         {
+               $$ = $4;
+         }
+       ;
+       
+// Has to use be extra rule to recover started block
+for_statement_cont
+       : opt_for_initializer SEMICOLON
          opt_for_condition SEMICOLON
-         opt_for_iterator CLOSE_PARENS 
+         opt_for_iterator CLOSE_PARENS
          embedded_statement
          {
-               if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
-                       Warning_EmptyStatement (GetLocation ($10));
+               if ($7 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
+                       Warning_EmptyStatement (GetLocation ($7));
          
-               For f = new For ((Statement) $4, (BooleanExpression) $6, (Statement) $8, (Statement) $10, GetLocation ($1));
+               For f = new For ((Statement) $1, (BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($-2));
                current_block.AddStatement (f);
                
-               lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7), GetLocation ($9));
+               lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation ($4), GetLocation ($6));
 
-               $$ = end_block (GetLocation ($5));
+               $$ = end_block (GetLocation ($2));
+         }
+       | error
+         {
+               Error_SyntaxError (yyToken);
+               $$ = end_block (current_block.StartLocation);
          }
        ;
 
@@ -5199,8 +5224,8 @@ yield_statement
                        Report.Error (1003, lt.Location, "; expected");
                } else if ($3 == null) {
                        Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
-               } else if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotAvailable (lt.Location, "iterators");
+               } else if (lang_version == LanguageVersion.ISO_1){
+                       FeatureIsNotAvailable (lt.Location, "iterators");
                }
                
                current_block.ParametersBlock.TopBlock.IsIterator = true;
@@ -5213,8 +5238,8 @@ yield_statement
                string s = lt.Value;
                if (s != "yield"){
                        Report.Error (1003, lt.Location, "; expected");
-               } else if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotAvailable (lt.Location, "iterators");
+               } else if (lang_version == LanguageVersion.ISO_1){
+                       FeatureIsNotAvailable (lt.Location, "iterators");
                }
                
                current_block.ParametersBlock.TopBlock.IsIterator = true;
@@ -5335,7 +5360,7 @@ unchecked_statement
 unsafe_statement
        : UNSAFE
          {
-               if (!RootContext.Unsafe)
+               if (!settings.Unsafe)
                        Error_UnsafeCodeNotAllowed (GetLocation ($1));
          } block {
                $$ = new Unsafe ((Block) $3, GetLocation ($1));
@@ -5358,6 +5383,7 @@ fixed_statement
          {
            start_block (GetLocation ($2));
            
+               current_block.IsCompilerGenerated = true;
                var lt = (Tokenizer.LocatedToken) $4;
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
                current_block.AddLocalName (li);
@@ -5384,6 +5410,7 @@ using_statement
          {
            start_block (GetLocation ($2));
            
+               current_block.IsCompilerGenerated = true;
                var lt = (Tokenizer.LocatedToken) $4;
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
                current_block.AddLocalName (li);
@@ -5471,7 +5498,7 @@ query_expression
 first_from_clause
        : FROM_FIRST IDENTIFIER IN expression
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
                var lt = (Tokenizer.LocatedToken) $2;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
@@ -5479,7 +5506,7 @@ first_from_clause
          }
        | FROM_FIRST type IDENTIFIER IN expression
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
                var lt = (Tokenizer.LocatedToken) $3;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
@@ -5494,7 +5521,7 @@ first_from_clause
 nested_from_clause
        : FROM IDENTIFIER IN expression
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
                var lt = (Tokenizer.LocatedToken) $2;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
@@ -5502,7 +5529,7 @@ nested_from_clause
          }
        | FROM type IDENTIFIER IN expression
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
                var lt = (Tokenizer.LocatedToken) $3;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
@@ -5517,7 +5544,7 @@ nested_from_clause
 from_clause
        : FROM IDENTIFIER IN
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression
          {
@@ -5532,7 +5559,7 @@ from_clause
          }       
        | FROM type IDENTIFIER IN
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression
          {
@@ -5567,12 +5594,17 @@ query_body
                $$ = head;
          }
        | opt_query_body_clauses COMPLETE_COMPLETION
+       | error
+         {
+               Error_SyntaxError (yyToken);
+               $$ = null;
+         }
        ;
        
 select_or_group_clause
        : SELECT
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression
          {
@@ -5586,7 +5618,7 @@ select_or_group_clause
                if (linq_clause_blocks == null)
                        linq_clause_blocks = new Stack<Linq.QueryBlock> ();
                        
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
          }
          expression
@@ -5594,7 +5626,7 @@ select_or_group_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
          
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          BY expression
          {
@@ -5630,7 +5662,7 @@ query_body_clause
 let_clause
        : LET IDENTIFIER ASSIGN 
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression
          {
@@ -5648,11 +5680,11 @@ let_clause
 where_clause
        : WHERE
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
-         boolean_expression
+         expression
          {
-               $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
+               $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
 
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
@@ -5665,7 +5697,7 @@ join_clause
                if (linq_clause_blocks == null)
                        linq_clause_blocks = new Stack<Linq.QueryBlock> ();
                        
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression ON
@@ -5673,7 +5705,7 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression EQUALS
@@ -5682,7 +5714,7 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression opt_join_into
          {
@@ -5725,7 +5757,7 @@ join_clause
                if (linq_clause_blocks == null)
                        linq_clause_blocks = new Stack<Linq.QueryBlock> ();
                        
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression ON
@@ -5733,7 +5765,7 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression EQUALS
@@ -5742,7 +5774,7 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression opt_join_into
          {
@@ -5797,7 +5829,7 @@ opt_join_into
 orderby_clause
        : ORDERBY
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          orderings
          {
@@ -5815,7 +5847,7 @@ orderings
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
          
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          orderings_then_by
          {
@@ -5831,7 +5863,7 @@ orderings_then_by
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
          
-               current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);         
+               current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);   
         }
         then_by
         {
@@ -5882,7 +5914,7 @@ opt_query_continuation
                current_block.SetEndLocation (GetLocation ($1));
                current_block = current_block.Parent;
        
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                
                if (linq_clause_blocks == null)
                        linq_clause_blocks = new Stack<Linq.QueryBlock> ();
@@ -5916,33 +5948,34 @@ opt_query_continuation
 interactive_parsing
        : EVAL_STATEMENT_PARSER EOF 
        | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
-       | 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);
-
-               var baseclass_list = new List<FullNamedExpression> ();
-               baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
-               current_container.AddBasesForPart (current_class, baseclass_list);
+       | EVAL_STATEMENT_PARSER
+        { 
+               current_container = new Class (current_namespace, current_class, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
+               current_class = current_container;
 
                // (ref object retval)
                Parameter [] mpar = new Parameter [1];
                mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
 
                ParametersCompiled pars = new ParametersCompiled (mpar);
+               var mods = Modifiers.PUBLIC | Modifiers.STATIC;
+               if (settings.Unsafe)
+                       mods |= Modifiers.UNSAFE;
+
                current_local_parameters = pars;
                Method method = new Method (
                        current_class,
                        null, // generic
                        new TypeExpression (TypeManager.void_type, Location.Null),
-                       Modifiers.PUBLIC | Modifiers.STATIC,
+                       mods,
                        new MemberName ("Host"),
                        pars,
                        null /* attributes */);
+                       
+               current_container.AddMethod (method);                   
 
                oob_stack.Push (method);
-               ++lexer.parsing_block;
+               ++lexer.parsing_block;
                start_block (lexer.Location);
          }             
          interactive_statement_list opt_COMPLETE_COMPLETION
@@ -5951,16 +5984,11 @@ interactive_parsing
                Method method = (Method) oob_stack.Pop ();
 
                method.Block = (ToplevelBlock) end_block(lexer.Location);
-               current_container.AddMethod (method);
 
-               --lexer.parsing_declaration;
-               InteractiveResult = pop_current_class ();
+               InteractiveResult = (Class) pop_current_class ();
                current_local_parameters = null;
          } 
-       | EVAL_COMPILATION_UNIT_PARSER {
-               Evaluator.LoadAliases (current_namespace);
-         }
-         interactive_compilation_unit
+       | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
        ;
 
 interactive_compilation_unit
@@ -6040,8 +6068,10 @@ void Error_NamedArgumentExpected (NamedArgument a)
 
 void push_current_class (TypeContainer tc, object partial_token)
 {
-       if (RootContext.EvalMode){
-               tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
+       if (module.Evaluator != null){
+               tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
+               if (undo == null)
+                       undo = new Undo ();
                undo.AddTypeContainer (current_container, tc);
        }
 
@@ -6142,18 +6172,24 @@ static CSharpParser ()
        oob_stack = new Stack<object> ();
 }
 
-public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
+public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module)
+       : this (reader, file, module, new NamespaceEntry (module, null, file, null))
 {
-       if (RootContext.EvalMode)
-               undo = new Undo ();
+}
 
+public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module, NamespaceEntry ns)
+{
        this.file = file;
-       this.compiler = ctx;
-       current_namespace = new NamespaceEntry (ctx, null, file, null);
+       this.module = module;
+       this.compiler = module.Compiler;
+       this.settings = compiler.Settings;
+       lang_version = settings.Version;
+       doc_support = settings.Documentation != null;
+       current_namespace = ns;
        current_class = current_namespace.SlaveDeclSpace;
        current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
        oob_stack.Clear ();
-       lexer = new Tokenizer (reader, file, ctx);
+       lexer = new Tokenizer (reader, file, compiler);
        
        use_global_stacks = true;
 }
@@ -6209,6 +6245,11 @@ string ConsumeStoredComment ()
        return s;
 }
 
+void FeatureIsNotAvailable (Location loc, string feature)
+{
+       compiler.Report.FeatureIsNotAvailable (compiler, loc, feature);
+}
+
 Location GetLocation (object obj)
 {
        var lt = obj as Tokenizer.LocatedToken;
@@ -6243,6 +6284,7 @@ void start_block (Location loc)
 {
        if (current_block == null) {
                current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
+               parsing_anonymous_method = false;
        } else if (parsing_anonymous_method) {
                current_block = new ParametersBlock (current_block, current_local_parameters, loc);
                parsing_anonymous_method = false;
@@ -6262,8 +6304,8 @@ end_block (Location loc)
 
 void start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
 {
-       if (RootContext.Version == LanguageVersion.ISO_1){
-               Report.FeatureIsNotAvailable (loc, "anonymous methods");
+       if (lang_version == LanguageVersion.ISO_1){
+               FeatureIsNotAvailable (loc, "anonymous methods");
        }
 
        oob_stack.Push (current_anonymous_method);
@@ -6511,6 +6553,8 @@ static string GetTokenName (int token)
                return "as";
        case Token.ADD:
                return "add";
+       case Token.ASYNC:
+               return "async";
        case Token.BASE:
                return "base";
        case Token.BREAK: