2002-08-19 Martin Baulig <martin@gnome.org>
[mono.git] / mcs / mcs / cs-parser.jay
index a40a1b17f8cf00a900c5fd54c2c8bb859d26319e..49b08716d9edced03471596cda0b062a7d981d52 100755 (executable)
@@ -2,26 +2,18 @@
 //
 // cs-parser.jay: The Parser for the C# compiler
 //
-// Author: Miguel de Icaza (miguel@gnu.org)
+// Authors: Miguel de Icaza (miguel@gnu.org)
+//          Ravi Pratap     (ravi@ximian.com)
 //
 // Licensed under the terms of the GNU GPL
 //
 // (C) 2001 Ximian, Inc (http://www.ximian.com)
 //
 // TODO:
-//   (1) Get rid of the *Collections.cs, that is an idea I took from System.CodeDOM
-//       And come to think of it, it is not that great, it duplicates a lot of code
-//       for something which is not really needed.  We still have piles of typecasts
-//       anwyays (due to the nature of the stack being a collection of Objects).
-//
-//   (2) Figure out why error productions dont work.  `type-declaration' is a
+//   (1) Figure out why error productions dont work.  `type-declaration' is a
 //       great spot to put an `error' because you can reproduce it with this input:
 //      "public X { }"
 //
-//   (3) Move Modifier checking from each object into the parser itself, that will
-//       get rid of the global "error" symbol that we use now to report errors. 
-//       We still need to pass a pointer to the tree.ErrorHandler, but that is a 
-//      separate problem
 //
 using System.Text;
 using System;
@@ -63,7 +55,7 @@ namespace Mono.CSharp
                //   value parameter that is passed to the "set" and "get"accesor
                //   methods (properties and indexers).
                // </summary>
-               string     implicit_value_parameter_type;
+               Expression implicit_value_parameter_type;
                Parameters indexer_parameters;
 
                // <summary>
@@ -72,18 +64,15 @@ namespace Mono.CSharp
                // </summmary>
                bool  parsing_indexer;
 
-               // <summary>
-               //   Used to record all types defined
-               // </summary>
-               Tree tree;
-
                //
                // An out-of-band stack.
                //
                Stack oob_stack;
 
-               RootContext rc;
-
+               //
+               // Switch stack.
+               //
+               Stack switch_stack;
 %}
 
 %token EOF
@@ -97,6 +86,7 @@ namespace Mono.CSharp
 %token ABSTRACT        
 %token AS
 %token ADD
+%token ASSEMBLY
 %token BASE    
 %token BOOL    
 %token BREAK   
@@ -153,6 +143,7 @@ namespace Mono.CSharp
 %token SEALED  
 %token SHORT   
 %token SIZEOF  
+%token STACKALLOC
 %token STATIC  
 %token STRING  
 %token STRUCT  
@@ -170,6 +161,7 @@ namespace Mono.CSharp
 %token USING   
 %token VIRTUAL 
 %token VOID    
+%token VOLATILE
 %token WHILE   
 
 /* C# keywords which are not really keywords */
@@ -256,16 +248,29 @@ namespace Mono.CSharp
 %nonassoc HIGHPREC
 
 %start compilation_unit
-/*%start namespace_declaration */
 %%
 
 compilation_unit
-       : opt_using_directives opt_namespace_member_declarations EOF
-         {
-               // Check that using comes only before namespace elements
-         }
+        : outer_declarations opt_EOF
+        | outer_declarations attribute_sections opt_EOF
+        | attribute_sections opt_EOF
+        ;
+       
+opt_EOF
+       : /* empty */
+       | EOF
        ;
 
+outer_declarations
+        : outer_declaration
+        | outer_declarations outer_declaration
+        ;
+outer_declaration
+        : using_directive
+        | namespace_member_declaration
+        ;
+  
 using_directives
        : using_directive 
        | using_directives using_directive
@@ -280,26 +285,36 @@ using_alias_directive
        : USING IDENTIFIER ASSIGN 
          namespace_or_type_name SEMICOLON
          {
-                 // FIXME : Need to implement actual action.
+                 current_namespace.UsingAlias ((string) $2, (string) $4, lexer.Location);
          }
        ;
 
 using_namespace_directive
        : USING namespace_name SEMICOLON 
          {
-               current_namespace.Using ((string) $2);
+               current_namespace.Using ((string) $2, lexer.Location);
           }
        ;
 
-//  namespace_declarations
-//     : namespace_declaration
-//     | namespace_declarations namespace_declaration
-
+//
+// Strictly speaking, namespaces don't have attributes but
+// we parse global attributes along with namespace declarations and then
+// detach them
+// 
 namespace_declaration
-       : NAMESPACE qualified_identifier 
-         {
-               current_namespace = tree.RecordNamespace (current_namespace, (string) $2);
-         } 
+       : opt_attributes NAMESPACE qualified_identifier 
+       {
+               Attributes attrs = (Attributes) $1;
+
+               if (attrs != null) {
+                       foreach (AttributeSection asec in attrs.AttributeSections)
+                               if (asec.Target == "assembly")
+                                       RootContext.AddGlobalAttribute (
+                                               current_container, asec, lexer.Location);
+               }
+
+               current_namespace = RootContext.Tree.RecordNamespace (current_namespace, name, (string) $3);
+       } 
          namespace_body opt_semicolon
          { 
                current_namespace = current_namespace.Parent;
@@ -354,8 +369,8 @@ namespace_member_declarations
 namespace_member_declaration
        : type_declaration
          {
-               int mod_flags = 0;
                string name = "";
+               int mod_flags;
 
                if ($1 is Class){
                        Class c = (Class) $1;
@@ -368,12 +383,13 @@ namespace_member_declaration
                } else
                        break;
 
-               //
-               // We remove this error until we can 
-               //if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
-               //      error (1527, "Namespace elements cant be explicitly " +
-               //                   "declared private or protected in `" + name + "'");
-               //}
+               if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
+                       Report.Error (
+                               1527, lexer.Location, 
+                               "Namespace elements cant be explicitly " +
+                               "declared private or protected in `" + name + "'");
+               }
+               current_namespace.DeclarationFound = true;
          }
        | namespace_declaration
        ;
@@ -383,23 +399,46 @@ type_declaration
        | struct_declaration            
        | interface_declaration         
        | enum_declaration              
-       | delegate_declaration         
+       | delegate_declaration
+//
+// Enable this when we have handled all errors, because this acts as a generic fallback
+//
+//     | error {
+//             Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
+//       }
        ;
 
 //
 // Attributes 17.2
 //
+
 opt_attributes
-       : /* empty */ { $$ = null; }
-       | attribute_section opt_attributes
+        : /* empty */
+       | attribute_sections { $$ = $1; }
+        ;
+attribute_sections
+       : attribute_section
+          {
+               AttributeSection sect = (AttributeSection) $1;
+
+               if (sect.Target == "assembly")
+                       RootContext.AddGlobalAttribute (current_container, sect, lexer.Location);
+                 
+               $$ = new Attributes ((AttributeSection) $1, lexer.Location);
+          }
+       | attribute_sections attribute_section
          {
-               Attributes attrs;
-               
-               if ($2 != null) {
-                       attrs = (Attributes) $2;
-                       attrs.AddAttribute ((AttributeSection) $1);
-               } else
-                       attrs = new Attributes ((AttributeSection) $1);
+               Attributes attrs = null;
+               AttributeSection sect = (AttributeSection) $2;
+
+               if (sect.Target == "assembly")
+                       RootContext.AddGlobalAttribute (current_container, sect, lexer.Location);
+
+               if ($1 != null) {
+                       attrs = (Attributes) $1;
+                       attrs.AddAttribute (sect);
+               }
                
                $$ = attrs;
          }
@@ -481,12 +520,16 @@ opt_attribute_arguments
 
 
 attribute_arguments
-       : positional_argument_list
+       : opt_positional_argument_list
          {
-               ArrayList args = new ArrayList ();
-               args.Add ($1);
+               if ($1 == null)
+                       $$ = null;
+               else {
+                       ArrayList args = new ArrayList ();
+                       args.Add ($1);
                
-               $$ = args;
+                       $$ = args;
+               }
          }
         | positional_argument_list COMMA named_argument_list
          {
@@ -507,6 +550,11 @@ attribute_arguments
         ;
 
 
+opt_positional_argument_list
+       : /* empty */           { $$ = null; } 
+       | positional_argument_list
+       ;
+
 positional_argument_list
        : expression
          {
@@ -587,38 +635,27 @@ struct_declaration
                Struct new_struct;
                string full_struct_name = MakeName ((string) $4);
 
-               new_struct = new Struct (rc, current_container, full_struct_name, (int) $2, 
+               new_struct = new Struct (current_container, full_struct_name, (int) $2, 
                                         (Attributes) $1, lexer.Location);
                current_container = new_struct;
                current_container.Namespace = current_namespace;
-               tree.RecordStruct (full_struct_name, new_struct);
+               RootContext.Tree.RecordDecl (full_struct_name, new_struct);
          }
-         opt_struct_interfaces
+         opt_class_base
          struct_body
          opt_semicolon
          {
                Struct new_struct = (Struct) current_container;
 
+               if ($6 != null)
+                       new_struct.Bases = (ArrayList) $6;
+
                current_container = current_container.Parent;
-               CheckDef (current_container.AddStruct (new_struct), new_struct.Name);
+               CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
                $$ = new_struct;
          }
        ;
 
-opt_struct_interfaces
-       : /* empty */
-       | struct_interfaces
-       ;
-
-struct_interfaces
-       : struct_interface
-       | struct_interfaces struct_interface
-       ; 
-
-struct_interface
-       : COLON type_list
-       ;
-
 struct_body
        : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
        ;
@@ -660,12 +697,14 @@ constant_declaration
          SEMICOLON
          {
                foreach (VariableDeclaration constant in (ArrayList) $5){
-                       Constant c = new Constant (
-                               (string) $4, (string) constant.identifier, 
-                               (Expression) constant.expression_or_array_initializer, (int) $2, (Attributes) $1,
-                               constant.Location);
+                       Location l = constant.Location;
 
-                       CheckDef (current_container.AddConstant (c), c.Name);
+                       Const c = new Const (
+                               (Expression) $4, (string) constant.identifier, 
+                               (Expression) constant.expression_or_array_initializer, (int) $2, 
+                               (Attributes) $1, l);
+
+                       CheckDef (current_container.AddConstant (c), c.Name, l);
                }
          }
        ;
@@ -699,14 +738,17 @@ field_declaration
          variable_declarators
          SEMICOLON
          { 
-               string type = (string) $3;
+               Expression type = (Expression) $3;
                int mod = (int) $2;
 
                foreach (VariableDeclaration var in (ArrayList) $4){
+                       Location l = var.Location;
+
                        Field field = new Field (type, mod, var.identifier, 
-                                                var.expression_or_array_initializer, (Attributes) $1, var.Location);
+                                                var.expression_or_array_initializer, 
+                                                (Attributes) $1, l);
 
-                       CheckDef (current_container.AddField (field), field.Name);
+                       CheckDef (current_container.AddField (field), field.Name, l);
                }
          }
        ;
@@ -743,9 +785,13 @@ variable_initializer
                $$ = $1;
          }
        | array_initializer
-       {
+         {
                $$ = $1;
-       }
+         }
+       | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
+         {
+               $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
+         }
        ;
 
 method_declaration
@@ -754,23 +800,48 @@ method_declaration
          {
                Method method = (Method) $1;
                Block b = (Block) $2;
-               
+               const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
+
                if (b == null){
-                       if ((method.ModFlags & (Modifiers.EXTERN | Modifiers.ABSTRACT)) == 0){
+                       if ((method.ModFlags & extern_abstract) == 0){
                                Report.Error (
-                                       501, lexer.Location, "`" + 
-                                       current_container.Name + "." + method.Name + "'" +
+                                       501, lexer.Location,  current_container.MakeName (method.Name) +
                                        "must declare a body because it is not marked abstract or extern");
                        }
+               } else {
+                       if ((method.ModFlags & Modifiers.EXTERN) != 0){
+                               Report.Error (
+                                       179, lexer.Location, current_container.MakeName (method.Name) +
+                                       " is declared extern, but has a body");
+                       }
                }
 
                method.Block = (Block) $2;
-               CheckDef (current_container.AddMethod (method), method.Name);
+               CheckDef (current_container.AddMethod (method), method.Name, method.Location);
 
                current_local_parameters = null;
          }
        ;
 
+opt_error_modifier
+       : /* empty */
+       | modifiers 
+         {
+               int m = (int) $1;
+               int i = 1;
+
+               while (m != 0){
+                       if ((i & m) != 0){
+                               Report.Error (
+                                       1585, lexer.Location, "Member modifier `" + 
+                                       Modifiers.Name (i) + "' must precede member type and name");
+                       }
+                       m &= ~i;
+                       i = i << 1;
+               }
+         }
+       ;
+
 method_header
        : opt_attributes
          opt_modifiers
@@ -778,7 +849,7 @@ method_header
          member_name
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
          {
-               Method method = new Method ((string) $3, (int) $2, (string) $4, 
+               Method method = new Method ((Expression) $3, (int) $2, (string) $4, 
                                            (Parameters) $6, (Attributes) $1, lexer.Location);
 
                current_local_parameters = (Parameters) $6;
@@ -791,7 +862,7 @@ method_header
          member_name
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
          {
-               Method method = new Method ("System.Void", (int) $2, (string) $4, 
+               Method method = new Method (TypeManager.system_void_expr, (int) $2, (string) $4, 
                                            (Parameters) $6, (Attributes) $1, lexer.Location);
 
                current_local_parameters = (Parameters) $6;
@@ -805,7 +876,7 @@ method_body
        ;
 
 opt_formal_parameter_list
-       : /* empty */                   { $$ = Parameters.GetEmptyReadOnlyParameters (); }
+       : /* empty */                   { $$ = Parameters.EmptyReadOnlyParameters; }
        | formal_parameter_list
        ;
 
@@ -817,7 +888,7 @@ formal_parameter_list
                Parameter [] pars = new Parameter [pars_list.Count];
                pars_list.CopyTo (pars);
 
-               $$ = new Parameters (pars, null); 
+               $$ = new Parameters (pars, null, lexer.Location); 
          } 
        | fixed_parameters COMMA parameter_array
          {
@@ -826,11 +897,11 @@ formal_parameter_list
                Parameter [] pars = new Parameter [pars_list.Count];
                pars_list.CopyTo (pars);
 
-               $$ = new Parameters (pars, (Parameter) $3); 
+               $$ = new Parameters (pars, (Parameter) $3, lexer.Location); 
          }
        | parameter_array 
          {
-               $$ = new Parameters (null, (Parameter) $1);
+               $$ = new Parameters (null, (Parameter) $1, lexer.Location);
          }
        ;
 
@@ -857,7 +928,7 @@ fixed_parameter
          type
          IDENTIFIER
          {
-               $$ = new Parameter ((string) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
+               $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
          }
        ;
 
@@ -867,14 +938,14 @@ opt_parameter_modifier
        ;
 
 parameter_modifier
-       : REF                   { $$ = Parameter.Modifier.REF; }
-       | OUT                   { $$ = Parameter.Modifier.OUT; }
+       : REF                   { $$ = Parameter.Modifier.REF | Parameter.Modifier.ISBYREF; }
+       | OUT                   { $$ = Parameter.Modifier.OUT | Parameter.Modifier.ISBYREF; }
        ;
 
 parameter_array
        : opt_attributes PARAMS type IDENTIFIER
          { 
-               $$ = new Parameter ((string) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
+               $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
                note ("type must be a single-dimension array type"); 
          }
        ;
@@ -889,32 +960,28 @@ property_declaration
          type member_name
          OPEN_BRACE 
          {
-               implicit_value_parameter_type = (string) $3;
+               implicit_value_parameter_type = (Expression) $3;
 
-               lexer.properties = true;
+               lexer.PropertyParsing = true;
 
                $$ = lexer.Location;
          }
          accessor_declarations 
          {
-               lexer.properties = false;
+               lexer.PropertyParsing = false;
          }
          CLOSE_BRACE
          { 
                Property prop;
-               DictionaryEntry pair = (DictionaryEntry) $7;
-               Block get_block = null;
-               Block set_block = null;
-
-               if (pair.Key != null)
-                       get_block = (Block) pair.Key;
-               if (pair.Value != null)
-                       set_block = (Block) pair.Value;
+               Pair pair = (Pair) $7;
+               Accessor get_block = (Accessor) pair.First;
+               Accessor set_block = (Accessor) pair.Second;
 
-               prop = new Property ((string) $3, (string) $4, (int) $2, get_block, set_block,
-                                    (Attributes) $1, (Location) $6);
+               Location loc = (Location) $6;
+               prop = new Property ((Expression) $3, (string) $4, (int) $2, get_block, set_block,
+                                    (Attributes) $1, loc);
                
-               CheckDef (current_container.AddProperty (prop), prop.Name);
+               CheckDef (current_container.AddProperty (prop), prop.Name, loc);
                implicit_value_parameter_type = null;
          }
        ;
@@ -922,11 +989,11 @@ property_declaration
 accessor_declarations
        : get_accessor_declaration opt_set_accessor_declaration
          { 
-               $$ = new DictionaryEntry ($1, $2);
+               $$ = new Pair ($1, $2);
          }
        | set_accessor_declaration opt_get_accessor_declaration
          {
-               $$ = new DictionaryEntry ($2, $1);
+               $$ = new Pair ($2, $1);
          }
        ;
 
@@ -949,13 +1016,13 @@ get_accessor_declaration
                        current_local_parameters = null;
                else 
                        current_local_parameters = indexer_parameters;
-
-               
+               lexer.PropertyParsing = false;
          }
           accessor_body
          {
-               $$ = $4;
+               $$ = new Accessor ((Block) $4, (Attributes) $1);
                current_local_parameters = null;
+               lexer.PropertyParsing = true;
          }
        ;
 
@@ -970,27 +1037,35 @@ set_accessor_declaration
                if (parsing_indexer == false) {
                        args  = new Parameter [1];
                        args [0] = implicit_value_parameter;
+                       current_local_parameters = new Parameters (args, null, lexer.Location);
                } else {
-                       Parameter [] fp = indexer_parameters.FixedParameters;
-                       int count = fp.Length;
-
-                       args = new Parameter [count + 1];
-       
-                       fp.CopyTo (args, 0);
-                       args [count] = implicit_value_parameter;
+                       Parameter [] fpars = indexer_parameters.FixedParameters;
+
+                       if (fpars != null){
+                               int count = fpars.Length;
+
+                               args = new Parameter [count + 1];
+                               fpars.CopyTo (args, 0);
+                               args [count] = implicit_value_parameter;
+                       } else 
+                               args = null;
+                       current_local_parameters = new Parameters (
+                               args, indexer_parameters.ArrayParameter, lexer.Location);
                }
-               current_local_parameters = new Parameters (args, null);
+               
+               lexer.PropertyParsing = false;
          }
          accessor_body
          {
-               $$ = $4;
+               $$ = new Accessor ((Block) $4, (Attributes) $1);
                current_local_parameters = null;
+               lexer.PropertyParsing = true;
          }
        ;
 
 accessor_body
        : block 
-       | SEMICOLON             { $$ = new Block (null); }
+       | SEMICOLON             { $$ = null; }
        ;
 
 interface_declaration
@@ -1001,17 +1076,18 @@ interface_declaration
                Interface new_interface;
                string full_interface_name = MakeName ((string) $4);
 
-               new_interface = new Interface (rc, current_container, full_interface_name, (int) $2, 
+               new_interface = new Interface (current_container, full_interface_name, (int) $2, 
                                               (Attributes) $1, lexer.Location);
                if (current_interface != null) {
                        Location l = lexer.Location;
                        Report.Error (-2, l, "Internal compiler error: interface inside interface");
                }
                current_interface = new_interface;
-               tree.RecordInterface (full_interface_name, new_interface);
+               new_interface.Namespace = current_namespace;
+               RootContext.Tree.RecordDecl (full_interface_name, new_interface);
          }
          opt_interface_base
-         interface_body
+         interface_body opt_semicolon
          { 
                Interface new_interface = (Interface) current_interface;
 
@@ -1019,7 +1095,8 @@ interface_declaration
                        new_interface.Bases = (ArrayList) $6;
 
                current_interface = null;
-               CheckDef (current_container.AddInterface (new_interface), new_interface.Name);
+               CheckDef (current_container.AddInterface (new_interface), 
+                         new_interface.Name, new_interface.Location);
          }
        ;
 
@@ -1069,25 +1146,25 @@ interface_member_declaration
          { 
                InterfaceMethod m = (InterfaceMethod) $1;
 
-               CheckDef (current_interface.AddMethod (m), m.Name);
+               CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
          }
        | interface_property_declaration        
          { 
                InterfaceProperty p = (InterfaceProperty) $1;
 
-               CheckDef (current_interface.AddProperty (p), p.Name);
+               CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
           }
        | interface_event_declaration 
           { 
                InterfaceEvent e = (InterfaceEvent) $1;
 
-               CheckDef (current_interface.AddEvent (e), e.Name);
+               CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
          }
        | interface_indexer_declaration
          { 
                InterfaceIndexer i = (InterfaceIndexer) $1;
 
-               CheckDef (current_interface.AddIndexer (i), "indexer");
+               CheckDef (current_interface.AddIndexer (i), "indexer", i.Location);
          }
        ;
 
@@ -1101,13 +1178,16 @@ interface_method_declaration
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          SEMICOLON
          {
-               $$ = new InterfaceMethod ((string) $3, (string) $4, (bool) $2, (Parameters) $6, (Attributes) $1);
+               $$ = new InterfaceMethod ((Expression) $3, (string) $4, (bool) $2, 
+                                         (Parameters) $6, (Attributes) $1, lexer.Location);
          }
        | opt_attributes opt_new VOID IDENTIFIER 
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          SEMICOLON
          {
-               $$ = new InterfaceMethod ("System.Void", (string) $4, (bool) $2, (Parameters) $6, (Attributes) $1);
+               $$ = new InterfaceMethod (
+                       TypeManager.system_void_expr, (string) $4, (bool) $2, (Parameters) $6, 
+                                         (Attributes) $1, lexer.Location);
          }
        ;
 
@@ -1116,15 +1196,16 @@ interface_property_declaration
          opt_new
          type IDENTIFIER 
          OPEN_BRACE 
-         { lexer.properties = true; }
+         { lexer.PropertyParsing = true; }
          interface_accesors 
-         { lexer.properties = false; }
+         { lexer.PropertyParsing = false; }
          CLOSE_BRACE
          {
                int gs = (int) $7;
 
-               $$ = new InterfaceProperty ((string) $3, (string) $4, (bool) $2, 
-                                           (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1);
+               $$ = new InterfaceProperty ((Expression) $3, (string) $4, (bool) $2, 
+                                           (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
+                                           lexer.Location);
          }
        ;
 
@@ -1140,7 +1221,8 @@ interface_accesors
 interface_event_declaration
        : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
          {
-               $$ = new InterfaceEvent ((string) $4, (string) $5, (bool) $2, (Attributes) $1);
+               $$ = new InterfaceEvent ((Expression) $4, (string) $5, (bool) $2, (Attributes) $1,
+                                        lexer.Location);
          }
        ;
 
@@ -1148,9 +1230,9 @@ interface_indexer_declaration
        : opt_attributes opt_new type THIS 
          OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
          OPEN_BRACE 
-         { lexer.properties = true; }
+         { lexer.PropertyParsing = true; }
          interface_accesors 
-         { lexer.properties = false; }
+         { lexer.PropertyParsing = false; }
          CLOSE_BRACE
          {
                int a_flags = (int) $10;
@@ -1158,12 +1240,13 @@ interface_indexer_declaration
                bool do_get = (a_flags & 1) == 1;
                bool do_set = (a_flags & 2) == 2;
 
-               $$ = new InterfaceIndexer ((string) $3, (Parameters) $6, do_get, do_set, (bool) $2, (Attributes) $1);
+               $$ = new InterfaceIndexer ((Expression) $3, (Parameters) $6, do_get, do_set,
+                                          (bool) $2, (Attributes) $1, lexer.Location);
          }
        ;
 
 operator_declaration
-       : opt_attributes opt_modifiers operator_declarator block
+       : opt_attributes opt_modifiers operator_declarator operator_body
          {
                OperatorDeclaration decl = (OperatorDeclaration) $3;
                
@@ -1177,6 +1260,10 @@ operator_declaration
          }
        ;
 
+operator_body 
+       : block
+       | SEMICOLON { $$ = null; }
+       ; 
 operator_declarator
        : type OPERATOR overloadable_operator 
          OPEN_PARENS type IDENTIFIER CLOSE_PARENS
@@ -1192,11 +1279,11 @@ operator_declarator
 
                Parameter [] pars = new Parameter [1];
 
-               pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
 
-               current_local_parameters = new Parameters (pars, null);
+               current_local_parameters = new Parameters (pars, null, lexer.Location);
 
-               $$ = new OperatorDeclaration (op, (string) $1, (string) $5, (string) $6,
+               $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
                                              null, null, lexer.Location);
        }
        | type OPERATOR overloadable_operator
@@ -1209,13 +1296,14 @@ operator_declarator
 
               Parameter [] pars = new Parameter [2];
 
-              pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
-              pars [1] = new Parameter ((string) $8, (string) $9, Parameter.Modifier.NONE, null);
+              pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
+              pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
 
-              current_local_parameters = new Parameters (pars, null);
+              current_local_parameters = new Parameters (pars, null, lexer.Location);
               
-              $$ = new OperatorDeclaration ((Operator.OpType) $3, (string) $1, (string) $5, (string) $6,
-                                            (string) $8, (string) $9, lexer.Location);
+              $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1, 
+                                            (Expression) $5, (string) $6,
+                                            (Expression) $8, (string) $9, lexer.Location);
         }
        | conversion_operator_declarator
        ;
@@ -1253,22 +1341,22 @@ conversion_operator_declarator
          {
                Parameter [] pars = new Parameter [1];
 
-               pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
 
-               current_local_parameters = new Parameters (pars, null);  
+               current_local_parameters = new Parameters (pars, null, lexer.Location);  
                  
-               $$ = new OperatorDeclaration (Operator.OpType.Implicit, (string) $3, (string) $5, (string) $6,
+               $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
                                              null, null, lexer.Location);
          }
        | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
          {
                Parameter [] pars = new Parameter [1];
 
-               pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
 
-               current_local_parameters = new Parameters (pars, null);  
+               current_local_parameters = new Parameters (pars, null, lexer.Location);  
                  
-               $$ = new OperatorDeclaration (Operator.OpType.Explicit, (string) $3, (string) $5, (string) $6,
+               $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
                                              null, null, lexer.Location);
          }
        | IMPLICIT error 
@@ -1285,7 +1373,7 @@ constructor_declaration
        : opt_attributes
          opt_modifiers
          constructor_declarator
-         block
+         constructor_body
          { 
                Constructor c = (Constructor) $3;
                c.Block = (Block) $4;
@@ -1294,22 +1382,25 @@ constructor_declaration
 
                if ((c.ModFlags & Modifiers.STATIC) != 0){
                        if ((c.ModFlags & Modifiers.Accessibility) != 0) {
-                               Location l = lexer.Location;
-                               Report.Error (515, l, "Access modifiers are not allowed on static constructors");
+                               Report.Error (
+                                       515, c.Location, 
+                                       "Access modifiers are not allowed on static constructors");
                        }
 
                        if (c.Initializer != null){
-                               Location l = lexer.Location;
-                               Report.Error (514, l, "Static constructors can not have an explicit this or base constructor invocations");
+                               Report.Error (
+                                       514, c.Location, 
+                                       "Static constructors can not have an explicit this or base " +
+                                       "constructor invocations");
                        }
 
                        if (!c.Parameters.Empty){
-                               Location l = lexer.Location;
-                               Report.Error (103, l, "Static constructors should not have parameters");
+                               Report.Error (
+                                       132, c.Location, "Static constructors should not have parameters");
                        }
                } 
                
-               CheckDef (current_container.AddConstructor (c), c.Name);
+               CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
 
                current_local_parameters = null;
          }
@@ -1318,14 +1409,21 @@ constructor_declaration
 constructor_declarator
        : IDENTIFIER 
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
-         opt_constructor_initializer
          {
-               Location l = lexer.Location;
+               oob_stack.Push (lexer.Location);
 
-               $$ = new Constructor ((string) $1, (Parameters) $3, (ConstructorInitializer) $5, l);
-       
                current_local_parameters = (Parameters) $3;
          }
+         opt_constructor_initializer
+         {
+               Location l = (Location) oob_stack.Pop ();
+               $$ = new Constructor ((string) $1, (Parameters) $3, (ConstructorInitializer) $6, l);
+         }
+       ;
+
+constructor_body
+       : block
+       | SEMICOLON             { $$ = null; }
        ;
 
 opt_constructor_initializer
@@ -1336,28 +1434,36 @@ opt_constructor_initializer
 constructor_initializer
        : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
          {
-               $$ = new ConstructorBaseInitializer ((ArrayList) $4, lexer.Location);
+               $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
          }
        | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
          {
-               $$ = new ConstructorThisInitializer ((ArrayList) $4, lexer.Location);
+               $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
          }
        ;
 
 destructor_declaration
        : opt_attributes TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
          {
-               if ((string) $3 != current_container.Name){
+               if ((string) $3 != current_container.Basename){
                        Report.Error (574, lexer.Location, "Name of destructor must match name of class");
                } else if (!(current_container is Class)){
                        Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
                } else {
+                       Location l = lexer.Location;
+
+                       int m;
+                       if (!RootContext.StdLib && current_container.Name == "System.Object")
+                               m = Modifiers.PROTECTED | Modifiers.VIRTUAL;
+                       else
+                               m = Modifiers.PROTECTED | Modifiers.OVERRIDE;
+
                        Method d = new Method (
-                               "System.Void", 0, "Finalize", 
-                               new Parameters (null, null), (Attributes) $1, lexer.Location);
+                               TypeManager.system_void_expr, m, "Finalize", 
+                               new Parameters (null, null, l), (Attributes) $1, l);
                  
                        d.Block = (Block) $6;
-                       CheckDef (current_container.AddMethod (d), d.Name);
+                       CheckDef (current_container.AddMethod (d), d.Name, d.Location);
                }
          }
        ;
@@ -1369,58 +1475,97 @@ event_declaration
          {
                foreach (VariableDeclaration var in (ArrayList) $5) {
 
-                       // FIXME : Is this right ?
-                       Event e = new Event ((string) $4, var.identifier, var.expression_or_array_initializer,
+                       Event e = new Event ((Expression) $4, var.identifier, 
+                                            var.expression_or_array_initializer,
                                             (int) $2, null, null, (Attributes) $1, lexer.Location);
 
-                       CheckDef (current_container.AddEvent (e), e.Name);
+                       CheckDef (current_container.AddEvent (e), e.Name, e.Location);
                                       
                }
          }
        | opt_attributes
          opt_modifiers
-         EVENT type member_name 
-         OPEN_BRACE event_accessor_declarations CLOSE_BRACE
-       {
-               DictionaryEntry pair = (DictionaryEntry) $7;
-               Block add_block = null;
-               Block rem_block = null;
-
-               if (pair.Key != null)
-                       add_block = (Block) pair.Key;
-               if (pair.Value != null)
-                       rem_block = (Block) pair.Value;
+         EVENT type member_name
+         OPEN_BRACE
+         {
+               implicit_value_parameter_type = (Expression) $4;  
+               lexer.EventParsing = true;
+               oob_stack.Push (lexer.Location);
+         }
+         event_accessor_declarations
+         {
+               lexer.EventParsing = false;  
+         }
+         CLOSE_BRACE
+         {
+               Location loc = (Location) oob_stack.Pop ();
+
+               Pair pair = (Pair) $8;
+               Accessor add_accessor = null;
+               Accessor rem_accessor = null;
+
+               if (pair.First != null)
+                       add_accessor = (Accessor) pair.First;
+               if (pair.Second != null)
+                       rem_accessor = (Accessor) pair.Second;
                
-               Event e = new Event ((string) $4, (string) $5, null, (int) $2, add_block, rem_block,
-                                    (Attributes) $1, lexer.Location);
+               Event e = new Event ((Expression) $4, (string) $5, null, (int) $2, add_accessor, rem_accessor,
+                                    (Attributes) $1, loc);
                
-               CheckDef (current_container.AddEvent (e), e.Name);
-       }
+               CheckDef (current_container.AddEvent (e), e.Name, loc);
+               implicit_value_parameter_type = null;
+         }
        ;
 
 event_accessor_declarations
        : add_accessor_declaration remove_accessor_declaration
        {
-               $$ = new DictionaryEntry ($1, $2);
+               $$ = new Pair ($1, $2);
        }
        | remove_accessor_declaration add_accessor_declaration
        {
-               $$ = new DictionaryEntry ($2, $1);
+               $$ = new Pair ($2, $1);
        }       
        ;
 
 add_accessor_declaration
-       : opt_attributes ADD block
+       : opt_attributes ADD
          {
-               $$ = $3;
+               Parameter [] args = new Parameter [1];
+               Parameter implicit_value_parameter = new Parameter (
+                       implicit_value_parameter_type, "value", 
+                       Parameter.Modifier.NONE, null);
+
+               args [0] = implicit_value_parameter;
+               
+               current_local_parameters = new Parameters (args, null, lexer.Location);  
+               lexer.EventParsing = false;
+         }
+          block
+         {
+               $$ = new Accessor ((Block) $4, (Attributes) $1);
+               lexer.EventParsing = true;
          }
        ;
 
 remove_accessor_declaration
-       : opt_attributes REMOVE block
-       {
-               $$ = $3;
-       }
+       : opt_attributes REMOVE
+         {
+               Parameter [] args = new Parameter [1];
+               Parameter implicit_value_parameter = new Parameter (
+                       implicit_value_parameter_type, "value", 
+                       Parameter.Modifier.NONE, null);
+
+               args [0] = implicit_value_parameter;
+               
+               current_local_parameters = new Parameters (args, null, lexer.Location);  
+               lexer.EventParsing = false;
+         }
+          block
+         {
+               $$ = new Accessor ((Block) $4, (Attributes) $1);
+               lexer.EventParsing = true;
+         }
        ;
 
 indexer_declaration
@@ -1431,35 +1576,30 @@ indexer_declaration
 
                implicit_value_parameter_type = decl.type;
                
-               lexer.properties = true;
+               lexer.PropertyParsing = true;
                parsing_indexer  = true;
                
                indexer_parameters = decl.param_list;
-               $$ = lexer.Location;
+               oob_stack.Push (lexer.Location);
          }
           accessor_declarations 
          {
-                 lexer.properties = false;
+                 lexer.PropertyParsing = false;
                  parsing_indexer  = false;
          }
          CLOSE_BRACE
          { 
                // The signature is computed from the signature of the indexer.  Look
                // at section 3.6 on the spec
-
+               Location loc = (Location) oob_stack.Pop ();
                Indexer indexer;
                IndexerDeclaration decl = (IndexerDeclaration) $3;
-               DictionaryEntry pair = (DictionaryEntry) $6;
-               Block get_block = null;
-               Block set_block = null;
-
-               if (pair.Key != null)
-                       get_block = (Block) pair.Key;
-               if (pair.Value != null)
-                       set_block = (Block) pair.Value;
+               Pair pair = (Pair) $6;
+               Accessor get_block = (Accessor) pair.First;
+               Accessor set_block = (Accessor) pair.Second;
 
                indexer = new Indexer (decl.type, decl.interface_type, (int) $2, decl.param_list,
-                                      get_block, set_block, (Attributes) $1, (Location) $5);
+                                      get_block, set_block, (Attributes) $1, loc);
 
                // Note that there is no equivalent of CheckDef for this case
                // We shall handle this in semantic analysis
@@ -1473,40 +1613,60 @@ indexer_declaration
        ;
 
 indexer_declarator
-       : type THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
+       : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
          {
-               $$ = new IndexerDeclaration ((string) $1, null, (Parameters) $4);
+               Parameters pars = (Parameters) $4;
+
+               if (pars.FixedParameters == null && pars.ArrayParameter == null){
+                       Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
+               }
+
+               $$ = new IndexerDeclaration ((Expression) $1, null, pars);
          }
-       | type interface_type DOT THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
+       | type qualified_identifier DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
          {
-               $$ = new IndexerDeclaration ((string) $1, (string) $2, (Parameters) $6);
+               Parameters pars = (Parameters) $6;
+
+               if (pars.FixedParameters == null && pars.ArrayParameter == null){
+                       Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
+               }
+               $$ = new IndexerDeclaration ((Expression) $1, (string) $2, pars);
          }
        ;
 
 enum_declaration
        : opt_attributes
          opt_modifiers
-         ENUM IDENTIFIER
+         ENUM IDENTIFIER 
          opt_enum_base
          enum_body
          opt_semicolon
          { 
-               string name = (string) $4;
-               Enum e = new Enum (rc, (string) $5, (int) $2, name, (Attributes) $1, lexer.Location);
+               Location enum_location = lexer.Location;
+
+               string full_name = MakeName ((string) $4);
+               Enum e = new Enum (current_container, (Expression) $5, (int) $2, full_name, 
+                                  (Attributes) $1, enum_location);
+               
+               foreach (VariableDeclaration ev in (ArrayList) $6) {
+                       Location loc = (Location) ev.Location;
 
-               foreach (VariableDeclaration ev in (ArrayList) $6){
                        CheckDef (e.AddEnumMember (ev.identifier, 
                                                   (Expression) ev.expression_or_array_initializer,
-                                                  (Location) ev.Location),
-                                 ev.identifier);
+                                                  loc, ev.OptAttributes),
+                                 ev.identifier, loc);
                }
 
-               CheckDef (current_container.AddEnum (e), name);
+               e.Namespace = current_namespace;
+
+               CheckDef (current_container.AddEnum (e), full_name, enum_location);
+               RootContext.Tree.RecordDecl (full_name, e);
+
          }
        ;
 
 opt_enum_base
-       : /* empty */           { $$ = "System.Int32"; }
+       : /* empty */           { $$ = TypeManager.system_int32_expr; }
        | COLON type            { $$ = $2;   }
        ;
 
@@ -1543,7 +1703,7 @@ enum_member_declarations
 enum_member_declaration
        : opt_attributes IDENTIFIER 
          {
-               $$ = new VariableDeclaration ((string) $2, null, lexer.Location);
+               $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
          }
        | opt_attributes IDENTIFIER
          {
@@ -1551,7 +1711,7 @@ enum_member_declaration
          }
           ASSIGN expression
          { 
-               $$ = new VariableDeclaration ((string) $2, $5, lexer.Location);
+               $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
          }
        ;
 
@@ -1560,28 +1720,34 @@ delegate_declaration
          opt_modifiers
          DELEGATE type   
          IDENTIFIER OPEN_PARENS 
-         formal_parameter_list
+         opt_formal_parameter_list
          CLOSE_PARENS 
          SEMICOLON
          {
-               Delegate del = new Delegate (rc, (string) $4, (int) $2, 
+               Location l = lexer.Location;
+               Delegate del = new Delegate (current_container, (Expression) $4, (int) $2, 
                                             MakeName ((string) $5), (Parameters) $7, 
-                                            (Attributes) $1, lexer.Location);
+                                            (Attributes) $1, l);
                  
-               CheckDef (current_container.AddDelegate (del), del.Name);
+               del.Namespace = current_namespace;
+               CheckDef (current_container.AddDelegate (del), del.Name, l);
          }     
        | opt_attributes
          opt_modifiers
          DELEGATE VOID   
          IDENTIFIER OPEN_PARENS 
-         formal_parameter_list
+         opt_formal_parameter_list
          CLOSE_PARENS 
          SEMICOLON
          {
-               Delegate del = new Delegate (rc, "System.Void", (int) $2, (string) $5, (Parameters) $7, 
-                                            (Attributes) $1, lexer.Location);
+               Location l = lexer.Location;
+               Delegate del = new Delegate (
+                       current_container,
+                       TypeManager.system_void_expr, (int) $2, MakeName ((string) $5), 
+                       (Parameters) $7, (Attributes) $1, l);
 
-               CheckDef (current_container.AddDelegate (del), del.Name);
+               del.Namespace = current_namespace;
+               CheckDef (current_container.AddDelegate (del), del.Name, l);
          }
        ;
 
@@ -1605,25 +1771,48 @@ type
                   This does interfaces, delegates, struct_types, class_types, 
                   parent classes, and more! 4.2 
                 */
-               $$ = $1; 
+               $$ = DecomposeQI ((string) $1, lexer.Location);
          }
        | builtin_types
        | array_type
+       | pointer_type    
        ;
 
-non_expression_type
-       : builtin_types 
+
+pointer_type
+       : type STAR
+         {
+               //
+               // Note that here only unmanaged types are allowed but we
+               // can't perform checks during this phase - we do it during
+               // semantic analysis.
+               //
+               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+         }
+       | VOID STAR
          {
-               $$ = new SimpleName ((string) $1, lexer.Location);
+               $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);
          }
+       ;
+
+non_expression_type
+       : builtin_types 
        | non_expression_type rank_specifier
          {
                $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
          }
+       | non_expression_type STAR
+         {
+               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+         }
        | expression rank_specifiers 
          {
                $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
          }
+       | expression STAR 
+         {
+               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+         }
        ;
 
 type_list
@@ -1648,25 +1837,26 @@ type_list
  * simple types, but we need this to reuse it easily in local_variable_type
  */
 builtin_types
-       : OBJECT        { $$ = "System.Object"; }
-       | STRING        { $$ = "System.String"; }
-       | BOOL          { $$ = "System.Boolean"; }
-       | DECIMAL       { $$ = "System.Decimal"; }
-       | FLOAT         { $$ = "System.Single"; }
-       | DOUBLE        { $$ = "System.Double"; }
+       : OBJECT        { $$ = TypeManager.system_object_expr; }
+       | STRING        { $$ = TypeManager.system_string_expr; }
+       | BOOL          { $$ = TypeManager.system_boolean_expr; }
+       | DECIMAL       { $$ = TypeManager.system_decimal_expr; }
+       | FLOAT         { $$ = TypeManager.system_single_expr; }
+       | DOUBLE        { $$ = TypeManager.system_double_expr; }
        | integral_type
        ;
 
 integral_type
-       : SBYTE         { $$ = "System.SByte"; }
-       | BYTE          { $$ = "System.Byte"; }
-       | SHORT         { $$ = "System.Int16"; }
-       | USHORT        { $$ = "System.UInt16"; }
-       | INT           { $$ = "System.Int32"; }
-       | UINT          { $$ = "System.UInt32"; }
-       | LONG          { $$ = "System.Int64"; }
-       | ULONG         { $$ = "System.UInt64"; }
-       | CHAR          { $$ = "System.Char"; }
+       : SBYTE         { $$ = TypeManager.system_sbyte_expr; }
+       | BYTE          { $$ = TypeManager.system_byte_expr; }
+       | SHORT         { $$ = TypeManager.system_int16_expr; }
+       | USHORT        { $$ = TypeManager.system_uint16_expr; }
+       | INT           { $$ = TypeManager.system_int32_expr; }
+       | UINT          { $$ = TypeManager.system_uint32_expr; }
+       | LONG          { $$ = TypeManager.system_int64_expr; }
+       | ULONG         { $$ = TypeManager.system_uint64_expr; }
+       | CHAR          { $$ = TypeManager.system_char_expr; }
+       | VOID          { $$ = TypeManager.system_void_expr; }
        ;
 
 interface_type
@@ -1676,7 +1866,7 @@ interface_type
 array_type
        : type rank_specifiers
          {
-                 $$ = (string) $1 + (string) $2;
+               $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
          }
        ;
 
@@ -1709,6 +1899,7 @@ primary_expression
        | sizeof_expression
        | checked_expression
        | unchecked_expression
+       | pointer_member_access
        ;
 
 literal
@@ -1730,10 +1921,6 @@ integer_literal
        : LITERAL_INTEGER       { 
                object v = lexer.Value;
 
-               // 
-               // FIXME: Possible optimization would be to 
-               // compute the *Literal objects directly in the scanner
-               //
                if (v is int)
                        $$ = new IntLiteral ((Int32) v); 
                else if (v is uint)
@@ -1764,7 +1951,7 @@ member_access
          }
        | predefined_type DOT IDENTIFIER
          {
-               $$ = new SimpleName ((string) $1 + "." + (string) $3, lexer.Location);
+               $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
          }
        ;
 
@@ -1780,7 +1967,6 @@ invocation_expression
                        Report.Error (1, l, "THIS IS CRAZY");
                }
                $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
-               
          }
        ; 
 
@@ -1828,6 +2014,28 @@ element_access
          {
                $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
          }
+       | primary_expression rank_specifiers
+         {
+               // So the super-trick is that primary_expression
+               // can only be either a SimpleName or a MemberAccess. 
+               // The MemberAccess case arises when you have a fully qualified type-name like :
+               // Foo.Bar.Blah i;
+               // SimpleName is when you have
+               // Blah i;
+                 
+               Expression expr = (Expression) $1;  
+               if (!(expr is SimpleName || expr is MemberAccess)) {
+                       Location l = lexer.Location;
+                       Report.Error (-1, l, "Invalid Type definition");
+                       $$ = "System.Object";
+               }
+               
+               //
+               // So we extract the string corresponding to the SimpleName
+               // or MemberAccess
+               // 
+               $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
+         }
        ;
 
 expression_list
@@ -1848,7 +2056,7 @@ expression_list
 this_access
        : THIS
          {
-               $$ = new This (lexer.Location);
+               $$ = new This (current_block, lexer.Location);
          }
        ;
 
@@ -1859,7 +2067,7 @@ base_access
          }
        | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
          {
-               $$ = new BaseIndexerAccess ((ArrayList) $3);
+               $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
          }
        ;
 
@@ -1887,7 +2095,7 @@ new_expression
 object_or_delegate_creation_expression
        : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
          {
-               $$ = new New ((string) $2, (ArrayList) $4, lexer.Location);
+               $$ = new New ((Expression) $2, (ArrayList) $4, lexer.Location);
          }
        ;
 
@@ -1896,12 +2104,15 @@ array_creation_expression
          opt_rank_specifier
          opt_array_initializer
          {
-               $$ = new ArrayCreation ((string) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, 
-                                       lexer.Location);
+               $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
          }
        | NEW type rank_specifiers array_initializer
          {
-               $$ = new ArrayCreation ((string) $2, (string) $3, (ArrayList) $4, lexer.Location);
+               $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
+         }
+       | NEW type error 
+         {
+               Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
          }
        ;
 
@@ -1997,33 +2208,39 @@ variable_initializer_list
 typeof_expression
        : TYPEOF OPEN_PARENS type CLOSE_PARENS
          {
-               $$ = new TypeOf ((string) $3);
+               $$ = new TypeOf ((Expression) $3, lexer.Location);
          }
        ;
 
 sizeof_expression
        : SIZEOF OPEN_PARENS type CLOSE_PARENS { 
-               $$ = new SizeOf ((string) $3);
-
-               note ("Verify type is unmanaged"); 
-               note ("if (5.8) builtin, yield constant expression");
+               $$ = new SizeOf ((Expression) $3, lexer.Location);
          }
        ;
 
 checked_expression
        : CHECKED OPEN_PARENS expression CLOSE_PARENS
          {
-               $$ = new CheckedExpr ((Expression) $3);
+               $$ = new CheckedExpr ((Expression) $3, lexer.Location);
          }
        ;
 
 unchecked_expression
        : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
          {
-               $$ = new UnCheckedExpr ((Expression) $3);
+               $$ = new UnCheckedExpr ((Expression) $3, lexer.Location);
          }
        ;
 
+pointer_member_access 
+       : primary_expression OP_PTR IDENTIFIER
+         {
+               Expression deref;
+
+               deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lexer.Location);
+               $$ = new MemberAccess (deref, (string) $3, lexer.Location);
+         }
+
 unary_expression
        : primary_expression
        | BANG prefixed_unary_expression
@@ -2038,7 +2255,7 @@ unary_expression
          {
                  $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
          }
-       | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
+        | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
          {
                  $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
          }
@@ -2165,11 +2382,11 @@ relational_expression
          }
        | relational_expression IS type
          {
-               $$ = new Is ((Expression) $1, (string) $3);
+               $$ = new Is ((Expression) $1, (Expression) $3, lexer.Location);
          }
        | relational_expression AS type
          {
-               $$ = new As ((Expression) $1, (string) $3);
+               $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
          }
        ;
 
@@ -2249,91 +2466,71 @@ assignment_expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Multiply, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
          }
        | prefixed_unary_expression OP_DIV_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Division, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
          }
        | prefixed_unary_expression OP_MOD_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Modulus, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.Modulus, (Expression) $1, (Expression) $3, l);
          }
        | prefixed_unary_expression OP_ADD_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Addition, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
          }
        | prefixed_unary_expression OP_SUB_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Subtraction, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
          }
        | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.LeftShift, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, l);
          }
        | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.RightShift, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.RightShift, (Expression) $1, (Expression) $3, l);
          }
        | prefixed_unary_expression OP_AND_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.BitwiseAnd, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, l);
          }
        | prefixed_unary_expression OP_OR_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.BitwiseOr, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, l);
          }
        | prefixed_unary_expression OP_XOR_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.ExclusiveOr, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, l);
          }
        ;
 
@@ -2359,13 +2556,15 @@ class_declaration
          CLASS IDENTIFIER
          {
                Class new_class;
-               string full_class_name = MakeName ((string) $4);
+               string name;
 
-               new_class = new Class (rc, current_container, full_class_name, (int) $2, 
+               name = MakeName ((string) $4);
+
+               new_class = new Class (current_container, name, (int) $2, 
                                       (Attributes) $1, lexer.Location);
                current_container = new_class;
                current_container.Namespace = current_namespace;
-               tree.RecordClass (full_class_name, new_class);
+               RootContext.Tree.RecordDecl (name, new_class);
          }
          opt_class_base
          class_body 
@@ -2377,7 +2576,7 @@ class_declaration
                        new_class.Bases = (ArrayList) $6;
 
                current_container = current_container.Parent;
-               CheckDef (current_container.AddClass (new_class), new_class.Name);
+               CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
 
                $$ = new_class;
          }
@@ -2397,7 +2596,7 @@ modifiers
 
                if ((m1 & m2) != 0) {
                        Location l = lexer.Location;
-                       Report.Error (1002, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
+                       Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
                }
                $$ = (int) (m1 | m2);
          }
@@ -2416,6 +2615,8 @@ modifier
        | VIRTUAL               { $$ = Modifiers.VIRTUAL; }
        | OVERRIDE              { $$ = Modifiers.OVERRIDE; }
        | EXTERN                { $$ = Modifiers.EXTERN; }
+       | VOLATILE              { $$ = Modifiers.VOLATILE; }
+       | UNSAFE                { $$ = Modifiers.UNSAFE; }
        ;
 
 opt_class_base
@@ -2443,13 +2644,15 @@ class_base
 block
        : OPEN_BRACE 
          {
-               current_block = new Block (current_block);
+               current_block = new Block (current_block, current_local_parameters,
+                                          lexer.Location, Location.Null);
          } 
          opt_statement_list CLOSE_BRACE 
          { 
                while (current_block.Implicit)
                        current_block = current_block.Parent;
                $$ = current_block;
+               current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
          }
        ;
@@ -2479,10 +2682,7 @@ statement
 
                current_block.AddStatement ((Statement) $1);
          }
-       | labeled_statement 
-         {
-               current_block.AddStatement ((Statement) $1);
-         }
+       | labeled_statement
        ;
 
 embedded_statement
@@ -2497,6 +2697,8 @@ embedded_statement
        | unchecked_statement
        | lock_statement
        | using_statement
+       | unsafe_statement
+       | fixed_statement
        ;
 
 empty_statement
@@ -2507,21 +2709,17 @@ empty_statement
        ;
 
 labeled_statement
-       : IDENTIFIER COLON statement
+       : IDENTIFIER COLON 
          {
-               string lab = (String) $1;
-               Block block;
-
-               block = new Block (current_block, lab);
-               block.AddStatement ((Statement) $3);
-               $$ = block;
+               LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
 
-               if (!current_block.AddLabel (lab, block)){
+               if (!current_block.AddLabel ((string) $1, labeled)){
                        Location l = lexer.Location;
-                       Report.Error (140, l, "The label '" + lab + "' is a duplicate");
-                       $$ = $3;
+                       Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
                }       
+               current_block.AddStatement (labeled);
          }
+         statement
        ;
 
 declaration_statement
@@ -2529,14 +2727,14 @@ declaration_statement
          {
                DictionaryEntry de = (DictionaryEntry) $1;
 
-               $$ = declare_local_variables ((string) de.Key, (ArrayList) de.Value, lexer.Location);
+               $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
          }
 
        | local_constant_declaration SEMICOLON
          {
                DictionaryEntry de = (DictionaryEntry) $1;
 
-               $$ = declare_local_constant ((string) de.Key, (VariableDeclaration) de.Value);
+               $$ = declare_local_constant ((Expression) de.Key, (VariableDeclaration) de.Value);
          }
        ;
 
@@ -2569,36 +2767,69 @@ local_variable_type
                if (!(expr is SimpleName || expr is MemberAccess)) {
                        Location l = lexer.Location;
                        Report.Error (-1, l, "Invalid Type definition");
-                       $$ = "System.Object";
+                       $$ = TypeManager.system_object_expr;
                }
                
                //
                // So we extract the string corresponding to the SimpleName
                // or MemberAccess
                // 
-               $$ = GetQualifiedIdentifier (expr) + (string) $2;
+               if ((string) $2 == "")
+                       $$ = $1;
+               else
+                       $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
          }
        | builtin_types opt_rank_specifier
          {
-                 $$ = (string) $1 + (string) $2;
+               if ((string) $2 == "")
+                       $$ = $1;
+               else
+                       $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
          }
         ;
 
-// FIXME : How can the type of a local variable be void ? I don't quite see ;-)
-//          | VOID 
-//       {
-//             // FIXME: this is a string that represents the type
-//             // Figure out something to make this work.
-//             $$ = "void";
-//       }
-//     ;
+local_variable_pointer_type
+       : primary_expression STAR
+         {
+               Expression expr = (Expression) $1;  
+               if (!(expr is SimpleName || expr is MemberAccess)) {
+                       Location l = lexer.Location;
+                       Report.Error (-1, l, "Invalid Type definition");
+                       $$ = "System.Object";
+               }
+               
+               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+         }
+        | builtin_types STAR
+         {
+               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);;
+         }
+        | VOID STAR
+         {
+               $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
+         }
+       | local_variable_pointer_type STAR
+          {
+               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+         }
+        ;
 
 local_variable_declaration
        : local_variable_type variable_declarators
          {
                $$ = new DictionaryEntry ($1, $2);
          }
-       ;
+        | local_variable_pointer_type opt_rank_specifier variable_declarators
+       {
+               Expression t;
+
+               if ((string) $2 == "")
+                       t = (Expression) $1;
+               else
+                       t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+               $$ = new DictionaryEntry (t, $3);
+       }
+       ;
 
 local_constant_declaration
        : CONST local_variable_type constant_declarator
@@ -2619,13 +2850,13 @@ expression_statement
        // because statement_expression is used for example in for_statement
        //
 statement_expression
-       : invocation_expression         { $$ = new StatementExpression ((ExpressionStatement) $1); }
-       | object_creation_expression    { $$ = new StatementExpression ((ExpressionStatement) $1); }
-       | assignment_expression         { $$ = new StatementExpression ((ExpressionStatement) $1); }
-       | post_increment_expression     { $$ = new StatementExpression ((ExpressionStatement) $1); }
-       | post_decrement_expression     { $$ = new StatementExpression ((ExpressionStatement) $1); }
-       | pre_increment_expression      { $$ = new StatementExpression ((ExpressionStatement) $1); }
-       | pre_decrement_expression      { $$ = new StatementExpression ((ExpressionStatement) $1); }
+       : invocation_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
+       | object_creation_expression    { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
+       | assignment_expression         { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
+       | post_increment_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
+       | post_decrement_expression     { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
+       | pre_increment_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
+       | pre_decrement_expression      { $$ = new StatementExpression ((ExpressionStatement) $1, lexer.Location); }
        | error {
                Report.Error (1002, lexer.Location, "Expecting `;'");
          }
@@ -2642,15 +2873,39 @@ selection_statement
        ; 
 
 if_statement
-       : IF OPEN_PARENS boolean_expression CLOSE_PARENS 
+       : if_statement_open if_statement_rest
+         {
+               $$ = $2;
+         }
+       ;
+
+if_statement_open
+       : IF OPEN_PARENS 
+         {
+               oob_stack.Push (lexer.Location);
+         }
+       ;
+
+if_statement_rest
+       : boolean_expression CLOSE_PARENS 
          embedded_statement
          { 
-               $$ = new If ((Expression) $3, (Statement) $5);
+               Location l = (Location) oob_stack.Pop ();
+
+               $$ = new If ((Expression) $1, (Statement) $3, l);
+
+               if (RootContext.WarningLevel >= 3){
+                       if ($3 is EmptyStatement)
+                               Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
+               }
+
          }
-       | IF OPEN_PARENS boolean_expression CLOSE_PARENS
+       | boolean_expression CLOSE_PARENS
          embedded_statement ELSE embedded_statement
          {
-               $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7);
+               Location l = (Location) oob_stack.Pop ();
+
+               $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
          }
        ;
 
@@ -2658,11 +2913,13 @@ switch_statement
        : SWITCH OPEN_PARENS 
          { 
                oob_stack.Push (lexer.Location);
+               switch_stack.Push (current_block);
          }
          expression CLOSE_PARENS 
          switch_block
          {
                $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
+               current_block = (Block) switch_stack.Pop ();
          }
        ;
 
@@ -2676,7 +2933,10 @@ switch_block
        ;
 
 opt_switch_sections
-       : /* empty */           { $$ = new ArrayList (); }
+       : /* empty */           
+          {
+               Report.Error (1522, lexer.Location, "Empty switch block"); 
+         }
        | switch_sections
        ;
 
@@ -2707,7 +2967,6 @@ switch_section
                while (current_block.Implicit)
                        current_block = current_block.Parent;
                $$ = new SwitchSection ((ArrayList) $1, current_block);
-               current_block = current_block.Parent;
          }
        ;
 
@@ -2731,6 +2990,11 @@ switch_labels
 switch_label
        : CASE constant_expression COLON        { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
        | DEFAULT COLON                         { $$ = new SwitchLabel (null, lexer.Location); }
+       | error {
+               Report.Error (
+                       1523, lexer.Location, 
+                       "The keyword case or default must precede code in switch block");
+         }
        ;
 
 iteration_statement
@@ -2741,9 +3005,19 @@ iteration_statement
        ;
 
 while_statement
-       : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
+       : WHILE OPEN_PARENS 
+       {
+               oob_stack.Push (lexer.Location);
+       }
+       boolean_expression CLOSE_PARENS embedded_statement
        {
-               $$ = new While ((Expression) $3, (Statement) $5);
+               Location l = (Location) oob_stack.Pop ();
+               $$ = new While ((Expression) $4, (Statement) $6, l);
+       
+               if (RootContext.WarningLevel >= 3){
+                       if ($6 is EmptyStatement)
+                               Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
+               }
        }
        ;
 
@@ -2751,7 +3025,7 @@ do_statement
        : DO embedded_statement 
          WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
          {
-               $$ = new Do ((Statement) $2, (Expression) $5);
+               $$ = new Do ((Statement) $2, (Expression) $5, lexer.Location);
          }
        ;
 
@@ -2765,50 +3039,51 @@ for_statement
                if ($3 is DictionaryEntry){
                        DictionaryEntry de = (DictionaryEntry) $3;
                        
-                       string type = (string) de.Key;
+                       Expression type = (Expression) de.Key;
                        ArrayList var_declarators = (ArrayList) de.Value;
 
                        foreach (VariableDeclaration decl in var_declarators){
-                               if (!current_block.AddVariable (type, decl.identifier, decl.Location)){
-                                       Report.Error (128, decl.Location, 
-                                       "A local variable `" + decl.identifier + "' is already" +
-                                       "defined in this scope");
-                               }
-                       }
-                       Location l = lexer.Location;
 
-                       foreach (VariableDeclaration decl in var_declarators){
+                               VariableInfo vi;
+
+                               vi = current_block.AddVariable (
+                                       type, decl.identifier, current_local_parameters, decl.Location);
+                               if (vi == null)
+                                       continue;
 
+                               Location l = lexer.Location;
                                Expression expr;
                                if (decl.expression_or_array_initializer is Expression){
                                        expr = (Expression) decl.expression_or_array_initializer;
-                                       
                                } else {
-
                                        ArrayList init = (ArrayList) decl.expression_or_array_initializer;
-                                       
-                                       string base_type = type.Substring (0, type.IndexOf ("["));
-                                       string rank = type.Substring (type.IndexOf ("["));
-                                       
-                                       expr = new ArrayCreation (base_type, rank, init, decl.Location);
+                                       expr = new ArrayCreation (type, "", init, decl.Location);
                                }
-
+                                       
                                LocalVariableReference var;
-                               var = new LocalVariableReference (
-                                       assign_block, decl.identifier, l);
-
+                               var = new LocalVariableReference (assign_block, decl.identifier, l);
+                                       
                                Assign a = new Assign (var, expr, decl.Location);
-                               
-                               assign_block.AddStatement (new StatementExpression (a));
+                                       
+                               assign_block.AddStatement (new StatementExpression (a, lexer.Location));
                        }
+                       
                        $3 = null;
                } 
+               oob_stack.Push (lexer.Location);
          } 
          opt_for_condition SEMICOLON
          opt_for_iterator CLOSE_PARENS 
          embedded_statement
          {
-               For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10);
+               Location l = (Location) oob_stack.Pop ();
+
+               For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
+
+               if (RootContext.WarningLevel >= 3){
+                       if ($10 is EmptyStatement)
+                               Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
+               }
 
                current_block.AddStatement (f);
                while (current_block.Implicit)
@@ -2829,7 +3104,7 @@ for_initializer
        ;
 
 opt_for_condition
-       : /* empty */           { $$ = new BoolLiteral (true); }
+       : /* empty */           { $$ = null; }
        | boolean_expression
        ;
 
@@ -2845,7 +3120,8 @@ for_iterator
 statement_expression_list
        : statement_expression  
          {
-               Block b = new Block (null, true);
+               // CHANGE: was `null'
+               Block b = new Block (current_block, true);   
 
                b.AddStatement ((Statement) $1);
                $$ = b;
@@ -2866,26 +3142,40 @@ foreach_statement
          }
          expression CLOSE_PARENS 
          {
+               oob_stack.Push (current_block);
+
                Block foreach_block = new Block (current_block, true);
-               LocalVariableReference v;
+               LocalVariableReference v = null;
                Location l = lexer.Location;
+               VariableInfo vi;
 
-               foreach_block.AddVariable ((string) $3, (string) $4, l);
-               v = new LocalVariableReference (foreach_block, (string) $4, l);
+               vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
+               if (vi != null) {
+                       vi.ReadOnly = true;
 
-               current_block.AddStatement (foreach_block);
+                       // Get a writable reference to this read-only variable.
+                       v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
+               }
                current_block = foreach_block;
 
-               oob_stack.Push (foreach_block);
                oob_stack.Push (v);
+               oob_stack.Push (current_block);
          } 
          embedded_statement 
          {
-               LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
                Block foreach_block = (Block) oob_stack.Pop ();
+               LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
+               Block prev_block = (Block) oob_stack.Pop ();
                Location l = (Location) oob_stack.Pop ();
 
-               $$ = new Foreach ((string) $3, v, (Expression) $7, (Statement) $10, l);
+               current_block = prev_block;
+
+               if (v != null) {
+                       Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
+                       foreach_block.AddStatement (f);
+               }
+
+               $$ = foreach_block;
          }
        ;
 
@@ -2914,7 +3204,7 @@ continue_statement
 goto_statement
        : GOTO IDENTIFIER SEMICOLON 
          {
-               $$ = new Goto ((string) $2, lexer.Location);
+               $$ = new Goto (current_block, (string) $2, lexer.Location);
          }
        | GOTO CASE constant_expression SEMICOLON
          {
@@ -2936,7 +3226,7 @@ return_statement
 throw_statement
        : THROW opt_expression SEMICOLON
          {
-               $$ = new Throw ((Expression) $2);
+               $$ = new Throw ((Expression) $2, lexer.Location);
          }
        ;
 
@@ -2952,7 +3242,7 @@ try_statement
                ArrayList s = new ArrayList ();
                
                foreach (Catch cc in (ArrayList) $3) {
-                       if (cc.Type == null)
+                       if (cc.IsGeneral)
                                g = cc;
                        else
                                s.Add (cc);
@@ -2961,21 +3251,28 @@ try_statement
                // Now s contains the list of specific catch clauses
                // and g contains the general one.
                
-               $$ = new Try ((Block) $2, s, g, null);
+               $$ = new Try ((Block) $2, s, g, null, lexer.Location);
        }
        | TRY block opt_catch_clauses FINALLY block
          {
                Catch g = null;
                ArrayList s = new ArrayList ();
-               
-               foreach (Catch cc in (ArrayList) $3) {
-                       if (cc.Type == null)
-                               g = cc;
-                       else
-                               s.Add (cc);
+               ArrayList catch_list = (ArrayList) $3;
+
+               if (catch_list != null){
+                       foreach (Catch cc in catch_list) {
+                               if (cc.IsGeneral)
+                                       g = cc;
+                               else
+                                       s.Add (cc);
+                       }
                }
 
-               $$ = new Try ((Block) $2, s, g, (Block) $5);
+               $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
+         }
+       | TRY block error 
+         {
+               Report.Error (1524, lexer.Location, "Expected catch or finally");
          }
        ;
 
@@ -3009,11 +3306,12 @@ opt_identifier
 catch_clause 
        : CATCH opt_catch_args 
        {
-               string type = null, id = null;
+               Expression type = null;
+               string id = null;
                
                if ($2 != null) {
                        DictionaryEntry cc = (DictionaryEntry) $2;
-                       type = (string) cc.Key;
+                       type = (Expression) cc.Key;
                        id   = (string) cc.Value;
 
                        if (id != null){
@@ -3026,26 +3324,28 @@ catch_clause
                                current_block = new Block (current_block);
                                Block b = declare_local_variables (type, one, loc);
                                current_block = b;
-
-                               
                        }
                }
        } block {
-               string type = null, id = null;
+               Expression type = null;
+               string id = null;
 
                if ($2 != null){
                        DictionaryEntry cc = (DictionaryEntry) $2;
-                       type = (string) cc.Key;
+                       type = (Expression) cc.Key;
                        id   = (string) cc.Value;
 
                        if ($1 != null){
+                               //
+                               // FIXME: I can change this for an assignment.
+                               //
                                while (current_block != (Block) $1)
                                        current_block = current_block.Parent;
                        }
                }
 
 
-               $$ = new Catch (type, id , (Block) $4);
+               $$ = new Catch (type, id , (Block) $4, lexer.Location);
        }
         ;
 
@@ -3075,6 +3375,78 @@ unchecked_statement
          }
        ;
 
+unsafe_statement
+       : UNSAFE 
+       {
+               if (!RootContext.Unsafe){
+                       Report.Error (227, lexer.Location, 
+                               "Unsafe code can only be used if --unsafe is used");
+               }
+       } block {
+               $$ = new Unsafe ((Block) $3);
+       }
+       ;
+
+fixed_statement
+       : FIXED OPEN_PARENS 
+         pointer_type fixed_pointer_declarators 
+         CLOSE_PARENS 
+         {
+               Block assign_block = new Block (current_block, true);
+               ArrayList list = (ArrayList) $4;
+               Expression type = (Expression) $3;
+               Location l = lexer.Location;
+               int top = list.Count;
+
+               for (int i = 0; i < top; i++){
+                       Pair p = (Pair) list [i];
+                       VariableInfo v;
+
+                       v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
+                       if (v == null)
+                               continue;
+                       v.ReadOnly = true;
+                       p.First = v;
+                       list [i] = p;
+               }
+               current_block.AddStatement (assign_block);
+               current_block = assign_block;
+               oob_stack.Push (assign_block);
+               oob_stack.Push (l);
+         }
+         embedded_statement 
+         {
+               Location l = (Location) oob_stack.Pop ();
+               Block assign_block = (Block) oob_stack.Pop ();
+
+               ArrayList list = (ArrayList) $4;
+               int top = list.Count;
+
+               $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
+         }
+       ;
+
+fixed_pointer_declarators
+       : fixed_pointer_declarator      { 
+               ArrayList declarators = new ArrayList (); 
+               declarators.Add ($1);
+               $$ = declarators;
+         }
+       | fixed_pointer_declarators COMMA fixed_pointer_declarator
+         {
+               ArrayList declarators = (ArrayList) $1;
+               declarators.Add ($3);
+               $$ = declarators;
+         }
+       ;
+
+fixed_pointer_declarator
+       : IDENTIFIER ASSIGN expression
+         {     
+               $$ = new Pair ($1, $3);
+         }
+       ;
+
 lock_statement
        : LOCK OPEN_PARENS expression CLOSE_PARENS 
          {
@@ -3098,41 +3470,33 @@ using_statement
                        DictionaryEntry de = (DictionaryEntry) $3;
                        Location l = lexer.Location;
 
-                       string type = (string) de.Key;
+                       Expression type = (Expression) de.Key;
                        ArrayList var_declarators = (ArrayList) de.Value;
 
-                       foreach (VariableDeclaration decl in var_declarators){
-                               if (!current_block.AddVariable (type, decl.identifier, decl.Location)){
-                                       Report.Error (128, decl.Location, 
-                                       "A local variable `" + decl.identifier + "' is already" +
-                                       "defined in this scope");
-                               }
-                       }
-
                        ArrayList vars = new ArrayList ();
 
                        foreach (VariableDeclaration decl in var_declarators){
 
+                               VariableInfo vi = current_block.AddVariable (
+                                       type, decl.identifier, 
+                                       current_local_parameters, decl.Location);
+                               if (vi == null)
+                                       continue;
+                               vi.ReadOnly = true;
+
                                Expression expr;
                                if (decl.expression_or_array_initializer is Expression){
                                        expr = (Expression) decl.expression_or_array_initializer;
-                                       
                                } else {
-
                                        ArrayList init = (ArrayList) decl.expression_or_array_initializer;
                                        
-                                       string base_type = type.Substring (0, type.IndexOf ("["));
-                                       string rank = type.Substring (type.IndexOf ("["));
-                                       
-                                       expr = new ArrayCreation (base_type, rank, init, decl.Location);
+                                       expr = new ArrayCreation (type, "", init, decl.Location);
                                }
 
                                LocalVariableReference var;
-                               VariableInfo vi;
 
-                               var = new LocalVariableReference (assign_block, decl.identifier, l);
-                               vi = var.VariableInfo;
-                               vi.ReadOnly = true;
+                               // Get a writable reference to this read-only variable.
+                               var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
 
                                // This is so that it is not a warning on using variables
                                vi.Used = true;
@@ -3140,7 +3504,7 @@ using_statement
                                vars.Add (new DictionaryEntry (var, expr));                             
 
                                // Assign a = new Assign (var, expr, decl.Location);
-                               // assign_block.AddStatement (new StatementExpression (a));
+                               // assign_block.AddStatement (new StatementExpression (a, lexer.Location));
                        }
                        $3 = new DictionaryEntry (type, vars);
                 }
@@ -3170,11 +3534,18 @@ public class VariableDeclaration {
        public string identifier;
        public object expression_or_array_initializer;
        public Location Location;
+       public Attributes OptAttributes;
 
-       public VariableDeclaration (string id, object eoai, Location l){
+       public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
+       {
                this.identifier = id;
                this.expression_or_array_initializer = eoai;
                this.Location = l;
+               this.OptAttributes = opt_attrs;
+       }
+
+       public VariableDeclaration (string id, object eoai, Location l) : this (id, eoai, l, null)
+       {
        }
 }
 
@@ -3183,11 +3554,11 @@ public class VariableDeclaration {
 // </summary>
 
 public class IndexerDeclaration {
-       public string type;
+       public Expression type;
        public string interface_type;
        public Parameters param_list;
 
-       public IndexerDeclaration (string type, string interface_type, Parameters param_list)
+       public IndexerDeclaration (Expression type, string interface_type, Parameters param_list)
        {
                this.type = type;
                this.interface_type = interface_type;
@@ -3201,15 +3572,13 @@ public class IndexerDeclaration {
 
 public class OperatorDeclaration {
        public Operator.OpType optype;
-       public string ret_type;
-       public string arg1type;
-       public string arg1name;
-       public string arg2type;
-       public string arg2name;
+       public Expression ret_type, arg1type, arg2type;
+       public string arg1name, arg2name;
        public Location location;
 
-       public OperatorDeclaration (Operator.OpType op, string ret_type, string arg1type, string arg1name,
-                                   string arg2type, string arg2name, Location location)
+       public OperatorDeclaration (Operator.OpType op, Expression ret_type, 
+                                   Expression arg1type, string arg1name,
+                                   Expression arg2type, string arg2name, Location location)
        {
                optype = op;
                this.ret_type = ret_type;
@@ -3246,68 +3615,46 @@ MakeName (string class_name)
 //   in the current declaration space
 // </summary>
 void 
-CheckDef (DeclSpace.AdditionResult result, string name)
+CheckDef (AdditionResult result, string name, Location l)
 {
-       if (result == DeclSpace.AdditionResult.Success)
+       if (result == AdditionResult.Success)
                return;
 
-       Location l = lexer.Location;
-       
        switch (result){
-       case DeclSpace.AdditionResult.NameExists:
-               Report.Error (102, l, "The namespace `" + current_container.Name + 
+       case AdditionResult.NameExists:
+               Report.Error (102, l, "The container `" + current_container.Name + 
                                 "' already contains a definition for `"+
                                 name + "'");
                break;
 
 
-//     NEED TO HANDLE THIS IN SEMANTIC ANALYSIS:
-//
-//     case DeclSpace.AdditionResult.MethodDuplicated:
-//             error (111, "Class `"+current_container.Name+
-//                         "' already defines a member called '" + 
-//                         name + "' with the same parameter types");
-//             break;
-
-       case DeclSpace.AdditionResult.EnclosingClash:
+               //
+               // This is handled only for static Constructors, because
+               // in reality we handle these by the semantic analysis later
+               //
+       case AdditionResult.MethodExists:
+               Report.Error (
+                       111, l, "Class `"+current_container.Name+
+                       "' already defines a member called '" + 
+                       name + "' with the same parameter types (more than one default constructor)");
+               break;
+
+       case AdditionResult.EnclosingClash:
                Report.Error (542, l, "Member names cannot be the same as their enclosing type");
                break;
                
-       case DeclSpace.AdditionResult.NotAConstructor:
+       case AdditionResult.NotAConstructor:
                Report.Error (1520, l, "Class, struct, or interface method must have a return type");
                break;
        }
 }
 
 void 
-CheckDef (bool result, string name)
+CheckDef (bool result, string name, Location l)
 {
        if (result)
                return;
-       CheckDef (DeclSpace.AdditionResult.NameExists, name);
-}
-
-Expression
-SimpleLookup (string name, Location loc)
-{
-       //
-       // we need to check against current_block not being null
-       // as `expression' is allowed in argument_lists, which 
-       // do not exist inside a block.  
-       //
-       if (current_block != null){
-               if (current_block.IsVariableDefined (name))
-                       return new LocalVariableReference (current_block, name, loc);
-       }
-
-       if (current_local_parameters != null){
-               int idx;
-               Parameter par = current_local_parameters.GetParameterByName (name, out idx);
-               if (par != null)
-                       return new ParameterReference (current_local_parameters, idx, name);
-       }
-
-       return null;
+       CheckDef (AdditionResult.NameExists, name, l);
 }
 
 Expression DecomposeQI (string name, Location loc)
@@ -3315,16 +3662,14 @@ Expression DecomposeQI (string name, Location loc)
        Expression o;
 
        if (name.IndexOf ('.') == -1){
-               o = SimpleLookup (name, loc);
-               if (o == null)
-                       return new SimpleName (name, loc);
-               return o;
+               return new SimpleName (name, loc);
        } else {
                int pos = name.LastIndexOf (".");
                string left = name.Substring (0, pos);
                string right = name.Substring (pos + 1);
 
                o = DecomposeQI (left, loc);
+
                return new MemberAccess (o, right, loc);
        }
 }
@@ -3342,11 +3687,11 @@ string GetQualifiedIdentifier (Expression expr)
        else if (expr is MemberAccess)
                return GetQualifiedIdentifier (((MemberAccess)expr).Expr) + "." + ((MemberAccess) expr).Identifier;
        else 
-               throw new Exception ("Expr has to be either SimpleName or MemberAccess !");
+               throw new Exception ("Expr has to be either SimpleName or MemberAccess! (" + expr + ")");
        
 }
 
-Block declare_local_variables (string type, ArrayList variable_declarators, Location loc)
+Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
 {
        Block implicit_block;
        ArrayList inits = null;
@@ -3367,20 +3712,18 @@ Block declare_local_variables (string type, ArrayList variable_declarators, Loca
        // int j = 1;  int k = j + 1;
        //
        if (current_block.Used)
-               implicit_block = new Block (current_block, true);
+               implicit_block = new Block (current_block, true, loc, Location.Null);
        else
                implicit_block = current_block;
 
        foreach (VariableDeclaration decl in variable_declarators){
-               if (implicit_block.AddVariable (type, decl.identifier, decl.Location)){
+
+               if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
                        if (decl.expression_or_array_initializer != null){
                                if (inits == null)
                                        inits = new ArrayList ();
                                inits.Add (decl);
                        }
-               } else {
-                       Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
-                                        "' is already defined in this scope");
                }
        }
 
@@ -3397,11 +3740,7 @@ Block declare_local_variables (string type, ArrayList variable_declarators, Loca
                } else {
                        ArrayList init = (ArrayList) decl.expression_or_array_initializer;
                        
-                       string base_type = type.Substring (0, type.IndexOf ("["));
-                       string rank = type.Substring (type.IndexOf ("["));
-
-                       expr = new ArrayCreation (base_type, rank, init, decl.Location);
-                       
+                       expr = new ArrayCreation (type, "", init, decl.Location);
                }
 
                LocalVariableReference var;
@@ -3409,13 +3748,13 @@ Block declare_local_variables (string type, ArrayList variable_declarators, Loca
 
                assign = new Assign (var, expr, decl.Location);
 
-               implicit_block.AddStatement (new StatementExpression (assign));
+               implicit_block.AddStatement (new StatementExpression (assign, lexer.Location));
        }
        
        return implicit_block;
 }
 
-Block declare_local_constant (string type, VariableDeclaration decl)
+Block declare_local_constant (Expression type, VariableDeclaration decl)
 {
        Block implicit_block;
 
@@ -3425,9 +3764,7 @@ Block declare_local_constant (string type, VariableDeclaration decl)
                implicit_block = current_block;
 
        if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
-                                         decl.Location))){
-               Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
-                             "' is already defined in this scope");
+                                         current_local_parameters, decl.Location))){
        }
        
        return implicit_block;
@@ -3442,7 +3779,7 @@ void CheckAttributeTarget (string a)
                
        default :
                Location l = lexer.Location;
-               Report.Error (658, l, "Invalid attribute target");
+               Report.Error (658, l, "`" + a + "' is an invalid attribute target");
                break;
        }
 
@@ -3524,46 +3861,34 @@ public Tokenizer Lexer {
        }
 }                 
 
-public CSharpParser(RootContext rc, string name, System.IO.Stream input)
+public CSharpParser (string name, System.IO.Stream input, ArrayList defines)
 {
        current_namespace = new Namespace (null, "");
-       this.rc = rc;
-       this.tree = rc.Tree;
        this.name = name;
        this.input = input;
-       current_container = tree.Types;
+       current_container = RootContext.Tree.Types;
        current_container.Namespace = current_namespace;
        oob_stack = new Stack ();
+       switch_stack = new Stack ();
 
-       lexer = new Tokenizer (input, name);
+       lexer = new Tokenizer (input, name, defines);
 }
 
-public override int parse ()
+public override void parse ()
 {
-       StringBuilder value = new StringBuilder ();
-
-       global_errors = 0;
        try {
                if (yacc_verbose_flag)
                        yyparse (lexer, new yydebug.yyDebugSimple ());
                else
                        yyparse (lexer);
        } catch (Exception e){
-               // Console.WriteLine ("Fatal error: " + name);
-               // Console.WriteLine (lexer.location);
-
-               // 
                // Please do not remove this, it is used during debugging
                // of the grammar
                //
                Console.WriteLine (lexer.location + "  : Parsing error ");
                Console.WriteLine (e);
-               global_errors++;
        }
-       
-       return global_errors;
 }
 
-
 /* end end end */
 }