2008-06-25 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / cs-parser.jay
index 6a6c8cf40d3c9db97ec8e173082693cd8fd7aac3..a48ed260b13b0aec6577dfa2c7418700c3d0eb02 100644 (file)
@@ -42,16 +42,20 @@ namespace Mono.CSharp
                ///   Current block is used to add statements as we find
                ///   them.  
                /// </summary>
-               Block      current_block, top_current_block;
+               Block      current_block;
 
                Delegate   current_delegate;
-
+               
+               GenericMethod current_generic_method;
                AnonymousMethodExpression current_anonymous_method;
 
                /// <summary>
                ///   This is used by the unary_expression code to resolve
                ///   a name against a parameter.  
                /// </summary>
+               
+               // FIXME: This is very ugly and it's very hard to reset it correctly
+               // on all places, especially when some parameters are autogenerated.
                Parameters current_local_parameters;
 
                /// <summary>
@@ -59,14 +63,14 @@ namespace Mono.CSharp
                ///   value parameter that is passed to the "set" and "get"accesor
                ///   methods (properties and indexers).
                /// </summary>
-               Expression implicit_value_parameter_type;
+               FullNamedExpression implicit_value_parameter_type;
                Parameters indexer_parameters;
 
                /// <summary>
                ///   Hack to help create non-typed array initializer
                /// </summary>
-               public static Expression current_array_type;
-               Expression pushed_current_array_type;
+               public static FullNamedExpression current_array_type;
+               FullNamedExpression pushed_current_array_type;
 
                /// <summary>
                ///   Used to determine if we are parsing the get/set pair
@@ -75,7 +79,7 @@ namespace Mono.CSharp
                bool parsing_indexer;
 
                bool parsing_anonymous_method;
-               
+
                ///
                /// An out-of-band stack.
                ///
@@ -88,13 +92,10 @@ namespace Mono.CSharp
 
                static public int yacc_verbose_flag;
 
-               // Name of the file we are parsing
-               public string name;
-
                ///
                /// The current file.
                ///
-               SourceFile file;
+               CompilationUnit file;
 
                ///
                /// Temporary Xml documentation cache.
@@ -109,6 +110,9 @@ namespace Mono.CSharp
                /// assembly and module attribute definitions are enabled
                bool global_attrs_enabled = true;
                bool has_get, has_set;
+               bool parameter_modifiers_not_allowed;
+               bool params_modifiers_not_allowed;
+               bool arglist_allowed;
 
 %}
 
@@ -200,10 +204,25 @@ namespace Mono.CSharp
 %token VIRTUAL 
 %token VOID    
 %token VOLATILE
+%token WHERE
 %token WHILE   
 %token ARGLIST
 %token PARTIAL
 %token ARROW
+%token QUERY_FIRST_TOKEN
+%token FROM
+%token JOIN
+%token ON
+%token EQUALS
+%token SELECT
+%token GROUP
+%token BY
+%token LET
+%token ORDERBY
+%token ASCENDING
+%token DESCENDING
+%token INTO
+%token QUERY_LAST_TOKEN
 
 /* C# keywords which are not really keywords */
 %token GET           "get"
@@ -263,6 +282,7 @@ namespace Mono.CSharp
 %token OP_XOR_ASSIGN          "^="
 %token OP_OR_ASSIGN           "|="
 %token OP_PTR                 "->"
+%token OP_COALESCING          "??"
 
 /* Numbers */
 %token LITERAL_INTEGER           "int literal"
@@ -278,6 +298,9 @@ namespace Mono.CSharp
 %token CLOSE_PARENS_NO_CAST
 %token CLOSE_PARENS_OPEN_PARENS
 %token CLOSE_PARENS_MINUS
+%token DEFAULT_OPEN_PARENS
+%token GENERIC_DIMENSION
+%token DEFAULT_COLON
 
 /* Add precedence rules to solve dangling else s/r conflict */
 %nonassoc LOWPREC
@@ -342,10 +365,10 @@ extern_alias_directive
                if (s != "alias"){
                        Report.Error (1003, lt.Location, "'alias' expected");
                } else if (RootContext.Version == LanguageVersion.ISO_1) {
-                       Report.FeatureIsNotISO1 (lt.Location, "external alias");
+                       Report.FeatureIsNotAvailable (lt.Location, "external alias");
                } else {
                        lt = (LocatedToken) $3; 
-                       current_namespace.UsingExternalAlias (lt.Value, lt.Location);
+                       current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
                }
          }
        ;
@@ -373,7 +396,7 @@ using_alias_directive
          namespace_or_type_name SEMICOLON
          {
                LocatedToken lt = (LocatedToken) $2;
-               current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
+               current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
          }
        | USING error {
                CheckIdentifierToken (yyToken, GetLocation ($2));
@@ -383,8 +406,8 @@ using_alias_directive
 using_namespace_directive
        : USING namespace_name SEMICOLON 
          {
-               current_namespace.Using ((MemberName) $2, (Location) $1);
-          }
+               current_namespace.AddUsing ((MemberName) $2, (Location) $1);
+         }
        ;
 
 //
@@ -401,6 +424,9 @@ namespace_declaration
                        Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
                }
 
+               if (name.TypeArguments != null)
+                       syntax_error (lexer.Location, "namespace name expected");
+
                current_namespace = new NamespaceEntry (
                        current_namespace, file, name.GetName ());
                current_class = current_namespace.SlaveDeclSpace;
@@ -425,7 +451,14 @@ opt_comma
        ;
 
 namespace_name
-       : namespace_or_type_name
+       : namespace_or_type_name {
+               MemberName name = (MemberName) $1;
+
+               if (name.TypeArguments != null)
+                       syntax_error (lexer.Location, "namespace name expected");
+
+               $$ = name;
+         }
        ;
 
 namespace_body
@@ -523,8 +556,16 @@ type_declaration
 global_attributes
        : attribute_sections
 {
-       if ($1 != null)
-               CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
+       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;
 }
@@ -632,9 +673,9 @@ attribute_target
                LocatedToken lt = (LocatedToken) $1;
                $$ = CheckAttributeTarget (lt.Value, lt.Location);
          }
-      | EVENT  { $$ = "event"; }         
-      | RETURN { $$ = "return"; }
-      | error
+       | EVENT  { $$ = "event"; }
+       | RETURN { $$ = "return"; }
+       | error
          {
                string name = yyNames [yyToken].ToLower ();
                $$ = CheckAttributeTarget (name, GetLocation ($1));
@@ -663,7 +704,12 @@ attribute
        : attribute_name opt_attribute_arguments
          {
                MemberName mname = (MemberName) $1;
-               object[] arguments = (object[]) $2;
+               if (mname.IsGeneric) {
+                       Report.Error (404, lexer.Location,
+                                     "'<' unexpected: attributes cannot be generic");
+               }
+
+               object [] arguments = (object []) $2;
                MemberName left = mname.Left;
                string identifier = mname.Name;
 
@@ -671,7 +717,7 @@ attribute
 
                if (current_attr_target == String.Empty)
                        $$ = null;
-               else if (current_attr_target == "assembly" || current_attr_target == "module")
+               else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
                        // FIXME: supply "nameEscaped" parameter here.
                        $$ = new GlobalAttribute (current_namespace, current_attr_target,
                                                  left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
@@ -800,18 +846,21 @@ struct_declaration
        : opt_attributes
          opt_modifiers
          opt_partial
-         STRUCT member_name
+         STRUCT
+         {
+               lexer.ConstraintsParsing = true;
+         }
+         type_name
          { 
-               MemberName name = MakeName ((MemberName) $5);
-               push_current_class (new Struct (
-                       current_namespace, current_class, name, (int) $2,
-                       (Attributes) $1), false, $3);
-
+               MemberName name = MakeName ((MemberName) $6);
+               push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
          }
          opt_class_base
+         opt_type_parameter_constraints_clauses
          {
-               if ($7 != null)
-                       current_container.AddBasesForPart (current_class, (ArrayList) $7);
+               lexer.ConstraintsParsing = false;
+
+               current_class.SetParameterInfo ((ArrayList) $9);
 
                if (RootContext.Documentation != null)
                        current_container.DocComment = Lexer.consume_doc_comment ();
@@ -884,7 +933,7 @@ constant_declaration
                        }
 
                        Const c = new Const (
-                               current_class, (Expression) $4, (string) constant.identifier, 
+                               current_class, (FullNamedExpression) $4, (string) constant.identifier, 
                                (Expression) constant.expression_or_array_initializer, modflags, 
                                (Attributes) $1, l);
 
@@ -934,7 +983,7 @@ field_declaration
          variable_declarators
          SEMICOLON
          { 
-               Expression type = (Expression) $3;
+               FullNamedExpression type = (FullNamedExpression) $3;
                int mod = (int) $2;
 
                current_array_type = null;
@@ -960,7 +1009,7 @@ field_declaration
          fixed_variable_declarators
          SEMICOLON
          { 
-                       Expression type = (Expression) $4;
+                       FullNamedExpression type = (FullNamedExpression) $4;
                        int mod = (int) $2;
 
                        current_array_type = null;
@@ -1092,6 +1141,7 @@ method_declaration
                current_container.AddMethod (method);
 
                anonymous_host = null;
+               current_generic_method = null;
                current_local_parameters = null;
 
                if (RootContext.Documentation != null)
@@ -1132,16 +1182,41 @@ open_parens
 method_header
        : opt_attributes
          opt_modifiers
-         type namespace_or_type_name
-         open_parens opt_formal_parameter_list CLOSE_PARENS 
+         type 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 = new Method (current_class, null, (Expression) $3, (int) $2,
-                                           false, name,  (Parameters) $6, (Attributes) $1);
+               Method method;
+
+               GenericMethod generic = null;
+               if (name.TypeArguments != null) {
+                       generic = new GenericMethod (current_namespace, current_class, name,
+                                                    (FullNamedExpression) $3, current_local_parameters);
+
+                       generic.SetParameterInfo ((ArrayList) $10);
+               }
+
+               method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2, false,
+                                    name, current_local_parameters, (Attributes) $1);
 
                anonymous_host = method;
-               current_local_parameters = (Parameters) $6;
+               current_generic_method = generic;
 
                if (RootContext.Documentation != null)
                        method.DocComment = Lexer.consume_doc_comment ();
@@ -1150,17 +1225,99 @@ method_header
          }
        | opt_attributes
          opt_modifiers
-         VOID namespace_or_type_name
-         open_parens opt_formal_parameter_list CLOSE_PARENS 
+         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;
 
-               Method method = new Method (current_class, null, TypeManager.system_void_expr,
-                                           (int) $2, false, name, (Parameters) $6,
-                                           (Attributes) $1);
+               if ($10 != null && name.TypeArguments == null)
+                       Report.Error (80, lexer.Location,
+                                     "Constraints are not allowed on non-generic declarations");
+
+               Method method;
+               GenericMethod generic = null;
+               if (name.TypeArguments != null) {
+                       generic = new GenericMethod (current_namespace, current_class, name,
+                                                    TypeManager.system_void_expr, current_local_parameters);
+
+                       generic.SetParameterInfo ((ArrayList) $10);
+               }
+
+               method = new Method (current_class, generic, TypeManager.system_void_expr,
+                                    (int) $2, false, name, current_local_parameters, (Attributes) $1);
+
+               anonymous_host = method;
+               current_generic_method = generic;
+
+               if (RootContext.Documentation != null)
+                       method.DocComment = Lexer.consume_doc_comment ();
+
+               $$ = method;
+       }
+       | opt_attributes
+         opt_modifiers
+         PARTIAL
+         VOID member_name
+         open_parens opt_formal_parameter_list CLOSE_PARENS 
+         {
+               lexer.ConstraintsParsing = true;
+         }
+         opt_type_parameter_constraints_clauses
+         {
+               lexer.ConstraintsParsing = false;
+
+               MemberName name = (MemberName) $5;
+               current_local_parameters = (Parameters) $7;
+
+               if ($9 != 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);
+               }
+
+               int modifiers = (int) $2;
+
+
+               const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
+                       Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
+
+               if ((modifiers & invalid_partial_mod) != 0) {
+                       Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
+                               "any of abstract, extern, new, override, sealed, or virtual modifiers");
+                       modifiers &= ~invalid_partial_mod;
+               }
+
+               if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
+                       Report.Error (751, name.Location, "A partial method must be declared within a " +
+                               "partial class or partial struct");
+               }
+
+               modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
+               
+               method = new Method (current_class, generic, TypeManager.system_void_expr,
+                                    modifiers, false, name, current_local_parameters, (Attributes) $1);
 
                anonymous_host = method;
-               current_local_parameters = (Parameters) $6;
+               current_generic_method = generic;
 
                if (RootContext.Documentation != null)
                        method.DocComment = Lexer.consume_doc_comment ();
@@ -1170,7 +1327,7 @@ method_header
        | opt_attributes
          opt_modifiers
          type 
-         modifiers namespace_or_type_name open_parens opt_formal_parameter_list CLOSE_PARENS
+         modifiers member_name open_parens opt_formal_parameter_list CLOSE_PARENS
          {
                MemberName name = (MemberName) $5;
                Report.Error (1585, name.Location, 
@@ -1197,6 +1354,19 @@ opt_formal_parameter_list
        : /* empty */                   { $$ = Parameters.EmptyReadOnlyParameters; }
        | formal_parameter_list
        ;
+       
+opt_parameter_list_no_mod
+       : /* empty */                   { $$ = Parameters.EmptyReadOnlyParameters; }
+       | 
+         {
+               parameter_modifiers_not_allowed = true;
+         }
+         formal_parameter_list
+         {
+               parameter_modifiers_not_allowed = false;
+               $$ = $2;
+         }
+       ;
 
 formal_parameter_list
        : fixed_parameters              
@@ -1218,7 +1388,7 @@ formal_parameter_list
 
                $$ = new Parameters (pars); 
          }
-       | fixed_parameters COMMA ARGLIST
+       | fixed_parameters COMMA arglist_modifier
          {
                ArrayList pars_list = (ArrayList) $1;
                //pars_list.Add (new ArglistParameter (GetLocation ($3)));
@@ -1240,7 +1410,7 @@ formal_parameter_list
                        Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
                $$ = null;
          }
-       | ARGLIST COMMA error
+       | arglist_modifier COMMA error
          {
                Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
                $$ = null;
@@ -1254,7 +1424,7 @@ formal_parameter_list
          {
                $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
          }
-       | ARGLIST
+       | arglist_modifier
          {
                $$ = new Parameters (new Parameter[0], true);
          }
@@ -1271,8 +1441,12 @@ fixed_parameters
        | fixed_parameters COMMA fixed_parameter
          {
                ArrayList pars = (ArrayList) $1;
-
-               pars.Add ($3);
+               Parameter p = (Parameter)$3;
+               if (p != null) {
+                       if (p.HasExtensionMethodModifier)
+                               Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
+                       pars.Add (p);
+               }
                $$ = $1;
          }
        ;
@@ -1284,7 +1458,7 @@ fixed_parameter
          IDENTIFIER
          {
                LocatedToken lt = (LocatedToken) $4;
-               $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
+               $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
          }
        | opt_attributes
          opt_parameter_modifier
@@ -1339,42 +1513,87 @@ parameter_modifiers
                if (((Parameter.Modifier)$1 & p2) == p2) {
                        Error_DuplicateParameterModifier (lexer.Location, p2);
                } else {
-                       Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
+                       switch (mod & ~Parameter.Modifier.This) {
+                               case Parameter.Modifier.REF:
+                                       Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
+                                       break;
+                               case Parameter.Modifier.OUT:
+                                       Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
+                                       break;
+                               default:
+                                       Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
+                                       break;
+                       }
                }
                $$ = mod;
          }
        ;
 
 parameter_modifier
-       : REF                   { $$ = Parameter.Modifier.REF; }
-       | OUT                   { $$ = Parameter.Modifier.OUT; }
-       | THIS                  { $$ = Parameter.Modifier.This; }
+       : REF
+         {
+               if (parameter_modifiers_not_allowed)
+                       Error_ParameterModifierNotValid ("ref", (Location)$1);
+                       
+               $$ = Parameter.Modifier.REF;
+         }
+       | OUT
+         {
+               if (parameter_modifiers_not_allowed)
+                       Error_ParameterModifierNotValid ("out", (Location)$1);
+         
+               $$ = Parameter.Modifier.OUT;
+         }
+       | THIS
+         {
+               if (parameter_modifiers_not_allowed)
+                       Error_ParameterModifierNotValid ("this", (Location)$1);
+
+               if (RootContext.Version <= LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
+                               
+               $$ = Parameter.Modifier.This;
+         }
        ;
 
 parameter_array
-       : opt_attributes PARAMS type IDENTIFIER
+       : opt_attributes params_modifier type IDENTIFIER
          { 
                LocatedToken lt = (LocatedToken) $4;
-               $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
+               $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
          }
-       | opt_attributes PARAMS PARAMS type IDENTIFIER 
-         {
-               Error_DuplicateParameterModifier (lexer.Location, Parameter.Modifier.PARAMS);
+       | opt_attributes params_modifier type error {
+               CheckIdentifierToken (yyToken, GetLocation ($4));
                $$ = null;
          }
-       | opt_attributes PARAMS parameter_modifier type IDENTIFIER 
+       ;
+       
+params_modifier
+       : PARAMS
+         {
+               if (params_modifiers_not_allowed)
+                       Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
+         }
+       | PARAMS parameter_modifier
          {
-               Parameter.Modifier mod = (Parameter.Modifier)$3;
+               Parameter.Modifier mod = (Parameter.Modifier)$2;
                if ((mod & Parameter.Modifier.This) != 0) {
-                       Report.Error (1104, lexer.Location, "The parameter modifiers `this' and `params' cannot be used altogether");
+                       Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
                } else {
-               Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
-               }
-                $$ = null;
+                       Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
+               }         
          }
-       | opt_attributes PARAMS type error {
-               CheckIdentifierToken (yyToken, GetLocation ($4));
-               $$ = null;
+       | PARAMS params_modifier
+         {
+               Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
+         }
+       ;
+       
+arglist_modifier
+       : ARGLIST
+         {
+               if (!arglist_allowed)
+                       Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
          }
        ;
 
@@ -1389,7 +1608,7 @@ property_declaration
          }
          OPEN_BRACE 
          {
-               implicit_value_parameter_type = (Expression) $3;
+               implicit_value_parameter_type = (FullNamedExpression) $3;
 
                lexer.PropertyParsing = true;
          }
@@ -1410,9 +1629,12 @@ property_declaration
 
                MemberName name = (MemberName) $4;
 
-               prop = new Property (current_class, (Expression) $3, (int) $2,
-                       false, name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse);
-               
+               if (name.TypeArguments != null)
+                       syntax_error (lexer.Location, "a property can't have type arguments");
+
+               prop = new Property (current_class, (FullNamedExpression) $3, (int) $2, false,
+                                    name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse, current_block);
+
                current_container.AddProperty (prop);
                implicit_value_parameter_type = null;
 
@@ -1548,24 +1770,28 @@ interface_declaration
        : opt_attributes
          opt_modifiers
          opt_partial
-         INTERFACE member_name
+         INTERFACE
          {
-               MemberName name = MakeName ((MemberName) $5);
-
-               push_current_class (new Interface (
-                       current_namespace, current_class, name, (int) $2,
-                       (Attributes) $1), true, $3);
+               lexer.ConstraintsParsing = true;
+         }
+         type_name
+         {
+               MemberName name = MakeName ((MemberName) $6);
+               push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
          }
          opt_class_base
+         opt_type_parameter_constraints_clauses
          {
-               current_container.AddBasesForPart (current_class, (ArrayList) $7);
+               lexer.ConstraintsParsing = false;
+
+               current_class.SetParameterInfo ((ArrayList) $9);
 
                if (RootContext.Documentation != null) {
                        current_container.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
          }
-         interface_body 
+         interface_body
          {
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
@@ -1627,7 +1853,7 @@ interface_member_declaration
 
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
-       }
+         }
        | interface_event_declaration 
           { 
                if ($1 != null){
@@ -1709,25 +1935,89 @@ opt_new
          }
        ;
 
+interface_method_declaration_body
+       : OPEN_BRACE 
+         {
+               Report.Error (531, (Location)$1,
+                             "`{0}.{1}{2}': interface members cannot have a definition",
+                             current_class.GetSignatureForError (),
+                             ((MemberName) $-0).GetSignatureForError (),
+                             ((Parameters)$-4).GetSignatureForError ());
+         
+               lexer.ConstraintsParsing = false;
+         }
+         opt_statement_list CLOSE_BRACE
+         {
+               $$ = null;
+         }
+       | SEMICOLON
+       ;
+
 interface_method_declaration
        : opt_attributes opt_new type namespace_or_type_name
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
-         SEMICOLON
+         open_parens opt_formal_parameter_list CLOSE_PARENS
+         {
+               lexer.ConstraintsParsing = true;
+         }
+         opt_type_parameter_constraints_clauses
+         {
+               // Refer to the name as $-1 in interface_method_declaration_body          
+               $$ = $4;
+         }
+         interface_method_declaration_body
          {
-               $$ = new Method (current_class, null, (Expression) $3, (int) $2, true,
-                                (MemberName) $4, (Parameters) $6, (Attributes) $1);
+               lexer.ConstraintsParsing = false;
+
+               MemberName name = (MemberName) $4;
+
+               if ($9 != null && name.TypeArguments == null)
+                       Report.Error (80, lexer.Location,
+                                     "Constraints are not allowed on non-generic declarations");
+
+               GenericMethod generic = null;
+               if (name.TypeArguments != null) {
+                       generic = new GenericMethod (current_namespace, current_class, name,
+                                                    (FullNamedExpression) $3, (Parameters) $6);
+
+                       generic.SetParameterInfo ((ArrayList) $9);
+               }
+
+               $$ = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2, true, name,
+                                (Parameters) $6, (Attributes) $1);
                if (RootContext.Documentation != null)
                        ((Method) $$).DocComment = Lexer.consume_doc_comment ();
          }
-       | opt_attributes opt_new type namespace_or_type_name
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
-         OPEN_BRACE opt_statement_list CLOSE_BRACE
+       | opt_attributes opt_new VOID namespace_or_type_name
+         open_parens opt_formal_parameter_list CLOSE_PARENS
+         {
+               lexer.ConstraintsParsing = true;
+         }
+         opt_type_parameter_constraints_clauses
+         {
+               $$ = $4;
+         }
+         interface_method_declaration_body
          {
-               $$ = new Method (current_class, null, (Expression) $3, (int) $2, true,
-                                (MemberName) $4, (Parameters) $6, (Attributes) $1);
+               lexer.ConstraintsParsing = false;
+
+               MemberName name = (MemberName) $4;
+
+               if ($9 != null && name.TypeArguments == null)
+                       Report.Error (80, lexer.Location,
+                                     "Constraints are not allowed on non-generic declarations");
+
+               GenericMethod generic = null;
+               if (name.TypeArguments != null) {
+                       generic = new GenericMethod (current_namespace, current_class, name,
+                                                    TypeManager.system_void_expr, (Parameters) $6);
 
-               Report.Error (531, lexer.Location, "`{0}': interface members cannot have a definition",
-                       ((Method)$$).GetSignatureForError ());
+                       generic.SetParameterInfo ((ArrayList) $9);
+               }
+
+               $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
+                                true, name, (Parameters) $6, (Attributes) $1);
+               if (RootContext.Documentation != null)
+                       ((Method) $$).DocComment = Lexer.consume_doc_comment ();
          }
        ;
 
@@ -1736,11 +2026,15 @@ interface_property_declaration
          opt_new
          type IDENTIFIER 
          OPEN_BRACE 
-         { lexer.PropertyParsing = true; }
+         {
+               lexer.PropertyParsing = true;
+               implicit_value_parameter_type = (FullNamedExpression)$3;
+         }
          accessor_declarations 
          {
                has_get = has_set = false; 
                lexer.PropertyParsing = false;
+               implicit_value_parameter_type = null;
          }
          CLOSE_BRACE
          {
@@ -1754,7 +2048,7 @@ interface_property_declaration
 
                Property p = null;
                if ($7 == null) {
-                       p = new Property (current_class, (Expression) $3, (int) $2, true,
+                       p = new Property (current_class, (FullNamedExpression) $3, (int) $2, true,
                                   name, (Attributes) $1,
                                   null, null, false);
 
@@ -1763,7 +2057,7 @@ interface_property_declaration
                }
 
                Accessors accessor = (Accessors) $7;
-               p = new Property (current_class, (Expression) $3, (int) $2, true,
+               p = new Property (current_class, (FullNamedExpression) $3, (int) $2, true,
                                   name, (Attributes) $1,
                                   accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
 
@@ -1797,7 +2091,7 @@ interface_event_declaration
        : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
          {
                LocatedToken lt = (LocatedToken) $5;
-               $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
+               $$ = new EventField (current_class, (FullNamedExpression) $4, (int) $2, true,
                                     new MemberName (lt.Value, lt.Location),
                                     (Attributes) $1);
                if (RootContext.Documentation != null)
@@ -1814,11 +2108,13 @@ interface_event_declaration
          }
        | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
          {
+               implicit_value_parameter_type = (FullNamedExpression) $4;
                lexer.EventParsing = true;
          }
          event_accessor_declarations
          {
                lexer.EventParsing = false;
+               implicit_value_parameter_type = null;
          }
          CLOSE_BRACE {
                Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
@@ -1828,19 +2124,23 @@ interface_event_declaration
 
 interface_indexer_declaration 
        : opt_attributes opt_new type THIS 
-         OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
-         OPEN_BRACE 
-         { lexer.PropertyParsing = true; }
+         OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
+         OPEN_BRACE
+         {
+               lexer.PropertyParsing = true;
+               implicit_value_parameter_type = (FullNamedExpression)$3;
+         }
          accessor_declarations 
          { 
                has_get = has_set = false;
                lexer.PropertyParsing = false;
+               implicit_value_parameter_type = null;
          }
          CLOSE_BRACE
          {
                Indexer i = null;
                if ($10 == null) {
-                       i = new Indexer (current_class, (Expression) $3,
+                       i = new Indexer (current_class, (FullNamedExpression) $3,
                                  new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
                                  (int) $2, true, (Parameters) $6, (Attributes) $1,
                                  null, null, false);
@@ -1850,7 +2150,7 @@ interface_indexer_declaration
                }
 
                Accessors accessors = (Accessors) $10;
-               i = new Indexer (current_class, (Expression) $3,
+               i = new Indexer (current_class, (FullNamedExpression) $3,
                                  new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
                                  (int) $2, true, (Parameters) $6, (Attributes) $1,
                                   accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
@@ -1885,16 +2185,9 @@ operator_declaration
                        break;
 
                OperatorDeclaration decl = (OperatorDeclaration) $3;
-               
-               Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
-
-               param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
-               if (decl.arg2type != null)
-                       param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
-
                Operator op = new Operator (
                        current_class, decl.optype, decl.ret_type, (int) $2, 
-                       new Parameters (param_list),
+                       current_local_parameters,
                        (ToplevelBlock) $5, (Attributes) $1, decl.location);
 
                if (RootContext.Documentation != null) {
@@ -1916,91 +2209,52 @@ operator_body
        : block
        | SEMICOLON { $$ = null; }
        ; 
+
 operator_declarator
-       : type OPERATOR overloadable_operator 
-         open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
+       : type OPERATOR overloadable_operator open_parens
          {
-               // TODO: wrong location
-               if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
-                       Error_ParameterModifierNotValid ((Location) $2);
-         
-               LocatedToken lt = (LocatedToken) $7;
-               Operator.OpType op = (Operator.OpType) $3;
-               CheckUnaryOperator (op, lt.Location);
-
-               if (op == Operator.OpType.Addition)
-                       op = Operator.OpType.UnaryPlus;
-
-               if (op == Operator.OpType.Subtraction)
-                       op = Operator.OpType.UnaryNegation;
-
-               Parameter [] pars = new Parameter [1];
-               Expression type = (Expression) $6;
-
-               pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
-
-               current_local_parameters = new Parameters (pars);
+               params_modifiers_not_allowed = true;
+         }
+         opt_parameter_list_no_mod CLOSE_PARENS
+         {
+               params_modifiers_not_allowed = false;
 
+               Location loc = (Location) $2;
+               Operator.OpType op = (Operator.OpType) $3;
+               current_local_parameters = (Parameters)$6;
+               
+               int p_count = current_local_parameters.Count;
+               if (p_count == 1) {
+                       if (op == Operator.OpType.Addition)
+                               op = Operator.OpType.UnaryPlus;
+                       else if (op == Operator.OpType.Subtraction)
+                               op = Operator.OpType.UnaryNegation;
+               }
+               
+               if (IsUnaryOperator (op)) {
+                       if (p_count == 2) {
+                               Report.Error (1020, loc, "Overloadable binary operator expected");
+                       } else if (p_count != 1) {
+                               Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
+                                       Operator.GetName (op));
+                       }
+               } else {
+                       if (p_count > 2) {
+                               Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
+                                       Operator.GetName (op));
+                       } else if (p_count != 2) {
+                               Report.Error (1019, loc, "Overloadable unary operator expected");
+                       }
+               }
+               
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
 
-               $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
-                                             null, null, (Location) $2);
+               $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
          }
-       | type OPERATOR overloadable_operator
-         open_parens 
-               opt_parameter_modifier type IDENTIFIER COMMA
-               opt_parameter_modifier type IDENTIFIER 
-         CLOSE_PARENS
-          {
-               // TODO: wrong location
-               if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE || (Parameter.Modifier)$9 != Parameter.Modifier.NONE)
-                       Error_ParameterModifierNotValid ((Location) $2);
-
-               LocatedToken ltParam1 = (LocatedToken) $7;
-               LocatedToken ltParam2 = (LocatedToken) $11;
-               CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
-
-               Parameter [] pars = new Parameter [2];
-
-               Expression typeL = (Expression) $6;
-               Expression typeR = (Expression) $10;
-
-              pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, null, ltParam1.Location);
-              pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, null, ltParam2.Location);
-
-              current_local_parameters = new Parameters (pars);
-
-               if (RootContext.Documentation != null) {
-                       tmpComment = Lexer.consume_doc_comment ();
-                       Lexer.doc_state = XmlCommentState.NotAllowed;
-               }
-              
-              $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1, 
-                                            typeL, ltParam1.Value,
-                                            typeR, ltParam2.Value, (Location) $2);
-          }
        | conversion_operator_declarator
-       | type OPERATOR overloadable_operator
-         open_parens 
-               opt_parameter_modifier type IDENTIFIER COMMA
-               opt_parameter_modifier type IDENTIFIER COMMA
-               opt_parameter_modifier type IDENTIFIER
-         CLOSE_PARENS
-         {
-               Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
-                       Operator.GetName ((Operator.OpType) $3));
-               $$ = null;
-         }
-       | type OPERATOR overloadable_operator 
-         open_parens CLOSE_PARENS
-         {
-               Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
-                       Operator.GetName ((Operator.OpType) $3));
-               $$ = null;
-         }
        ;
 
 overloadable_operator
@@ -2032,47 +2286,41 @@ overloadable_operator
        ;
 
 conversion_operator_declarator
-       : IMPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
+       : IMPLICIT OPERATOR type open_parens
          {
-               // TODO: wrong location
-               if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
-                       Error_ParameterModifierNotValid (GetLocation ($4));
-
-               LocatedToken lt = (LocatedToken) $7;
-               Parameter [] pars = new Parameter [1];
-
-               pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
+               params_modifiers_not_allowed = true;
+         }
+         opt_parameter_list_no_mod CLOSE_PARENS
+         {
+               params_modifiers_not_allowed = false;
 
-               current_local_parameters = new Parameters (pars);  
+               Location loc = (Location) $2;
+               current_local_parameters = (Parameters)$6;  
                  
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
 
-               $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $6, lt.Value,
-                                             null, null, (Location) $2);
+               $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
          }
-       | EXPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
+       | EXPLICIT OPERATOR type open_parens
          {
-               // TODO: wrong location
-               if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
-                       Error_ParameterModifierNotValid (GetLocation ($4));
-         
-               LocatedToken lt = (LocatedToken) $7;
-               Parameter [] pars = new Parameter [1];
-
-               pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
-
-               current_local_parameters = new Parameters (pars);  
+               params_modifiers_not_allowed = true;
+         }
+         opt_parameter_list_no_mod CLOSE_PARENS
+         {
+               params_modifiers_not_allowed = false;
+               
+               Location loc = (Location) $2;
+               current_local_parameters = (Parameters)$6;  
                  
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
 
-               $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $6, lt.Value,
-                                             null, null, (Location) $2);
+               $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
          }
        | IMPLICIT error 
          {
@@ -2093,34 +2341,27 @@ constructor_declaration
                Constructor c = (Constructor) $3;
                c.Block = (ToplevelBlock) $4;
                c.OptAttributes = (Attributes) $1;
-               c.ModFlags = (int) $2;
-       
+               int yield_method = c.ModFlags & Modifiers.METHOD_YIELDS;
+               int mods = (int) $2;
+               
                if (RootContext.Documentation != null)
                        c.DocComment = ConsumeStoredComment ();
 
-               if (c.Name == current_container.Basename){
-                       if ((c.ModFlags & Modifiers.STATIC) != 0){
-                               if ((c.ModFlags & Modifiers.Accessibility) != 0){
-                                       Report.Error (515, c.Location,
-                                               "`{0}': access modifiers are not allowed on static constructors",
-                                               c.GetSignatureForError ());
-                               }
-       
-                               c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);   
+               if ((mods & Modifiers.STATIC) != 0 && c.Name == current_container.Basename) {
+                       if ((mods & Modifiers.Accessibility) != 0){
+                               Report.Error (515, c.Location,
+                                       "`{0}': access modifiers are not allowed on static constructors",
+                                       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 ());
-                               }
-                       } else {
-                               c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
+                       if (c.Initializer != null){
+                               Report.Error (514, c.Location,
+                                       "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
+                                       c.GetSignatureForError ());
                        }
-               } else {
-                       // We let another layer check the validity of the constructor.
-                       //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
                }
 
+               c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, mods, Modifiers.PRIVATE, c.Location) | yield_method;
                current_container.AddConstructor (c);
 
                current_local_parameters = null;
@@ -2151,21 +2392,20 @@ constructor_header
          }
          open_parens opt_formal_parameter_list CLOSE_PARENS
          {
-               current_local_parameters = (Parameters) $4;
-               current_block = top_current_block = new ToplevelBlock (null,
-                       current_local_parameters, null, Location.Null);
-                       
                LocatedToken lt = (LocatedToken) $1;
+               current_local_parameters = (Parameters) $4;
+               current_block = new ToplevelBlock (null, current_local_parameters, null, lt.Location);
+
                $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
                                      null, lt.Location);
-                                     
+
                anonymous_host = (IAnonymousHost) $$;
          }
        ;
 
 constructor_body
        : block_prepared
-       | SEMICOLON             { current_block = top_current_block = null; $$ = null; }
+       | SEMICOLON             { current_block = null; $$ = null; }
        ;
 
 constructor_initializer
@@ -2200,7 +2440,7 @@ destructor_declaration
          IDENTIFIER OPEN_PARENS CLOSE_PARENS block
          {
                LocatedToken lt = (LocatedToken) $5;
-               if (lt.Value != current_container.Basename){
+               if (lt.Value != current_container.MemberName.Name){
                        Report.Error (574, lt.Location, "Name of destructor must match name of class");
                } else if (current_container.Kind != Kind.Class){
                        Report.Error (575, lt.Location, "Only class types can contain destructor");
@@ -2237,7 +2477,7 @@ event_declaration
                                var.Location);
 
                        EventField e = new EventField (
-                               current_class, (Expression) $4, (int) $2, false, name,
+                               current_class, (FullNamedExpression) $4, (int) $2, false, name,
                                (Attributes) $1);
 
                        e.Initializer = var.expression_or_array_initializer;
@@ -2255,7 +2495,7 @@ event_declaration
          EVENT type namespace_or_type_name
          OPEN_BRACE
          {
-               implicit_value_parameter_type = (Expression) $4;  
+               implicit_value_parameter_type = (FullNamedExpression) $4;  
                lexer.EventParsing = true;
          }
          event_accessor_declarations
@@ -2268,16 +2508,20 @@ event_declaration
 
                if ($8 == null){
                        Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
-                               current_container.Name, name.ToString ());
+                               current_container.Name, name.GetSignatureForError ());
                        $$ = null;
                } else {
                        Accessors accessors = (Accessors) $8;
+                       
+                       if (name.TypeArguments != null)
+                               syntax_error (lexer.Location, "an event can't have type arguments");
+
                        if (accessors.get_or_add == null || accessors.set_or_remove == null)
                                // CS0073 is already reported, so no CS0065 here.
                                $$ = null;
                        else {
                                Event e = new EventProperty (
-                                       current_class, (Expression) $4, (int) $2, false, name,
+                                       current_class, (FullNamedExpression) $4, (int) $2, false, name,
                                        (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
                                if (RootContext.Documentation != null) {
                                        e.DocComment = Lexer.consume_doc_comment ();
@@ -2335,11 +2579,19 @@ add_accessor_declaration
                
                current_local_parameters = new Parameters (args);  
                lexer.EventParsing = false;
+               
+               anonymous_host = SimpleAnonymousHost.GetSimple ();
          }
-          block
+         block
          {
-               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
+               Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
                lexer.EventParsing = true;
+               
+               current_local_parameters = null;
+               SimpleAnonymousHost.Simple.Propagate (accessor);
+               anonymous_host = null;
+               
+               $$ = accessor;
          }
        | opt_attributes ADD error {
                Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
@@ -2364,10 +2616,11 @@ remove_accessor_declaration
                current_local_parameters = new Parameters (args);  
                lexer.EventParsing = false;
          }
-          block
+         block
          {
                $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
                lexer.EventParsing = true;
+               current_local_parameters = null;
          }
        | opt_attributes REMOVE error {
                Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
@@ -2435,13 +2688,10 @@ indexer_declaration
        ;
 
 indexer_declarator
-       : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
+       : type THIS OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
          {
                Parameters pars = (Parameters) $4;
-               if (pars.HasArglist) {
-                       // "__arglist is not valid in this context"
-                       Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
-               } else if (pars.Empty){
+               if (pars.Empty){
                        Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
                }
                if (RootContext.Documentation != null) {
@@ -2449,21 +2699,17 @@ indexer_declarator
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
 
-               $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
+               $$ = 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.HasArglist) {
-                       // "__arglist is not valid in this context"
-                       Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
-               } else if (pars.Empty){
+               if (pars.Empty){
                        Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
                }
 
                MemberName name = (MemberName) $2;
-               $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
+               $$ = new IndexerDeclaration ((FullNamedExpression) $1, name, pars, (Location) $4);
 
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -2487,7 +2733,7 @@ enum_declaration
                Location enum_location = lt.Location;
 
                MemberName name = MakeName (new MemberName (lt.Value, enum_location));
-               Enum e = new Enum (current_namespace, current_class, (Expression) $5, (int) $2,
+               Enum e = new Enum (current_namespace, current_class, (FullNamedExpression) $5, (int) $2,
                                   name, (Attributes) $1);
                
                if (RootContext.Documentation != null)
@@ -2496,8 +2742,9 @@ enum_declaration
 
                EnumMember em = null;
                foreach (VariableDeclaration ev in (ArrayList) $7) {
-                       em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
-                               new MemberName (ev.identifier, ev.Location), ev.OptAttributes);
+                       em = new EnumMember (
+                               e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
+                               ev.OptAttributes, ev.Location);
 
 //                     if (RootContext.Documentation != null)
                                em.DocComment = ev.DocComment;
@@ -2505,7 +2752,7 @@ enum_declaration
                        e.AddEnumMember (em);
                }
 
-               current_container.AddEnum (e);
+               current_container.AddTypeContainer (e);
                $$ = e;
 
          }
@@ -2592,18 +2839,14 @@ enum_member_declaration
 delegate_declaration
        : opt_attributes
          opt_modifiers
-         DELEGATE type member_name
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
-         SEMICOLON
+         DELEGATE
+         type type_name
+         open_parens opt_formal_parameter_list CLOSE_PARENS
          {
                MemberName name = MakeName ((MemberName) $5);
                Parameters p = (Parameters) $7;
-               if (p.HasArglist) {
-                       // TODO: wrong location
-                       Report.Error (1669, name.Location, "__arglist is not valid in this context");
-               }
 
-               Delegate del = new Delegate (current_namespace, current_class, (Expression) $4,
+               Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
                                             (int) $2, name, p, (Attributes) $1);
 
                if (RootContext.Documentation != null) {
@@ -2612,30 +2855,141 @@ delegate_declaration
                }
 
                current_container.AddDelegate (del);
-               $$ = del;
-         }     
-       ;
-
-namespace_or_type_name
-       : member_name
-       | IDENTIFIER DOUBLE_COLON IDENTIFIER {
-               LocatedToken lt1 = (LocatedToken) $1;
-               LocatedToken lt2 = (LocatedToken) $3;
-               $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
+               current_delegate = del;
+               lexer.ConstraintsParsing = true;
          }
-       | namespace_or_type_name DOT IDENTIFIER {
+         opt_type_parameter_constraints_clauses
+         {
+               lexer.ConstraintsParsing = false;
+         }
+         SEMICOLON
+         {
+               current_delegate.SetParameterInfo ((ArrayList) $10);
+               $$ = current_delegate;
+
+               current_delegate = null;
+         }
+       ;
+
+opt_nullable
+       : /* empty */
+         {
+               lexer.CheckNullable (false);
+               $$ = false;
+         }
+       | INTERR
+         {
+               // FIXME: A hack with parsing conditional operator as nullable type
+               //if (RootContext.Version < LanguageVersion.ISO_2)
+               //      Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
+                       
+               lexer.CheckNullable (true);
+               $$ = true;
+         }
+       ;
+
+namespace_or_type_name
+       : 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");
+               
+               $$ = 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);
+               $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
          }
        ;
 
 member_name
-       : IDENTIFIER {
+       : IDENTIFIER opt_type_parameter_list
+         {
                LocatedToken lt = (LocatedToken) $1;
-               $$ = new MemberName (lt.Value, lt.Location);
+               $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
+         }
+       | namespace_or_type_name DOT IDENTIFIER opt_type_parameter_list 
+         {
+               LocatedToken lt = (LocatedToken) $3;
+               $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
+         }
+       ;
+
+type_name
+       : IDENTIFIER opt_type_parameter_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
+         {
+               if (RootContext.Version < LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (GetLocation ($1), "generics");      
+         
+               $$ = $2;
+         }
+       ;
+
+//
+// Generics parameters (identifiers only, with attributes), used in type, method declarations
+//
+
+opt_type_parameter_list
+       : /* empty */                { $$ = null; } 
+       | OP_GENERICS_LT type_arguments OP_GENERICS_GT
+         {
+               if (RootContext.Version < LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+         
+               $$ = $2;
+         }
+       ;
+
+type_arguments
+       : type_argument
+         {
+               TypeArguments type_args = new TypeArguments (lexer.Location);
+               type_args.Add ((Expression) $1);
+               $$ = type_args;
          }
+       | type_arguments COMMA type_argument
+         {
+               TypeArguments type_args = (TypeArguments) $1;
+               type_args.Add ((Expression) $3);
+               $$ = type_args;
+         }       
        ;
 
+type_argument
+       : type
+         {
+               $$ = $1;
+         }
+       | attribute_sections type
+         {
+               SimpleName sn = $2 as SimpleName;
+               if (sn == null)
+                       Error_TypeExpected (GetLocation ($2));
+               else
+                       $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
+               $$ = $2;          
+         }
+       ;
+       
 /* 
  * 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
@@ -2643,17 +2997,28 @@ member_name
  * gets rid of a shift/reduce couple
  */
 type
-       : namespace_or_type_name
+       : namespace_or_type_name opt_nullable
          {
                MemberName name = (MemberName) $1;
-               $$ = name.GetTypeExpression ();
+
+               if ((bool) $2) {
+                       $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
+               } else {
+                       if (RootContext.Version > LanguageVersion.ISO_2 && name.Left == null && name.Name == "var")
+                               $$ = new VarExpr (name.Location);
+                       else
+                               $$ = name.GetTypeExpression ();
+               }
+         }
+       | builtin_types opt_nullable
+         {
+               if ((bool) $2)
+                       $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
          }
-       | builtin_types
        | array_type
-       | pointer_type    
+       | pointer_type
        ;
 
-
 pointer_type
        : type STAR
          {
@@ -2662,7 +3027,7 @@ pointer_type
                // can't perform checks during this phase - we do it during
                // semantic analysis.
                //
-               $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
+               $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
          }
        | VOID STAR
          {
@@ -2671,28 +3036,24 @@ pointer_type
        ;
 
 non_expression_type
-       : builtin_types 
+       : builtin_types opt_nullable
+         {
+               if ((bool) $2)
+                       $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
+         }
        | non_expression_type rank_specifier
          {
                Location loc = GetLocation ($1);
                if (loc.IsNull)
                        loc = lexer.Location;
-               $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
+               $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, loc);
          }
        | non_expression_type STAR
          {
                Location loc = GetLocation ($1);
                if (loc.IsNull)
                        loc = lexer.Location;
-               $$ = new ComposedCast ((Expression) $1, "*", loc);
-         }
-       | expression rank_specifiers 
-         {
-               $$ = new ComposedCast ((Expression) $1, (string) $2);
-         }
-       | expression STAR 
-         {
-               $$ = new ComposedCast ((Expression) $1, "*");
+               $$ = new ComposedCast ((FullNamedExpression) $1, "*", loc);
          }
        
        //
@@ -2701,27 +3062,38 @@ non_expression_type
        //
        | multiplicative_expression STAR 
          {
-               $$ = new ComposedCast ((Expression) $1, "*");
+               FullNamedExpression e = $1 as FullNamedExpression;
+               if (e != null)
+                       $$ = new ComposedCast (e, "*");
+               else
+                       Error_TypeExpected (GetLocation ($1));
          }
        ;
 
 type_list
-       : type
+       : base_type_name
          {
-               ArrayList types = new ArrayList (4);
-
+               ArrayList types = new ArrayList (2);
                types.Add ($1);
                $$ = types;
          }
-       | type_list COMMA type
+       | type_list COMMA base_type_name
          {
                ArrayList types = (ArrayList) $1;
-
                types.Add ($3);
                $$ = types;
          }
        ;
 
+base_type_name
+       : type
+         {
+               if ($1 is ComposedCast)
+                       Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
+               $$ = $1;
+         }
+       ;
+       
 /*
  * replaces all the productions for isolating the various
  * simple types, but we need this to reuse it easily in local_variable_type
@@ -2750,9 +3122,13 @@ integral_type
        ;
 
 array_type
-       : type rank_specifiers
+       : type rank_specifiers opt_nullable
          {
-               $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2);
+               string rank_specifiers = (string) $2;
+               if ((bool) $3)
+                       rank_specifiers += "?";
+
+               $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
          }
        ;
 
@@ -2764,18 +3140,22 @@ primary_expression
          {
                // 7.5.1: Literals
          }
-       | member_name
+       | type_name
          {
                MemberName mn = (MemberName) $1;
                $$ = mn.GetTypeExpression ();
          }
-       | IDENTIFIER DOUBLE_COLON IDENTIFIER
+       | IDENTIFIER DOUBLE_COLON IDENTIFIER opt_type_argument_list
          {
                LocatedToken lt1 = (LocatedToken) $1;
                LocatedToken lt2 = (LocatedToken) $3;
-               $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
+               if (RootContext.Version == LanguageVersion.ISO_1)
+                       Report.FeatureIsNotAvailable (lt1.Location, "namespace alias qualifier");
+
+               $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $4, lt1.Location);
          }
        | parenthesized_expression
+       | default_value_expression
        | member_access
        | invocation_expression
        | element_access
@@ -2860,16 +3240,16 @@ parenthesized_expression
        ;
 
 member_access
-       : primary_expression DOT IDENTIFIER
+       : primary_expression DOT IDENTIFIER opt_type_argument_list
          {
                LocatedToken lt = (LocatedToken) $3;
-               $$ = new MemberAccess ((Expression) $1, lt.Value);
+               $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
          }
-       | predefined_type DOT IDENTIFIER
+       | predefined_type DOT IDENTIFIER opt_type_argument_list
          {
                LocatedToken lt = (LocatedToken) $3;
                // TODO: Location is wrong as some predefined types doesn't hold a location
-               $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
+               $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
          }
        ;
 
@@ -2907,6 +3287,73 @@ invocation_expression
          }
        ;
 
+opt_object_or_collection_initializer
+       : /* empty */           { $$ = null; }
+       | object_or_collection_initializer
+       ;
+
+object_or_collection_initializer
+       : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
+         {
+               if ($2 == null)
+                 $$ = CollectionOrObjectInitializers.Empty;
+               else
+                 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
+         }
+       | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
+         {
+               $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
+         }
+       ;
+
+opt_member_initializer_list
+       : /* empty */           { $$ = null; }
+       | member_initializer_list
+       {
+               $$ = $1;
+       }
+       ;
+
+member_initializer_list
+       : member_initializer
+         {
+               ArrayList a = new ArrayList ();
+               a.Add ($1);
+               $$ = a;
+         }
+       | member_initializer_list COMMA member_initializer
+         {
+               ArrayList a = (ArrayList)$1;
+               a.Add ($3);
+               $$ = a;
+         }
+       ;
+
+member_initializer
+       : IDENTIFIER ASSIGN initializer_value
+         {
+               LocatedToken lt = $1 as LocatedToken;
+               $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
+         }
+       | non_assignment_expression
+         {
+               $$ = new CollectionElementInitializer ((Expression)$1);
+         }
+       | OPEN_BRACE expression_list CLOSE_BRACE
+         {
+               $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
+         }
+       | OPEN_BRACE CLOSE_BRACE
+         {
+               Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
+         }       
+       ;
+
+initializer_value
+       : expression
+       | object_or_collection_initializer
+       ;
+
 opt_argument_list
        : /* empty */           { $$ = null; }
        | argument_list
@@ -2960,6 +3407,10 @@ non_simple_argument
                Expression expr = new Arglist (args, (Location) $1);
                $$ = new Argument (expr, Argument.AType.Expression);
          }
+       | ARGLIST OPEN_PARENS CLOSE_PARENS
+         {
+               $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
+         }       
        | ARGLIST
          {
                $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
@@ -2986,18 +3437,19 @@ element_access
                  
                Expression expr = (Expression) $1;  
                if (expr is ComposedCast){
-                       $$ = new ComposedCast (expr, (string) $2);
-               } else if (!(expr is SimpleName || expr is MemberAccess || expr is QualifiedAliasMember)){
-                       Error_ExpectingTypeName (expr);
-                       $$ = TypeManager.system_object_expr;
-               } else {
+                       $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
+               } else if (expr is ATypeNameExpression){
                        //
                        // So we extract the string corresponding to the SimpleName
                        // or MemberAccess
                        // 
-                       $$ = new ComposedCast (expr, (string) $2);
+                       $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
+               } else {
+                       Error_ExpectingTypeName (expr);
+                       $$ = TypeManager.system_object_expr;
                }
-               current_array_type = (Expression)$$;
+               
+               current_array_type = (FullNamedExpression)$$;
          }
        ;
 
@@ -3024,10 +3476,10 @@ this_access
        ;
 
 base_access
-       : BASE DOT IDENTIFIER
+       : BASE DOT IDENTIFIER opt_type_argument_list
          {
                LocatedToken lt = (LocatedToken) $3;
-               $$ = new BaseAccess (lt.Value, lt.Location);
+               $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
          }
        | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
          {
@@ -3058,12 +3510,27 @@ 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
+       : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
          {
-               $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
+               if ($6 != null) {
+                       if (RootContext.Version <= LanguageVersion.ISO_2)
+                               Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
+                               
+                       $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (CollectionOrObjectInitializers) $6, (Location) $1);
+               }
+               else
+                       $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
+         }
+       | NEW type object_or_collection_initializer
+         {
+               if (RootContext.Version <= LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
+         
+               $$ = new NewInitialize ((Expression) $2, null, (CollectionOrObjectInitializers) $3, (Location) $1);
          }
        ;
 
@@ -3072,11 +3539,15 @@ array_creation_expression
          opt_rank_specifier
          opt_array_initializer
          {
-               $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
+               $$ = new ArrayCreation ((FullNamedExpression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
          }
        | NEW type rank_specifiers array_initializer
          {
-               $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
+               $$ = new ArrayCreation ((FullNamedExpression) $2, (string) $3, (ArrayList) $4, (Location) $1);
+         }
+       | NEW rank_specifiers array_initializer
+         {
+               $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
          }
        | NEW error
          {
@@ -3090,6 +3561,65 @@ array_creation_expression
          }
        ;
 
+anonymous_type_expression
+       : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
+         {
+               if (RootContext.Version <= LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
+
+               $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
+         }
+       ;
+
+anonymous_type_parameters_opt_comma
+       : anonymous_type_parameters_opt
+       | anonymous_type_parameters COMMA
+       ;
+
+anonymous_type_parameters_opt
+       : { $$ = null; }
+       | anonymous_type_parameters
+       ;
+
+anonymous_type_parameters
+       : anonymous_type_parameter
+         {
+               ArrayList a = new ArrayList (4);
+               a.Add ($1);
+               $$ = a;
+         }
+       | anonymous_type_parameters COMMA anonymous_type_parameter
+         {
+               ArrayList a = (ArrayList) $1;
+               a.Add ($3);
+               $$ = a;
+         }
+       ;
+
+anonymous_type_parameter
+       : IDENTIFIER ASSIGN variable_initializer
+         {
+               LocatedToken lt = (LocatedToken)$1;
+               $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
+         }
+       | IDENTIFIER
+         {
+               LocatedToken lt = (LocatedToken)$1;
+               $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
+                       lt.Value, lt.Location);
+         }
+       | member_access
+         {
+               MemberAccess ma = (MemberAccess) $1;
+               $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
+         }
+       | error
+         {
+               Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
+               "Anonymous type members must be a member assignment, simple name or member access expression");
+         }
+       ;
+
 opt_rank_specifier
        : /* empty */
          {
@@ -3101,6 +3631,31 @@ opt_rank_specifier
          }
        ;
 
+opt_rank_specifier_or_nullable
+       : /* empty */
+         {
+               $$ = "";
+         }
+       | INTERR
+         {
+               $$ = "?";
+         }
+       | opt_nullable rank_specifiers
+         {
+               if ((bool) $1)
+                       $$ = "?" + $2;
+               else
+                       $$ = $2;
+         }
+       | opt_nullable rank_specifiers INTERR
+         {
+               if ((bool) $1)
+                       $$ = "?" + $2 + "?";
+               else
+                       $$ = $2 + "?";
+         }
+       ;
+
 rank_specifiers
        : rank_specifier opt_rank_specifier
          {
@@ -3179,9 +3734,11 @@ typeof_expression
        : TYPEOF
       {
                pushed_current_array_type = current_array_type;
+               lexer.TypeOfParsing = true;
          }
-         OPEN_PARENS type CLOSE_PARENS
+         OPEN_PARENS typeof_type_expression CLOSE_PARENS
          {
+               lexer.TypeOfParsing = false;
                Expression type = (Expression)$4;
                if (type == TypeManager.system_void_expr)
                        $$ = new TypeOfVoid ((Location) $1);
@@ -3190,6 +3747,57 @@ typeof_expression
                current_array_type = pushed_current_array_type;
          }
        ;
+       
+typeof_type_expression
+       : type
+         {
+               $$ = $1;
+         }
+       | unbound_type_name
+         {
+               $$ = new UnboundTypeExpression ((MemberName)$1, lexer.Location);
+         }
+       ;
+       
+unbound_type_name
+       : IDENTIFIER GENERIC_DIMENSION
+         {
+               if (RootContext.Version < LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (lexer.Location, "generics");
+         
+               LocatedToken lt = (LocatedToken) $1;
+               TypeArguments ta = new TypeArguments ((int)$2, lt.Location);
+
+               $$ = new MemberName (lt.Value, ta, lt.Location);
+         }
+       | IDENTIFIER DOUBLE_COLON 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);
+         }
+       | unbound_type_name DOT IDENTIFIER GENERIC_DIMENSION
+         {
+               LocatedToken lt = (LocatedToken) $3;
+               TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
+               
+               $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
+         }
+       | namespace_or_type_name DOT IDENTIFIER GENERIC_DIMENSION
+         {
+               LocatedToken lt = (LocatedToken) $3;
+               TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
+               
+               $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
+         }
+       ;
+
 
 sizeof_expression
        : SIZEOF OPEN_PARENS type CLOSE_PARENS { 
@@ -3217,7 +3825,7 @@ pointer_member_access
                Expression deref;
                LocatedToken lt = (LocatedToken) $3;
 
-               deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
+               deref = new Indirection ((Expression) $1, lt.Location);
                $$ = new MemberAccess (deref, lt.Value);
          }
        ;
@@ -3230,7 +3838,7 @@ anonymous_method_expression
          block
          {
                $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
-         }
+       }
        ;
 
 opt_anonymous_method_signature
@@ -3239,47 +3847,24 @@ opt_anonymous_method_signature
        ;
 
 anonymous_method_signature
-       : open_parens opt_anonymous_method_parameter_list CLOSE_PARENS 
+       : open_parens
          {
-               if ($2 == null)
-                       $$ = Parameters.EmptyReadOnlyParameters;
-               else {
-                       ArrayList par_list = (ArrayList) $2;
-                       Parameter [] pars = new Parameter [par_list.Count];
-                       par_list.CopyTo (pars);
-                       $$ = new Parameters (pars);
-               }
+               params_modifiers_not_allowed = true; 
          }
-       ;
-
-opt_anonymous_method_parameter_list
-       : /* empty */                      { $$ = null; } 
-       | anonymous_method_parameter_list  { $$ = $1; }
-       ;
-
-anonymous_method_parameter_list
-       : anonymous_method_parameter 
+         opt_formal_parameter_list CLOSE_PARENS
          {
-               ArrayList a = new ArrayList (4);
-               a.Add ($1);
-               $$ = a;
+               params_modifiers_not_allowed = false;
+               $$ = $3;
          }
-       | anonymous_method_parameter_list COMMA anonymous_method_parameter 
+       ;
+
+default_value_expression
+       : DEFAULT_OPEN_PARENS type CLOSE_PARENS
          {
-               ArrayList a = (ArrayList) $1;
-               a.Add ($3);
-               $$ = a;
-         }
-       ; 
+               if (RootContext.Version < LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
 
-anonymous_method_parameter
-       : opt_parameter_modifier type IDENTIFIER {
-               LocatedToken lt = (LocatedToken) $3;
-               $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
-         }
-       | PARAMS type IDENTIFIER {
-               Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
-               $$ = null;
+               $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
          }
        ;
 
@@ -3301,6 +3886,10 @@ cast_list
          {
                $$ = new Cast ((Expression) $1, (Expression) $3);
          }
+       | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
+         {
+               $$ = new Cast ((Expression) $1, (Expression) $3);
+         }
        | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
          {
                $$ = new Cast ((Expression) $1, (Expression) $3);
@@ -3342,7 +3931,7 @@ prefixed_unary_expression
          }
        | STAR prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
+               $$ = new Indirection ((Expression) $2, (Location) $1);
          }
        | BITWISE_AND prefixed_unary_expression
          {
@@ -3350,22 +3939,6 @@ prefixed_unary_expression
          }
        ;
 
-pre_increment_expression
-       : OP_INC prefixed_unary_expression 
-         {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
-                                      (Expression) $2, (Location) $1);
-         }
-       ;
-
-pre_decrement_expression
-       : OP_DEC prefixed_unary_expression 
-         {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
-                                      (Expression) $2, (Location) $1);
-         }
-       ;
-
 multiplicative_expression
        : prefixed_unary_expression
        | multiplicative_expression STAR prefixed_unary_expression
@@ -3413,6 +3986,28 @@ shift_expression
          }
        ; 
 
+opt_error
+       : /* empty */
+         {
+               $$ = false;
+         }
+       | error
+         {
+               lexer.PutbackNullable ();
+               $$ = true;
+         }
+       ;
+
+nullable_type_or_conditional
+       : type opt_error
+         {
+               if (((bool) $2) && ($1 is ComposedCast))
+                       $$ = ((ComposedCast) $1).RemoveNullable ();
+               else
+                       $$ = $1;
+         }
+       ;
+
 relational_expression
        : shift_expression
        | relational_expression OP_LT shift_expression
@@ -3435,13 +4030,19 @@ relational_expression
                $$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
                                 (Expression) $1, (Expression) $3);
          }
-       | relational_expression IS type
+       | relational_expression IS
          {
-               $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
+               yyErrorFlag = 3;
+         } nullable_type_or_conditional
+         {
+               $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
          }
-       | relational_expression AS type
+       | relational_expression AS
+         {
+               yyErrorFlag = 3;
+         } nullable_type_or_conditional
          {
-               $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
+               $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
          }
        ;
 
@@ -3510,12 +4111,25 @@ conditional_expression
          {
                $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
          }
+       | conditional_or_expression OP_COALESCING expression
+         {
+               if (RootContext.Version < LanguageVersion.ISO_2)
+                       Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
+                       
+               $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
+         }
+       // We'll be resolved into a `parenthesized_expression_0' later on.
+       | conditional_or_expression INTERR CLOSE_PARENS
+         {
+               $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
+               lexer.PutbackCloseParens ();
+         }
        ;
 
 assignment_expression
        : prefixed_unary_expression ASSIGN expression
          {
-               $$ = new Assign ((Expression) $1, (Expression) $3);
+               $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_MULT_ASSIGN expression
          {
@@ -3569,67 +4183,52 @@ assignment_expression
          }
        ;
 
-implicitly_typed_lambda_parameter_list
-       : IDENTIFIER { 
-               LocatedToken lt = (LocatedToken) $1;
-               ArrayList a = new ArrayList (4); 
-
-               a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
-               $$ = a;
-         } 
-       | implicitly_typed_lambda_parameter_list COMMA IDENTIFIER {
-               LocatedToken lt = (LocatedToken) $3;
-               ArrayList a = (ArrayList) $1;
-               a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
-               $$ = a;
-         }
-       ;
-
-explicitly_typed_lambda_parameter_list
-       : explicitly_typed_lambda_parameter
+lambda_parameter_list
+       : lambda_parameter
          {
                ArrayList pars = new ArrayList (4);
                pars.Add ($1);
 
                $$ = pars;
          }
-       | explicitly_typed_lambda_parameter_list COMMA explicitly_typed_lambda_parameter
+       | lambda_parameter_list COMMA lambda_parameter
          {
                ArrayList pars = (ArrayList) $1;
-               pars.Add ($3);
-
+               Parameter p = (Parameter)$3;
+               if (pars[0].GetType () != p.GetType ()) {
+                       Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
+               }
+               
+               pars.Add (p);
                $$ = pars;
          }
        ;
 
-explicitly_typed_lambda_parameter
+lambda_parameter
        : parameter_modifier type IDENTIFIER
          {
                LocatedToken lt = (LocatedToken) $3;
 
-               $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
+               $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
          }
        | type IDENTIFIER
          {
                LocatedToken lt = (LocatedToken) $2;
 
-               $$ = new Parameter ((Expression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
+               $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
+         }
+       | IDENTIFIER
+         {
+               LocatedToken lt = (LocatedToken) $1;
+               $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
          }
-       ;
-
-lambda_parameter_list
-       : implicitly_typed_lambda_parameter_list { $$ = $1; }
-       | explicitly_typed_lambda_parameter_list { $$ = $1; }
        ;
 
 opt_lambda_parameter_list
-       : /* empty */                   { $$ = null; }
+       : /* empty */                   { $$ = Parameters.EmptyReadOnlyParameters; }
        | lambda_parameter_list         { 
                ArrayList pars_list = (ArrayList) $1;
-
-               Parameter [] pars = new Parameter [pars_list.Count];
-               pars_list.CopyTo (pars);
-               $$ = new Parameters (pars);
+               $$ = new Parameters ((Parameter[])pars_list.ToArray (typeof (Parameter)));
          }
        ;
 
@@ -3651,13 +4250,9 @@ lambda_expression_body
 lambda_expression
        : IDENTIFIER ARROW 
          {
-               Parameter [] pars = new Parameter [1];
                LocatedToken lt = (LocatedToken) $1;
-               pars [0] = new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
-
-               Parameters parameters = new Parameters (pars);
-
-               start_anonymous (true, parameters, (Location) $2);
+               Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
+               start_anonymous (true, new Parameters (p), (Location) $2);
          }
          lambda_expression_body
          {
@@ -3674,9 +4269,14 @@ lambda_expression
        ;
 
 expression
+       : assignment_expression
+       | non_assignment_expression
+       ;
+       
+non_assignment_expression
        : conditional_expression
-       | assignment_expression
        | lambda_expression
+       | query_expression
        ;
 
 constant_expression
@@ -3694,25 +4294,21 @@ class_declaration
        : opt_attributes
          opt_modifiers
          opt_partial
-         CLASS member_name
+         CLASS
          {
-               MemberName name = MakeName ((MemberName) $5);
-               int mod_flags = (int) $2;
-
-               push_current_class (new Class (
-                       current_namespace, current_class, name,
-                       mod_flags, (Attributes) $1), false, $3);
+               lexer.ConstraintsParsing = true;
+         }
+         type_name
+         {
+               MemberName name = MakeName ((MemberName) $6);
+               push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
          }
          opt_class_base
+         opt_type_parameter_constraints_clauses
          {
-               if ($7 != null) {
-                       if (current_class.Name == "System.Object") {
-                               Report.Error (537, current_class.Location,
-                                             "The class System.Object cannot have a base " +
-                                             "class or implement an interface.");
-                       }
-                       current_container.AddBasesForPart (current_class, (ArrayList) $7);
-               }
+               lexer.ConstraintsParsing = false;
+
+               current_class.SetParameterInfo ((ArrayList) $9);
 
                if (RootContext.Documentation != null) {
                        current_container.DocComment = Lexer.consume_doc_comment ();
@@ -3741,7 +4337,7 @@ opt_modifiers
        : /* empty */           { $$ = (int) 0; }
        | modifiers
        ;
-       
+
 modifiers
        : modifier
        | modifiers modifier
@@ -3755,7 +4351,7 @@ modifiers
                }
                $$ = (int) (m1 | m2);
          }
-      ;
+       ;
 
 modifier
        : NEW                   { $$ = Modifiers.NEW; }
@@ -3775,12 +4371,74 @@ modifier
        ;
 
 opt_class_base
-       : /* empty */           { $$ = null; }
-       | class_base            { $$ = $1;   }
+       : /* empty */
+       | class_base
        ;
 
 class_base
-       : COLON type_list { $$ = $2; }
+       : COLON type_list       { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
+       ;
+
+opt_type_parameter_constraints_clauses
+       : /* empty */           { $$ = null; }
+       | type_parameter_constraints_clauses 
+         { $$ = $1; }
+       ;
+
+type_parameter_constraints_clauses
+       : type_parameter_constraints_clause {
+               ArrayList constraints = new ArrayList (1);
+               constraints.Add ($1);
+               $$ = constraints;
+         }
+       | type_parameter_constraints_clauses type_parameter_constraints_clause {
+               ArrayList constraints = (ArrayList) $1;
+               Constraints new_constraint = (Constraints)$2;
+
+               foreach (Constraints c in constraints) {
+                       if (new_constraint.TypeParameter == c.TypeParameter) {
+                               Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
+                                       new_constraint.TypeParameter);
+                       }
+               }
+
+               constraints.Add (new_constraint);
+               $$ = constraints;
+         }
+       ; 
+
+type_parameter_constraints_clause
+       : WHERE IDENTIFIER COLON type_parameter_constraints {
+               LocatedToken lt = (LocatedToken) $2;
+               $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
+         }
+       ; 
+
+type_parameter_constraints
+       : type_parameter_constraint {
+               ArrayList constraints = new ArrayList (1);
+               constraints.Add ($1);
+               $$ = constraints;
+         }
+       | type_parameter_constraints COMMA type_parameter_constraint {
+               ArrayList constraints = (ArrayList) $1;
+
+               constraints.Add ($3);
+               $$ = constraints;
+         }
+       ;
+
+type_parameter_constraint
+       : type
+       | NEW OPEN_PARENS CLOSE_PARENS {
+               $$ = SpecialConstraint.Constructor;
+         }
+       | CLASS {
+               $$ = SpecialConstraint.ReferenceType;
+         }
+       | STRUCT {
+               $$ = SpecialConstraint.ValueType;
+         }
        ;
 
 //
@@ -3797,21 +4455,27 @@ class_base
 //     event_declaration as part of add_accessor_declaration or remove_accessor_declaration
 //      
 block
-       : OPEN_BRACE 
+       : OPEN_BRACE  
          {
+               ++lexer.parsing_block;
                start_block ((Location) $1);
          } 
          opt_statement_list CLOSE_BRACE 
-         { 
+         {
+               --lexer.parsing_block;
                $$ = end_block ((Location) $4);
          }
        ;
 
 block_prepared
-       : OPEN_BRACE 
+       : OPEN_BRACE
+         {
+               ++lexer.parsing_block;
+         }
          opt_statement_list CLOSE_BRACE 
-         { 
-               $$ = end_block ((Location) $3);
+         {
+               --lexer.parsing_block;
+               $$ = end_block ((Location) $4);
          }
        ;
 
@@ -3919,7 +4583,7 @@ declaration_statement
  * > The expressions are converted into types during semantic analysis.
  */
 local_variable_type
-       : primary_expression opt_rank_specifier
+       : primary_expression opt_rank_specifier_or_nullable
          { 
                // FIXME: Do something smart here regarding the composition of the type.
 
@@ -3936,47 +4600,54 @@ local_variable_type
                // Foo.Bar.Blah i;
                // SimpleName is when you have
                // Blah i;
-                 
+               
                Expression expr = (Expression) $1;  
-               if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is QualifiedAliasMember)) {
-                       Error_ExpectingTypeName (expr);
-                       $$ = null;
+               if (expr is ComposedCast){
+                       $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
+               } else if (expr is ATypeNameExpression){
+                       //
+                       // So we extract the string corresponding to the SimpleName
+                       // or MemberAccess
+                       //
+                       
+                       if ((string) $2 == "") {
+                               SimpleName sn = expr as SimpleName;
+                               if (sn != null && RootContext.Version > LanguageVersion.ISO_2 && sn.Name == "var")
+                                       $$ = new VarExpr (sn.Location);
+                               else
+                                       $$ = $1;
+                       } else {
+                               $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
+                       }
                } else {
-                       //
-                       // So we extract the string corresponding to the SimpleName
-                       // or MemberAccess
-                       // 
-
-                       if ((string) $2 == "")
-                               $$ = $1;
-                       else
-                               $$ = new ComposedCast ((Expression) $1, (string) $2);
+                       Error_ExpectingTypeName (expr);
+                       $$ = TypeManager.system_object_expr;
                }
          }
-       | builtin_types opt_rank_specifier
+       | builtin_types opt_rank_specifier_or_nullable
          {
                if ((string) $2 == "")
                        $$ = $1;
                else
-                       $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+                       $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
          }
         ;
 
 local_variable_pointer_type
        : primary_expression STAR
          {
-               Expression expr = (Expression) $1;  
-
-               if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is QualifiedAliasMember)) {
-                       Error_ExpectingTypeName (expr);
+               ATypeNameExpression expr = $1 as ATypeNameExpression;
 
-                       $$ = null;
-               } else 
-                       $$ = new ComposedCast ((Expression) $1, "*");
+               if (expr != null) {
+                       $$ = new ComposedCast (expr, "*");
+               } else {
+                       Error_ExpectingTypeName ((Expression)$1);
+                       $$ = expr;
+               }
          }
         | builtin_types STAR
          {
-               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+               $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
          }
         | VOID STAR
          {
@@ -3984,19 +4655,23 @@ local_variable_pointer_type
          }
        | local_variable_pointer_type STAR
           {
-               $$ = new ComposedCast ((Expression) $1, "*");
+               $$ = new ComposedCast ((FullNamedExpression) $1, "*");
          }
         ;
 
 local_variable_declaration
        : local_variable_type variable_declarators
          {
-               if ($1 != null)
+               if ($1 != null) {
+                       VarExpr ve = $1 as VarExpr;
+                       if (ve != null)
+                               ve.VariableInitializer = (ArrayList)$2;
+                               
                        $$ = new DictionaryEntry ($1, $2);
-               else
+               else
                        $$ = null;
          }
-        | local_variable_pointer_type opt_rank_specifier variable_declarators
+       | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
          {
                if ($1 != null){
                        Expression t;
@@ -4004,7 +4679,7 @@ local_variable_declaration
                        if ((string) $2 == "")
                                t = (Expression) $1;
                        else
-                               t = new ComposedCast ((Expression) $1, (string) $2);
+                               t = new ComposedCast ((FullNamedExpression) $1, (string) $2);
                        $$ = new DictionaryEntry (t, $3);
                } else 
                        $$ = null;
@@ -4047,11 +4722,6 @@ statement_expression
          }
        ;
 
-object_creation_expression
-       : object_or_delegate_creation_expression
-         { note ("complain if this is a delegate maybe?"); } 
-       ;
-
 selection_statement
        : if_statement
        | switch_statement
@@ -4142,11 +4812,7 @@ switch_section
          }
          statement_list 
          {
-               Block topmost = current_block;
-
-               while (topmost.Implicit)
-                       topmost = topmost.Parent;
-               $$ = new SwitchSection ((ArrayList) $1, topmost);
+               $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
          }
        ;
 
@@ -4169,7 +4835,7 @@ switch_labels
 
 switch_label
        : CASE constant_expression COLON        { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
-       | DEFAULT COLON                         { $$ = new SwitchLabel (null, (Location) $1); }
+       | DEFAULT_COLON                         { $$ = new SwitchLabel (null, (Location) $1); }
        | error {
                Report.Error (
                        1523, GetLocation ($1), 
@@ -4206,8 +4872,9 @@ for_statement
        : FOR open_parens 
          opt_for_initializer SEMICOLON
          {
-               Block assign_block = new Block (current_block);
-               current_block = assign_block;
+               Location l = lexer.Location;
+               start_block (l);  
+               Block assign_block = current_block;
 
                if ($3 is DictionaryEntry){
                        DictionaryEntry de = (DictionaryEntry) $3;
@@ -4223,14 +4890,13 @@ for_statement
                                if (vi == null)
                                        continue;
 
-                               Location l = lexer.Location;
                                Expression expr = decl.expression_or_array_initializer;
                                        
                                LocalVariableReference var;
                                var = new LocalVariableReference (assign_block, decl.identifier, l);
 
                                if (expr != null) {
-                                       Assign a = new Assign (var, expr, decl.Location);
+                                       Assign a = new SimpleAssign (var, expr, decl.Location);
                                        
                                        assign_block.AddStatement (new StatementExpression (a));
                                }
@@ -4252,10 +4918,8 @@ for_statement
                For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
 
                current_block.AddStatement (f);
-               while (current_block.Implicit)
-                       current_block = current_block.Parent;
-               $$ = current_block;
-               current_block = current_block.Parent;
+
+               $$ = end_block (lexer.Location);
          }
        ;
 
@@ -4288,7 +4952,7 @@ statement_expression_list
          {
                // CHANGE: was `null'
                Statement s = (Statement) $1;
-               Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);   
+               Block b = new Block (current_block, s.loc, lexer.Location);   
 
                b.AddStatement (s);
                $$ = b;
@@ -4311,14 +4975,12 @@ foreach_statement
        | FOREACH open_parens type IDENTIFIER IN
          expression CLOSE_PARENS 
          {
-               Block foreach_block = new Block (current_block);
-               current_block = foreach_block;
+               start_block (lexer.Location);
+               Block foreach_block = current_block;
 
                LocatedToken lt = (LocatedToken) $4;
                Location l = lt.Location;
-               LocalInfo vi;
-
-               vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
+               LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
                if (vi != null) {
                        vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
 
@@ -4341,10 +5003,7 @@ foreach_statement
                        current_block.AddStatement (f);
                }
 
-               while (current_block.Implicit)
-                         current_block = current_block.Parent;
-               $$ = current_block;
-               current_block = current_block.Parent;
+               $$ = end_block (lexer.Location);
          }
        ;
 
@@ -4411,7 +5070,7 @@ yield_statement
                        $$ = null;
                }
                if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotISO1 (lt.Location, "yield statement");
+                       Report.FeatureIsNotAvailable (lt.Location, "yield statement");
                        $$ = null;
                }
                if (anonymous_host == null){
@@ -4436,7 +5095,7 @@ yield_statement
                        $$ = null;
                }
                if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotISO1 (lt.Location, "yield statement");
+                       Report.FeatureIsNotAvailable (lt.Location, "yield statement");
                        $$ = null;
                }
                if (anonymous_host == null){
@@ -4455,43 +5114,17 @@ opt_expression
        ;
 
 try_statement
-       : TRY block catch_clauses 
+       : TRY block catch_clauses
          {
-               Catch g = null;
-               
-               ArrayList c = (ArrayList)$3;
-               for (int i = 0; i < c.Count; ++i) {
-                       Catch cc = (Catch) c [i];
-                       if (cc.IsGeneral) {
-                               if (i != c.Count - 1)
-                                       Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
-                               g = cc;
-                               c.RemoveAt (i);
-                               i--;
-                       }
-               }
-
-               // Now s contains the list of specific catch clauses
-               // and g contains the general one.
-               
-               $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
+               $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
          }
-       | TRY block opt_catch_clauses FINALLY block
+       | TRY block FINALLY block
          {
-               Catch g = null;
-               ArrayList s = new ArrayList (4);
-               ArrayList catch_list = (ArrayList) $3;
-
-               if (catch_list != null){
-                       foreach (Catch cc in catch_list) {
-                               if (cc.IsGeneral)
-                                       g = cc;
-                               else
-                                       s.Add (cc);
-                       }
-               }
-
-               $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
+               $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
+         }
+       | TRY block catch_clauses FINALLY block
+         {
+               $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
          }
        | TRY block error 
          {
@@ -4500,11 +5133,6 @@ try_statement
          }
        ;
 
-opt_catch_clauses
-       : /* empty */  { $$ = null; }
-        | catch_clauses
-       ;
-
 catch_clauses
        : catch_clause 
          {
@@ -4542,9 +5170,8 @@ catch_clause
 
                                one.Add (new VariableDeclaration (lt, null));
 
-                               current_block = new Block (current_block);
-                               Block b = declare_local_variables (type, one, lt.Location);
-                               current_block = b;
+                               start_block (lexer.Location);
+                               current_block = declare_local_variables (type, one, lt.Location);
                        }
                }
          } block {
@@ -4559,10 +5186,7 @@ catch_clause
 
                        if (lt != null){
                                id = lt.Value;
-                               while (current_block.Implicit)
-                                       current_block = current_block.Parent;
-                               var_block = current_block;
-                               current_block = current_block.Parent;
+                               var_block = end_block (lexer.Location);
                        }
                }
 
@@ -4572,16 +5196,19 @@ catch_clause
 
 opt_catch_args
        : /* empty */ { $$ = null; }
-        | catch_args
+       | catch_args
        ;         
 
 catch_args 
-        : open_parens type opt_identifier CLOSE_PARENS 
-          {
+       : OPEN_PARENS type opt_identifier CLOSE_PARENS 
+         {
                $$ = new DictionaryEntry ($2, $3);
          }
-        ;
-
+       | OPEN_PARENS CLOSE_PARENS 
+         {
+               Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
+         }
+       ;
 
 checked_statement
        : CHECKED block
@@ -4616,8 +5243,7 @@ fixed_statement
                Location l = (Location) $1;
                int top = list.Count;
 
-               Block assign_block = new Block (current_block);
-               current_block = assign_block;
+               start_block (lexer.Location);
 
                for (int i = 0; i < top; i++){
                        Pair p = (Pair) list [i];
@@ -4640,10 +5266,8 @@ fixed_statement
                Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
 
                current_block.AddStatement (f);
-               while (current_block.Implicit)
-                       current_block = current_block.Parent;
-               $$ = current_block;
-               current_block = current_block.Parent;
+
+               $$ = end_block (lexer.Location);
          }
        ;
 
@@ -4689,69 +5313,328 @@ lock_statement
        ;
 
 using_statement
-       : USING open_parens resource_acquisition CLOSE_PARENS
+       : USING open_parens local_variable_declaration CLOSE_PARENS
          {
-               Block assign_block = new Block (current_block);
-               current_block = assign_block;
-
-               if ($3 is DictionaryEntry){
-                       DictionaryEntry de = (DictionaryEntry) $3;
-                       Location l = (Location) $1;
+               start_block (lexer.Location);
+               Block assign_block = current_block;
 
-                       Expression type = (Expression) de.Key;
-                       ArrayList var_declarators = (ArrayList) de.Value;
+               DictionaryEntry de = (DictionaryEntry) $3;
+               Location l = (Location) $1;
 
-                       ArrayList vars = new ArrayList (4);
+               Expression type = (Expression) de.Key;
+               ArrayList var_declarators = (ArrayList) de.Value;
 
-                       foreach (VariableDeclaration decl in var_declarators){
+               Stack vars = new Stack ();
 
-                               LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
-                               if (vi == null)
-                                       continue;
-                               vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
+               foreach (VariableDeclaration decl in var_declarators) {
+                       LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
+                       if (vi == null)
+                               continue;
+                       vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
 
-                               Expression expr = decl.expression_or_array_initializer;
-                               if (expr == null) {
-                                       Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
-                               }
+                       Expression expr = decl.expression_or_array_initializer;
+                       if (expr == null) {
+                               Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
+                               continue;
+                       }
+                       LocalVariableReference var;
 
-                               LocalVariableReference var;
+                       // Get a writable reference to this read-only variable.
+                       var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
 
-                               // Get a writable reference to this read-only variable.
-                               var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
+                       // This is so that it is not a warning on using variables
+                       vi.Used = true;
 
-                               // This is so that it is not a warning on using variables
-                               vi.Used = true;
+                       vars.Push (new DictionaryEntry (var, expr));
 
-                               vars.Add (new DictionaryEntry (var, expr));                             
+                       // Assign a = new SimpleAssign (var, expr, decl.Location);
+                       // assign_block.AddStatement (new StatementExpression (a));
+               }
 
-                               // Assign a = new Assign (var, expr, decl.Location);
-                               // assign_block.AddStatement (new StatementExpression (a));
-                       }
+               // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
+               // It can be referred to as $5 below.
+               $$ = vars;
+         }
+         embedded_statement
+         {
+               Statement stmt = (Statement) $6;
+               Stack vars = (Stack) $5;
+               Location l = (Location) $1;
 
-                       // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
-                       // It can be referred to as $5 below.
-                       $$ = new DictionaryEntry (type, vars);
-                } else {
-                       $$ = $3;
-                }
-         } 
+               while (vars.Count > 0) {
+                         DictionaryEntry de = (DictionaryEntry) vars.Pop ();
+                         stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
+               }
+               current_block.AddStatement (stmt);
+               $$ = end_block (lexer.Location);
+         }
+       | USING open_parens expression CLOSE_PARENS
+         {
+               start_block (lexer.Location);
+         }
          embedded_statement
          {
-               Using u = new Using ($5, (Statement) $6, (Location) $1);
-               current_block.AddStatement (u);
-               while (current_block.Implicit)
-                       current_block = current_block.Parent;
-               $$ = current_block;
-               current_block = current_block.Parent;
+               current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
+               $$ = end_block (lexer.Location);
          }
        ; 
 
-resource_acquisition
-       : local_variable_declaration
-       | expression
+
+// LINQ
+
+query_expression
+       : first_from_clause
+         {
+               ++lexer.query_parsing;
+         }
+         query_body
+         {
+               if (--lexer.query_parsing == 1)
+                       lexer.query_parsing = 0;
+                       
+               Linq.AQueryClause from = $1 as Linq.AQueryClause;
+                       
+               from.Tail.Next = (Linq.AQueryClause)$3;
+               $$ = from;
+               
+               current_block.SetEndLocation (lexer.Location);
+               current_block = current_block.Parent;
+         }     
+       ;
+       
+first_from_clause
+       : FROM IDENTIFIER IN expression
+         {
+               current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
+               LocatedToken lt = (LocatedToken) $2;
+               
+               current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
+               $$ = new Linq.QueryExpression (lt, new Linq.QueryStartClause ((Expression)$4));
+         }
+       | FROM type IDENTIFIER IN expression
+         {
+               current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
+               LocatedToken lt = (LocatedToken) $3;
+
+               Expression type = (Expression)$2;
+               current_block.AddVariable (type, lt.Value, lt.Location);
+               $$ = new Linq.QueryExpression (lt, new Linq.Cast (type, (Expression)$5));
+         }
+       ;
+       
+from_clause
+       : FROM IDENTIFIER IN expression
+         {
+               LocatedToken lt = (LocatedToken) $2;
+               
+               current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
+                       lt.Value, lt.Location);
+                       
+               $$ = new Linq.SelectMany (lt, (Expression)$4);                  
+         }
+       | FROM type IDENTIFIER IN expression
+         {
+               LocatedToken lt = (LocatedToken) $3;
+
+               Expression type = (Expression)$2;
+               current_block.AddVariable (type, lt.Value, lt.Location);
+               $$ = new Linq.SelectMany (lt, new Linq.Cast (type, (Expression)$5));
+         }
+       ;       
+
+query_body
+       : opt_query_body_clauses select_or_group_clause opt_query_continuation
+         {
+               Linq.AQueryClause head = (Linq.AQueryClause)$2;
+               
+               if ($3 != null)
+                       head.Next = (Linq.AQueryClause)$3;
+                               
+               if ($1 != null) {
+                       Linq.AQueryClause clause = (Linq.AQueryClause)$1;
+                       clause.Tail.Next = head;
+                       head = clause;
+               }
+               
+               $$ = head;
+         }
+       ;
+       
+select_or_group_clause
+       : SELECT expression
+         {
+               $$ = new Linq.Select ((Expression)$2, GetLocation ($1));
+         }
+       | GROUP expression BY expression
+         {
+           $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation ($1));
+         }
+       ;
+       
+opt_query_body_clauses
+       : /* empty */
+       | query_body_clauses
+       ;
+       
+query_body_clauses
+       : query_body_clause
+       | query_body_clauses query_body_clause
+         {
+               ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
+               $$ = $1;
+         }
+       ;
+       
+query_body_clause
+       : from_clause
+       | let_clause
+       | where_clause
+       | join_clause
+       | orderby_clause
+       ;
+       
+let_clause
+       : LET IDENTIFIER ASSIGN expression
+         {
+               LocatedToken lt = (LocatedToken) $2;
+               current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
+                       lt.Value, lt.Location);   
+               $$ = new Linq.Let (lt, (Expression)$4, GetLocation ($1));
+         }
+       ;
+
+where_clause
+       : WHERE boolean_expression
+         {
+               $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
+         }
+       ;
+       
+join_clause
+       : JOIN IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
+         {
+               Location loc = GetLocation ($1);
+               LocatedToken lt = (LocatedToken) $2;
+               current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
+                       lt.Value, lt.Location);
+               
+               if ($9 == null) {
+                       $$ = new Linq.Join (lt, (Expression)$4, (Expression)$6,
+                               (Expression)$8, loc);
+               } else {
+                       LocatedToken lt_into = (LocatedToken) $9;
+                       $$ = new Linq.GroupJoin (lt, (Expression)$4, (Expression)$6,
+                               (Expression)$8, lt_into, loc);
+               }
+         }
+       | JOIN type IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
+         {
+               Location loc = GetLocation ($1);
+               LocatedToken lt = (LocatedToken) $3;
+               current_block.AddVariable ((Expression)$2, lt.Value, lt.Location);
+               
+               Linq.Cast cast = new Linq.Cast ((Expression)$2, (Expression)$5);
+               if ($10 == null) {
+                       $$ = new Linq.Join (lt, cast, (Expression)$7,
+                               (Expression)$9, loc);
+               } else {
+                       LocatedToken lt_into = (LocatedToken) $10;
+                       $$ = new Linq.GroupJoin (lt, cast, (Expression)$7,
+                               (Expression)$9, lt_into, loc);
+               }
+         }
+       ;
+       
+opt_join_into
+       : /* empty */
+       | INTO IDENTIFIER
+         {
+               $$ = $2;
+         }
+       ;
+       
+orderby_clause
+       : ORDERBY orderings
+         {
+               $$ = $2;
+         }
+       ;
+       
+orderings
+       : order_by
+       | order_by COMMA orderings_then_by
+         {
+               ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$3;
+               $$ = $1;
+         }
+       ;
+       
+orderings_then_by
+       : then_by
+         {
+               $$ = $1;
+         }
+       | orderings_then_by COMMA then_by
+         {
+               ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
+               $$ = $1;
+         }
+       ;       
+       
+order_by
+       : expression
+         {
+               $$ = new Linq.OrderByAscending ((Expression)$1);        
+         }
+       | expression ASCENDING
+         {
+               $$ = new Linq.OrderByAscending ((Expression)$1);        
+         }
+       | expression DESCENDING
+         {
+               $$ = new Linq.OrderByDescending ((Expression)$1);       
+         }
+       ;
+
+then_by
+       : expression
+         {
+               $$ = new Linq.ThenByAscending ((Expression)$1); 
+         }
+       | expression ASCENDING
+         {
+               $$ = new Linq.ThenByAscending ((Expression)$1); 
+         }
+       | expression DESCENDING
+         {
+               $$ = new Linq.ThenByDescending ((Expression)$1);        
+         }     
        ;
 
+
+opt_query_continuation
+       : /* empty */
+       | INTO IDENTIFIER
+         {
+               // query continuation block is not linked with query block but with block
+               // before. This means each query can use same range variable names for
+               // different identifiers.
+
+               current_block.SetEndLocation (GetLocation ($1));
+               current_block = current_block.Parent;
+               current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
+               
+               LocatedToken lt = (LocatedToken) $2;
+               current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
+                       lt.Value, lt.Location);
+         }
+         query_body
+         {
+               $$ = new Linq.QueryExpression ((LocatedToken) $2,
+                       (Linq.AQueryClause)$4);
+         }
+       ;
+       
 %%
 
 // <summary>
@@ -4768,9 +5651,6 @@ public class VariableDeclaration {
        {
                this.identifier = lt.Value;
                if (eoai is ArrayList) {
-                       if (CSharpParser.current_array_type == null)
-                               Report.Error (622, lt.Location,
-                                       "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
                        this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
                } else {
                        this.expression_or_array_initializer = (Expression)eoai;
@@ -4788,12 +5668,12 @@ public class VariableDeclaration {
 //   A class used to hold info about an indexer declarator
 // </summary>
 public class IndexerDeclaration {
-       public Expression type;
+       public FullNamedExpression type;
        public MemberName interface_type;
        public Parameters param_list;
        public Location location;
 
-       public IndexerDeclaration (Expression type, MemberName interface_type,
+       public IndexerDeclaration (FullNamedExpression type, MemberName interface_type,
                                   Parameters param_list, Location loc)
        {
                this.type = type;
@@ -4810,11 +5690,9 @@ public class SimpleAnonymousHost : IAnonymousHost {
        public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
 
        bool yields;
-       ArrayList anonymous_methods;
 
        public static SimpleAnonymousHost GetSimple () {
                Simple.yields = false;
-               Simple.anonymous_methods = null;
                return Simple;
        }
 
@@ -4822,47 +5700,28 @@ public class SimpleAnonymousHost : IAnonymousHost {
        {
                yields = true;
        }
-
-       public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
-       {
-               if (anonymous_methods == null)
-                       anonymous_methods = new ArrayList ();
-               anonymous_methods.Add (anonymous);
-       }
-
+       
        public void Propagate (IAnonymousHost real_host)
        {
                if (yields)
                        real_host.SetYields ();
-               if (anonymous_methods != null) {
-                       foreach (AnonymousMethodExpression ame in anonymous_methods)
-                               real_host.AddAnonymousMethod (ame);
-               }
        }
 }
 
 // <summary>
 //  A class used to hold info about an operator declarator
 // </summary>
-public class OperatorDeclaration {
-       public Operator.OpType optype;
-       public Expression ret_type, arg1type, arg2type;
-       public string arg1name, arg2name;
-       public Location location;
+struct OperatorDeclaration {
+       public readonly Operator.OpType optype;
+       public readonly FullNamedExpression ret_type;
+       public readonly Location location;
 
-       public OperatorDeclaration (Operator.OpType op, Expression ret_type, 
-                                   Expression arg1type, string arg1name,
-                                   Expression arg2type, string arg2name, Location location)
+       public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
        {
                optype = op;
                this.ret_type = ret_type;
-               this.arg1type = arg1type;
-               this.arg1name = arg1name;
-               this.arg2type = arg2type;
-               this.arg2name = arg2name;
                this.location = location;
        }
-
 }
 
 void Error_ExpectingTypeName (Expression expr)
@@ -4874,9 +5733,10 @@ void Error_ExpectingTypeName (Expression expr)
        }
 }
 
-public static void Error_ParameterModifierNotValid (Location loc)
+static void Error_ParameterModifierNotValid (string modifier, Location loc)
 {
-       Report.Error (631, loc, "The modifiers `ref' and `out' are not valid in this context");
+       Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
+                                     modifier);
 }
 
 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
@@ -4885,12 +5745,17 @@ static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier m
                Parameter.GetModifierSignature (mod));
 }
 
-void push_current_class (TypeContainer tc, bool is_interface, object partial_token)
+static void Error_TypeExpected (Location loc)
+{
+       Report.Error (1031, loc, "Type expected");
+}
+
+void push_current_class (TypeContainer tc, object partial_token)
 {
        if (partial_token != null)
-               current_container = current_container.AddPartial (tc, is_interface);
+               current_container = current_container.AddPartial (tc);
        else
-               current_container = current_container.AddTypeContainer (tc, is_interface);
+               current_container = current_container.AddTypeContainer (tc);
        current_class = tc;
 }
 
@@ -4944,7 +5809,7 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
        // int j = 1;  int k = j + 1;
        //
        if (current_block.Used)
-               implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
+               implicit_block = new Block (current_block, loc, Location.Null);
        else
                implicit_block = current_block;
 
@@ -4969,7 +5834,7 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
                LocalVariableReference var;
                var = new LocalVariableReference (implicit_block, decl.identifier, loc);
 
-               assign = new Assign (var, expr, decl.Location);
+               assign = new SimpleAssign (var, expr, decl.Location);
 
                implicit_block.AddStatement (new StatementExpression (assign));
        }
@@ -4982,7 +5847,7 @@ Block declare_local_constants (Expression type, ArrayList declarators)
        Block implicit_block;
 
        if (current_block.Used)
-               implicit_block = new Block (current_block, Block.Flags.Implicit);
+               implicit_block = new Block (current_block);
        else
                implicit_block = current_block;
 
@@ -4996,16 +5861,16 @@ Block declare_local_constants (Expression type, ArrayList declarators)
 string CheckAttributeTarget (string a, Location l)
 {
        switch (a) {
-               case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
+       case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
                        return a;
        }
-       
+
        Report.Warning (658, 1, l,
                 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
        return string.Empty;
 }
 
-void CheckUnaryOperator (Operator.OpType op, Location l)
+static bool IsUnaryOperator (Operator.OpType op)
 {
        switch (op) {
                
@@ -5015,45 +5880,11 @@ void CheckUnaryOperator (Operator.OpType op, Location l)
        case Operator.OpType.Decrement:
        case Operator.OpType.True: 
        case Operator.OpType.False: 
-       case Operator.OpType.Addition: 
-       case Operator.OpType.Subtraction:
-               
-               break;
-               
-       default :
-               Report.Error (1019, l, "Overloadable unary operator expected"); 
-               break;
-               
-       }
-}
-
-void CheckBinaryOperator (Operator.OpType op, Location l)
-{
-       switch (op) {
-               
-       case Operator.OpType.Addition: 
-       case Operator.OpType.Subtraction: 
-       case Operator.OpType.Multiply:
-       case Operator.OpType.Division:
-       case Operator.OpType.Modulus: 
-       case Operator.OpType.BitwiseAnd: 
-       case Operator.OpType.BitwiseOr:
-       case Operator.OpType.ExclusiveOr: 
-       case Operator.OpType.LeftShift: 
-       case Operator.OpType.RightShift:
-       case Operator.OpType.Equality: 
-       case Operator.OpType.Inequality:
-       case Operator.OpType.GreaterThan: 
-       case Operator.OpType.LessThan: 
-       case Operator.OpType.GreaterThanOrEqual:
-       case Operator.OpType.LessThanOrEqual:
-               break;
-               
-       default :
-               Report.Error (1020, l, "Overloadable binary operator expected");
-               break;
+       case Operator.OpType.UnaryPlus: 
+       case Operator.OpType.UnaryNegation:
+               return true;
        }
-       
+       return false;
 }
 
 void syntax_error (Location l, string msg)
@@ -5079,9 +5910,8 @@ static CSharpParser ()
        oob_stack = new Stack ();
 }
 
-public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
+public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ArrayList defines)
 {
-       this.name = file.Name;
        this.file = file;
        current_namespace = new NamespaceEntry (null, file, null);
        current_class = current_namespace.SlaveDeclSpace;
@@ -5101,7 +5931,7 @@ public void parse ()
                Tokenizer tokenizer = lexer as Tokenizer;
                tokenizer.cleanup ();
        } catch (Exception e){
-               // 
+               //
                // Removed for production use, use parser verbose to get the output.
                //
                // Console.WriteLine (e);
@@ -5149,39 +5979,22 @@ Location GetLocation (object obj)
        return lexer.Location;
 }
 
-static GenericMethod current_generic_method = null;
-
 void start_block (Location loc)
 {
-       if (parsing_anonymous_method) {
-               top_current_block = new ToplevelBlock (
-                       current_block, current_local_parameters, current_generic_method, loc);
-               if (current_block != null)
-                       current_block.AddAnonymousChild ((ToplevelBlock) top_current_block);
-               current_block = top_current_block;
+       if (current_block == null || parsing_anonymous_method) {
+               current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
                parsing_anonymous_method = false;
-       } else if (current_block == null) {
-               current_block = new ToplevelBlock (
-                       (ToplevelBlock) top_current_block, current_local_parameters,
-                       current_generic_method, loc);
-               top_current_block = current_block;
        } else {
-               current_block = new Block (current_block, loc, Location.Null);
+               current_block = new ExplicitBlock (current_block, loc, Location.Null);
        }
 }
 
 Block
 end_block (Location loc)
 {
-       Block retval;
-
-       while (current_block.Implicit)
-               current_block = current_block.Parent;
-       retval = current_block;
-       current_block.SetEndLocation (loc);
-       current_block = current_block.Parent;
-       if (current_block == null)
-               top_current_block = null;
+       Block retval = current_block.Explicit;
+       retval.SetEndLocation (loc);
+       current_block = retval.Parent;
        return retval;
 }
 
@@ -5193,18 +6006,11 @@ start_anonymous (bool lambda, Parameters parameters, Location loc)
 
        current_local_parameters = parameters;
 
-       // Force the next block to be created as a ToplevelBlock
-       oob_stack.Push (current_block);
-       oob_stack.Push (top_current_block);
-
        current_anonymous_method = lambda 
-               ? new LambdaExpression (
-                       current_anonymous_method, current_generic_method, current_container,
-                       parameters, (ToplevelBlock) top_current_block, loc) 
-               : new AnonymousMethodExpression (
-                       current_anonymous_method, current_generic_method, current_container,
-                       parameters, (ToplevelBlock) top_current_block, loc);
+               ? new LambdaExpression (current_container, parameters, loc) 
+               : new AnonymousMethodExpression (current_container, parameters, loc);
 
+       // Force the next block to be created as a ToplevelBlock
        parsing_anonymous_method = true;
 }
 
@@ -5212,24 +6018,15 @@ start_anonymous (bool lambda, Parameters parameters, Location loc)
  * Completes the anonymous method processing, if lambda_expr is null, this
  * means that we have a Statement instead of an Expression embedded 
  */
-AnonymousMethodExpression 
-end_anonymous (ToplevelBlock anon_block, Location loc)
+AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
 {
        AnonymousMethodExpression retval;
 
-       top_current_block = (Block) oob_stack.Pop ();
-       current_block = (Block) oob_stack.Pop ();
-
        if (RootContext.Version == LanguageVersion.ISO_1){
-               Report.FeatureIsNotISO1 (loc, "anonymous methods");
+               Report.FeatureIsNotAvailable (loc, "anonymous methods");
                retval = null;
        } else  {
-               anon_block.Parent = current_block;
-
                current_anonymous_method.Block = anon_block;
-               if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
-                       anonymous_host.AddAnonymousMethod (current_anonymous_method);
-
                retval = current_anonymous_method;
        }