Merge pull request #637 from LogosBible/enetdown
[mono.git] / mcs / mcs / cs-parser.jay
index dd0a8a96673886a489647690f0b57f6a2c424e00..e5ecaa22626634f1b11ed4d1944469ec55f48981 100644 (file)
@@ -54,7 +54,7 @@ namespace Mono.CSharp
                /// </summary>
                Block      current_block;
                
-               BlockVariableDeclaration current_variable;
+               BlockVariable current_variable;
 
                Delegate   current_delegate;
                
@@ -139,6 +139,7 @@ namespace Mono.CSharp
                //
                LocationsBag lbag;
                List<Tuple<Modifiers, Location>> mod_locations;
+               Stack<Location> location_stack;
 %}
 
 %token EOF
@@ -416,7 +417,7 @@ extern_alias_directives
 extern_alias_directive
        : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                string s = lt.Value;
                if (s != "alias") {
                        syntax_error (lt.Location, "`alias' expected");
@@ -424,7 +425,7 @@ extern_alias_directive
                        if (lang_version == LanguageVersion.ISO_1)
                                FeatureIsNotAvailable (lt.Location, "external alias");
 
-                       lt = (Tokenizer.LocatedToken) $3;
+                       lt = (LocatedToken) $3;
                        if (lt.Value == QualifiedAliasMember.GlobalAlias) {
                                RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
                        }
@@ -464,7 +465,7 @@ using_namespace
          }
        | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
                        report.Warning (440, 2, lt.Location,
                         "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
@@ -521,7 +522,7 @@ namespace_declaration
                if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
-         opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon
+         opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
          {
                if ($11 != null)
                        lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
@@ -530,17 +531,36 @@ namespace_declaration
          
                current_container = current_namespace = current_namespace.Parent;
          }
+       | opt_attributes NAMESPACE namespace_name
+         {
+               report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
+
+               var name = (MemberName) $3;             
+               var ns = new NamespaceContainer (name, current_namespace);
+               lbag.AddLocation (ns, GetLocation ($2));
+               current_namespace.AddTypeContainer (ns);
+         }
+       ;
+
+opt_semicolon_error
+       : /* empty */
+       | SEMICOLON
+       | error
+         {
+               Error_SyntaxError (yyToken);
+               $$ = null;
+         }
        ;
 
 namespace_name
        : IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                $$ = new MemberName (lt.Value, lt.Location);
          }
        | namespace_name DOT IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);           
          }
        | error
@@ -656,6 +676,7 @@ attribute_sections
 attribute_section
        : OPEN_BRACKET
          {
+               PushLocation (GetLocation ($1));
                lexer.parsing_attribute_section = true;
          }
          attribute_section_cont
@@ -680,34 +701,54 @@ attribute_section_cont
                        $$ = new List<Attribute> (0);
                else
                        $$ = $4;
-         
+
+               lbag.InsertLocation ($$, 0, PopLocation ());
+               if ($5 != null) {
+                       lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
+               } else {
+                       lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
+               }
+
                current_attr_target = null;
                lexer.parsing_attribute_section = false;
          }
        | attribute_list opt_comma CLOSE_BRACKET
          {
                $$ = $1;
+
+               lbag.InsertLocation ($$, 0, PopLocation ());
+               if ($2 != null) {
+                       lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
+               } else {
+                       lbag.AddLocation ($$, GetLocation($3));
+               }
+         }
+       | IDENTIFIER error
+         {
+               Error_SyntaxError (yyToken);
+
+               var lt = (LocatedToken) $1;
+               var tne = new SimpleName (lt.Value, null, lt.Location);
+
+               $$ = new List<Attribute> () {
+                       new Attribute (null, tne, null, GetLocation ($1), false)
+               };
+         }
+       | error
+         {
+               $$ = CheckAttributeTarget (GetTokenName (yyToken), GetLocation ($1)); 
+               $$ = null;
          }
        ;       
 
 attribute_target
        : IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                $$ = CheckAttributeTarget (lt.Value, lt.Location);
          }
        | EVENT  { $$ = "event"; }
        | RETURN { $$ = "return"; }
-       | error
-         {
-               if (yyToken == Token.IDENTIFIER) {
-                       Error_SyntaxError (yyToken);
-                       $$ = null;
-               } else {
-                       string name = GetTokenName (yyToken);
-                       $$ = CheckAttributeTarget (name, GetLocation ($1));
-               }
-         }
        ;
 
 attribute_list
@@ -718,7 +759,10 @@ attribute_list
        | attribute_list COMMA attribute
          {
                var attrs = (List<Attribute>) $1;
-               attrs.Add ((Attribute) $3);
+               if (attrs != null) {
+                       attrs.Add ((Attribute) $3);
+                       lbag.AppendTo (attrs, GetLocation ($2));
+               }
 
                $$ = attrs;
          }
@@ -800,6 +844,11 @@ positional_or_named_argument
                $$ = new Argument ((Expression) $1);
          }
        | named_argument
+       | error
+         {
+               Error_SyntaxError (yyToken);
+               $$ = null;
+         }
        ;
 
 named_attribute_argument
@@ -810,14 +859,14 @@ named_attribute_argument
          expression
          {
                --lexer.parsing_block;
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);          
                lbag.AddLocation ($$, GetLocation($2));
          }
        ;
        
 named_argument
-       : identifier_inside_body COLON opt_named_modifier expression
+       : identifier_inside_body COLON opt_named_modifier expression_or_error
          {
                if (lang_version <= LanguageVersion.V_3)
                        FeatureIsNotAvailable (GetLocation ($1), "named argument");
@@ -825,7 +874,7 @@ named_argument
                // Avoid boxing in common case (no modifier)
                var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
                        
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
                lbag.AddLocation ($$, GetLocation($2));
          }
@@ -871,13 +920,14 @@ class_member_declaration
        | destructor_declaration
        | type_declaration
        | attributes_without_members
+       | incomplete_member
        | error
          {
                report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
                        GetSymbolName (yyToken));
                $$ = null;
                lexer.parsing_generic_declaration = false;
-         }
+         }     
        ;
 
 struct_declaration
@@ -886,10 +936,10 @@ struct_declaration
          opt_partial
          STRUCT
          {
-               lexer.ConstraintsParsing = true;
          }
          type_declaration_name
          { 
+               lexer.ConstraintsParsing = true;
                push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
          }
          opt_class_base
@@ -934,7 +984,7 @@ constant_declaration
          opt_modifiers
          CONST type IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken) $5;
+               var lt = (LocatedToken) $5;
                var mod = (Modifiers) $2;
                current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
                current_type.AddMember (current_field);
@@ -956,6 +1006,14 @@ constant_declaration
                lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
                current_field = null;
          }
+       | opt_attributes 
+         opt_modifiers
+         CONST type error
+         {
+               Error_SyntaxError (yyToken);
+
+               current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
+         }     
        ;
        
 opt_constant_declarators
@@ -977,7 +1035,7 @@ constant_declarators
 constant_declarator
        : COMMA IDENTIFIER constant_initializer
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
                lbag.AddLocation ($$, GetLocation ($1));
          }
@@ -1016,7 +1074,7 @@ field_declaration
                if (type.Type != null && type.Type.Kind == MemberKind.Void)
                        report.Error (670, GetLocation ($3), "Fields cannot have void type");
                        
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
                current_type.AddField (current_field);
                $$ = current_field;
@@ -1041,7 +1099,7 @@ field_declaration
                if (lang_version < LanguageVersion.ISO_2)
                        FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
 
-               var lt = (Tokenizer.LocatedToken) $5;
+               var lt = (LocatedToken) $5;
                current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
                        new MemberName (lt.Value, lt.Location), (Attributes) $1);
                        
@@ -1104,7 +1162,7 @@ field_declarators
 field_declarator
        : COMMA IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
                lbag.AddLocation ($$, GetLocation ($1));
          }
@@ -1115,7 +1173,7 @@ field_declarator
          variable_initializer
          {
                --lexer.parsing_block;
-               var lt = (Tokenizer.LocatedToken) $2;     
+               var lt = (LocatedToken) $2;       
                $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
                lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
          }
@@ -1140,7 +1198,7 @@ fixed_field_declarators
 fixed_field_declarator
        : COMMA IDENTIFIER fixed_field_size
          {
-               var lt = (Tokenizer.LocatedToken) $2;     
+               var lt = (LocatedToken) $2;       
                $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
                lbag.AddLocation ($$, GetLocation ($1));
          }
@@ -1181,10 +1239,7 @@ method_declaration
                if (doc_support)
                        Lexer.doc_state = XmlCommentState.NotAllowed;
 
-               // Add it early in the case of body being eof for full ast
-               Method m = (Method) $1;
-               async_block = (m.ModFlags & Modifiers.ASYNC) != 0;
-               current_type.AddMember (m);
+               // Was added earlier in the case of body being eof for full ast
          }
          method_body
          {
@@ -1223,26 +1278,36 @@ method_header
          }
          opt_formal_parameter_list CLOSE_PARENS
          {
-               lexer.ConstraintsParsing = true;
-         }
-         opt_type_parameter_constraints_clauses
-         {
-               lexer.ConstraintsParsing = false;
                valid_param_mod = 0;
                MemberName name = (MemberName) $4;
                current_local_parameters = (ParametersCompiled) $7;
 
                var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
-                                    name, current_local_parameters, (Attributes) $1, $10 != null);
+                                    name, current_local_parameters, (Attributes) $1);
+
+               current_type.AddMember (method);
+
+               async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
 
-               if ($10 != null)
-                       method.SetConstraints ((List<Constraints>) $10);
-                                    
                if (doc_support)
                        method.DocComment = Lexer.consume_doc_comment ();
 
                lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
+
                $$ = method;
+
+               lexer.ConstraintsParsing = true;
+         }
+         opt_type_parameter_constraints_clauses
+         {
+               lexer.ConstraintsParsing = false;
+
+               if ($10 != null) {
+                       var method = (Method) $9;
+                       method.SetConstraints ((List<Constraints>) $10);
+               }
+
+               $$ = $9;
          }
        | opt_attributes
          opt_modifiers
@@ -1273,10 +1338,14 @@ method_header
                modifiers |= Modifiers.PARTIAL;
 
                var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
-                                    modifiers, name, current_local_parameters, (Attributes) $1, $11 != null);
+                                    modifiers, name, current_local_parameters, (Attributes) $1);
 
-               if ($11 != null)
-                       method.SetConstraints ((List<Constraints>) $11);
+               current_type.AddMember (method);
+
+               async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
+
+               if ($12 != null)
+                       method.SetConstraints ((List<Constraints>) $12);
 
                if (doc_support)
                        method.DocComment = Lexer.consume_doc_comment ();
@@ -1295,7 +1364,9 @@ method_header
                        "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
 
                var method = Method.Create (current_type, (FullNamedExpression) $3,
-                                           0, name, (ParametersCompiled) $7, (Attributes) $1, false);
+                                           0, name, (ParametersCompiled) $7, (Attributes) $1);
+
+               current_type.AddMember (method);
 
                current_local_parameters = (ParametersCompiled) $7;
 
@@ -1314,7 +1385,9 @@ method_header
 
                MemberName name = (MemberName) $4;
                var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
-                                                                       name, current_local_parameters, (Attributes) $1, false);
+                                                                       name, current_local_parameters, (Attributes) $1);
+
+               current_type.AddMember (method);
 
                if (doc_support)
                        method.DocComment = Lexer.consume_doc_comment ();
@@ -1433,17 +1506,17 @@ fixed_parameter
        : opt_attributes
          opt_parameter_modifier
          parameter_type
-         IDENTIFIER
+         identifier_inside_body
          {
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
          }
        | opt_attributes
          opt_parameter_modifier
          parameter_type
-         IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
+         identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
          {
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
                $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
          }
@@ -1465,7 +1538,7 @@ fixed_parameter
        | opt_attributes
          opt_parameter_modifier
          parameter_type
-         IDENTIFIER
+         identifier_inside_body
          ASSIGN
          {
                ++lexer.parsing_block;
@@ -1500,7 +1573,7 @@ fixed_parameter
                if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
                        report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
                
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
                lbag.AddLocation ($$, GetLocation ($5));
                
@@ -1572,20 +1645,21 @@ parameter_modifier
 parameter_array
        : opt_attributes params_modifier type IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
          }
        | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
          {
                report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
                
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);            
          }
        | opt_attributes params_modifier type error
          {
                Error_SyntaxError (yyToken);
-               $$ = null;
+
+               $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
          }
        ;
        
@@ -1662,7 +1736,7 @@ indexer_declaration
          {
                valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
          }
-         opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
+         opt_formal_parameter_list CLOSE_BRACKET 
          {
                valid_param_mod = 0;
                var type = (FullNamedExpression) $3;
@@ -1671,7 +1745,7 @@ indexer_declaration
                current_property = indexer;
 
                current_type.AddIndexer (indexer);
-               lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
+               lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
                
                if (type.Type != null && type.Type.Kind == MemberKind.Void)
                        report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());           
@@ -1687,7 +1761,7 @@ indexer_declaration
 
                lexer.PropertyParsing = true;
          }
-         accessor_declarations 
+         OPEN_BRACE accessor_declarations 
          {
                lexer.PropertyParsing = false;
          }
@@ -1699,7 +1773,7 @@ indexer_declaration
                if (doc_support)
                        current_property.DocComment = ConsumeStoredComment ();
                        
-               lbag.AppendToMember (current_property, GetLocation ($12));
+               lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
                current_property = null;                
          }
        ;
@@ -1834,10 +1908,10 @@ interface_declaration
          opt_partial
          INTERFACE
          {
-               lexer.ConstraintsParsing = true;
          }
          type_declaration_name
          {
+               lexer.ConstraintsParsing = true;
                push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
                lbag.AddMember (current_container, mod_locations, GetLocation ($4));            
          }
@@ -1990,11 +2064,11 @@ operator_declarator
                                        Operator.GetName (op));
                        }
                } else {
-                       if (p_count > 2) {
+                       if (p_count == 1) {
+                               report.Error (1019, loc, "Overloadable unary operator expected");
+                       } else if (p_count != 2) {
                                report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
                                        Operator.GetName (op));
-                       } else if (p_count != 2) {
-                               report.Error (1019, loc, "Overloadable unary operator expected");
                        }
                }
                
@@ -2048,7 +2122,11 @@ conversion_operator_declarator
 
                Location loc = GetLocation ($2);
                current_local_parameters = (ParametersCompiled)$6;  
-                 
+
+               if (current_local_parameters.Count != 1) {
+                       report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
+               }
+
                if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
@@ -2067,7 +2145,11 @@ conversion_operator_declarator
                
                Location loc = GetLocation ($2);
                current_local_parameters = (ParametersCompiled)$6;  
-                 
+
+               if (current_local_parameters.Count != 1) {
+                       report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
+               }
+
                if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
@@ -2123,7 +2205,7 @@ constructor_declarator
                valid_param_mod = 0;
                current_local_parameters = (ParametersCompiled) $6;
                
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                var mods = (Modifiers) $2;
                var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
 
@@ -2220,7 +2302,7 @@ destructor_declaration
          }
          IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
          {
-               var lt = (Tokenizer.LocatedToken) $5;
+               var lt = (LocatedToken) $5;
                if (lt.Value != current_container.MemberName.Name){
                        report.Error (574, lt.Location, "Name of destructor must match name of class");
                } else if (current_container.Kind != MemberKind.Class){
@@ -2296,6 +2378,14 @@ event_declaration
                current_event = null;   
                current_local_parameters = null;
          }
+       | opt_attributes
+         opt_modifiers
+         EVENT type error
+         {
+               Error_SyntaxError (yyToken);
+
+               current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
+         }
        ;
        
 opt_event_initializer
@@ -2330,7 +2420,7 @@ event_declarators
 event_declarator
        : COMMA IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
                lbag.AddLocation ($$, GetLocation ($1));
          }
@@ -2341,7 +2431,7 @@ event_declarator
          event_variable_initializer
          {
                --lexer.parsing_block;
-               var lt = (Tokenizer.LocatedToken) $2;     
+               var lt = (LocatedToken) $2;       
                $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
                lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
          }
@@ -2458,6 +2548,23 @@ attributes_without_members
                lexer.putback ('}');
          }
        ;
+
+// For full ast try to recover incomplete ambiguous member
+// declaration in form on class X { public int }
+incomplete_member
+       : opt_attributes opt_modifiers member_type CLOSE_BRACE
+         {
+               report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
+               lexer.putback ('}');
+
+               lexer.parsing_generic_declaration = false;
+               FullNamedExpression type = (FullNamedExpression) $3;
+               current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
+               current_type.AddField (current_field);
+               $$ = current_field;
+         }
+       ;
          
 enum_declaration
        : opt_attributes
@@ -2539,7 +2646,7 @@ enum_member_declarations
 enum_member_declaration
        : opt_attributes IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
                ((Enum) current_type).AddEnumMember (em);
 
@@ -2562,7 +2669,7 @@ enum_member_declaration
          { 
                --lexer.parsing_block;
                
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
                em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
                ((Enum) current_type).AddEnumMember (em);
@@ -2576,7 +2683,7 @@ enum_member_declaration
          {
                Error_SyntaxError (yyToken);
          
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
                ((Enum) current_type).AddEnumMember (em);
 
@@ -2650,8 +2757,8 @@ namespace_or_type_expr
        : member_name
        | qualified_alias_member IDENTIFIER opt_type_argument_list
          {
-               var lt1 = (Tokenizer.LocatedToken) $1;
-               var lt2 = (Tokenizer.LocatedToken) $2;
+               var lt1 = (LocatedToken) $1;
+               var lt2 = (LocatedToken) $2;
                
                $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
                lbag.AddLocation ($$, GetLocation ($2));
@@ -2662,7 +2769,7 @@ member_name
        : simple_name_expr
        | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
                lbag.AddLocation ($$, GetLocation ($2));
          }
@@ -2671,7 +2778,7 @@ member_name
 simple_name_expr
        : IDENTIFIER opt_type_argument_list
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
          }
        ;
@@ -2721,7 +2828,7 @@ type_declaration_name
          opt_type_parameter_list
          {
                lexer.parsing_generic_declaration = false;
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
          }
        ;
@@ -2741,7 +2848,7 @@ method_declaration_name
        | explicit_interface IDENTIFIER opt_type_parameter_list
          {
                lexer.parsing_generic_declaration = false;        
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
          }
        ;
@@ -2762,21 +2869,21 @@ indexer_declaration_name
 explicit_interface
        : IDENTIFIER opt_type_argument_list DOT
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
                lbag.AddLocation ($$, GetLocation ($3));
          }
        | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
          {
-               var lt1 = (Tokenizer.LocatedToken) $1;
-               var lt2 = (Tokenizer.LocatedToken) $2;
+               var lt1 = (LocatedToken) $1;
+               var lt2 = (LocatedToken) $2;
 
                $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
                lbag.AddLocation ($$, GetLocation ($4));
          }
        | explicit_interface IDENTIFIER opt_type_argument_list DOT
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
                lbag.AddLocation ($$, GetLocation ($4));
          }
@@ -2813,7 +2920,7 @@ type_parameters
 type_parameter
        : opt_attributes opt_type_parameter_variance IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken)$3;
+               var lt = (LocatedToken)$3;
                $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
          }
        | error
@@ -2997,11 +3104,11 @@ primary_expression
 primary_expression_or_type
        : IDENTIFIER opt_type_argument_list
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);   
          }
        | IDENTIFIER GENERATE_COMPLETION {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
               $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
          }
        | member_access
@@ -3042,38 +3149,38 @@ close_parens
 parenthesized_expression
        : OPEN_PARENS expression CLOSE_PARENS
          {
-               $$ = new ParenthesizedExpression ((Expression) $2);
+               $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
                lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
          }
        | OPEN_PARENS expression COMPLETE_COMPLETION
          {
-               $$ = new ParenthesizedExpression ((Expression) $2);
+               $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
          }
        ;
        
 member_access
-       : primary_expression DOT IDENTIFIER opt_type_argument_list
+       : primary_expression DOT identifier_inside_body opt_type_argument_list
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
                lbag.AddLocation ($$, GetLocation ($2));
          }
-       | builtin_types DOT IDENTIFIER opt_type_argument_list
+       | builtin_types DOT identifier_inside_body opt_type_argument_list
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
                lbag.AddLocation ($$, GetLocation ($2));
          }
-       | BASE DOT IDENTIFIER opt_type_argument_list
+       | BASE DOT identifier_inside_body opt_type_argument_list
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
                lbag.AddLocation ($$, GetLocation ($2));
          }
-       | qualified_alias_member IDENTIFIER opt_type_argument_list
+       | qualified_alias_member identifier_inside_body opt_type_argument_list
          {
-               var lt1 = (Tokenizer.LocatedToken) $1;
-               var lt2 = (Tokenizer.LocatedToken) $2;
+               var lt1 = (LocatedToken) $1;
+               var lt2 = (LocatedToken) $2;
 
                $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
                lbag.AddLocation ($$, GetLocation ($2));
@@ -3082,7 +3189,7 @@ member_access
                $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
          }
        | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
          }
        | builtin_types DOT GENERATE_COMPLETION
@@ -3090,7 +3197,7 @@ member_access
                $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
          }
        | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
          }
        ;
@@ -3108,7 +3215,13 @@ invocation_expression
                $$ = new Invocation ((Expression) $1, (Arguments) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
-       
+       | primary_expression open_parens_any error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Invocation ((Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ;
 
 opt_object_or_collection_initializer
@@ -3120,12 +3233,11 @@ object_or_collection_initializer
        : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
          {
                if ($2 == null) {
-                       $$ = CollectionOrObjectInitializers.Empty;
-                       // TODO: lbag
+                       $$ = new CollectionOrObjectInitializers (GetLocation ($1));
                } else {
                        $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
-                       lbag.AddLocation ($$, GetLocation ($3));
                }
+               lbag.AddLocation ($$, GetLocation ($3));
          }
        | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
          {
@@ -3164,7 +3276,13 @@ member_initializer_list
 member_initializer
        : IDENTIFIER ASSIGN initializer_value
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
+               $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | AWAIT ASSIGN initializer_value
+         {
+               var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
                $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
                lbag.AddLocation ($$, GetLocation ($2));
          }
@@ -3190,7 +3308,7 @@ member_initializer
          {
                report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
                $$ = null;
-         }       
+         }
        ;
 
 initializer_value
@@ -3235,7 +3353,8 @@ argument_list
          }
        | argument_list COMMA error
          {
-               lexer.putback (')'); // TODO: Wrong but what can I do
+               if (lexer.putback_char == -1)
+                       lexer.putback (')'); // TODO: Wrong but what can I do
                Error_SyntaxError (yyToken);
                $$ = $1;
          }
@@ -3305,22 +3424,18 @@ element_access
        ;
 
 expression_list
-       : expression
+       : expression_or_error
          {
                var list = new List<Expression> (4);
                list.Add ((Expression) $1);
                $$ = list;
          }
-       | expression_list COMMA expression
+       | expression_list COMMA expression_or_error
          {
                var list = (List<Expression>) $1;
                list.Add ((Expression) $3);
                $$ = list;
          }
-       | expression_list error {
-               Error_SyntaxError (yyToken);
-               $$ = $1;
-         }
        ;
        
 expression_list_arguments
@@ -3494,15 +3609,15 @@ anonymous_type_parameters
        ;
 
 anonymous_type_parameter
-       : IDENTIFIER ASSIGN variable_initializer
+       : identifier_inside_body ASSIGN variable_initializer
          {
-               var lt = (Tokenizer.LocatedToken)$1;
+               var lt = (LocatedToken)$1;
                $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
                lbag.AddLocation ($$, GetLocation ($2));
          }
-       | IDENTIFIER
+       | identifier_inside_body
          {
-               var lt = (Tokenizer.LocatedToken)$1;
+               var lt = (LocatedToken)$1;
                $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
                        lt.Value, lt.Location);
          }
@@ -3630,27 +3745,27 @@ typeof_type_expression
 unbound_type_name
        : identifier_inside_body generic_dimension
          {  
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
 
                $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
          }
        | qualified_alias_member identifier_inside_body generic_dimension
          {
-               var lt1 = (Tokenizer.LocatedToken) $1;
-               var lt2 = (Tokenizer.LocatedToken) $2;
+               var lt1 = (LocatedToken) $1;
+               var lt2 = (LocatedToken) $2;
 
                $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
                lbag.AddLocation ($$, GetLocation ($2));
          }
        | unbound_type_name DOT identifier_inside_body
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                
                $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);         
          }
        | unbound_type_name DOT identifier_inside_body generic_dimension
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                
                $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);               
          }
@@ -3660,7 +3775,7 @@ unbound_type_name
                if (tne.HasTypeArguments)
                        Error_TypeExpected (GetLocation ($4));
 
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);           
          }
        ;
@@ -3678,7 +3793,7 @@ generic_dimension
 qualified_alias_member
        : IDENTIFIER DOUBLE_COLON
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                if (lang_version == LanguageVersion.ISO_1)
                        FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
 
@@ -3692,6 +3807,13 @@ sizeof_expression
                $$ = new SizeOf ((Expression) $3, GetLocation ($1));
                lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
          }
+       | SIZEOF open_parens_any type error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new SizeOf ((Expression) $3, GetLocation ($1));
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ;
 
 checked_expression
@@ -3700,6 +3822,12 @@ checked_expression
                $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
                lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
          }
+       | CHECKED error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new CheckedExpr (null, GetLocation ($1));
+         }
        ;
 
 unchecked_expression
@@ -3708,12 +3836,18 @@ unchecked_expression
                $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
                lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
          }
+       | UNCHECKED error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new UnCheckedExpr (null, GetLocation ($1));
+         }
        ;
 
 pointer_member_access
        : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
          }
        ;
@@ -3802,6 +3936,31 @@ unary_expression
                
                $$ = new Await ((Expression) $2, GetLocation ($1));
          }
+       | BANG error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
+         }
+       | TILDE error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
+         }
+       | OPEN_PARENS_CAST type CLOSE_PARENS error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
+               lbag.AddLocation ($$, GetLocation ($3));
+         }
+       | AWAIT error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Await (null, GetLocation ($1));
+         }
        ;
 
        //
@@ -3834,6 +3993,42 @@ prefixed_unary_expression
          {
                $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
          }
+       | PLUS error
+         { 
+               Error_SyntaxError (yyToken);
+
+               $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
+         } 
+       | MINUS error 
+         { 
+               Error_SyntaxError (yyToken);
+
+               $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
+         }
+       | OP_INC error 
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
+         }
+       | OP_DEC error 
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
+         }
+       | STAR error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Indirection (null, GetLocation ($1));
+         }
+       | BITWISE_AND error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
+         }
        ;
 
 multiplicative_expression
@@ -3853,6 +4048,27 @@ multiplicative_expression
                $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
+       | multiplicative_expression STAR error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | multiplicative_expression DIV error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | multiplicative_expression PERCENT error 
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ;
 
 additive_expression
@@ -3875,6 +4091,32 @@ additive_expression
          {
                $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
          }       
+       | additive_expression PLUS error 
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | additive_expression MINUS error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | additive_expression AS error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new As ((Expression) $1, null, GetLocation ($2));
+         }
+       | additive_expression IS error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Is ((Expression) $1, null, GetLocation ($2));
+         }
        ;
 
 shift_expression
@@ -3889,6 +4131,20 @@ shift_expression
                $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
+       | shift_expression OP_SHIFT_LEFT error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | shift_expression OP_SHIFT_RIGHT error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ; 
 
 relational_expression
@@ -3913,6 +4169,34 @@ relational_expression
                $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
+       | relational_expression OP_LT error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | relational_expression OP_GT error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | relational_expression OP_LE error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | relational_expression OP_GE error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ;
 
 equality_expression
@@ -3927,6 +4211,20 @@ equality_expression
                $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
+       | equality_expression OP_EQ error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | equality_expression OP_NE error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ; 
 
 and_expression
@@ -3936,6 +4234,13 @@ and_expression
                $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
+       | and_expression BITWISE_AND error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ;
 
 exclusive_or_expression
@@ -3945,6 +4250,13 @@ exclusive_or_expression
                $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
+       | exclusive_or_expression CARRET error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ;
 
 inclusive_or_expression
@@ -3954,6 +4266,13 @@ inclusive_or_expression
                $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
+       | inclusive_or_expression BITWISE_OR error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ;
 
 conditional_and_expression
@@ -3963,6 +4282,13 @@ conditional_and_expression
                $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
+       | conditional_and_expression OP_AND error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ;
 
 conditional_or_expression
@@ -3972,6 +4298,13 @@ conditional_or_expression
                $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
                lbag.AddLocation ($$, GetLocation ($2));
          }
+       | conditional_or_expression OP_OR error
+         {
+               Error_SyntaxError (yyToken);
+
+               $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
        ;
        
 null_coalescing_expression
@@ -3988,7 +4321,7 @@ null_coalescing_expression
 
 conditional_expression
        : null_coalescing_expression
-       | null_coalescing_expression INTERR expression COLON expression_or_error
+       | null_coalescing_expression INTERR expression COLON expression
          {
                $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
                lbag.AddLocation ($$, GetLocation ($4));
@@ -3996,7 +4329,23 @@ conditional_expression
        | null_coalescing_expression INTERR expression error
          {
                Error_SyntaxError (yyToken);
+
+               $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
+         }
+       | null_coalescing_expression INTERR expression COLON error
+         {
+               Error_SyntaxError (yyToken);
+
                $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
+               lbag.AddLocation ($$, GetLocation ($4));
+         }
+       | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
+         {
+               Error_SyntaxError (Token.CLOSE_BRACE);
+
+               $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
+               lbag.AddLocation ($$, GetLocation ($4));
+               lexer.putback ('}');
          }
        ;
 
@@ -4082,19 +4431,24 @@ lambda_parameter_list
 lambda_parameter
        : parameter_modifier parameter_type identifier_inside_body
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
 
                $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
          }
        | parameter_type identifier_inside_body
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
 
                $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
          }
        | IDENTIFIER
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
+               $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
+         }
+       | AWAIT
+         {
+               var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
                $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
          }
        ;
@@ -4108,36 +4462,53 @@ opt_lambda_parameter_list
        ;
 
 lambda_expression_body
-       : lambda_expression_body_simple
-       | block
-       ;
-       
-lambda_expression_body_simple
        : {
                start_block (Location.Null);
          }
-         expression_or_error   // Have to close block when error occurs
+         expression    // All expressions must handle error or current block won't be restored and breaking ast completely
          {
                Block b = end_block (Location.Null);
                b.IsCompilerGenerated = true;
                b.AddStatement (new ContextualReturn ((Expression) $2));
                $$ = b;
          } 
+       | block
+       | error
+         {
+               // Handles only cases like foo = x.FirstOrDefault (l => );
+               // where we must restore current_variable
+               Block b = end_block (Location.Null);
+               b.IsCompilerGenerated = true;
+
+               Error_SyntaxError (yyToken);
+               $$ = null;
+         }
        ;
-       
+
 expression_or_error
        : expression
        | error
          {
-               Error_SyntaxError (yyToken);    
-               $$ = EmptyExpression.Null;
+               Error_SyntaxError (yyToken);
+               $$ = null;
          }
        ;
-
+       
 lambda_expression
        : IDENTIFIER ARROW 
          {
-               var lt = (Tokenizer.LocatedToken) $1;   
+               var lt = (LocatedToken) $1;     
+               Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
+               start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
+         }
+         lambda_expression_body
+         {
+               $$ = end_anonymous ((ParametersBlock) $4);
+               lbag.AddLocation ($$, GetLocation ($2));
+         }
+       | AWAIT ARROW
+         {
+               var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
                Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
                start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
          }
@@ -4148,7 +4519,7 @@ lambda_expression
          }
        | ASYNC identifier_inside_body ARROW
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
                start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
          }
@@ -4240,10 +4611,11 @@ class_declaration
          opt_partial
          CLASS
          {
-               lexer.ConstraintsParsing = true;
          }
          type_declaration_name
          {
+               lexer.ConstraintsParsing = true;
+
                Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
                if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
                        FeatureIsNotAvailable (c.Location, "static classes");
@@ -4407,13 +4779,13 @@ opt_class_base
        : /* empty */
        | COLON type_list
         {
-               current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
+               current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
         }
        | COLON type_list error
          {
                Error_SyntaxError (yyToken);
 
-               current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
+               current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
          }
        ;
 
@@ -4453,7 +4825,7 @@ type_parameter_constraints_clauses
 type_parameter_constraints_clause
        : WHERE IDENTIFIER COLON type_parameter_constraints
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
                lbag.AddLocation ($$, GetLocation ($3));
          }
@@ -4461,7 +4833,7 @@ type_parameter_constraints_clause
          {
                Error_SyntaxError (yyToken);
          
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
          }
        ; 
@@ -4710,7 +5082,7 @@ empty_statement
 labeled_statement
        : identifier_inside_body COLON 
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
                lbag.AddLocation (labeled, GetLocation ($2));
                current_block.AddLabel (labeled);
@@ -4820,33 +5192,33 @@ identifier_inside_body
        : IDENTIFIER
        | AWAIT
          {
-               if (async_block) {
-                       report.Error (4003, GetLocation ($1), "`await' cannot be used as an identifier within an async method or lambda expression");
-                       $$ = new Tokenizer.LocatedToken ("await", GetLocation ($1));
-               }
+               $$ = Error_AwaitAsIdentifier ($1);
          }
        ;
 
 block_variable_declaration
        : variable_type identifier_inside_body
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var li = new LocalVariable (current_block, lt.Value, lt.Location);
                current_block.AddLocalName (li);
-               current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
+               current_variable = new BlockVariable ((FullNamedExpression) $1, li);
          }
          opt_local_variable_initializer opt_variable_declarators SEMICOLON
          {
                $$ = current_variable;
                current_variable = null;
-               lbag.AddLocation ($$, GetLocation ($6));
+               if ($4 != null)
+                       lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
+               else
+                       lbag.AddLocation ($$, GetLocation ($6));
          }
        | CONST variable_type identifier_inside_body
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
                current_block.AddLocalName (li);
-               current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
+               current_variable = new BlockConstant ((FullNamedExpression) $2, li);
          }
          const_variable_initializer opt_const_declarators SEMICOLON
          {
@@ -4861,7 +5233,8 @@ opt_local_variable_initializer
        | ASSIGN block_variable_initializer
          {
                current_variable.Initializer = (Expression) $2;
-               // TODO: lbag
+               PushLocation (GetLocation ($1));
+               $$ = current_variable;
          }
        | error
          {
@@ -4898,18 +5271,18 @@ variable_declarators
 variable_declarator
        : COMMA identifier_inside_body
          {
-               var lt = (Tokenizer.LocatedToken) $2;     
+               var lt = (LocatedToken) $2;       
                var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
-               var d = new BlockVariableDeclaration.Declarator (li, null);
+               var d = new BlockVariableDeclarator (li, null);
                current_variable.AddDeclarator (d);
                current_block.AddLocalName (li);
                lbag.AddLocation (d, GetLocation ($1));
          }
        | COMMA identifier_inside_body ASSIGN block_variable_initializer
          {
-               var lt = (Tokenizer.LocatedToken) $2;     
+               var lt = (LocatedToken) $2;       
                var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
-               var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
+               var d = new BlockVariableDeclarator (li, (Expression) $4);
                current_variable.AddDeclarator (d);
                current_block.AddLocalName (li);
                lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
@@ -4940,9 +5313,9 @@ const_declarators
 const_declarator
        : COMMA identifier_inside_body ASSIGN constant_initializer_expr
          {
-               var lt = (Tokenizer.LocatedToken) $2;     
+               var lt = (LocatedToken) $2;       
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
-               var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
+               var d = new BlockVariableDeclarator (li, (Expression) $4);
                current_variable.AddDeclarator (d);
                current_block.AddLocalName (li);
                lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
@@ -4992,8 +5365,8 @@ statement_expression
          {
                ExpressionStatement s = $1 as ExpressionStatement;
                if (s == null) {
-                       Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
-                       $$ = new StatementErrorExpression ($1 as Expression);
+                       var expr = $1 as Expression;
+                       $$ = new StatementErrorExpression (expr);
                } else {
                        $$ = new StatementExpression (s);
                }
@@ -5058,7 +5431,7 @@ switch_statement
          }
          opt_switch_sections CLOSE_BRACE
          {
-               $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));  
+               $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));    
                end_block (GetLocation ($8));
                lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
          }
@@ -5066,7 +5439,7 @@ switch_statement
          {
                Error_SyntaxError (yyToken);
          
-               $$ = new Switch ((Expression) $3, null, null, GetLocation ($1));        
+               $$ = new Switch ((Expression) $3, null, GetLocation ($1));      
                lbag.AddStatement ($$, GetLocation ($2));
          }
        ;
@@ -5075,58 +5448,33 @@ opt_switch_sections
        : /* empty */           
       {
                report.Warning (1522, 1, current_block.StartLocation, "Empty switch block"); 
-               $$ = new List<SwitchSection> ();
          }
        | switch_sections
        ;
 
 switch_sections
        : switch_section 
-         {
-               var sections = new List<SwitchSection> (4);
-
-               sections.Add ((SwitchSection) $1);
-               $$ = sections;
-         }
        | switch_sections switch_section
-         {
-               var sections = (List<SwitchSection>) $1;
-
-               sections.Add ((SwitchSection) $2);
-               $$ = sections;
-         }
        | error
          {
                Error_SyntaxError (yyToken);
-               $$ = new List<SwitchSection> ();
          } 
        ;
 
 switch_section
-       : switch_labels
-         {
-               current_block = current_block.CreateSwitchBlock (lexer.Location);
-         }
-         statement_list 
-         {
-               $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
-         }
+       : switch_labels statement_list 
        ;
 
 switch_labels
        : switch_label 
          {
-               var labels = new List<SwitchLabel> (2);
-
-               labels.Add ((SwitchLabel) $1);
-               $$ = labels;
+               var label = (SwitchLabel) $1;
+               label.SectionStart = true;
+               current_block.AddStatement (label);
          }
        | switch_labels switch_label 
          {
-               var labels = (List<SwitchLabel>) ($1);
-               labels.Add ((SwitchLabel) $2);
-
-               $$ = labels;
+               current_block.AddStatement ((Statement) $2);
          }
        ;
 
@@ -5284,14 +5632,17 @@ opt_for_initializer
 for_initializer
        : variable_type identifier_inside_body
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var li = new LocalVariable (current_block, lt.Value, lt.Location);
                current_block.AddLocalName (li);
-               current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
+               current_variable = new BlockVariable ((FullNamedExpression) $1, li);
          }
          opt_local_variable_initializer opt_variable_declarators
          {
                $$ = current_variable;
+               if ($4 != null)
+                       lbag.AddLocation (current_variable, PopLocation ());
+
                current_variable = null;
          }
        | statement_expression_list
@@ -5349,7 +5700,7 @@ foreach_statement
                start_block (GetLocation ($2));
                current_block.IsCompilerGenerated = true;
                
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
                current_block.AddLocalName (li);
                
@@ -5364,7 +5715,7 @@ foreach_statement
                start_block (GetLocation ($2));
                current_block.IsCompilerGenerated = true;
                
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
                current_block.AddLocalName (li);
                $$ = li;
@@ -5415,7 +5766,7 @@ continue_statement
 goto_statement
        : GOTO identifier_inside_body SEMICOLON 
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                $$ = new Goto (lt.Value, GetLocation ($1));
                lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
          }
@@ -5465,7 +5816,7 @@ throw_statement
 yield_statement 
        : identifier_inside_body RETURN opt_expression SEMICOLON
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                string s = lt.Value;
                if (s != "yield"){
                        report.Error (1003, lt.Location, "; expected");
@@ -5483,7 +5834,7 @@ yield_statement
          {
                Error_SyntaxError (yyToken);
 
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                string s = lt.Value;
                if (s != "yield"){
                        report.Error (1003, lt.Location, "; expected");
@@ -5499,7 +5850,7 @@ yield_statement
          }
        | identifier_inside_body BREAK SEMICOLON
          {
-               var lt = (Tokenizer.LocatedToken) $1;
+               var lt = (LocatedToken) $1;
                string s = lt.Value;
                if (s != "yield"){
                        report.Error (1003, lt.Location, "; expected");
@@ -5507,7 +5858,7 @@ yield_statement
                        FeatureIsNotAvailable (lt.Location, "iterators");
                }
                
-               current_block.Explicit.RegisterIteratorYield ();
+               current_block.ParametersBlock.TopBlock.IsIterator = true;
                $$ = new YieldBreak (lt.Location);
                lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
          }
@@ -5579,7 +5930,7 @@ catch_clause
                c.TypeExpression = (FullNamedExpression) $3;
 
                if ($4 != null) {
-                       var lt = (Tokenizer.LocatedToken) $4;
+                       var lt = (LocatedToken) $4;
                        c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
                        current_block.AddLocalName (c.Variable);
                }
@@ -5602,6 +5953,24 @@ catch_clause
                
                $$ = new Catch (null, GetLocation ($1));
          }
+       | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
+         {
+               Error_SyntaxError (yyToken);
+
+               // Required otherwise missing block could not be detected because
+               // start_block is run early
+               var c = new Catch (null, GetLocation ($1));
+               c.TypeExpression = (FullNamedExpression) $3;
+
+               if ($4 != null) {
+                       var lt = (LocatedToken) $4;
+                       c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
+               }
+
+               lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
+
+               $$ = c;
+         }
        ;
 
 checked_statement
@@ -5652,7 +6021,7 @@ fixed_statement
            start_block (GetLocation ($2));
            
                current_block.IsCompilerGenerated = true;
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
                current_block.AddLocalName (li);
                current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
@@ -5679,7 +6048,7 @@ using_statement
            start_block (GetLocation ($2));
            
                current_block.IsCompilerGenerated = true;
-               var lt = (Tokenizer.LocatedToken) $4;
+               var lt = (LocatedToken) $4;
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
                current_block.AddLocalName (li);
                current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
@@ -5783,7 +6152,7 @@ first_from_clause
          {
                current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
                $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
          }
@@ -5791,7 +6160,7 @@ first_from_clause
          {
                current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
                $$ = new Linq.QueryExpression (
                        new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
@@ -5806,7 +6175,7 @@ nested_from_clause
          {
                current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
                $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
          }
@@ -5814,7 +6183,7 @@ nested_from_clause
          {
                current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
                $$ = new Linq.QueryExpression (
                        new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
@@ -5831,7 +6200,7 @@ from_clause
          }
          expression_or_error
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var sn = new Linq.RangeVariable (lt.Value, lt.Location);
                $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
                
@@ -5846,7 +6215,7 @@ from_clause
          }
          expression_or_error
          {
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                var sn = new Linq.RangeVariable (lt.Value, lt.Location);
 
                $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
@@ -5928,15 +6297,29 @@ select_or_group_clause
          
                current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
-         BY expression_or_error
+         by_expression
          {
-               $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
-               lbag.AddLocation ($$, GetLocation ($5));
+               var obj = (object[]) $5;
+
+               $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
+               lbag.AddLocation ($$, (Location) obj[1]);
                
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
          }
        ;
+
+by_expression
+       : BY expression_or_error
+         {
+               $$ = new object[] { $2, GetLocation ($1) };
+         }
+       | error
+         {
+               Error_SyntaxError (yyToken);
+               $$ = new object[2] { null, Location.Null };
+         }
+       ;
        
 query_body_clauses
        : query_body_clause
@@ -5962,7 +6345,7 @@ let_clause
          }
          expression_or_error
          {
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var sn = new Linq.RangeVariable (lt.Value, lt.Location);
                $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
                lbag.AddLocation ($$, GetLocation ($3));
@@ -6021,7 +6404,7 @@ join_clause
                var outer_selector = linq_clause_blocks.Pop ();
                var block = linq_clause_blocks.Pop ();
 
-               var lt = (Tokenizer.LocatedToken) $2;   
+               var lt = (LocatedToken) $2;     
                var sn = new Linq.RangeVariable (lt.Value, lt.Location);
                Linq.RangeVariable into;
                
@@ -6041,7 +6424,7 @@ join_clause
                        
                        ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
                
-                       lt = (Tokenizer.LocatedToken) $12;
+                       lt = (LocatedToken) $12;
                        into = new Linq.RangeVariable (lt.Value, lt.Location);
 
                        $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));   
@@ -6083,7 +6466,7 @@ join_clause
                var outer_selector = linq_clause_blocks.Pop ();
                var block = linq_clause_blocks.Pop ();
                
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                var sn = new Linq.RangeVariable (lt.Value, lt.Location);
                Linq.RangeVariable into;
                
@@ -6104,7 +6487,7 @@ join_clause
                
                        ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
                
-                       lt = (Tokenizer.LocatedToken) $13;
+                       lt = (LocatedToken) $13;
                        into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
                        
                        $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
@@ -6227,7 +6610,7 @@ opt_query_continuation
          query_body
          {
                var current_block = linq_clause_blocks.Pop ();    
-               var lt = (Tokenizer.LocatedToken) $2;
+               var lt = (LocatedToken) $2;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
                $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
                        next = (Linq.AQueryClause)$4
@@ -6332,7 +6715,7 @@ doc_cref
          {
                module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
                module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
-               var lt = (Tokenizer.LocatedToken) $3;
+               var lt = (LocatedToken) $3;
                $$ = new MemberName (lt.Value);
          }
        | doc_type_declaration_name DOT THIS
@@ -6449,7 +6832,7 @@ void Error_ExpectingTypeName (Expression expr)
        if (expr is Invocation){
                report.Error (1002, expr.Location, "Expecting `;'");
        } else {
-               Expression.Error_InvalidExpressionStatement (report, expr.Location);
+               expr.Error_InvalidExpressionStatement (report);
        }
 }
 
@@ -6490,6 +6873,16 @@ void Error_MissingInitializer (Location loc)
        report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
 }
 
+object Error_AwaitAsIdentifier (object token)
+{
+       if (async_block) {
+               report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
+               return new LocatedToken ("await", GetLocation (token));
+       }
+
+       return token;
+}
+
 void push_current_container (TypeDefinition tc, object partial_token)
 {
        if (module.Evaluator != null){
@@ -6532,6 +6925,23 @@ void StoreModifierLocation (object token, Location loc)
        mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
 }
 
+[System.Diagnostics.Conditional ("FULL_AST")]
+void PushLocation (Location loc)
+{
+       if (location_stack == null)
+               location_stack = new Stack<Location> ();
+
+       location_stack.Push (loc);
+}
+
+Location PopLocation ()
+{
+       if (location_stack == null)
+               return Location.Null;
+
+       return location_stack.Pop ();
+}
+
 string CheckAttributeTarget (string a, Location l)
 {
        switch (a) {
@@ -6619,7 +7029,8 @@ public void parse ()
                }
                        
                if (e is yyParser.yyException) {
-                       report.Error (-25, lexer.Location, "Parsing error");
+                       if (report.Errors == 0)
+                               report.Error (-25, lexer.Location, "Parsing error");
                } else {
                        // Used by compiler-tester to test internal errors
                        if (yacc_verbose_flag > 0 || e is FatalException)
@@ -6653,7 +7064,7 @@ void FeatureIsNotAvailable (Location loc, string feature)
 
 Location GetLocation (object obj)
 {
-       var lt = obj as Tokenizer.LocatedToken;
+       var lt = obj as LocatedToken;
        if (lt != null)
                return lt.Location;
                
@@ -6730,7 +7141,7 @@ AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
        retval = current_anonymous_method;
 
        async_block = (bool) oob_stack.Pop ();
-       current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
+       current_variable = (BlockVariable) oob_stack.Pop ();
        current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
        current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
 
@@ -6754,6 +7165,10 @@ void Error_SyntaxError (int error_code, int token, string msg)
        // An error message has been reported by tokenizer
        if (token == Token.ERROR)
                return;
+       
+       // Avoid duplicit error message after unterminated string literals
+       if (token == Token.LITERAL && lexer.Location.Column == 0)
+               return;
 
        string symbol = GetSymbolName (token);
        string expecting = GetExpecting ();
@@ -6835,7 +7250,7 @@ string GetSymbolName (int token)
        case Token.LITERAL:
                return ((Constant)lexer.Value).GetValue ().ToString ();
        case Token.IDENTIFIER:
-               return ((Tokenizer.LocatedToken)lexer.Value).Value;
+               return ((LocatedToken)lexer.Value).Value;
 
        case Token.BOOL:
                return "bool";