* tree.cs (Tree.RecordDecl): Remove.
[mono.git] / mcs / mcs / cs-parser.jay
index 72d8ba14c04d3b8ff3b9e5f56a2e4b13d852d416..8b948ae19b18b4577579f15eb9779a914b8c100f 100644 (file)
@@ -57,6 +57,11 @@ namespace Mono.CSharp
                Expression implicit_value_parameter_type;
                Parameters indexer_parameters;
 
+               /// <summary>
+               ///   Hack to help create non-typed array initializer
+               /// </summary>
+               public static Expression current_array_type;
+
                /// <summary>
                ///   Used to determine if we are parsing the get/set pair
                ///   of an indexer or a property
@@ -93,7 +98,7 @@ namespace Mono.CSharp
                /// Current attribute target
                string current_attr_target;
                
-               /// assembly and module attribute definition is enabled
+               /// assembly and module attribute definitions are enabled
                bool global_attrs_enabled = true;
 
                bool has_get, has_set;
@@ -226,6 +231,7 @@ namespace Mono.CSharp
 %token INTERR         "?"
 
 /* C# multi-character operators. */
+%token DOUBLE_COLON          "::"
 %token OP_INC                 "++"
 %token OP_DEC                 "--"
 %token OP_SHIFT_LEFT          "<<"
@@ -293,13 +299,13 @@ compilation_unit
        
 opt_EOF
        : /* empty */
-       {
+         {
                Lexer.check_incorrect_doc_comment ();
-       }
+         }
        | EOF
-       {
+         {
                Lexer.check_incorrect_doc_comment ();
-       }
+         }
        ;
 
 outer_declarations
@@ -308,10 +314,31 @@ outer_declarations
         ;
  
 outer_declaration
-        : using_directive
+       : extern_alias_directive
+        | using_directive 
         | namespace_member_declaration
         ;
-  
+
+extern_alias_directives
+       : extern_alias_directive
+       | extern_alias_directives extern_alias_directive;
+
+extern_alias_directive
+       : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
+         {
+               LocatedToken lt = (LocatedToken) $2;
+               string s = lt.Value;
+               if (s != "alias"){
+                       Report.Error (1003, lt.Location, "'alias' expected");
+               } else if (RootContext.Version == LanguageVersion.ISO_1) {
+                       Report.FeatureIsNotStandardized (lt.Location, "external alias");
+               } else {
+                       lt = (LocatedToken) $3; 
+                       current_namespace.UsingExternalAlias (lt.Value, lt.Location);
+               }
+         }
+       ;
 using_directives
        : using_directive 
        | using_directives using_directive
@@ -319,34 +346,33 @@ using_directives
 
 using_directive
        : using_alias_directive
-       {
+         {
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
-       }
+         }
        | using_namespace_directive
-       {
+         {
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
-       }
+         }
        ;
 
 using_alias_directive
        : USING IDENTIFIER ASSIGN 
          namespace_or_type_name SEMICOLON
          {
-               MemberName name = (MemberName) $4;
-               current_namespace.UsingAlias ((string) $2, name.GetTypeExpression (lexer.Location), lexer.Location);
+               LocatedToken lt = (LocatedToken) $2;
+               current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
          }
        | USING error {
-               CheckIdentifierToken (yyToken);
+               CheckIdentifierToken (yyToken, GetLocation ($2));
          }
        ;
 
 using_namespace_directive
        : USING namespace_name SEMICOLON 
          {
-               MemberName ns_name = (MemberName) $2;
-               current_namespace.Using (ns_name.GetTypeExpression (lexer.Location), lexer.Location);
+               current_namespace.Using ((MemberName) $2, (Location) $1);
           }
        ;
 
@@ -357,21 +383,15 @@ using_namespace_directive
 // 
 namespace_declaration
        : opt_attributes NAMESPACE namespace_or_type_name
-       {
-               if ($1 != null) {
-                       Report.Error(1671, Lexer.Location, "A namespace declaration cannot have modifiers or attributes");
-               }
-
+         {
                MemberName name = (MemberName) $3;
 
-               if ((current_namespace.Parent != null) && (name.Left != null)) {
-                       Report.Error (134, lexer.Location,
-                                     "Cannot use qualified namespace names in nested " +
-                                     "namespace declarations");
+               if ($1 != null) {
+                       Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
                }
 
                current_namespace = new NamespaceEntry (
-                       current_namespace, file, name.GetName (), lexer.Location);
+                       current_namespace, file, name.GetName ());
          } 
          namespace_body opt_semicolon
          { 
@@ -399,11 +419,10 @@ namespace_body
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
+         opt_extern_alias_directives
          opt_using_directives
          opt_namespace_member_declarations
          CLOSE_BRACE
-         {
-         }
        ;
 
 opt_using_directives
@@ -411,6 +430,11 @@ opt_using_directives
        | using_directives
        ;
 
+opt_extern_alias_directives
+       : /* empty */
+       | extern_alias_directives
+       ;
+
 opt_namespace_member_declarations
        : /* empty */
        | namespace_member_declarations
@@ -424,25 +448,13 @@ namespace_member_declarations
 namespace_member_declaration
        : type_declaration
          {
-               string name = "";
-               int mod_flags;
-
-               if ($1 is Class){
-                       Class c = (Class) $1;
-                       mod_flags = c.ModFlags;
-                       name = c.Name;
-               } else if ($1 is Struct){
-                       Struct s = (Struct) $1;
-                       mod_flags = s.ModFlags;
-                       name = s.Name;
-               } else
-                       break;
+               if ($1 != null) {
+                       DeclSpace ds = (DeclSpace)$1;
 
-               if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
-                       Report.Error (
-                               1527, lexer.Location, 
-                               "Namespace elements cant be explicitly " +
-                               "declared private or protected in `" + name + "'");
+                       if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
+                               Report.Error (1527, ds.Location, 
+                               "Namespace elements cannot be explicitly declared as private, protected or protected internal");
+                       }
                }
                current_namespace.DeclarationFound = true;
          }
@@ -451,10 +463,10 @@ namespace_member_declaration
          }
 
        | field_declaration {
-               Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
+               Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
          }
        | method_declaration {
-               Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
+               Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
          }
        ;
 
@@ -469,7 +481,7 @@ type_declaration
 //
 //     | error {
 //             Console.WriteLine ("Token=" + yyToken);
-//             Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
+//             Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
 //       }
        ;
 
@@ -509,7 +521,7 @@ attribute_sections
                        if (current_attr_target == "module") {
                                CodeGen.Module.AddAttributes (sect);
                                $$ = null;
-                       } else if (current_attr_target == "assembly") {
+                       } else if (current_attr_target != null && current_attr_target.Length > 0) {
                                CodeGen.Assembly.AddAttributes (sect);
                                $$ = null;
                        } else {
@@ -578,8 +590,9 @@ attribute_target_specifier
 attribute_target
        : IDENTIFIER
          {
-               CheckAttributeTarget ((string) $1);
-               $$ = $1;
+               LocatedToken lt = (LocatedToken) $1;
+               CheckAttributeTarget (lt.Value, lt.Location);
+               $$ = lt.Value; // Location won't be required anymore.
          }
         | EVENT  { $$ = "event"; }       
         | RETURN { $$ = "return"; }
@@ -604,24 +617,21 @@ attribute_list
        ;
 
 attribute
-       : attribute_name
-         {
-               $$ = lexer.Location;
-         }
-         opt_attribute_arguments
+       : attribute_name opt_attribute_arguments
          {
-                 Location loc = (Location) $2;
                MemberName mname = (MemberName) $1;
+               object[] arguments = (object[]) $2;
                MemberName left = mname.Left;
                string identifier = mname.Name;
 
-               Expression left_expr = left == null ? null : left.GetTypeExpression (loc);
+               Expression left_expr = left == null ? null : left.GetTypeExpression ();
 
                if (current_attr_target == "assembly" || current_attr_target == "module")
-                       $$ = new GlobalAttribute (current_container, current_attr_target,
-                                                 left_expr, identifier, (ArrayList) $3, loc);
+                       // FIXME: supply "nameEscaped" parameter here.
+                       $$ = new GlobalAttribute (current_namespace, current_attr_target,
+                                                 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
                else
-                       $$ = new Attribute (current_attr_target, left_expr, identifier, (ArrayList) $3, loc);
+                       $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
          }
        ;
 
@@ -644,29 +654,18 @@ attribute_arguments
                if ($1 == null)
                        $$ = null;
                else {
-                       ArrayList args = new ArrayList (4);
-                       args.Add ($1);
-               
-                       $$ = args;
+                       $$ = new object [] { $1, null };
                }
          }
-        | positional_argument_list COMMA named_argument_list
+    | positional_argument_list COMMA named_argument_list
          {
-               ArrayList args = new ArrayList (4);
-               args.Add ($1);
-               args.Add ($3);
-
-               $$ = args;
+               $$ = new object[] { $1, $3 };
          }
-        | named_argument_list
+    | named_argument_list
          {
-               ArrayList args = new ArrayList (4);
-               args.Add (null);
-               args.Add ($1);
-               
-               $$ = args;
+               $$ = new object [] { null, $1 };
          }
-        ;
+    ;
 
 
 opt_positional_argument_list
@@ -708,7 +707,7 @@ named_argument_list
          }
          | named_argument_list COMMA expression
            {
-                 Report.Error (1016, lexer.Location, "Named attribute argument expected");
+                 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
                  $$ = null;
                }
         ;
@@ -716,8 +715,9 @@ named_argument_list
 named_argument
        : IDENTIFIER ASSIGN expression
          {
+               // FIXME: keep location
                $$ = new DictionaryEntry (
-                       (string) $1
+                       ((LocatedToken) $1).Value
                        new Argument ((Expression) $3, Argument.AType.Expression));
          }
        ;
@@ -758,22 +758,15 @@ struct_declaration
          STRUCT member_name
          { 
                MemberName name = MakeName ((MemberName) $5);
-               bool partial = (bool) $3;
-
-               if (partial) {
-                       ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, (int) $2,
-                               (Attributes) $1, Kind.Struct, lexer.Location);
+               current_class = new Struct (
+                       current_namespace, current_class, name, (int) $2,
+                       (Attributes) $1);
 
-                       current_container = part.PartialContainer;
-                       current_class = part;
+               if ($3 != null) {
+                       current_container = current_container.AddPartial (current_class);
                } else {
-                       current_class = new Struct (
-                               current_namespace, current_container, name, (int) $2,
-                               (Attributes) $1, lexer.Location);
-
+                       current_container.AddClassOrStruct (current_class);
                        current_container = current_class;
-                       RootContext.Tree.RecordDecl (name.GetName (true), current_class);
                }
          }
          opt_class_base
@@ -782,9 +775,7 @@ struct_declaration
                        current_class.Bases = (ArrayList) $7;
 
                if (RootContext.Documentation != null)
-                       current_class.DocComment = Lexer.consume_doc_comment ();
-
-               current_class.Register ();
+                       current_container.DocComment = Lexer.consume_doc_comment ();
          }
          struct_body
          {
@@ -793,13 +784,10 @@ struct_declaration
          }
          opt_semicolon
          {
-               $$ = current_class;
-
-               current_container = current_container.Parent;
-               current_class = current_container;
+               $$ = pop_current_class ();
          }
        | opt_attributes opt_modifiers opt_partial STRUCT error {
-               CheckIdentifierToken (yyToken);
+               CheckIdentifierToken (yyToken, GetLocation ($5));
          }
        ;
 
@@ -852,7 +840,7 @@ constant_declaration
                foreach (VariableDeclaration constant in (ArrayList) $5){
                        Location l = constant.Location;
                        if ((modflags & Modifiers.STATIC) != 0) {
-                               Report.Error (504, l, "The constant '{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
+                               Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
                                continue;
                        }
 
@@ -890,12 +878,12 @@ constant_declarators
 constant_declarator
        : IDENTIFIER ASSIGN constant_expression
          {
-               $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
+               $$ = new VariableDeclaration ((LocatedToken) $1, $3);
          }
        | IDENTIFIER
          {
                // A const field requires a value to be provided
-               Report.Error (145, lexer.Location, "A const field requires a value to be provided");
+               Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
                $$ = null;
          }
        ;
@@ -910,16 +898,20 @@ field_declaration
                Expression type = (Expression) $3;
                int mod = (int) $2;
 
+               current_array_type = null;
+
                foreach (VariableDeclaration var in (ArrayList) $4){
                        Field field = new Field (current_class, type, mod, var.identifier, 
-                                                var.expression_or_array_initializer, 
                                                 (Attributes) $1, var.Location);
 
+                       field.Initializer = var.expression_or_array_initializer;
+
                        if (RootContext.Documentation != null) {
                                field.DocComment = Lexer.consume_doc_comment ();
                                Lexer.doc_state = XmlCommentState.Allowed;
                        }
                        current_container.AddField (field);
+                       $$ = field; // FIXME: might be better if it points to the top item
                }
          }
        | opt_attributes
@@ -932,6 +924,8 @@ field_declaration
                        Expression type = (Expression) $4;
                        int mod = (int) $2;
 
+                       current_array_type = null;
+
                        foreach (VariableDeclaration var in (ArrayList) $5) {
                                FixedField field = new FixedField (current_class, type, mod, var.identifier,
                                        (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
@@ -941,6 +935,7 @@ field_declaration
                                        Lexer.doc_state = XmlCommentState.Allowed;
                                }
                                current_container.AddField (field);
+                               $$ = field; // FIXME: might be better if it points to the top item
                        }
          }
        | opt_attributes
@@ -948,37 +943,44 @@ field_declaration
          VOID  
          variable_declarators
          SEMICOLON {
-               Report.Error (670, lexer.Location, "void type is not allowed for fields");
+               current_array_type = null;
+               Report.Error (670, (Location) $3, "Fields cannot have void type");
          }
        ;
 
 fixed_variable_declarators
        : fixed_variable_declarator
-               {
-                       ArrayList decl = new ArrayList (2);
-                       decl.Add ($1);
-                       $$ = decl;
-               }
+         {
+               ArrayList decl = new ArrayList (2);
+               decl.Add ($1);
+               $$ = decl;
+         }
        | fixed_variable_declarators COMMA fixed_variable_declarator
-               {
-                       ArrayList decls = (ArrayList) $1;
-                       decls.Add ($3);
-                       $$ = $1;
-               }
+         {
+               ArrayList decls = (ArrayList) $1;
+               decls.Add ($3);
+               $$ = $1;
+         }
        ;
 
 fixed_variable_declarator
        : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
-               {
-                       $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
-               }
+         {
+               $$ = new VariableDeclaration ((LocatedToken) $1, $3);
+         }
+       | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
+         {
+               Report.Error (443, lexer.Location, "Value or constant expected");
+               $$ = new VariableDeclaration ((LocatedToken) $1, null);
+         }
        ;
 
 variable_declarators
        : variable_declarator 
          {
                ArrayList decl = new ArrayList (4);
-               decl.Add ($1);
+               if ($1 != null)
+                       decl.Add ($1);
                $$ = decl;
          }
        | variable_declarators COMMA variable_declarator
@@ -992,16 +994,17 @@ variable_declarators
 variable_declarator
        : IDENTIFIER ASSIGN variable_initializer
          {
-               $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
+               $$ = new VariableDeclaration ((LocatedToken) $1, $3);
          }
        | IDENTIFIER
          {
-               $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
+               $$ = new VariableDeclaration ((LocatedToken) $1, null);
          }
        | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
          {
-               Report.Error (650, lexer.Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
-                       "To declare a fixed buffer field, use the fixed keyword before the field type");
+               Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
+                       "To declare a fixed size buffer field, use the fixed keyword before the field type");
+               $$ = null;
          }
        ;
 
@@ -1016,11 +1019,15 @@ variable_initializer
          }
        | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
          {
-               $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
+               $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
+         }
+       | ARGLIST
+         {
+               $$ = new ArglistAccess ((Location) $1);
          }
        | STACKALLOC type
          {
-               Report.Error (1575, lexer.Location, "A stackalloc expression requires [] after type");
+               Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
                 $$ = null;
          }
        ;
@@ -1034,23 +1041,6 @@ method_declaration
          method_body
          {
                Method method = (Method) $1;
-               Block b = (Block) $3;
-               const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
-
-               if (b == null){
-                       if ((method.ModFlags & extern_abstract) == 0){
-                               Report.Error (
-                                       501, lexer.Location,  current_container.MakeName (method.Name) +
-                                       "must declare a body because it is not marked abstract or extern");
-                       }
-               } else {
-                       if ((method.ModFlags & Modifiers.EXTERN) != 0){
-                               Report.Error (
-                                       179, lexer.Location, current_container.MakeName (method.Name) +
-                                       " is declared extern, but has a body");
-                       }
-               }
-
                method.Block = (ToplevelBlock) $3;
                current_container.AddMethod (method);
 
@@ -1071,9 +1061,9 @@ opt_error_modifier
 
                while (m != 0){
                        if ((i & m) != 0){
-                               Report.Error (
-                                       1585, lexer.Location, "Member modifier `" + 
-                                       Modifiers.Name (i) + "' must precede member type and name");
+                               Report.Error (1585, lexer.Location,
+                                       "Member modifier `{0}' must precede the member type and name",
+                                       Modifiers.Name (i));
                        }
                        m &= ~i;
                        i = i << 1;
@@ -1090,8 +1080,7 @@ method_header
                MemberName name = (MemberName) $4;
 
                Method method = new Method (current_class, (Expression) $3, (int) $2,
-                                           false, name,  (Parameters) $6, (Attributes) $1,
-                                           lexer.Location);
+                                           false, name,  (Parameters) $6, (Attributes) $1);
 
                current_local_parameters = (Parameters) $6;
 
@@ -1109,7 +1098,7 @@ method_header
 
                Method method = new Method (current_class, TypeManager.system_void_expr,
                                            (int) $2, false, name, (Parameters) $6,
-                                           (Attributes) $1, lexer.Location);
+                                           (Attributes) $1);
 
                current_local_parameters = (Parameters) $6;
 
@@ -1123,21 +1112,19 @@ method_header
          type 
          modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
-               Report.Error (1585, lexer.Location, 
-                       String.Format ("Modifier {0} should appear before type", 
-                               Modifiers.Name ((int) $4)));
-               MemberName name = (MemberName) $4;
+               MemberName name = (MemberName) $5;
+               Report.Error (1585, name.Location, 
+                       "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
 
                Method method = new Method (current_class, TypeManager.system_void_expr,
-                                           0, false, name, (Parameters) $7, (Attributes) $1,
-                                           lexer.Location);
+                                           0, false, name, (Parameters) $7, (Attributes) $1);
 
                current_local_parameters = (Parameters) $7;
 
                if (RootContext.Documentation != null)
                        method.DocComment = Lexer.consume_doc_comment ();
 
-               $$ = method;
+               $$ = null;
          }
        ;
 
@@ -1159,43 +1146,57 @@ formal_parameter_list
                Parameter [] pars = new Parameter [pars_list.Count];
                pars_list.CopyTo (pars);
 
-               $$ = new Parameters (pars, null, lexer.Location); 
+               $$ = new Parameters (pars); 
          } 
        | fixed_parameters COMMA parameter_array
          {
                ArrayList pars_list = (ArrayList) $1;
+               pars_list.Add ($3);
 
                Parameter [] pars = new Parameter [pars_list.Count];
                pars_list.CopyTo (pars);
 
-               $$ = new Parameters (pars, (Parameter) $3, lexer.Location); 
+               $$ = new Parameters (pars); 
          }
        | fixed_parameters COMMA ARGLIST
          {
                ArrayList pars_list = (ArrayList) $1;
+               //pars_list.Add (new ArglistParameter (GetLocation ($3)));
 
                Parameter [] pars = new Parameter [pars_list.Count];
                pars_list.CopyTo (pars);
 
-               $$ = new Parameters (pars, true, lexer.Location);
+               $$ = new Parameters (pars, true);
+         }
+       | parameter_array COMMA error
+         {
+               if ($1 != null)
+                       Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
+               $$ = null;
          }
-       | parameter_array COMMA fixed_parameters
+       | fixed_parameters COMMA parameter_array COMMA error
          {
-               Report.Error (231, lexer.Location, "A params parameter must be the last parameter in a formal parameter list");
+               if ($3 != null)
+                       Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
+               $$ = null;
+         }
+       | ARGLIST COMMA error
+         {
+               Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
                $$ = null;
          }
-       | ARGLIST COMMA fixed_parameters
+       | fixed_parameters COMMA ARGLIST COMMA error 
          {
-               Report.Error (257, lexer.Location, "An __arglist parameter must be the last parameter in a formal parameter list");
+               Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
                $$ = null;
          }
        | parameter_array 
          {
-               $$ = new Parameters (null, (Parameter) $1, lexer.Location);
+               $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
          }
        | ARGLIST
          {
-               $$ = new Parameters (null, true, lexer.Location);
+               $$ = new Parameters (new Parameter[0], true);
          }
        ;
 
@@ -1222,20 +1223,30 @@ fixed_parameter
          type
          IDENTIFIER
          {
-               $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
+               LocatedToken lt = (LocatedToken) $4;
+               $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
+         }
+       | opt_attributes
+         opt_parameter_modifier
+         type
+         IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
+         {
+               LocatedToken lt = (LocatedToken) $4;
+               Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
+               $$ = null;
          }
        | opt_attributes
          opt_parameter_modifier
          type
          {
-               Report.Error (1001, lexer.Location, "Identifier expected");
+               Report.Error (1001, GetLocation ($3), "Identifier expected");
                $$ = null;
          }
        | opt_attributes
          opt_parameter_modifier
          type
          error {
-               CheckIdentifierToken (yyToken);
+               CheckIdentifierToken (yyToken, GetLocation ($4));
                $$ = null;
          }
        | opt_attributes
@@ -1245,7 +1256,8 @@ fixed_parameter
          ASSIGN
          constant_expression
           {
-                Report.Error (241, lexer.Location, "Default parameter specifiers are not permitted");
+               LocatedToken lt = (LocatedToken) $4;
+               Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
                 $$ = null;
           }
        ;
@@ -1256,23 +1268,24 @@ opt_parameter_modifier
        ;
 
 parameter_modifier
-       : REF                   { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
-       | OUT                   { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
+       : REF                   { $$ = Parameter.Modifier.REF; }
+       | OUT                   { $$ = Parameter.Modifier.OUT; }
        ;
 
 parameter_array
        : opt_attributes PARAMS type IDENTIFIER
          { 
-               $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
+               LocatedToken lt = (LocatedToken) $4;
+               $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
                note ("type must be a single-dimension array type"); 
          }
        | opt_attributes PARAMS parameter_modifier type IDENTIFIER 
          {
-               Report.Error (1611, lexer.Location, "The params parameter cannot be declared as ref or out");
+               Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
                 $$ = null;
          }
        | opt_attributes PARAMS type error {
-               CheckIdentifierToken (yyToken);
+               CheckIdentifierToken (yyToken, GetLocation ($4));
                $$ = null;
          }
        ;
@@ -1291,10 +1304,6 @@ property_declaration
                implicit_value_parameter_type = (Expression) $3;
 
                lexer.PropertyParsing = true;
-
-               $$ = lexer.Location;
-
-               iterator_container = SimpleIteratorContainer.GetSimple ();
          }
          accessor_declarations 
          {
@@ -1311,17 +1320,13 @@ property_declaration
                Accessor get_block = (Accessor) pair.First;
                Accessor set_block = (Accessor) pair.Second;
 
-               Location loc = (Location) $7;
                MemberName name = (MemberName) $4;
 
-               prop = new Property (current_class, (Expression) $3, (int) $2, false,
-                                    name, (Attributes) $1, get_block, set_block, loc);
-               if (SimpleIteratorContainer.Simple.Yields)
-                       prop.SetYields ();
+               prop = new Property (current_class, (Expression) $3, (int) $2,
+                       false, name, (Attributes) $1, get_block, set_block);
                
                current_container.AddProperty (prop);
                implicit_value_parameter_type = null;
-               iterator_container = null;
 
                if (RootContext.Documentation != null)
                        prop.DocComment = ConsumeStoredComment ();
@@ -1352,7 +1357,7 @@ accessor_declarations
         }
        | error
          {
-               Report.Error (1014, lexer.Location, "A get or set accessor expected");
+               Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
                $$ = null;
          }
        ;
@@ -1367,21 +1372,30 @@ get_accessor_declaration
                else 
                        current_local_parameters = indexer_parameters;
                lexer.PropertyParsing = false;
+
+               iterator_container = SimpleIteratorContainer.GetSimple ();
          }
           accessor_body
          {
                if (has_get) {
-                       Report.Error (1007, lexer.Location, "Property accessor already defined");
+                       Report.Error (1007, (Location) $3, "Property accessor already defined");
                        break;
                }
-               $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
+               Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
                has_get = true;
                current_local_parameters = null;
                lexer.PropertyParsing = true;
 
+               if (SimpleIteratorContainer.Simple.Yields)
+                       accessor.SetYields ();
+
+               iterator_container = null;
+
                if (RootContext.Documentation != null)
                        if (Lexer.doc_state == XmlCommentState.Error)
                                Lexer.doc_state = XmlCommentState.NotAllowed;
+
+               $$ = accessor;
          }
        ;
 
@@ -1391,12 +1405,12 @@ set_accessor_declaration
                Parameter [] args;
                Parameter implicit_value_parameter = new Parameter (
                        implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null);
+                       Parameter.Modifier.NONE, null, (Location) $3);
 
                if (parsing_indexer == false) {
                        args  = new Parameter [1];
                        args [0] = implicit_value_parameter;
-                       current_local_parameters = new Parameters (args, null, lexer.Location);
+                       current_local_parameters = new Parameters (args);
                } else {
                        Parameter [] fpars = indexer_parameters.FixedParameters;
 
@@ -1409,25 +1423,34 @@ set_accessor_declaration
                        } else 
                                args = null;
                        current_local_parameters = new Parameters (
-                               args, indexer_parameters.ArrayParameter, lexer.Location);
+                               args);
                }
                
                lexer.PropertyParsing = false;
+
+               iterator_container = SimpleIteratorContainer.GetSimple ();
          }
          accessor_body
          {
                if (has_set) {
-                       Report.Error (1007, lexer.Location, "Property accessor already defined");
+                       Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
                        break;
                }
-               $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
+               Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
                has_set = true;
                current_local_parameters = null;
                lexer.PropertyParsing = true;
 
+               if (SimpleIteratorContainer.Simple.Yields)
+                       accessor.SetYields ();
+
+               iterator_container = null;
+
                if (RootContext.Documentation != null
                        && Lexer.doc_state == XmlCommentState.Error)
                        Lexer.doc_state = XmlCommentState.NotAllowed;
+
+               $$ = accessor;
          }
        ;
 
@@ -1443,22 +1466,16 @@ interface_declaration
          INTERFACE member_name
          {
                MemberName name = MakeName ((MemberName) $5);
-               bool partial = (bool) $3;
 
-               if (partial) {
-                       ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, (int) $2,
-                               (Attributes) $1, Kind.Interface, lexer.Location);
+               current_class = new Interface (
+                       current_namespace, current_class, name, (int) $2,
+                       (Attributes) $1);
 
-                       current_container = part.PartialContainer;
-                       current_class = part;
+               if ($3 != null) {
+                       current_container = current_container.AddPartial (current_class);
                } else {
-                       current_class = new Interface (
-                               current_namespace, current_container, name, (int) $2,
-                               (Attributes) $1, lexer.Location);
-
+                       current_container.AddInterface (current_class);
                        current_container = current_class;
-                       RootContext.Tree.RecordDecl (name.GetName (true), current_class);
                }
          }
          opt_class_base
@@ -1466,11 +1483,9 @@ interface_declaration
                current_class.Bases = (ArrayList) $7;
 
                if (RootContext.Documentation != null) {
-                       current_class.DocComment = Lexer.consume_doc_comment ();
+                       current_container.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
-
-               current_class.Register ();
          }
          interface_body 
          {
@@ -1479,13 +1494,10 @@ interface_declaration
          }
          opt_semicolon 
          {
-               $$ = current_class;
-
-               current_container = current_container.Parent;
-               current_class = current_container;
+               $$ = pop_current_class ();
          }
        | opt_attributes opt_modifiers opt_partial INTERFACE error {
-               CheckIdentifierToken (yyToken);
+               CheckIdentifierToken (yyToken, GetLocation ($5));
          }
        ;
 
@@ -1514,8 +1526,8 @@ interface_member_declaration
                Method m = (Method) $1;
 
                if (m.IsExplicitImpl)
-                       Report.Error (541, lexer.Location, 
-                               "Explicit interface declaration can only be declared in a class or struct");
+                       Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
+                               m.GetSignatureForError ());
 
                current_container.AddMethod (m);
 
@@ -1530,8 +1542,8 @@ interface_member_declaration
                Property p = (Property) $1;
 
                if (p.IsExplicitImpl)
-                       Report.Error (541, lexer.Location, 
-                               "Explicit interface declaration can only be declared in a class or struct");
+                       Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
+                               p.GetSignatureForError ());
 
                current_container.AddProperty (p);
 
@@ -1544,8 +1556,8 @@ interface_member_declaration
                        Event e = (Event) $1;
 
                        if (e.IsExplicitImpl)
-                               Report.Error (541, lexer.Location, 
-                                   "Explicit interface declaration can only be declared in a class or struct");
+                       Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
+                               e.GetSignatureForError ());
                        
                        current_container.AddEvent (e);
                }
@@ -1561,8 +1573,8 @@ interface_member_declaration
                Indexer i = (Indexer) $1;
 
                if (i.IsExplicitImpl)
-                       Report.Error (541, lexer.Location, 
-                               "Explicit interface declaration can only be declared in a class or struct");
+                       Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
+                               i.GetSignatureForError ());
 
                current_container.AddIndexer (i);
 
@@ -1571,27 +1583,42 @@ interface_member_declaration
          }
        | delegate_declaration
          {
-               Report.Error (524, lexer.Location, "Interfaces can not declare delegates");
+               if ($1 != null) {
+                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
+                               ((MemberCore)$1).GetSignatureForError ());
+               }
          }
        | class_declaration
          {
-               Report.Error (524, lexer.Location, "Interfaces can not declare classes");
+               if ($1 != null) {
+                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
+                               ((MemberCore)$1).GetSignatureForError ());
+               }
          }
        | struct_declaration
          {
-               Report.Error (524, lexer.Location, "Interfaces can not declare structures");
+               if ($1 != null) {
+                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
+                               ((MemberCore)$1).GetSignatureForError ());
+               }
          }
        | enum_declaration 
          {
-               Report.Error (524, lexer.Location, "Interfaces can not declare enumerations");
+               if ($1 != null) {
+                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
+                               ((MemberCore)$1).GetSignatureForError ());
+               }
          }
        | interface_declaration 
          {
-               Report.Error (524, lexer.Location, "Interfaces can not declare interfaces");
+               if ($1 != null) {
+                       Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
+                               ((MemberCore)$1).GetSignatureForError ());
+               }
          } 
        | constant_declaration
          {
-               Report.Error (525, lexer.Location, "Interfaces cannot contain constants");
+               Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
          }
        ;
 
@@ -1599,7 +1626,7 @@ opt_new
        : opt_modifiers 
          {
                int val = (int) $1;
-               val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
+               val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
                $$ = val;
          }
        ;
@@ -1609,10 +1636,8 @@ interface_method_declaration
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          SEMICOLON
          {
-               MemberName name = (MemberName) $4;
-
                $$ = new Method (current_class, (Expression) $3, (int) $2, true,
-                                name, (Parameters) $6, (Attributes) $1, lexer.Location);
+                                (MemberName) $4, (Parameters) $6, (Attributes) $1);
                if (RootContext.Documentation != null)
                        ((Method) $$).DocComment = Lexer.consume_doc_comment ();
          }
@@ -1620,8 +1645,11 @@ interface_method_declaration
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          OPEN_BRACE opt_statement_list CLOSE_BRACE
          {
-               Report.Error (531, lexer.Location, "'{0}': interface members cannot have a definition", $4);
-               $$ = null;
+               $$ = new Method (current_class, (Expression) $3, (int) $2, true,
+                                (MemberName) $4, (Parameters) $6, (Attributes) $1);
+
+               Report.Error (531, lexer.Location, "`{0}': interface members cannot have a definition",
+                       ((Method)$$).GetSignatureForError ());
          }
        ;
 
@@ -1631,81 +1659,91 @@ interface_property_declaration
          type IDENTIFIER 
          OPEN_BRACE 
          { lexer.PropertyParsing = true; }
-         interface_accessors 
-         { lexer.PropertyParsing = false; }
+         accessor_declarations 
+         {
+               has_get = has_set = false; 
+               lexer.PropertyParsing = false;
+         }
          CLOSE_BRACE
          {
+               LocatedToken lt = (LocatedToken) $4;
+               MemberName name = new MemberName (lt.Value, lt.Location);
+
                if ($3 == TypeManager.system_void_expr) {
-                       Report.Error (547, lexer.Location, "'{0}': property cannot have void type", $4);
+                       Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
+                       break;
+               }
+
+               Property p = null;
+               if ($7 == null) {
+                       p = new Property (current_class, (Expression) $3, (int) $2, true,
+                                  name, (Attributes) $1,
+                                  null, null);
+
+                       Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
                        break;
                }
 
-               if ($7 == null)
+               Pair pair = (Pair) $7;
+               p = new Property (current_class, (Expression) $3, (int) $2, true,
+                                  name, (Attributes) $1,
+                                  (Accessor)pair.First, (Accessor)pair.Second);
+
+               if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
+                       Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
+                       $$ = null;
                        break;
+               }
 
-                InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
+               if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
+                       Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
+                       $$ = null;
+                       break;
+               }
 
-               $$ = new Property (current_class, (Expression) $3, (int) $2, true,
-                                  new MemberName ((string) $4), (Attributes) $1,
-                                  pinfo.Get, pinfo.Set, lexer.Location);
                if (RootContext.Documentation != null)
-                       ((Property) $$).DocComment = Lexer.consume_doc_comment ();
+                       p.DocComment = Lexer.consume_doc_comment ();
+
+               $$ = p;
          }
        | opt_attributes
          opt_new
          type error {
-               CheckIdentifierToken (yyToken);
+               CheckIdentifierToken (yyToken, GetLocation ($4));
                $$ = null;
          }
        ;
 
-interface_accessors
-       : opt_attributes opt_modifiers GET SEMICOLON    
-       { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, lexer.Location, lexer.Location); }
-       | opt_attributes opt_modifiers GET OPEN_BRACE
-        {  
-               Report.Error (531, lexer.Location, "'{0}': interface members cannot have a definition", ".get");
-               $$ = null;
-        }
-       | opt_attributes opt_modifiers SET SEMICOLON            
-       { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, 0, (int) $2, lexer.Location, lexer.Location); }
-       | opt_attributes opt_modifiers GET SEMICOLON opt_attributes opt_modifiers SET SEMICOLON 
-         { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $5, (int) $2, (int) $6, lexer.Location, lexer.Location); }
-       | opt_attributes opt_modifiers SET SEMICOLON opt_attributes opt_modifiers GET SEMICOLON
-         { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $5, (Attributes) $1, (int) $6, (int) $2, lexer.Location, lexer.Location); }
-       |
-         {
-               Report.Error (548, lexer.Location, "'{0}' : property or indexer must have at least one accessor", "");
-         }
-       ;
 
 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 MemberName ((string) $5), null,
-                                    (Attributes) $1, lexer.Location);
+                                    new MemberName (lt.Value, lt.Location),
+                                    (Attributes) $1);
                if (RootContext.Documentation != null)
                        ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
          }
        | opt_attributes opt_new EVENT type error {
-               CheckIdentifierToken (yyToken);
+               CheckIdentifierToken (yyToken, GetLocation ($5));
                $$ = null;
          }
        | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN  {
-               Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
+               LocatedToken lt = (LocatedToken) $5;
+               Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
                $$ = null;
          }
        | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
-       {
+         {
                lexer.EventParsing = true;
-       }
-       event_accessor_declarations
-       {
+         }
+         event_accessor_declarations
+         {
                lexer.EventParsing = false;
-       }
-       CLOSE_BRACE {
-               Report.Error (69, lexer.Location, "Event in interface cannot have add or remove accessors");
+         }
+         CLOSE_BRACE {
+               Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
                $$ = null;
          }
        ;
@@ -1715,21 +1753,46 @@ interface_indexer_declaration
          OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
          OPEN_BRACE 
          { lexer.PropertyParsing = true; }
-         interface_accessors 
-         { lexer.PropertyParsing = false; }
+         accessor_declarations 
+         { 
+               has_get = has_set = false;
+               lexer.PropertyParsing = false;
+         }
          CLOSE_BRACE
          {
-               if ($10 == null)
-                       break;
+               Indexer i = null;
+               if ($10 == null) {
+                       i = new Indexer (current_class, (Expression) $3,
+                                 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
+                                 (int) $2, true, (Parameters) $6, (Attributes) $1,
+                                 null, null);
 
-               InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
+                       Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
+                       break;
+               }
 
-               $$ = new Indexer (current_class, (Expression) $3,
-                                 new MemberName (TypeContainer.DefaultIndexerName),
+               Pair pair = (Pair) $10;
+               i = new Indexer (current_class, (Expression) $3,
+                                 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
                                  (int) $2, true, (Parameters) $6, (Attributes) $1,
-                                 info.Get, info.Set, lexer.Location);
+                                  (Accessor)pair.First, (Accessor)pair.Second);
+
+               if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
+                       Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
+                       $$ = null;
+                       break;
+               }
+
+               if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
+                       Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
+                       $$ = null;
+                       break;
+               }
+
                if (RootContext.Documentation != null)
-                       ((Indexer) $$).DocComment = ConsumeStoredComment ();
+                       i.DocComment = ConsumeStoredComment ();
+
+               $$ = i;
          }
        ;
 
@@ -1740,17 +1803,20 @@ operator_declaration
          }
          operator_body
          {
+               if ($3 == null)
+                       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);
+               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);
+                       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, null, decl.location),
+                       new Parameters (param_list),
                        (ToplevelBlock) $5, (Attributes) $1, decl.location);
 
                if (RootContext.Documentation != null) {
@@ -1776,9 +1842,10 @@ operator_body
 operator_declarator
        : type OPERATOR overloadable_operator 
          OPEN_PARENS type IDENTIFIER CLOSE_PARENS
-       {
+         {
+               LocatedToken lt = (LocatedToken) $6;
                Operator.OpType op = (Operator.OpType) $3;
-               CheckUnaryOperator (op);
+               CheckUnaryOperator (op, lt.Location);
 
                if (op == Operator.OpType.Addition)
                        op = Operator.OpType.UnaryPlus;
@@ -1789,35 +1856,37 @@ operator_declarator
                Parameter [] pars = new Parameter [1];
                Expression type = (Expression) $5;
 
-               pars [0] = new Parameter (type, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
 
-               current_local_parameters = new Parameters (pars, null, lexer.Location);
+               current_local_parameters = new Parameters (pars);
 
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
 
-               $$ = new OperatorDeclaration (op, (Expression) $1, type, (string) $6,
-                                             null, null, lexer.Location);
-       }
+               $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
+                                             null, null, (Location) $2);
+         }
        | type OPERATOR overloadable_operator
          OPEN_PARENS 
                type IDENTIFIER COMMA
                type IDENTIFIER 
          CLOSE_PARENS
-        {
-               CheckBinaryOperator ((Operator.OpType) $3);
+          {
+               LocatedToken ltParam1 = (LocatedToken) $6;
+               LocatedToken ltParam2 = (LocatedToken) $9;
+               CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
 
                Parameter [] pars = new Parameter [2];
 
                Expression typeL = (Expression) $5;
                Expression typeR = (Expression) $8;
 
-              pars [0] = new Parameter (typeL, (string) $6, Parameter.Modifier.NONE, null);
-              pars [1] = new Parameter (typeR, (string) $9, Parameter.Modifier.NONE, null);
+              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, null, lexer.Location);
+              current_local_parameters = new Parameters (pars);
 
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -1825,10 +1894,28 @@ operator_declarator
                }
               
               $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1, 
-                                            typeL, (string) $6,
-                                            typeR, (string) $9, lexer.Location);
-        }
+                                            typeL, ltParam1.Value,
+                                            typeR, ltParam2.Value, (Location) $2);
+          }
        | conversion_operator_declarator
+       | type OPERATOR overloadable_operator
+         OPEN_PARENS 
+               type IDENTIFIER COMMA
+               type IDENTIFIER COMMA
+               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
@@ -1862,43 +1949,45 @@ overloadable_operator
 conversion_operator_declarator
        : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
          {
+               LocatedToken lt = (LocatedToken) $6;
                Parameter [] pars = new Parameter [1];
 
-               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
 
-               current_local_parameters = new Parameters (pars, null, lexer.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.Implicit, (Expression) $3, (Expression) $5, (string) $6,
-                                             null, null, lexer.Location);
+               $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, lt.Value,
+                                             null, null, (Location) $2);
          }
        | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
          {
+               LocatedToken lt = (LocatedToken) $6;
                Parameter [] pars = new Parameter [1];
 
-               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
 
-               current_local_parameters = new Parameters (pars, null, lexer.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.Explicit, (Expression) $3, (Expression) $5, (string) $6,
-                                             null, null, lexer.Location);
+               $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, lt.Value,
+                                             null, null, (Location) $2);
          }
        | IMPLICIT error 
          {
-               syntax_error (lexer.Location, "'operator' expected");
+               syntax_error ((Location) $1, "'operator' expected");
          }
        | EXPLICIT error 
          {
-               syntax_error (lexer.Location, "'operator' expected");
+               syntax_error ((Location) $1, "'operator' expected");
          }
        ;
 
@@ -1919,24 +2008,17 @@ constructor_declaration
                if (c.Name == current_container.Basename){
                        if ((c.ModFlags & Modifiers.STATIC) != 0){
                                if ((c.ModFlags & Modifiers.Accessibility) != 0){
-                                       Report.Error (
-                                               515, c.Location, String.Format (
-                                               "`{0}.{1}': static constructor can not have access modifiers",
-                                               c.Name, current_container.Name));
+                                       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 (c.Initializer != null){
-                                       Report.Error (
-                                               514, c.Location, 
-                                               "Static constructors can not have an explicit this or base " +
-                                               "constructor invocations");
-                               }
-       
-                               if (!c.Parameters.Empty){
-                                       Report.Error (
-                                               132, c.Location, "Static constructors should not have parameters");
+                                       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);
@@ -1962,14 +2044,15 @@ constructor_declarator
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
          }
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS _mark_
+         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
                current_local_parameters = (Parameters) $4;
          }
          opt_constructor_initializer
          {
-               $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $4,
-                                     (ConstructorInitializer) $8, (Location) $6);
+               LocatedToken lt = (LocatedToken) $1;
+               $$ = new Constructor (current_class, lt.Value, 0, (Parameters) $4,
+                                     (ConstructorInitializer) $7, lt.Location);
          }
        ;
 
@@ -1986,14 +2069,14 @@ opt_constructor_initializer
 constructor_initializer
        : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
          {
-               $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
+               $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
          }
        | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
          {
-               $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
+               $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
          }
        | COLON error {
-               Report.Error (1018, lexer.Location, "Keyword this or base expected");
+               Report.Error (1018, (Location) $1, "Keyword this or base expected");
                $$ = null;
          }
        ;
@@ -2014,12 +2097,13 @@ destructor_declaration
          }
          IDENTIFIER OPEN_PARENS CLOSE_PARENS block
          {
-               if ((string) $5 != current_container.Basename){
-                       Report.Error (574, lexer.Location, "Name of destructor must match name of class");
+               LocatedToken lt = (LocatedToken) $5;
+               if (lt.Value != current_container.Basename){
+                       Report.Error (574, lt.Location, "Name of destructor must match name of class");
                } else if (current_container.Kind != Kind.Class){
-                       Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
+                       Report.Error (575, lt.Location, "Only class types can contain destructor");
                } else {
-                       Location l = lexer.Location;
+                       Location l = lt.Location;
 
                        int m = (int) $2;
                        if (!RootContext.StdLib && current_container.Name == "System.Object")
@@ -2027,17 +2111,9 @@ destructor_declaration
                        else
                                m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
                         
-                        if ((m & Modifiers.UNSAFE) != 0){
-                                if (!RootContext.Unsafe){
-                                        Report.Error (227, l,
-                                             "Unsafe code requires the -unsafe command " +
-                                             "line option to be specified");
-                                }
-                        }
-                        
                        Method d = new Destructor (
                                current_class, TypeManager.system_void_expr, m, "Finalize", 
-                               new Parameters (null, null, l), (Attributes) $1, l);
+                               Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
                        if (RootContext.Documentation != null)
                                d.DocComment = ConsumeStoredComment ();
                  
@@ -2052,14 +2128,17 @@ event_declaration
          opt_modifiers
          EVENT type variable_declarators SEMICOLON
          {
+               current_array_type = null;
                foreach (VariableDeclaration var in (ArrayList) $5) {
 
-                       MemberName name = new MemberName (var.identifier);
+                       MemberName name = new MemberName (var.identifier,
+                               var.Location);
 
-                       Event e = new EventField (
+                       EventField e = new EventField (
                                current_class, (Expression) $4, (int) $2, false, name,
-                               var.expression_or_array_initializer, (Attributes) $1,
-                               lexer.Location);
+                               (Attributes) $1);
+
+                       e.Initializer = var.expression_or_array_initializer;
 
                        current_container.AddEvent (e);
 
@@ -2072,7 +2151,7 @@ event_declaration
        | opt_attributes
          opt_modifiers
          EVENT type namespace_or_type_name
-         OPEN_BRACE _mark_
+         OPEN_BRACE
          {
                implicit_value_parameter_type = (Expression) $4;  
                lexer.EventParsing = true;
@@ -2083,36 +2162,38 @@ event_declaration
          }
          CLOSE_BRACE
          {
-               Location loc = (Location) $7;
+               MemberName name = (MemberName) $5;
 
-               if ($9 == null){
-                       Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
+               if ($8 == null){
+                       Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
+                               current_container.Name, name.ToString ());
                        $$ = null;
                } else {
-                       Pair pair = (Pair) $9;
-                       
-                       MemberName name = (MemberName) $5;
+                       Pair pair = (Pair) $8;
+                       if (pair.First == null || pair.Second == null)
+                               // CS0073 is already reported, so no CS0065 here.
+                               $$ = null;
+                       else {
+                               Event e = new EventProperty (
+                                       current_class, (Expression) $4, (int) $2, false, name,
+                                       (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);
+                               if (RootContext.Documentation != null) {
+                                       e.DocComment = Lexer.consume_doc_comment ();
+                                       Lexer.doc_state = XmlCommentState.Allowed;
+                               }
 
-                       Event e = new EventProperty (
-                               current_class, (Expression) $4, (int) $2, false, name, null,
-                               (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
-                               loc);
-                       if (RootContext.Documentation != null) {
-                               e.DocComment = Lexer.consume_doc_comment ();
-                               Lexer.doc_state = XmlCommentState.Allowed;
+                               current_container.AddEvent (e);
+                               implicit_value_parameter_type = null;
                        }
-
-                       current_container.AddEvent (e);
-                       implicit_value_parameter_type = null;
                }
          }
-       | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
+       | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
                MemberName mn = (MemberName) $5;
 
                if (mn.Left != null)
-                       Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
+                       Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
                else 
-                       Report.Error (71, lexer.Location, "Event declaration should use property syntax");
+                       Report.Error (71, mn.Location, "Event declaration should use property syntax");
 
                if (RootContext.Documentation != null)
                        Lexer.doc_state = XmlCommentState.Allowed;
@@ -2121,20 +2202,20 @@ event_declaration
 
 event_accessor_declarations
        : add_accessor_declaration remove_accessor_declaration
-       {
+         {
                $$ = new Pair ($1, $2);
-       }
+         }
        | remove_accessor_declaration add_accessor_declaration
-       {
+         {
                $$ = new Pair ($2, $1);
-       }       
+         }     
        | add_accessor_declaration  { $$ = null; } 
        | remove_accessor_declaration { $$ = null; } 
        | error
-       { 
-               Report.Error (1055, lexer.Location, "An add or remove accessor expected");
+         
+               Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
                $$ = null;
-       }
+         }
        | { $$ = null; }
        ;
 
@@ -2144,24 +2225,24 @@ add_accessor_declaration
                Parameter [] args = new Parameter [1];
                Parameter implicit_value_parameter = new Parameter (
                        implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null);
+                       Parameter.Modifier.NONE, null, (Location) $2);
 
                args [0] = implicit_value_parameter;
                
-               current_local_parameters = new Parameters (args, null, lexer.Location);  
+               current_local_parameters = new Parameters (args);  
                lexer.EventParsing = false;
          }
           block
          {
-               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
+               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
                lexer.EventParsing = true;
          }
        | opt_attributes ADD error {
-               Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
+               Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
                $$ = null;
          }
        | opt_attributes modifiers ADD {
-               Report.Error (1609, lexer.Location, "Modifiers cannot be placed on event accessor declarations");
+               Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
                $$ = null;
          }
        ;
@@ -2172,31 +2253,31 @@ remove_accessor_declaration
                Parameter [] args = new Parameter [1];
                Parameter implicit_value_parameter = new Parameter (
                        implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null);
+                       Parameter.Modifier.NONE, null, (Location) $2);
 
                args [0] = implicit_value_parameter;
                
-               current_local_parameters = new Parameters (args, null, lexer.Location);  
+               current_local_parameters = new Parameters (args);  
                lexer.EventParsing = false;
          }
           block
          {
-               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
+               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
                lexer.EventParsing = true;
          }
        | opt_attributes REMOVE error {
-               Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
+               Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
                $$ = null;
          }
        | opt_attributes modifiers REMOVE {
-               Report.Error (1609, lexer.Location, "Modifiers cannot be placed on event accessor declarations");
+               Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
                $$ = null;
          }
        ;
 
 indexer_declaration
        : opt_attributes opt_modifiers indexer_declarator 
-         OPEN_BRACE _mark_
+         OPEN_BRACE
          {
                IndexerDeclaration decl = (IndexerDeclaration) $3;
 
@@ -2215,28 +2296,28 @@ indexer_declaration
          }
          CLOSE_BRACE
          { 
-               if ($7 == null)
+               if ($6 == null)
                        break;
 
                // The signature is computed from the signature of the indexer.  Look
                // at section 3.6 on the spec
-               Location loc = (Location) $5;
                Indexer indexer;
                IndexerDeclaration decl = (IndexerDeclaration) $3;
-               Pair pair = (Pair) $7;
+               Location loc = decl.location;
+               Pair pair = (Pair) $6;
                Accessor get_block = (Accessor) pair.First;
                Accessor set_block = (Accessor) pair.Second;
 
                MemberName name;
                if (decl.interface_type != null)
-                       name = new MemberName (decl.interface_type,
-                                              TypeContainer.DefaultIndexerName);
+                       name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);
                else
-                       name = new MemberName (TypeContainer.DefaultIndexerName);
+                       name = new MemberName (TypeContainer.DefaultIndexerName, loc);
 
                indexer = new Indexer (current_class, decl.type, name,
                                       (int) $2, false, decl.param_list, (Attributes) $1,
-                                      get_block, set_block, loc);
+                                      get_block, set_block);
+
                if (RootContext.Documentation != null)
                        indexer.DocComment = ConsumeStoredComment ();
 
@@ -2254,16 +2335,16 @@ indexer_declarator
                Parameters pars = (Parameters) $4;
                if (pars.HasArglist) {
                        // "__arglist is not valid in this context"
-                       Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
-               } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
-                       Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
+                       Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
+               } else if (pars.Empty){
+                       Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
                }
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
 
-               $$ = new IndexerDeclaration ((Expression) $1, null, pars);
+               $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
          }
        | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
          {
@@ -2271,13 +2352,13 @@ indexer_declarator
 
                if (pars.HasArglist) {
                        // "__arglist is not valid in this context"
-                       Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
-               } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
-                       Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
+                       Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
+               } else 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);
+               $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
 
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -2289,6 +2370,7 @@ indexer_declarator
 enum_declaration
        : opt_attributes
          opt_modifiers
+         opt_partial
          ENUM IDENTIFIER 
          opt_enum_base {
                if (RootContext.Documentation != null)
@@ -2296,26 +2378,36 @@ enum_declaration
          }
          enum_body
          opt_semicolon
-         { 
-               Location enum_location = lexer.Location;
+         {
+               LocatedToken lt = (LocatedToken) $5;
+               Location enum_location = lt.Location;
+
+               if ($3 != null) {
+                       Report.Error (267, lt.Location, "The partial modifier can only appear immediately before `class', `struct' or `interface'");
+                       break;  // assumes that the parser put us in a switch
+               }
 
-               MemberName full_name = MakeName (new MemberName ((string) $4));
-               Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
-                                  full_name, (Attributes) $1, enum_location);
+               MemberName name = MakeName (new MemberName (lt.Value, enum_location));
+               Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
+                                  name, (Attributes) $1);
                
                if (RootContext.Documentation != null)
                        e.DocComment = enumTypeComment;
 
-               foreach (VariableDeclaration ev in (ArrayList) $7) {
-                       e.AddEnumMember (ev.identifier, 
-                                        (Expression) ev.expression_or_array_initializer,
-                                        ev.Location, ev.OptAttributes,
-                                        ev.DocComment);
+
+               EnumMember em = null;
+               foreach (VariableDeclaration ev in (ArrayList) $8) {
+                       em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
+                               new MemberName (ev.identifier, ev.Location), ev.OptAttributes);
+
+//                     if (RootContext.Documentation != null)
+                               em.DocComment = ev.DocComment;
+
+                       e.AddEnumMember (em);
                }
 
-               string name = full_name.GetName ();
                current_container.AddEnum (e);
-               RootContext.Tree.RecordDecl (name, e);
+               $$ = e;
 
          }
        ;
@@ -2369,7 +2461,8 @@ enum_member_declarations
 enum_member_declaration
        : opt_attributes IDENTIFIER 
          {
-               VariableDeclaration vd = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
+               VariableDeclaration vd = new VariableDeclaration (
+                       (LocatedToken) $2, null, (Attributes) $1);
 
                if (RootContext.Documentation != null) {
                        vd.DocComment = Lexer.consume_doc_comment ();
@@ -2380,7 +2473,6 @@ enum_member_declaration
          }
        | opt_attributes IDENTIFIER
          {
-               $$ = lexer.Location;
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
@@ -2388,7 +2480,8 @@ enum_member_declaration
          }
           ASSIGN expression
          { 
-               VariableDeclaration vd = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
+               VariableDeclaration vd = new VariableDeclaration (
+                       (LocatedToken) $2, $5, (Attributes) $1);
 
                if (RootContext.Documentation != null)
                        vd.DocComment = ConsumeStoredComment ();
@@ -2404,10 +2497,15 @@ delegate_declaration
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
          SEMICOLON
          {
-               Location l = lexer.Location;
                MemberName name = MakeName ((MemberName) $5);
-               Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
-                                            (int) $2, name, (Parameters) $7, (Attributes) $1, l);
+               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,
+                                            (int) $2, name, p, (Attributes) $1);
 
                if (RootContext.Documentation != null) {
                        del.DocComment = Lexer.consume_doc_comment ();
@@ -2415,20 +2513,27 @@ delegate_declaration
                }
 
                current_container.AddDelegate (del);
-               RootContext.Tree.RecordDecl (name.GetName (true), 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);
+         }
        | namespace_or_type_name DOT IDENTIFIER {
-               $$ = new MemberName ((MemberName) $1, (string) $3);
+               LocatedToken lt = (LocatedToken) $3;
+               $$ = new MemberName ((MemberName) $1, lt.Value);
          }
        ;
 
 member_name
        : IDENTIFIER {
-               $$ = new MemberName ((string) $1);
+               LocatedToken lt = (LocatedToken) $1;
+               $$ = new MemberName (lt.Value, lt.Location);
          }
        ;
 
@@ -2441,7 +2546,8 @@ member_name
 type
        : namespace_or_type_name
          {
-               $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
+               MemberName name = (MemberName) $1;
+               $$ = name.GetTypeExpression ();
          }
        | builtin_types
        | array_type
@@ -2457,11 +2563,11 @@ pointer_type
                // can't perform checks during this phase - we do it during
                // semantic analysis.
                //
-               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+               $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
          }
        | VOID STAR
          {
-               $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
+               $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
          }
        ;
 
@@ -2469,19 +2575,25 @@ non_expression_type
        : builtin_types 
        | non_expression_type rank_specifier
          {
-               $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+               Location loc = GetLocation ($1);
+               if (loc.IsNull)
+                       loc = lexer.Location;
+               $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
          }
        | non_expression_type STAR
          {
-               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+               Location loc = GetLocation ($1);
+               if (loc.IsNull)
+                       loc = lexer.Location;
+               $$ = new ComposedCast ((Expression) $1, "*", loc);
          }
        | expression rank_specifiers 
          {
-               $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+               $$ = new ComposedCast ((Expression) $1, (string) $2);
          }
        | expression STAR 
          {
-               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+               $$ = new ComposedCast ((Expression) $1, "*");
          }
        
        //
@@ -2490,7 +2602,7 @@ non_expression_type
        //
        | multiplicative_expression STAR 
          {
-               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+               $$ = new ComposedCast ((Expression) $1, "*");
          }
        ;
 
@@ -2541,7 +2653,7 @@ integral_type
 array_type
        : type rank_specifiers
          {
-               $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+               $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2);
          }
        ;
 
@@ -2556,7 +2668,14 @@ primary_expression
  
        | member_name
          {
-               $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
+               MemberName mn = (MemberName) $1;
+               $$ = mn.GetTypeExpression ();
+         }
+       | IDENTIFIER DOUBLE_COLON IDENTIFIER
+         {
+               LocatedToken lt1 = (LocatedToken) $1;
+               LocatedToken lt2 = (LocatedToken) $3;
+               $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
          }
        | parenthesized_expression
        | member_access
@@ -2579,15 +2698,15 @@ literal
        : boolean_literal
        | integer_literal
        | real_literal
-       | LITERAL_CHARACTER     { $$ = new CharLiteral ((char) lexer.Value); }
-       | LITERAL_STRING        { $$ = new StringLiteral ((string) lexer.Value); }
-       | NULL                  { $$ = NullLiteral.Null; }
+       | LITERAL_CHARACTER     { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
+       | LITERAL_STRING        { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); } 
+       | NULL                  { $$ = new NullLiteral (lexer.Location); }
        ;
 
 real_literal
-       : LITERAL_FLOAT         { $$ = new FloatLiteral ((float) lexer.Value); }
-       | LITERAL_DOUBLE        { $$ = new DoubleLiteral ((double) lexer.Value); }
-       | LITERAL_DECIMAL       { $$ = new DecimalLiteral ((decimal) lexer.Value); }
+       : LITERAL_FLOAT         { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
+       | LITERAL_DOUBLE        { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
+       | LITERAL_DECIMAL       { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
        ;
 
 integer_literal
@@ -2595,28 +2714,21 @@ integer_literal
                object v = lexer.Value;
 
                if (v is int){
-                       int i = (int) v;
-
-                       if (i == 0)
-                               $$ = IntLiteral.Zero;
-                       else if (i == 1)
-                               $$ = IntLiteral.One;
-                       else
-                               $$ = new IntLiteral (i);
+                       $$ = new IntLiteral ((int) v, lexer.Location);
                } else if (v is uint)
-                       $$ = new UIntLiteral ((UInt32) v);
+                       $$ = new UIntLiteral ((UInt32) v, lexer.Location);
                else if (v is long)
-                       $$ = new LongLiteral ((Int64) v);
+                       $$ = new LongLiteral ((Int64) v, lexer.Location);
                else if (v is ulong)
-                       $$ = new ULongLiteral ((UInt64) v);
+                       $$ = new ULongLiteral ((UInt64) v, lexer.Location);
                else
                        Console.WriteLine ("OOPS.  Unexpected result from scanner");
          }
        ;
 
 boolean_literal
-       : TRUE                  { $$ = new BoolLiteral (true); }
-       | FALSE                 { $$ = new BoolLiteral (false); }
+       : TRUE                  { $$ = new BoolLiteral (true, lexer.Location); }
+       | FALSE                 { $$ = new BoolLiteral (false, lexer.Location); }
        ;
 
 parenthesized_expression_0
@@ -2628,6 +2740,7 @@ parenthesized_expression_0
                // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
                // or CLOSE_PARENS_MINUS.
          }
+       | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
        ;
 
 parenthesized_expression
@@ -2640,18 +2753,20 @@ parenthesized_expression
                // If a parenthesized expression is followed by a minus, we need to wrap
                // the expression inside a ParenthesizedExpression for the CS0075 check
                // in Binary.DoResolve().
-               $$ = new ParenthesizedExpression ((Expression) $1, lexer.Location);
+               $$ = new ParenthesizedExpression ((Expression) $1);
          }
-       ;;
+       ;
 
 member_access
        : primary_expression DOT IDENTIFIER
          {
-               $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
+               LocatedToken lt = (LocatedToken) $3;
+               $$ = new MemberAccess ((Expression) $1, lt.Value);
          }
        | predefined_type DOT IDENTIFIER
          {
-               $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
+               LocatedToken lt = (LocatedToken) $3;
+               $$ = new MemberAccess ((Expression) $1, lt.Value);
          }
        ;
 
@@ -2662,31 +2777,30 @@ predefined_type
 invocation_expression
        : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
          {
-               if ($1 == null) {
-                       Location l = lexer.Location;
-                       Report.Error (1, l, "Parse error");
-               }
-               $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
+               if ($1 == null)
+                       Report.Error (1, (Location) $2, "Parse error");
+               else
+                       $$ = new Invocation ((Expression) $1, (ArrayList) $3);
          }
        | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
          {
-               $$ = new Invocation ((Expression) $1, new ArrayList (), lexer.Location);
+               $$ = new Invocation ((Expression) $1, new ArrayList ());
          }
        | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
          {
-               $$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
+               $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
          }
        | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
          {
                ArrayList args = new ArrayList (1);
                args.Add ($4);
-               $$ = new Invocation ((Expression) $1, args, lexer.Location);
+               $$ = new Invocation ((Expression) $1, args);
          }
        | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
          {
                ArrayList args = ((ArrayList) $4);
                args.Add ($6);
-               $$ = new Invocation ((Expression) $1, args, lexer.Location);
+               $$ = new Invocation ((Expression) $1, args);
          }
        ;
 
@@ -2709,7 +2823,8 @@ argument_list
                $$ = list;
          }
        | argument_list error {
-               CheckToken (1026, yyToken, ", or ) expected");
+               CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
+               $$ = null;
          }
        ;
 
@@ -2739,12 +2854,12 @@ non_simple_argument
                Argument[] args = new Argument [list.Count];
                list.CopyTo (args, 0);
 
-               Expression expr = new Arglist (args, lexer.Location);
+               Expression expr = new Arglist (args, (Location) $1);
                $$ = new Argument (expr, Argument.AType.Expression);
          }
        | ARGLIST
          {
-               $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
+               $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
          }
        ;
 
@@ -2755,7 +2870,7 @@ variable_reference
 element_access
        : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET 
          {
-               $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
+               $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
          }
        | primary_expression rank_specifiers
          {
@@ -2768,17 +2883,18 @@ element_access
                  
                Expression expr = (Expression) $1;  
                if (expr is ComposedCast){
-                       $$ = new ComposedCast (expr, (string) $2, lexer.Location);
-               } else if (!(expr is SimpleName || expr is MemberAccess)){
-                       Error_ExpectingTypeName (lexer.Location, expr);
+                       $$ = new ComposedCast (expr, (string) $2);
+               } else if (!(expr is SimpleName || expr is MemberAccess || expr is QualifiedAliasMember)){
+                       Error_ExpectingTypeName (expr);
                        $$ = TypeManager.system_object_expr;
                } else {
                        //
                        // So we extract the string corresponding to the SimpleName
                        // or MemberAccess
                        // 
-                       $$ = new ComposedCast (expr, (string) $2, lexer.Location);
+                       $$ = new ComposedCast (expr, (string) $2);
                }
+               current_array_type = (Expression)$$;
          }
        ;
 
@@ -2800,21 +2916,22 @@ expression_list
 this_access
        : THIS
          {
-               $$ = new This (current_block, lexer.Location);
+               $$ = new This (current_block, (Location) $1);
          }
        ;
 
 base_access
        : BASE DOT IDENTIFIER
          {
-               $$ = new BaseAccess ((string) $3, lexer.Location);
+               LocatedToken lt = (LocatedToken) $3;
+               $$ = new BaseAccess (lt.Value, lt.Location);
          }
        | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
          {
-               $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
+               $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
          }
        | BASE error {
-               Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
+               Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
                $$ = null;
          }
        ;
@@ -2823,7 +2940,7 @@ post_increment_expression
        : primary_expression OP_INC
          {
                $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
-                                      (Expression) $1, lexer.Location);
+                                      (Expression) $1, (Location) $2);
          }
        ;
 
@@ -2831,7 +2948,7 @@ post_decrement_expression
        : primary_expression OP_DEC
          {
                $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
-                                      (Expression) $1, lexer.Location);
+                                      (Expression) $1, (Location) $2);
          }
        ;
 
@@ -2843,7 +2960,7 @@ new_expression
 object_or_delegate_creation_expression
        : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
          {
-               $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
+               $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
          }
        ;
 
@@ -2852,20 +2969,21 @@ array_creation_expression
          opt_rank_specifier
          opt_array_initializer
          {
-               $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
+               $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
          }
        | NEW type rank_specifiers array_initializer
          {
-               $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
+               $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
          }
        | NEW error
          {
-               Report.Error (1031, lexer.Location, "Type expected");
+               Report.Error (1031, (Location) $1, "Type expected");
                 $$ = null;
          }          
        | NEW type error 
          {
-               Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
+               Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
+               $$ = null;
          }
        ;
 
@@ -2957,31 +3075,31 @@ variable_initializer_list
 typeof_expression
        : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
          {
-               $$ = new TypeOfVoid (lexer.Location);
+               $$ = new TypeOfVoid ((Location) $1);
          }
        | TYPEOF OPEN_PARENS type CLOSE_PARENS
          {
-               $$ = new TypeOf ((Expression) $3, lexer.Location);
+               $$ = new TypeOf ((Expression) $3, (Location) $1);
          }
        ;
 
 sizeof_expression
        : SIZEOF OPEN_PARENS type CLOSE_PARENS { 
-               $$ = new SizeOf ((Expression) $3, lexer.Location);
+               $$ = new SizeOf ((Expression) $3, (Location) $1);
          }
        ;
 
 checked_expression
        : CHECKED OPEN_PARENS expression CLOSE_PARENS
          {
-               $$ = new CheckedExpr ((Expression) $3, lexer.Location);
+               $$ = new CheckedExpr ((Expression) $3, (Location) $1);
          }
        ;
 
 unchecked_expression
        : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
          {
-               $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
+               $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
          }
        ;
 
@@ -2989,15 +3107,19 @@ pointer_member_access
        : primary_expression OP_PTR IDENTIFIER
          {
                Expression deref;
+               LocatedToken lt = (LocatedToken) $3;
 
-               deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
-               $$ = new MemberAccess (deref, (string) $3, lexer.Location);
+               deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
+               $$ = new MemberAccess (deref, lt.Value);
          }
        ;
 
 anonymous_method_expression
-       : DELEGATE opt_anonymous_method_signature _mark_
+       : DELEGATE opt_anonymous_method_signature
          {
+               if (oob_stack == null)
+                       oob_stack = new Stack (6);
+
                oob_stack.Push (current_local_parameters);
                current_local_parameters = (Parameters)$2;
 
@@ -3008,17 +3130,17 @@ anonymous_method_expression
          } 
          block
          {
-               Location loc = (Location) $3;
+               Location loc = (Location) $1;
                top_current_block = (Block) oob_stack.Pop ();
                current_block = (Block) oob_stack.Pop ();
                if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
+                       Report.FeatureIsNotStandardized (loc, "anonymous methods");
                        $$ = null;
                } else  {
-                       ToplevelBlock anon_block = (ToplevelBlock) $5;
+                       ToplevelBlock anon_block = (ToplevelBlock) $4;
 
                        anon_block.Parent = current_block;
-                       $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block, 
+                       $$ = new AnonymousMethod (current_container, (Parameters) $2, (ToplevelBlock) top_current_block, 
                                anon_block, loc);
                }
                current_local_parameters = (Parameters) oob_stack.Pop ();
@@ -3039,7 +3161,7 @@ anonymous_method_signature
                        ArrayList par_list = (ArrayList) $2;
                        Parameter [] pars = new Parameter [par_list.Count];
                        par_list.CopyTo (pars);
-                       $$ = new Parameters (pars, null, lexer.Location);
+                       $$ = new Parameters (pars);
                }
          }
        ;
@@ -3066,10 +3188,11 @@ anonymous_method_parameter_list
 
 anonymous_method_parameter
        : opt_parameter_modifier type IDENTIFIER {
-               $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null);
+               LocatedToken lt = (LocatedToken) $3;
+               $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
          }
        | PARAMS type IDENTIFIER {
-               Report.Error (1670, lexer.Location, "params modifier not allowed in anonymous method declaration");
+               Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
                $$ = null;
          }
        ;
@@ -3078,11 +3201,11 @@ unary_expression
        : primary_expression
        | BANG prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
+               $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
          }
        | TILDE prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
+               $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
          }
        | cast_expression
        ;
@@ -3090,11 +3213,11 @@ unary_expression
 cast_list
        : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
          {
-               $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
+               $$ = new Cast ((Expression) $1, (Expression) $3);
          }
        | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
          {
-               $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
+               $$ = new Cast ((Expression) $1, (Expression) $3);
          }     
        ;
 
@@ -3102,6 +3225,7 @@ cast_expression
        : cast_list
        | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
          {
+               // TODO: wrong location
                $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
          }
        ;
@@ -3114,29 +3238,29 @@ prefixed_unary_expression
        : unary_expression
        | PLUS prefixed_unary_expression
          { 
-               $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
+               $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
          } 
        | MINUS prefixed_unary_expression 
          { 
-               $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
+               $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
          }
        | OP_INC prefixed_unary_expression 
          {
                $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
-                                      (Expression) $2, lexer.Location);
+                                      (Expression) $2, (Location) $1);
          }
        | OP_DEC prefixed_unary_expression 
          {
                $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
-                                      (Expression) $2, lexer.Location);
+                                      (Expression) $2, (Location) $1);
          }
        | STAR prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
+               $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
          }
        | BITWISE_AND prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
+               $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
          }
        ;
 
@@ -3144,7 +3268,7 @@ pre_increment_expression
        : OP_INC prefixed_unary_expression 
          {
                $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
-                                      (Expression) $2, lexer.Location);
+                                      (Expression) $2, (Location) $1);
          }
        ;
 
@@ -3152,7 +3276,7 @@ pre_decrement_expression
        : OP_DEC prefixed_unary_expression 
          {
                $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
-                                      (Expression) $2, lexer.Location);
+                                      (Expression) $2, (Location) $1);
          }
        ;
 
@@ -3161,17 +3285,17 @@ multiplicative_expression
        | multiplicative_expression STAR prefixed_unary_expression
          {
                $$ = new Binary (Binary.Operator.Multiply, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        | multiplicative_expression DIV prefixed_unary_expression
          {
                $$ = new Binary (Binary.Operator.Division, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        | multiplicative_expression PERCENT prefixed_unary_expression 
          {
                $$ = new Binary (Binary.Operator.Modulus, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        ;
 
@@ -3180,12 +3304,12 @@ additive_expression
        | additive_expression PLUS multiplicative_expression 
          {
                $$ = new Binary (Binary.Operator.Addition, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        | additive_expression MINUS multiplicative_expression
          {
                $$ = new Binary (Binary.Operator.Subtraction, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        ;
 
@@ -3194,12 +3318,12 @@ shift_expression
        | shift_expression OP_SHIFT_LEFT additive_expression
          {
                $$ = new Binary (Binary.Operator.LeftShift, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        | shift_expression OP_SHIFT_RIGHT additive_expression
          {
                $$ = new Binary (Binary.Operator.RightShift, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        ; 
 
@@ -3208,30 +3332,30 @@ relational_expression
        | relational_expression OP_LT shift_expression
          {
                $$ = new Binary (Binary.Operator.LessThan, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        | relational_expression OP_GT shift_expression
          {
                $$ = new Binary (Binary.Operator.GreaterThan, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        | relational_expression OP_LE shift_expression
          {
                $$ = new Binary (Binary.Operator.LessThanOrEqual, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        | relational_expression OP_GE shift_expression
          {
                $$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        | relational_expression IS type
          {
-               $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
+               $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
          }
        | relational_expression AS type
          {
-               $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
+               $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
          }
        ;
 
@@ -3240,12 +3364,12 @@ equality_expression
        | equality_expression OP_EQ relational_expression
          {
                $$ = new Binary (Binary.Operator.Equality, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        | equality_expression OP_NE relational_expression
          {
                $$ = new Binary (Binary.Operator.Inequality, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        ; 
 
@@ -3254,7 +3378,7 @@ and_expression
        | and_expression BITWISE_AND equality_expression
          {
                $$ = new Binary (Binary.Operator.BitwiseAnd, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        ;
 
@@ -3263,7 +3387,7 @@ exclusive_or_expression
        | exclusive_or_expression CARRET and_expression
          {
                $$ = new Binary (Binary.Operator.ExclusiveOr, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        ;
 
@@ -3272,7 +3396,7 @@ inclusive_or_expression
        | inclusive_or_expression BITWISE_OR exclusive_or_expression
          {
                $$ = new Binary (Binary.Operator.BitwiseOr, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        ;
 
@@ -3281,7 +3405,7 @@ conditional_and_expression
        | conditional_and_expression OP_AND inclusive_or_expression
          {
                $$ = new Binary (Binary.Operator.LogicalAnd, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        ;
 
@@ -3290,7 +3414,7 @@ conditional_or_expression
        | conditional_or_expression OP_OR conditional_and_expression
          {
                $$ = new Binary (Binary.Operator.LogicalOr, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
+                                (Expression) $1, (Expression) $3);
          }
        ;
 
@@ -3298,84 +3422,64 @@ conditional_expression
        : conditional_or_expression
        | conditional_or_expression INTERR expression COLON expression 
          {
-               $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
+               $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
          }
        ;
 
 assignment_expression
        : prefixed_unary_expression ASSIGN expression
          {
-               $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
+               $$ = new Assign ((Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_MULT_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_DIV_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.Division, (Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_MOD_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_ADD_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.Addition, (Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_SUB_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_AND_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_OR_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_XOR_ASSIGN expression
          {
-               Location l = lexer.Location;
-
                $$ = new CompoundAssign (
-                       Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
+                       Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
          }
        ;
 
@@ -3402,29 +3506,17 @@ class_declaration
          CLASS member_name
          {
                MemberName name = MakeName ((MemberName) $5);
-               bool partial = (bool) $3;
                int mod_flags = (int) $2;
 
-               if (partial) {
-                       ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, mod_flags,
-                               (Attributes) $1, Kind.Class, lexer.Location);
+               current_class = new Class (
+                       current_namespace, current_class, name,
+                       mod_flags, (Attributes) $1);
 
-                       current_container = part.PartialContainer;
-                       current_class = part;
+               if ($3 != null) {
+                       current_container = current_container.AddPartial (current_class);
                } else {
-                       if ((mod_flags & Modifiers.STATIC) != 0) {
-                               current_class = new StaticClass (
-                                       current_namespace, current_container, name,
-                                       mod_flags, (Attributes) $1, lexer.Location);
-                       } else {
-                               current_class = new Class (
-                                       current_namespace, current_container, name,
-                                       mod_flags, (Attributes) $1, lexer.Location);
-                       }
-
+                       current_container.AddClassOrStruct (current_class);
                        current_container = current_class;
-                       RootContext.Tree.RecordDecl (name.GetName (true), current_class);
                }
          }
          opt_class_base
@@ -3439,11 +3531,9 @@ class_declaration
                }
 
                if (RootContext.Documentation != null) {
-                       current_class.DocComment = Lexer.consume_doc_comment ();
+                       current_container.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
-
-               current_class.Register ();
          }
          class_body
          {
@@ -3452,18 +3542,15 @@ class_declaration
          }
          opt_semicolon 
          {
-               $$ = current_class;
-
-               current_container = current_container.Parent;
-               current_class = current_container;
+               $$ = pop_current_class ();
          }
        ;       
 
 opt_partial
        : /* empty */
-         { $$ = (bool) false; }
+         { $$ = null; }
        | PARTIAL
-         { $$ = (bool) true; }
+         { $$ = $1; } // location
        ;
 
 opt_modifiers
@@ -3480,7 +3567,7 @@ modifiers
 
                if ((m1 & m2) != 0) {
                        Location l = lexer.Location;
-                       Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
+                       Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
                }
                $$ = (int) (m1 | m2);
          }
@@ -3529,11 +3616,10 @@ block
        : OPEN_BRACE 
          {
                if (current_block == null){
-                       current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, lexer.Location);
+                       current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, (Location) $1);
                        top_current_block = current_block;
                } else {
-               current_block = new Block (current_block, current_local_parameters,
-                                          lexer.Location, Location.Null);
+                       current_block = new Block (current_block, (Location) $1, Location.Null);
                }
          } 
          opt_statement_list CLOSE_BRACE 
@@ -3541,7 +3627,7 @@ block
                while (current_block.Implicit)
                        current_block = current_block.Parent;
                $$ = current_block;
-               current_block.SetEndLocation (lexer.Location);
+               current_block.SetEndLocation ((Location) $4);
                current_block = current_block.Parent;
                if (current_block == null)
                        top_current_block = null;
@@ -3593,12 +3679,12 @@ embedded_statement
        : valid_declaration_statement
        | declaration_statement
          {
-                 Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
+                 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
                  $$ = null;
          }
        | labeled_statement
          {
-                 Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
+                 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
                  $$ = null;
          }
        ;
@@ -3613,9 +3699,10 @@ empty_statement
 labeled_statement
        : IDENTIFIER COLON 
          {
-               LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
+               LocatedToken lt = (LocatedToken) $1;
+               LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
 
-               if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
+               if (current_block.AddLabel (labeled))
                        current_block.AddStatement (labeled);
          }
          statement
@@ -3624,15 +3711,18 @@ labeled_statement
 declaration_statement
        : local_variable_declaration SEMICOLON
          {
+               current_array_type = null;
                if ($1 != null){
                        DictionaryEntry de = (DictionaryEntry) $1;
+                       Expression e = (Expression) de.Key;
 
-                       $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
+                       $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
                }
          }
 
        | local_constant_declaration SEMICOLON
          {
+               current_array_type = null;
                if ($1 != null){
                        DictionaryEntry de = (DictionaryEntry) $1;
 
@@ -3667,8 +3757,8 @@ local_variable_type
                // Blah i;
                  
                Expression expr = (Expression) $1;  
-               if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
-                       Error_ExpectingTypeName (lexer.Location, expr);
+               if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is QualifiedAliasMember)) {
+                       Error_ExpectingTypeName (expr);
                        $$ = null;
                } else {
                        //
@@ -3679,7 +3769,7 @@ local_variable_type
                        if ((string) $2 == "")
                                $$ = $1;
                        else
-                               $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+                               $$ = new ComposedCast ((Expression) $1, (string) $2);
                }
          }
        | builtin_types opt_rank_specifier
@@ -3687,7 +3777,7 @@ local_variable_type
                if ((string) $2 == "")
                        $$ = $1;
                else
-                       $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+                       $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
          }
         ;
 
@@ -3695,26 +3785,25 @@ local_variable_pointer_type
        : primary_expression STAR
          {
                Expression expr = (Expression) $1;  
-               Location l = lexer.Location;
 
-               if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast)) {
-                       Error_ExpectingTypeName (l, expr);
+               if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is QualifiedAliasMember)) {
+                       Error_ExpectingTypeName (expr);
 
                        $$ = null;
                } else 
-                       $$ = new ComposedCast ((Expression) $1, "*", l);
+                       $$ = new ComposedCast ((Expression) $1, "*");
          }
         | builtin_types STAR
          {
-               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
+               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
          }
         | VOID STAR
          {
-               $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
+               $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
          }
        | local_variable_pointer_type STAR
           {
-               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+               $$ = new ComposedCast ((Expression) $1, "*");
          }
         ;
 
@@ -3727,18 +3816,18 @@ local_variable_declaration
                        $$ = null;
          }
         | local_variable_pointer_type opt_rank_specifier variable_declarators
-       {
+         {
                if ($1 != null){
                        Expression t;
 
                        if ((string) $2 == "")
                                t = (Expression) $1;
                        else
-                               t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+                               t = new ComposedCast ((Expression) $1, (string) $2);
                        $$ = new DictionaryEntry (t, $3);
                } else 
                        $$ = null;
-       }
+         }
        ;
 
 local_constant_declaration
@@ -3752,10 +3841,7 @@ local_constant_declaration
        ;
 
 expression_statement
-       : statement_expression SEMICOLON
-         {
-               $$ = $1;
-         }
+       : statement_expression SEMICOLON { $$ = $1; }
        ;
 
        //
@@ -3763,15 +3849,19 @@ expression_statement
        // because statement_expression is used for example in for_statement
        //
 statement_expression
-       : invocation_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
-       | object_creation_expression    { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
-       | assignment_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
-       | post_increment_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
-       | post_decrement_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
-       | pre_increment_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
-       | pre_decrement_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
-       | error {
-               Report.Error (1002, lexer.Location, "Expecting `;'");
+       : expression
+         {
+               Expression expr = (Expression) $1;
+               ExpressionStatement s = expr as ExpressionStatement;
+               if (s == null) {
+                       Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
+                       $$ = null;
+               }
+               $$ = new StatementExpression (s);
+         }
+       | error
+         {
+               Report.Error (1002, GetLocation ($1), "Expecting `;'");
                $$ = null;
          }
        ;
@@ -3787,37 +3877,44 @@ selection_statement
        ; 
 
 if_statement
-       : IF OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS 
+       : IF OPEN_PARENS boolean_expression CLOSE_PARENS 
          embedded_statement
          { 
-               Location l = (Location) $3;
+               Location l = (Location) $1;
 
-               $$ = new If ((Expression) $4, (Statement) $6, l);
+               $$ = new If ((Expression) $3, (Statement) $5, l);
 
-               if (RootContext.WarningLevel >= 4){
-                       if ($6 == EmptyStatement.Value)
-                               Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
-               }
+               // FIXME: location for warning should be loc property of $5.
+               if ($5 == EmptyStatement.Value)
+                       Report.Warning (642, 3, l, "Possible mistaken empty statement");
 
          }
-       | IF OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS
+       | IF OPEN_PARENS boolean_expression CLOSE_PARENS
          embedded_statement ELSE embedded_statement
          {
-               Location l = (Location) $3;
+               Location l = (Location) $1;
+
+               $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
 
-               $$ = new If ((Expression) $4, (Statement) $6, (Statement) $8, l);
+               // FIXME: location for warning should be loc property of $5 and $7.
+               if ($5 == EmptyStatement.Value)
+                       Report.Warning (642, 3, l, "Possible mistaken empty statement");
+               if ($7 == EmptyStatement.Value)
+                       Report.Warning (642, 3, l, "Possible mistaken empty statement");
          }
        ;
 
 switch_statement
-       : SWITCH OPEN_PARENS _mark_
+       : SWITCH OPEN_PARENS
          { 
+               if (switch_stack == null)
+                       switch_stack = new Stack (2);
                switch_stack.Push (current_block);
          }
          expression CLOSE_PARENS 
          switch_block
          {
-               $$ = new Switch ((Expression) $5, (ArrayList) $7, (Location) $3);
+               $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
                current_block = (Block) switch_stack.Pop ();
          }
        ;
@@ -3889,11 +3986,11 @@ switch_labels
        ;
 
 switch_label
-       : CASE constant_expression COLON        { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
-       | DEFAULT COLON                         { $$ = new SwitchLabel (null, lexer.Location); }
+       : CASE constant_expression COLON        { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
+       | DEFAULT COLON                         { $$ = new SwitchLabel (null, (Location) $1); }
        | error {
                Report.Error (
-                       1523, lexer.Location
+                       1523, GetLocation ($1)
                        "The keyword case or default must precede code in switch block");
          }
        ;
@@ -3906,31 +4003,26 @@ iteration_statement
        ;
 
 while_statement
-       : WHILE OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS embedded_statement
-       {
-               Location l = (Location) $3;
-               $$ = new While ((Expression) $4, (Statement) $6, l);
-       
-               if (RootContext.WarningLevel >= 4){
-                       if ($6 == EmptyStatement.Value)
-                               Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
-               }
-       }
+       : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
+         {
+               Location l = (Location) $1;
+               $$ = new While ((Expression) $3, (Statement) $5, l);
+         }
        ;
 
 do_statement
        : DO embedded_statement 
-         WHILE OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS SEMICOLON
+         WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
          {
-               Location l = (Location) $5;
+               Location l = (Location) $1;
 
-               $$ = new Do ((Statement) $2, (Expression) $6, l);
+               $$ = new Do ((Statement) $2, (Expression) $5, l);
          }
        ;
 
 for_statement
        : FOR OPEN_PARENS 
-         opt_for_initializer SEMICOLON _mark_
+         opt_for_initializer SEMICOLON
          {
                Block assign_block = new Block (current_block);
                current_block = assign_block;
@@ -3945,21 +4037,12 @@ for_statement
 
                                LocalInfo vi;
 
-                               vi = current_block.AddVariable (
-                                       type, decl.identifier, current_local_parameters, decl.Location);
+                               vi = current_block.AddVariable (type, decl.identifier, decl.Location);
                                if (vi == null)
                                        continue;
 
                                Location l = lexer.Location;
-                               Expression expr;
-                               if (decl.expression_or_array_initializer is Expression){
-                                       expr = (Expression) decl.expression_or_array_initializer;
-                               } else if (decl.expression_or_array_initializer == null) {
-                                       expr = null;
-                               } else {
-                                       ArrayList init = (ArrayList) decl.expression_or_array_initializer;
-                                       expr = new ArrayCreation (type, "", init, decl.Location);
-                               }
+                               Expression expr = decl.expression_or_array_initializer;
                                        
                                LocalVariableReference var;
                                var = new LocalVariableReference (assign_block, decl.identifier, l);
@@ -3967,12 +4050,12 @@ for_statement
                                if (expr != null) {
                                        Assign a = new Assign (var, expr, decl.Location);
                                        
-                                       assign_block.AddStatement (new StatementExpression (a, lexer.Location));
+                                       assign_block.AddStatement (new StatementExpression (a));
                                }
                        }
                        
                        // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
-                       // This can be referred to as $6 below.
+                       // This can be referred to as $5 below.
                        $$ = null;
                } else {
                        $$ = $3;
@@ -3982,14 +4065,9 @@ for_statement
          opt_for_iterator CLOSE_PARENS 
          embedded_statement
          {
-               Location l = (Location) $5;
-
-               For f = new For ((Statement) $6, (Expression) $7, (Statement) $9, (Statement) $11, l);
+               Location l = (Location) $1;
 
-               if (RootContext.WarningLevel >= 4){
-                       if ($11 == EmptyStatement.Value)
-                               Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
-               }
+               For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
 
                current_block.AddStatement (f);
                while (current_block.Implicit)
@@ -4027,9 +4105,10 @@ statement_expression_list
        : statement_expression  
          {
                // CHANGE: was `null'
-               Block b = new Block (current_block, Block.Flags.Implicit);   
+               Statement s = (Statement) $1;
+               Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);   
 
-               b.AddStatement ((Statement) $1);
+               b.AddStatement (s);
                $$ = b;
          }
        | statement_expression_list COMMA statement_expression
@@ -4043,39 +4122,40 @@ statement_expression_list
 
 foreach_statement
        : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
-       {
-               Report.Error (230, lexer.Location, "Type and identifier are both required in a foreach statement");
+         {
+               Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
                $$ = null;
-       }
-       | FOREACH OPEN_PARENS type IDENTIFIER IN _mark_
+         }
+       | FOREACH OPEN_PARENS type IDENTIFIER IN
          expression CLOSE_PARENS 
          {
                Block foreach_block = new Block (current_block);
                current_block = foreach_block;
 
-               Location l = lexer.Location;
+               LocatedToken lt = (LocatedToken) $4;
+               Location l = lt.Location;
                LocalInfo vi;
 
-               vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
+               vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
                if (vi != null) {
-                       vi.ReadOnly = true;
+                       vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
 
                        // Get a writable reference to this read-only variable.
                        //
                        // Note that the $$ here refers to the value of _this_ code block,
-                       // not the value of the LHS non-terminal.  This can be referred to as $9 below.
-                       $$ = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
+                       // not the value of the LHS non-terminal.  This can be referred to as $8 below.
+                       $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
                } else {
                        $$ = null;
                }
          } 
          embedded_statement 
          {
-               LocalVariableReference v = (LocalVariableReference) $9;
-               Location l = (Location) $6;
+               LocalVariableReference v = (LocalVariableReference) $8;
+               Location l = (Location) $1;
 
                if (v != null) {
-                       Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
+                       Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
                        current_block.AddStatement (f);
                }
 
@@ -4098,88 +4178,91 @@ jump_statement
 break_statement
        : BREAK SEMICOLON
          {
-               $$ = new Break (lexer.Location);
+               $$ = new Break ((Location) $1);
          }
        ;
 
 continue_statement
        : CONTINUE SEMICOLON
          {
-               $$ = new Continue (lexer.Location);
+               $$ = new Continue ((Location) $1);
          }
        ;
 
 goto_statement
        : GOTO IDENTIFIER SEMICOLON 
          {
-               $$ = new Goto (current_block, (string) $2, lexer.Location);
+               LocatedToken lt = (LocatedToken) $2;
+               $$ = new Goto (lt.Value, lt.Location);
          }
        | GOTO CASE constant_expression SEMICOLON
          {
-               $$ = new GotoCase ((Expression) $3, lexer.Location);
+               $$ = new GotoCase ((Expression) $3, (Location) $1);
          }
        | GOTO DEFAULT SEMICOLON 
          {
-               $$ = new GotoDefault (lexer.Location);
+               $$ = new GotoDefault ((Location) $1);
          }
        ; 
 
 return_statement
        : RETURN opt_expression SEMICOLON
          {
-               $$ = new Return ((Expression) $2, lexer.Location);
+               $$ = new Return ((Expression) $2, (Location) $1);
          }
        ;
 
 throw_statement
        : THROW opt_expression SEMICOLON
          {
-               $$ = new Throw ((Expression) $2, lexer.Location);
+               $$ = new Throw ((Expression) $2, (Location) $1);
          }
        ;
 
 yield_statement 
        : IDENTIFIER RETURN expression SEMICOLON
          {
-               string s = (string) $1;
+               LocatedToken lt = (LocatedToken) $1;
+               string s = lt.Value;
                if (s != "yield"){
-                       Report.Error (1003, lexer.Location, "; expected");
+                       Report.Error (1003, lt.Location, "; expected");
                        $$ = null;
                }
                if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
+                       Report.FeatureIsNotStandardized (lt.Location, "yield statement");
                        $$ = null;
                }
                if (iterator_container == null){
-                       Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
+                       Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
                        $$ = null;
                } else {
                        iterator_container.SetYields ();
-                       $$ = new Yield ((Expression) $3, lexer.Location); 
+                       $$ = new Yield ((Expression) $3, lt.Location); 
                }
          }
        | IDENTIFIER RETURN SEMICOLON
-       {
-               Report.Error (1627, lexer.Location, "Expression expected after yield return");
+         {
+               Report.Error (1627, (Location) $2, "Expression expected after yield return");
                $$ = null;
-       }
+         }
        | IDENTIFIER BREAK SEMICOLON
          {
-               string s = (string) $1;
+               LocatedToken lt = (LocatedToken) $1;
+               string s = lt.Value;
                if (s != "yield"){
-                       Report.Error (1003, lexer.Location, "; expected");
+                       Report.Error (1003, lt.Location, "; expected");
                        $$ = null;
                }
                if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
+                       Report.FeatureIsNotStandardized (lt.Location, "yield statement");
                        $$ = null;
                }
                if (iterator_container == null){
-                       Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
+                       Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
                        $$ = null;
                } else {
                        iterator_container.SetYields ();
-                       $$ = new YieldBreak (lexer.Location);
+                       $$ = new YieldBreak (lt.Location);
                }
          }
        ;
@@ -4191,7 +4274,7 @@ opt_expression
 
 try_statement
        : TRY block catch_clauses 
-       {
+         {
                Catch g = null;
                
                ArrayList c = (ArrayList)$3;
@@ -4199,7 +4282,7 @@ try_statement
                        Catch cc = (Catch) c [i];
                        if (cc.IsGeneral) {
                                if (i != c.Count - 1)
-                                       Report.Error (1017, cc.loc, "Empty catch block must be the last in a series of catch blocks");
+                                       Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
                                g = cc;
                                c.RemoveAt (i);
                                i--;
@@ -4210,7 +4293,7 @@ try_statement
                // and g contains the general one.
                
                $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
-       }
+         }
        | TRY block opt_catch_clauses FINALLY block
          {
                Catch g = null;
@@ -4230,7 +4313,8 @@ try_statement
          }
        | TRY block error 
          {
-               Report.Error (1524, lexer.Location, "Expected catch or finally");
+               Report.Error (1524, (Location) $1, "Expected catch or finally");
+               $$ = null;
          }
        ;
 
@@ -4263,44 +4347,45 @@ opt_identifier
 
 catch_clause 
        : CATCH opt_catch_args 
-       {
+         {
                Expression type = null;
-               string id = null;
                
                if ($2 != null) {
                        DictionaryEntry cc = (DictionaryEntry) $2;
                        type = (Expression) cc.Key;
-                       id   = (string) cc.Value;
+                       LocatedToken lt = (LocatedToken) cc.Value;
 
-                       if (id != null){
+                       if (lt != null){
                                ArrayList one = new ArrayList (4);
-                               Location loc = lexer.Location;
 
-                               one.Add (new VariableDeclaration (id, null, loc));
+                               one.Add (new VariableDeclaration (lt, null));
 
                                current_block = new Block (current_block);
-                               Block b = declare_local_variables (type, one, loc);
+                               Block b = declare_local_variables (type, one, lt.Location);
                                current_block = b;
                        }
                }
-       } block {
+         } block {
                Expression type = null;
                string id = null;
+               Block var_block = null;
 
                if ($2 != null){
                        DictionaryEntry cc = (DictionaryEntry) $2;
                        type = (Expression) cc.Key;
-                       id   = (string) cc.Value;
+                       LocatedToken lt = (LocatedToken) cc.Value;
 
-                       if (id != null){
+                       if (lt != null){
+                               id = lt.Value;
                                while (current_block.Implicit)
                                        current_block = current_block.Parent;
+                               var_block = current_block;
                                current_block = current_block.Parent;
                        }
                }
 
-               $$ = new Catch (type, id, (Block) $4, ((Block) $4).loc);
-       }
+               $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
+         }
         ;
 
 opt_catch_args
@@ -4310,11 +4395,12 @@ opt_catch_args
 
 catch_args 
         : OPEN_PARENS type opt_identifier CLOSE_PARENS 
-        {
+          {
                $$ = new DictionaryEntry ($2, $3);
-       }
+         }
         ;
 
+
 checked_statement
        : CHECKED block
          {
@@ -4331,24 +4417,21 @@ unchecked_statement
 
 unsafe_statement
        : UNSAFE 
-       {
-               if (!RootContext.Unsafe){
-                       Report.Error (227, lexer.Location, 
-                               "Unsafe code can only be used if --unsafe is used");
-               }
-       } block {
+         {
+               RootContext.CheckUnsafeOption ((Location) $1);
+         } block {
                $$ = new Unsafe ((Block) $3);
-       }
+         }
        ;
 
 fixed_statement
        : FIXED OPEN_PARENS 
          type fixed_pointer_declarators 
-         CLOSE_PARENS _mark_
+         CLOSE_PARENS
          {
                ArrayList list = (ArrayList) $4;
                Expression type = (Expression) $3;
-               Location l = lexer.Location;
+               Location l = (Location) $1;
                int top = list.Count;
 
                Block assign_block = new Block (current_block);
@@ -4358,11 +4441,11 @@ fixed_statement
                        Pair p = (Pair) list [i];
                        LocalInfo v;
 
-                       v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
+                       v = current_block.AddVariable (type, (string) p.First, l);
                        if (v == null)
                                continue;
 
-                       v.ReadOnly = true;
+                       v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
                        v.Pinned = true;
                        p.First = v;
                        list [i] = p;
@@ -4370,14 +4453,9 @@ fixed_statement
          }
          embedded_statement 
          {
-               Location l = (Location) $6;
-
-               Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $8, l);
+               Location l = (Location) $1;
 
-               if (RootContext.WarningLevel >= 4){
-                       if ($8 == EmptyStatement.Value)
-                               Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
-               }
+               Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
 
                current_block.AddStatement (f);
                while (current_block.Implicit)
@@ -4405,12 +4483,14 @@ fixed_pointer_declarators
 
 fixed_pointer_declarator
        : IDENTIFIER ASSIGN expression
-         {     
-               $$ = new Pair ($1, $3);
+         {
+               LocatedToken lt = (LocatedToken) $1;
+               // FIXME: keep location
+               $$ = new Pair (lt.Value, $3);
          }
        | IDENTIFIER
          {
-               Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
+               Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
                $$ = null;
          }
        ;
@@ -4422,19 +4502,19 @@ lock_statement
          } 
          embedded_statement
          {
-               $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
+               $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
          }
        ;
 
 using_statement
-       : USING OPEN_PARENS resource_acquisition CLOSE_PARENS _mark_
+       : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
          {
                Block assign_block = new Block (current_block);
                current_block = assign_block;
 
                if ($3 is DictionaryEntry){
                        DictionaryEntry de = (DictionaryEntry) $3;
-                       Location l = lexer.Location;
+                       Location l = (Location) $1;
 
                        Expression type = (Expression) de.Key;
                        ArrayList var_declarators = (ArrayList) de.Value;
@@ -4443,23 +4523,14 @@ using_statement
 
                        foreach (VariableDeclaration decl in var_declarators){
 
-                               LocalInfo vi    = current_block.AddVariable (
-                                       type, decl.identifier, 
-                                       current_local_parameters, decl.Location);
+                               LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
                                if (vi == null)
                                        continue;
-                               vi.ReadOnly = true;
-
-                               Expression expr;
-                               if (decl.expression_or_array_initializer is Expression){
-                                       expr = (Expression) decl.expression_or_array_initializer;
-                               } else {
-                                       ArrayList init = (ArrayList) decl.expression_or_array_initializer;
-                                       if (init == null) {
-                                               Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
-                                       }
-                                       
-                                       expr = new ArrayCreation (type, "", init, decl.Location);
+                               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");
                                }
 
                                LocalVariableReference var;
@@ -4473,11 +4544,11 @@ using_statement
                                vars.Add (new DictionaryEntry (var, expr));                             
 
                                // Assign a = new Assign (var, expr, decl.Location);
-                               // assign_block.AddStatement (new StatementExpression (a, lexer.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 $6 below.
+                       // It can be referred to as $5 below.
                        $$ = new DictionaryEntry (type, vars);
                 } else {
                        $$ = $3;
@@ -4485,7 +4556,7 @@ using_statement
          } 
          embedded_statement
          {
-               Using u = new Using ($6, (Statement) $7, (Location) $5);
+               Using u = new Using ($5, (Statement) $6, (Location) $1);
                current_block.AddStatement (u);
                while (current_block.Implicit)
                        current_block = current_block.Parent;
@@ -4499,11 +4570,6 @@ resource_acquisition
        | expression
        ;
 
-// Utility rule to save location information
-_mark_
-       : /* empty */
-       { $$ = lexer.Location; }
-
 %%
 
 // <summary>
@@ -4511,48 +4577,31 @@ _mark_
 // </summary>
 public class VariableDeclaration {
        public string identifier;
-       public object expression_or_array_initializer;
+       public Expression expression_or_array_initializer;
        public Location Location;
        public Attributes OptAttributes;
        public string DocComment;
 
-       public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
+       public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
        {
-               this.identifier = id;
-               this.expression_or_array_initializer = eoai;
-               this.Location = l;
+               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;
+               }
+               this.Location = lt.Location;
                this.OptAttributes = opt_attrs;
        }
 
-       public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
+       public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
        {
        }
 }
 
-/// <summary>
-///  Used to pass around interface property information
-/// </summary>
-public class InterfaceAccessorInfo {
-
-        public readonly Accessor Get, Set;
-
-        public InterfaceAccessorInfo (bool has_get, bool has_set,
-                                      Attributes get_attrs, Attributes set_attrs, int get_mod, int set_mod, Location get_loc, Location set_loc)
-        {
-               if (get_mod != 0)
-                       Report.Error (275, get_loc, "Accessibility modifiers can not be used on accessors in interfaces");
-               if (set_mod != 0)
-                       Report.Error (275, set_loc, "Accessibility modifiers can not be used on accessors in interfaces");
-                       
-               if (has_get)
-                       Get = new Accessor (null, 0, get_attrs, get_loc);
-               if (has_set)
-                       Set = new Accessor (null, 0, set_attrs, set_loc);
-        }
-
-}
-
-
 // <summary>
 //   A class used to hold info about an indexer declarator
 // </summary>
@@ -4560,13 +4609,15 @@ public class IndexerDeclaration {
        public Expression type;
        public MemberName interface_type;
        public Parameters param_list;
+       public Location location;
 
        public IndexerDeclaration (Expression type, MemberName interface_type,
-                                  Parameters param_list)
+                                  Parameters param_list, Location loc)
        {
                this.type = type;
                this.interface_type = interface_type;
                this.param_list = param_list;
+               this.location = loc;
        }
 }
 
@@ -4613,15 +4664,25 @@ public class OperatorDeclaration {
 
 }
 
-void Error_ExpectingTypeName (Location l, Expression expr)
+void Error_ExpectingTypeName (Expression expr)
 {
        if (expr is Invocation){
-               Report.Error (1002, l, "; expected");
+               Report.Error (1002, expr.Location, "Expecting `;'");
        } else {
-               Report.Error (-1, l, "Invalid Type definition");
+               Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
        }
 }
 
+TypeContainer pop_current_class ()
+{
+       TypeContainer retval = current_class;
+
+       current_class = (TypeContainer) current_class.Parent;
+       current_container = current_class.PartialContainer;
+
+       return retval;
+}
+
 // <summary>
 //   Given the @class_name name, it creates a fully qualified name
 //   based on the containing declaration space
@@ -4629,11 +4690,11 @@ void Error_ExpectingTypeName (Location l, Expression expr)
 MemberName
 MakeName (MemberName class_name)
 {
-       string ns = current_namespace.FullName;
+       Namespace ns = current_namespace.NS;
 
-       if (current_container.Name == ""){
-               if (ns != "")
-                       return new MemberName (new MemberName (ns), class_name);
+       if (current_container.Name.Length == 0){
+               if (ns.Name.Length != 0)
+                       return new MemberName (ns.MemberName, class_name);
                else
                        return class_name;
        } else {
@@ -4668,7 +4729,7 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
 
        foreach (VariableDeclaration decl in variable_declarators){
 
-               if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
+               if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
                        if (decl.expression_or_array_initializer != null){
                                if (inits == null)
                                        inits = new ArrayList (4);
@@ -4682,23 +4743,14 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
 
        foreach (VariableDeclaration decl in inits){
                Assign assign;
-               Expression expr;
+               Expression expr = decl.expression_or_array_initializer;
                
-               if (decl.expression_or_array_initializer is Expression){
-                       expr = (Expression) decl.expression_or_array_initializer;
-
-               } else {
-                       ArrayList init = (ArrayList) decl.expression_or_array_initializer;
-                       
-                       expr = new ArrayCreation (type, "", init, decl.Location);
-               }
-
                LocalVariableReference var;
                var = new LocalVariableReference (implicit_block, decl.identifier, loc);
 
                assign = new Assign (var, expr, decl.Location);
 
-               implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
+               implicit_block.AddStatement (new StatementExpression (assign));
        }
        
        return implicit_block;
@@ -4714,14 +4766,13 @@ Block declare_local_constants (Expression type, ArrayList declarators)
                implicit_block = current_block;
 
        foreach (VariableDeclaration decl in declarators){
-               implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
-                                                 current_local_parameters, decl.Location);
+               implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
        }
        
        return implicit_block;
 }
 
-void CheckAttributeTarget (string a)
+void CheckAttributeTarget (string a, Location l)
 {
        switch (a) {
 
@@ -4729,14 +4780,13 @@ void CheckAttributeTarget (string a)
                return;
                
        default :
-               Location l = lexer.Location;
                Report.Error (658, l, "`" + a + "' is an invalid attribute target");
                break;
        }
 
 }
 
-void CheckUnaryOperator (Operator.OpType op)
+void CheckUnaryOperator (Operator.OpType op, Location l)
 {
        switch (op) {
                
@@ -4752,14 +4802,13 @@ void CheckUnaryOperator (Operator.OpType op)
                break;
                
        default :
-               Location l = lexer.Location;
                Report.Error (1019, l, "Overloadable unary operator expected"); 
                break;
                
        }
 }
 
-void CheckBinaryOperator (Operator.OpType op)
+void CheckBinaryOperator (Operator.OpType op, Location l)
 {
        switch (op) {
                
@@ -4782,7 +4831,6 @@ void CheckBinaryOperator (Operator.OpType op)
                break;
                
        default :
-               Location l = lexer.Location;
                Report.Error (1020, l, "Overloadable binary operator expected");
                break;
        }
@@ -4794,11 +4842,6 @@ void syntax_error (Location l, string msg)
        Report.Error (1003, l, "Syntax error, " + msg);
 }
 
-void output (string s)
-{
-       Console.WriteLine (s);
-}
-
 void note (string s)
 {
        // Used to put annotations
@@ -4814,49 +4857,52 @@ public Tokenizer Lexer {
 
 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
 {
-       current_namespace = new NamespaceEntry (null, file, null, Location.Null);
+       current_namespace = new NamespaceEntry (null, file, null);
        this.name = file.Name;
        this.file = file;
        current_container = RootContext.Tree.Types;
+       // TODO: Make RootContext.Tree.Types a PartialContainer.
+       current_class = current_container;
        current_container.NamespaceEntry = current_namespace;
-       oob_stack = new Stack ();
-       switch_stack = new Stack ();
 
        lexer = new Tokenizer (reader, file, defines);
 }
 
 public void parse ()
 {
+       int errors = Report.Errors;
        try {
                if (yacc_verbose_flag > 1)
                        yyparse (lexer, new yydebug.yyDebugSimple ());
                else
                        yyparse (lexer);
                Tokenizer tokenizer = lexer as Tokenizer;
-               tokenizer.cleanup ();           
+               tokenizer.cleanup ();
        } catch (Exception e){
                // 
                // Removed for production use, use parser verbose to get the output.
                //
                // Console.WriteLine (e);
-               Report.Error (-25, lexer.Location, "Parsing error");
+               if (Report.Errors == errors)
+                       Report.Error (-25, lexer.Location, "Parsing error");
                if (yacc_verbose_flag > 0)
                        Console.WriteLine (e);
        }
+
+       RootContext.Tree.Types.NamespaceEntry = null;
 }
 
-void CheckToken (int error, int yyToken, string msg)
+static void CheckToken (int error, int yyToken, string msg, Location loc)
 {
-       if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
-               Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
-               return;
-       }               
-       Report.Error (error, lexer.Location, msg);
+       if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
+               Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
+       else
+               Report.Error (error, loc, msg);
 }
 
-void CheckIdentifierToken (int yyToken)
+void CheckIdentifierToken (int yyToken, Location loc)
 {
-       CheckToken (1041, yyToken, "Identifier expected");
+       CheckToken (1041, yyToken, "Identifier expected", loc);
 }
 
 string ConsumeStoredComment ()
@@ -4867,5 +4913,18 @@ string ConsumeStoredComment ()
        return s;
 }
 
+Location GetLocation (object obj)
+{
+       if (obj is MemberCore)
+               return ((MemberCore) obj).Location;
+       if (obj is MemberName)
+               return ((MemberName) obj).Location;
+       if (obj is LocatedToken)
+               return ((LocatedToken) obj).Location;
+       if (obj is Location)
+               return (Location) obj;
+       return lexer.Location;
+}
+
 /* end end end */
 }