2010-06-02 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / cs-parser.jay
index 18c8c57b1899ab1729223ae23dc016495a2e4b03..adccfdf4da46cdb75f6113233ba148aefd1cf8d9 100644 (file)
@@ -54,7 +54,6 @@ namespace Mono.CSharp
 
                Delegate   current_delegate;
                
-               GenericMethod current_generic_method;
                AnonymousMethodExpression current_anonymous_method;
 
                /// <summary>
@@ -135,7 +134,7 @@ namespace Mono.CSharp
                //
                public Undo undo;
                
-               Stack<Block> linq_clause_blocks;
+               Stack<Linq.QueryBlock> linq_clause_blocks;
 
                // A counter to create new class names in interactive mode
                static int class_count;
@@ -1273,7 +1272,6 @@ method_declaration
                        Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
                }
 
-               current_generic_method = null;
                current_local_parameters = null;
 
                if (RootContext.Documentation != null)
@@ -1300,24 +1298,25 @@ method_header
                MemberName name = (MemberName) $4;
                current_local_parameters = (ParametersCompiled) $7;
 
-               if ($10 != null && name.TypeArguments == null)
-                       Report.Error (80, lexer.Location,
-                                     "Constraints are not allowed on non-generic declarations");
-
-               Method method;
-
                GenericMethod generic = null;
                if (name.TypeArguments != null) {
                        generic = new GenericMethod (current_namespace, current_class, name,
                                                     (FullNamedExpression) $3, current_local_parameters);
 
                        generic.SetParameterInfo ((List<Constraints>) $10);
+               } else if ($10 != null) {
+                       Report.Error (80, GetLocation ($10),
+                               "Constraints are not allowed on non-generic declarations");
                }
 
-               method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
+               Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
                                     name, current_local_parameters, (Attributes) $1);
-
-               current_generic_method = generic;
+                                    
+               if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
+                       Report.Error (460, method.Location,
+                               "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
+                               method.GetSignatureForError ());
+               }
 
                if (RootContext.Documentation != null)
                        method.DocComment = Lexer.consume_doc_comment ();
@@ -1379,8 +1378,6 @@ method_header
                method = new Method (current_class, generic, TypeManager.system_void_expr,
                                     modifiers, name, current_local_parameters, (Attributes) $1);
 
-               current_generic_method = generic;
-
                if (RootContext.Documentation != null)
                        method.DocComment = Lexer.consume_doc_comment ();
 
@@ -2944,8 +2941,9 @@ type_list
 base_type_name
        : type
          {
-               if ($1 is ComposedCast)
+               if ($1 is ComposedCast) {
                        Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
+               }
                $$ = $1;
          }
        | error
@@ -2981,14 +2979,6 @@ integral_type
        | CHAR          { $$ = TypeManager.system_char_expr; }
        ;
 
-predefined_type
-       : builtin_types
-       | VOID
-         {
-               $$ = TypeManager.system_void_expr;      
-         }
-       ;
-
 //
 // Expressions, section 7.5
 //
@@ -3004,7 +2994,7 @@ primary_expression_no_array_creation
        | IDENTIFIER opt_type_argument_list
          {
                var lt = (Tokenizer.LocatedToken) $1;
-               $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);          
+               $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);   
          }
        | IDENTIFIER GENERATE_COMPLETION {
                var lt = (Tokenizer.LocatedToken) $1;
@@ -3078,7 +3068,7 @@ member_access
                var lt = (Tokenizer.LocatedToken) $3;
                $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
          }
-       | predefined_type DOT IDENTIFIER opt_type_argument_list
+       | builtin_types DOT IDENTIFIER opt_type_argument_list
          {
                var lt = (Tokenizer.LocatedToken) $3;
                // TODO: Location is wrong as some predefined types doesn't hold a location
@@ -3098,12 +3088,12 @@ member_access
                var lt = (Tokenizer.LocatedToken) $3;
                $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
          }
-       | predefined_type DOT GENERATE_COMPLETION
+       | builtin_types DOT GENERATE_COMPLETION
          {
                // TODO: Location is wrong as some predefined types doesn't hold a location
                $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
          }
-       | predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
+       | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
                var lt = (Tokenizer.LocatedToken) $3;
                $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
          }
@@ -3156,6 +3146,10 @@ member_initializer_list
                a.Add ((Expression) $3);
                $$ = a;
          }
+       | member_initializer_list error {
+               Error_SyntaxError (yyToken);
+               $$ = $1;
+         }
        ;
 
 member_initializer
@@ -3177,7 +3171,10 @@ member_initializer
          }
        | OPEN_BRACE expression_list CLOSE_BRACE
          {
-               $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
+               if ($2 == null)
+                       $$ = null;
+               else
+                       $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
          }
        | OPEN_BRACE CLOSE_BRACE
          {
@@ -3229,12 +3226,12 @@ argument_list
        | argument_list COMMA
          {
                Report.Error (839, GetLocation ($2), "An argument is missing");
-               $$ = null;
+               $$ = $1;
          }
        | COMMA argument_or_named_argument
          {
                Report.Error (839, GetLocation ($1), "An argument is missing");
-               $$ = null;
+               $$ = $1;
          }
        ;
 
@@ -3326,6 +3323,10 @@ expression_list
                list.Add ((Expression) $3);
                $$ = list;
          }
+       | expression_list error {
+               Error_SyntaxError (yyToken);
+               $$ = $1;
+         }
        ;
        
 expression_list_arguments
@@ -3354,7 +3355,7 @@ expression_list_argument
 this_access
        : THIS
          {
-               $$ = new This (current_block, GetLocation ($1));
+               $$ = new This (GetLocation ($1));
          }
        ;
 
@@ -3550,7 +3551,7 @@ rank_specifiers
        : rank_specifier
        | rank_specifier rank_specifiers
          {
-               $$ = (string) $2 + (string) $1;
+               $$ = (string) $1 + (string) $2;
          }
        ;
 
@@ -3654,14 +3655,14 @@ unbound_type_name
          {  
                var lt = (Tokenizer.LocatedToken) $1;
 
-               $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
+               $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
          }
        | qualified_alias_member IDENTIFIER generic_dimension
          {
                var lt1 = (Tokenizer.LocatedToken) $1;
                var lt2 = (Tokenizer.LocatedToken) $2;
 
-               $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
+               $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
          }
        | unbound_type_name DOT IDENTIFIER
          {
@@ -3673,14 +3674,14 @@ unbound_type_name
          {
                var lt = (Tokenizer.LocatedToken) $3;
                
-               $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);         
+               $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);               
          }
        | namespace_or_type_name DOT IDENTIFIER generic_dimension
          {
                var lt = (Tokenizer.LocatedToken) $3;
                MemberName name = (MemberName) $1;
 
-               $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);               
+               $$ = new MemberAccess (name.GetTypeExpression (), lt.Value, (int) $4, lt.Location);             
          }
        ;
 
@@ -3797,7 +3798,7 @@ cast_expression
          {
                $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
          }
-       | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
+       | OPEN_PARENS builtin_types CLOSE_PARENS prefixed_unary_expression
          {
                $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
          }
@@ -4345,6 +4346,9 @@ type_parameter_constraints
 type_parameter_constraint
        : type
          {
+               if ($1 is ComposedCast)
+                       Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
+         
                $$ = $1;
          }
        | NEW OPEN_PARENS CLOSE_PARENS
@@ -4540,7 +4544,7 @@ embedded_statement
 empty_statement
        : SEMICOLON
          {
-                 $$ = EmptyStatement.Value;
+               $$ = new EmptyStatement (GetLocation ($1));
          }
        ;
 
@@ -4753,7 +4757,7 @@ interactive_statement_expression
        | error
          {
                Error_SyntaxError (yyToken);
-               $$ = EmptyStatement.Value;
+               $$ = new EmptyStatement (GetLocation ($1));
          }
        ;
        
@@ -4766,27 +4770,20 @@ if_statement
        : IF open_parens_any boolean_expression CLOSE_PARENS 
          embedded_statement
          { 
-               Location l = GetLocation ($1);
-
-               $$ = new If ((BooleanExpression) $3, (Statement) $5, l);
-
-               // FIXME: location for warning should be loc property of $5.
-               if ($5 == EmptyStatement.Value)
-                       Report.Warning (642, 3, l, "Possible mistaken empty statement");
-
+               if ($5 is EmptyStatement)
+                       Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
+               
+               $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
          }
        | IF open_parens_any boolean_expression CLOSE_PARENS
          embedded_statement ELSE embedded_statement
          {
-               Location l = GetLocation ($1);
-
-               $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, l);
+               $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
 
-               // 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");
+               if ($5 is EmptyStatement)
+                       Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
+               if ($7 is EmptyStatement)
+                       Report.Warning (642, 3, GetLocation ($7), "Possible mistaken empty statement");
          }
        ;
 
@@ -4958,7 +4955,7 @@ for_statement
        ;
 
 opt_for_initializer
-       : /* empty */           { $$ = EmptyStatement.Value; }
+       : /* empty */           { $$ = new EmptyStatement (lexer.Location); }
        | for_initializer       
        ;
 
@@ -4973,7 +4970,7 @@ opt_for_condition
        ;
 
 opt_for_iterator
-       : /* empty */           { $$ = EmptyStatement.Value; }
+       : /* empty */           { $$ = new EmptyStatement (lexer.Location); }
        | for_iterator
        ;
 
@@ -5441,66 +5438,78 @@ query_expression
 first_from_clause
        : FROM_FIRST IDENTIFIER IN expression
          {
-               $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
-               var lt = (Tokenizer.LocatedToken) $2;
-               current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+         
+               var lt = (Tokenizer.LocatedToken) $2;     
+               $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
          }
        | FROM_FIRST type IDENTIFIER IN expression
          {
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+         
                var lt = (Tokenizer.LocatedToken) $3;
-               $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
-               current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+               $$ = new Linq.QueryExpression (
+                       new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
+                               IdentifierType = (FullNamedExpression)$2
+                       }
+               );
          }
        ;
 
 nested_from_clause
        : FROM IDENTIFIER IN expression
          {
-               $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
-               var lt = (Tokenizer.LocatedToken) $2;
-               current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+         
+               var lt = (Tokenizer.LocatedToken) $2;     
+               $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
          }
        | FROM type IDENTIFIER IN expression
          {
-               $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+         
                var lt = (Tokenizer.LocatedToken) $3;
-               current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+               $$ = new Linq.QueryExpression (
+                       new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
+                               IdentifierType = (FullNamedExpression)$2
+                       }
+               );
          }
        ;
        
 from_clause
        : FROM IDENTIFIER IN
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
          }
          expression
          {
                var lt = (Tokenizer.LocatedToken) $2;
                var sn = new SimpleMemberName (lt.Value, lt.Location);
-               $$ = new Linq.SelectMany (current_block.Toplevel, sn, (Expression)$5);
+               $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
                
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
                
-               ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
+               ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
          }       
        | FROM type IDENTIFIER IN
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
          }
          expression
          {
                var lt = (Tokenizer.LocatedToken) $3;
                var sn = new SimpleMemberName (lt.Value, lt.Location);
 
-               FullNamedExpression type = (FullNamedExpression)$2;
-               
-               $$ = new Linq.SelectMany (current_block.Toplevel, sn, new Linq.Cast (type, (FullNamedExpression)$6));
+               $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
+                       IdentifierType = (FullNamedExpression)$2
+               };
                
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
                
-               ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
+               ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
          }
        ;       
 
@@ -5530,7 +5539,7 @@ select_or_group_clause
          }
          expression
          {
-               $$ = new Linq.Select (current_block.Toplevel, (Expression)$3, GetLocation ($1));
+               $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
 
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
@@ -5538,10 +5547,10 @@ select_or_group_clause
        | GROUP
          {
                if (linq_clause_blocks == null)
-                       linq_clause_blocks = new Stack<Block> ();
+                       linq_clause_blocks = new Stack<Linq.QueryBlock> ();
                        
                current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
-               linq_clause_blocks.Push (current_block);
+               linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
          }
          expression
          {
@@ -5552,7 +5561,7 @@ select_or_group_clause
          }
          BY expression
          {
-               $$ = new Linq.GroupBy (current_block.Toplevel, (Expression)$3, (ToplevelBlock) linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
+               $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
                
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
@@ -5584,18 +5593,18 @@ query_body_clause
 let_clause
        : LET IDENTIFIER ASSIGN 
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
          }
          expression
          {
                var lt = (Tokenizer.LocatedToken) $2;
                var sn = new SimpleMemberName (lt.Value, lt.Location);
-               $$ = new Linq.Let (current_block.Toplevel, current_container, sn, (Expression)$5);
+               $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
                
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
                
-               ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
+               ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
          }
        ;
 
@@ -5606,7 +5615,7 @@ where_clause
          }
          boolean_expression
          {
-               $$ = new Linq.Where (current_block.Toplevel, (BooleanExpression)$3, GetLocation ($1));
+               $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
 
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
@@ -5617,10 +5626,10 @@ join_clause
        : JOIN IDENTIFIER IN
          {
                if (linq_clause_blocks == null)
-                       linq_clause_blocks = new Stack<Block> ();
+                       linq_clause_blocks = new Stack<Linq.QueryBlock> ();
                        
                current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
-               linq_clause_blocks.Push (current_block);
+               linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression ON
          {
@@ -5628,7 +5637,7 @@ join_clause
                current_block = current_block.Parent;
 
                current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
-               linq_clause_blocks.Push (current_block);
+               linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression EQUALS
          {
@@ -5636,8 +5645,7 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               var lt = (Tokenizer.LocatedToken) $2;
-               current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location);
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
          }
          expression opt_join_into
          {
@@ -5645,15 +5653,15 @@ join_clause
                var sn = new SimpleMemberName (lt.Value, lt.Location);
                SimpleMemberName sn2 = null;
                
-               ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
-               ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
+               var outer_selector = linq_clause_blocks.Pop ();
+               var block = linq_clause_blocks.Pop ();
 
                if ($12 == null) {
-                       $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
+                       $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
                } else {
                        var lt2 = (Tokenizer.LocatedToken) $12;
                        sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
-                       $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, current_block.Toplevel,
+                       $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block,
                                sn2, GetLocation ($1));
                }
 
@@ -5661,18 +5669,15 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
                        
-               if (sn2 == null)
-                       ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
-               else
-                       ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2);
+               ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
          }
        | JOIN type IDENTIFIER IN
          {
                if (linq_clause_blocks == null)
-                       linq_clause_blocks = new Stack<Block> ();
+                       linq_clause_blocks = new Stack<Linq.QueryBlock> ();
                        
                current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
-               linq_clause_blocks.Push (current_block);
+               linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression ON
          {
@@ -5680,7 +5685,7 @@ join_clause
                current_block = current_block.Parent;
 
                current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
-               linq_clause_blocks.Push (current_block);
+               linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression EQUALS
          {
@@ -5688,35 +5693,33 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               var lt = (Tokenizer.LocatedToken) $3;
-               current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location);
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
          }
          expression opt_join_into
          {
                var lt = (Tokenizer.LocatedToken) $3;
                var sn = new SimpleMemberName (lt.Value, lt.Location);
                SimpleMemberName sn2 = null;
-               ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
-               ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
+               var outer_selector = linq_clause_blocks.Pop ();
+               var block = linq_clause_blocks.Pop ();
                
-               Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
                if ($13 == null) {
-                       $$ = new Linq.Join (block, sn, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
+                       $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
+                               IdentifierType = (FullNamedExpression)$2
+                       };
                } else {
                        var lt2 = (Tokenizer.LocatedToken) $13;
                        sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
-                       $$ = new Linq.GroupJoin (block, sn, cast, outer_selector, current_block.Toplevel,
-                               sn2, GetLocation ($1));
+                       $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, sn2, GetLocation ($1)) {
+                               IdentifierType = (FullNamedExpression)$2
+                       };                      
                }
                
                current_block.AddStatement (new ContextualReturn ((Expression) $12));
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
                        
-               if (sn2 == null)
-                       ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
-               else
-                       ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2);
+               ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
          }
        ;
        
@@ -5765,11 +5768,11 @@ orderings_then_by
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
          
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);   
+               current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);         
         }
         then_by
         {
-               ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
+               ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
                $$ = $1;
         }
        ;       
@@ -5777,30 +5780,30 @@ orderings_then_by
 order_by
        : expression
          {
-               $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);        
+               $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);       
          }
        | expression ASCENDING
          {
-               $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);        
+               $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);       
          }
        | expression DESCENDING
          {
-               $$ = new Linq.OrderByDescending (current_block.Toplevel, (Expression)$1);       
+               $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);      
          }
        ;
 
 then_by
        : expression
          {
-               $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1); 
+               $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);        
          }
        | expression ASCENDING
          {
-               $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1); 
+               $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);        
          }
        | expression DESCENDING
          {
-               $$ = new Linq.ThenByDescending (current_block.Toplevel, (Expression)$1);        
+               $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);       
          }     
        ;
 
@@ -5815,14 +5818,21 @@ opt_query_continuation
 
                current_block.SetEndLocation (GetLocation ($1));
                current_block = current_block.Parent;
-
-               var lt = (Tokenizer.LocatedToken) $2;
+       
+               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
                
-               current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+               if (linq_clause_blocks == null)
+                       linq_clause_blocks = new Stack<Linq.QueryBlock> ();
+                       
+               linq_clause_blocks.Push ((Linq.QueryBlock) current_block);              
          }
          query_body
          {
-               $$ = new Linq.QueryExpression (current_block, (Linq.AQueryClause)$4);
+               var current_block = linq_clause_blocks.Pop ();    
+               var lt = (Tokenizer.LocatedToken) $2;
+               $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
+                       next = (Linq.AQueryClause)$4
+               };
          }
        ;
        
@@ -6284,6 +6294,9 @@ Location GetLocation (object obj)
        if (obj is MemberName)
                return ((MemberName) obj).Location;
 
+//     if (obj is Expression)
+//             return ((Expression) obj).Location;             
+
        return lexer.Location;
 }
 
@@ -6294,7 +6307,7 @@ Report Report {
 void start_block (Location loc)
 {
        if (current_block == null || parsing_anonymous_method) {
-               current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, current_generic_method, loc);
+               current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, loc);
                parsing_anonymous_method = false;
        } else {
                current_block = new ExplicitBlock (current_block, loc, Location.Null);