Anirban Bhattacharjee <banirban@novell.com>
[mono.git] / mcs / mbas / mb-parser.jay
index c27a21a4bab710f0c15ad8edf4446c841dee6c1b..8463b685797863637342a9f23ce8bf603fd2871b 100644 (file)
@@ -3,13 +3,12 @@
 // Mono.MonoBASIC.Parser.cs (from .jay): The Parser for the MonoBASIC compiler
 //
 // Author: A Rafael D Teixeira (rafaelteixeirabr@hotmail.com)
+//                Anirban Bhattacharjee (banirban@novell.com)
 //
 // Licensed under the terms of the GNU GPL
 //
 // Copyright (C) 2001 A Rafael D Teixeira
 //
-// TODO:
-//     Nearly everything
 //
 
 namespace Mono.MonoBASIC
@@ -415,12 +414,14 @@ namespace Mono.MonoBASIC
 %token DEFAULT 
 %token DELEGATE        
 %token DIM
+%token DIRECTCAST
 %token DO      
 %token DOUBLE  
 %token EACH    
 %token ELSE
 %token ELSEIF
 %token END
+%token ENDIF
 %token ENUM    
 %token EOL
 %token ERASE
@@ -434,7 +435,8 @@ namespace Mono.MonoBASIC
 %token FRIEND
 %token FUNCTION
 %token GET
-//%token GETTYPE
+%token GETTYPE
+%token GOSUB
 %token GOTO    
 %token HANDLES
 %token IF      
@@ -512,6 +514,7 @@ namespace Mono.MonoBASIC
 %token UNICODE
 %token UNTIL
 %token VARIANT 
+%token WEND
 %token WHEN    
 %token WHILE   
 %token WITH
@@ -543,7 +546,7 @@ namespace Mono.MonoBASIC
 %token DIV            "/"
 %token OP_EXP         "^"
 %token INTERR         "?"
-%token OP_IDIV        "\\"
+%token OP_IDIV        "\\" //FIXME: This should be "\"
 %token OP_CONCAT      "&"
 %token EXCLAMATION    "!"
 
@@ -618,11 +621,6 @@ logical_end_of_line
        | logical_end_of_line pp_directive 
        ;
 
-opt_logical_end_of_line
-       : /* empty */
-       | logical_end_of_line
-       ;
-
 compilation_unit
        : logical_end_of_line
          opt_option_directives
@@ -769,7 +767,7 @@ opt_type_character
 
 qualified_identifier
        : identifier
-       | qualified_identifier DOT identifier 
+       | qualified_identifier DOT identifier // FIXME: It should be qualified_identifier DOT identifier-or-keyword
          { 
            $$ = (($1).ToString ()) + "." + ($3.ToString ()); 
          }
@@ -791,15 +789,15 @@ imports_directive
 
 imports_terms
        : imports_term
-       | imports_terms COMMA imports_terms
+       | imports_terms COMMA imports_term
        ;
        
 imports_term
-       : qualified_identifier
+       : namespace_or_type_name 
          {
                RootContext.SourceBeingCompiled.Imports ((string) $1, lexer.Location);
          }
-       | qualified_identifier ASSIGN qualified_identifier
+       | identifier ASSIGN namespace_or_type_name 
          {
                RootContext.SourceBeingCompiled.ImportsWithAlias ((string) $1, (string) $3, lexer.Location);
          }
@@ -810,130 +808,99 @@ opt_params
        | OPEN_PARENS CLOSE_PARENS      { $$ = Parameters.EmptyReadOnlyParameters; }
        | OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS    { $$ = $2; }
        ;
-       
-opt_attributes
-       : /* empty */
-       | attribute_sections    { $$ = $1; }
+
+global_attribute_list
+       : global_attribute
+       | global_attribute_list COMMA global_attribute
        ;
 
-attribute_sections
-       : attribute_section
-          { 
-               AttributeSection sect = (AttributeSection) $1;
+global_attribute
+       : attribute_modifier COLON attribute
 
-               if (sect.Target == "assembly") 
-                       RootContext.AddGlobalAttributeSection (current_container, sect);
-               
-               $$ = new Attributes ((AttributeSection) $1, lexer.Location);
-               
-          }    
-          /* 
-             FIXME: we should check if extended syntax is enabled;
-                    otherwise an exception should be thrown since VB.NET 
-                    only allows one attribute section 
-          */  
-       | attribute_sections attribute_section
-         {
-               Attributes attrs = null;
-               AttributeSection sect = (AttributeSection) $2;
-
-               if (sect.Target == "assembly")
-                       RootContext.AddGlobalAttributeSection (current_container, sect);
-
-               if ($1 != null) {
-                       attrs = (Attributes) $1;
-                       attrs.AddAttributeSection (sect);
-               }
-               
-               $$ = attrs;
-         }     
+attribute_modifier
+       : ASSEMBLY 
+       | MODULE
+       | identifier 
+          { 
+               Report.Error (658, lexer.Location, "`" + (string)$1 + "' is an invalid attribute target");
+          }
        ;
-       
-attribute_section
-       : OP_LT attribute_target_specifier attribute_list OP_GT
-         { 
-               string target = null;
-               
-               if ($2 != null)
-                       target = (string) $2;
-               
-               $$ = new AttributeSection (target, (ArrayList) $3);
-         }     
-       | OP_LT attribute_list OP_GT
-         {
-               $$ = new AttributeSection (null, (ArrayList) $2);
-         }     
-       ; 
 
-attribute_target_specifier
-       : attribute_target COLON
-         {
-               $$ = $1;
-         }
+opt_attributes
+       : /* empty */
+       | attributes    { $$ = $1; }
+       ;
+
+attr_begin
+       : OP_LT
        ;
 
-attribute_target
-       : identifier
-         {
-               CheckAttributeTarget ((string) $1);
-               $$ = $1;
-         }
-        | EVENT  { $$ = "event"; }       
-        | RETURN { $$ = "return"; }
+attr_end
+       : OP_GT
        ;
-       
+
+attributes
+       : attr_begin attribute_list attr_end
+         {
+               AttributeSection sect = new AttributeSection (null, (ArrayList) $2);
+               $$ = new Attributes (sect, lexer.Location);
+         }
+       | attr_begin global_attribute_list attr_end logical_end_of_line
+       ; 
+
 attribute_list
-       : attribute 
-         {
-               ArrayList attrs = new ArrayList ();
-               attrs.Add ($1);
+       : attribute 
+         {
+               ArrayList attrs = new ArrayList ();
+               attrs.Add ($1);
 
-               $$ = attrs;
+               $$ = attrs;
               
-         }     
-       | attribute_list COMMA attribute
-         {
-               ArrayList attrs = (ArrayList) $1;
-               attrs.Add ($3);
+         }     
+       | attribute_list COMMA attribute
+         {
+               ArrayList attrs = (ArrayList) $1;
+               attrs.Add ($3);
+
+               $$ = attrs;
+         }     
+       ;
 
-               $$ = attrs;
-         }     
-       ;
-       
 attribute 
-       : attribute_name
-         {
-               $$ = lexer.Location;
-         }
-         opt_attribute_arguments
-         {
-               $$ = new Mono.MonoBASIC.Attribute ((string) $1, (ArrayList) $3, (Location) $2);
-         }       
-       ;
-       
+       : attribute_name
+         {
+               $$ = lexer.Location;
+         }
+         opt_attribute_arguments
+         {
+               $$ = new Mono.MonoBASIC.Attribute ((string) $1, (ArrayList) $3, (Location) $2);
+         }       
+       ;
+
 attribute_name
-       : type_name 
+       : namespace_or_type_name 
        ;
                        
 opt_attribute_arguments
        : /* empty */   { $$ = null; }
-       | OPEN_PARENS attribute_arguments CLOSE_PARENS
+       | OPEN_PARENS opt_attribute_arguments_list CLOSE_PARENS
          {
                $$ = $2;
          }     
        ;
+
+opt_attribute_arguments_list
+       : /* empty */
+       | attribute_arguments_list
+       ;               
        
-attribute_arguments
-       : opt_positional_argument_list
+attribute_arguments_list
+       : positional_argument_list
          {
-               if ($1 == null)
-                       $$ = null;
-               else {
-                       ArrayList args = new ArrayList ();
-                       args.Add ($1);
-               
-                       $$ = args;
-               }
+               ArrayList args = new ArrayList ();
+               args.Add ($1);
+       
+               $$ = args;
          }
         | positional_argument_list COMMA named_argument_list
          {
@@ -953,21 +920,15 @@ attribute_arguments
          }
         ;
 
-
-opt_positional_argument_list
-       : /* empty */           { $$ = null; } 
-       | positional_argument_list
-       ;
-
 positional_argument_list
-       : expression
+       : constant_expression
          {
                ArrayList args = new ArrayList ();
                args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
 
                $$ = args;
          }
-        | positional_argument_list COMMA expression
+        | positional_argument_list COMMA constant_expression
         {
                ArrayList args = (ArrayList) $1;
                args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
@@ -994,7 +955,7 @@ named_argument_list
         ;
 
 named_argument
-       : identifier ATTR_ASSIGN expression
+       : identifier ATTR_ASSIGN constant_expression //FIXME: It should be identifier_or_keyword ATTR_ASSIGN constant_expression
          {
                $$ = new DictionaryEntry (
                        (string) $1, 
@@ -1003,19 +964,10 @@ named_argument
        ;
                                
 namespace_declaration
-       : opt_attributes NAMESPACE qualified_identifier logical_end_of_line
+       : NAMESPACE qualified_identifier logical_end_of_line
          {
-               Attributes attrs = (Attributes) $1;
-
-               if (attrs != null) {
-                       foreach (AttributeSection asec in attrs.AttributeSections)
-                               if (asec.Target == "assembly")
-                                       RootContext.AddGlobalAttributeSection (current_container, asec);
-               }
-                         
-               current_namespace = RootContext.Tree.RecordNamespace(current_namespace, name, (string)$3);
+               current_namespace = RootContext.Tree.RecordNamespace(current_namespace, name, (string)$2);
          } 
-         opt_imports_directives
          opt_declarations
          END NAMESPACE logical_end_of_line
          { 
@@ -1066,7 +1018,17 @@ class_declaration
          END CLASS logical_end_of_line
          {
                Class new_class = (Class) current_container;
-               new_class.Bases = (ArrayList) $4;       
+               
+               ArrayList bases = (ArrayList) $4;
+
+               ArrayList ifaces = (ArrayList) $5;
+               if (ifaces != null){
+                       if (bases != null)      
+                               bases.AddRange(ifaces);
+                       else
+                               bases = ifaces;
+               }
+               new_class.Bases = bases;
        
                current_container = current_container.Parent;
                CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
@@ -1340,7 +1302,7 @@ sub_declaration
          {
                Method method = new Method (TypeManager.system_void_expr, (int) current_modifiers, (string) $2,
                                            (Parameters) current_local_parameters, (Attributes) current_attributes, 
-                                           (Expression) $5, member_location);
+                                           (ArrayList) $5, member_location);
        
                method.Block = (Block) end_block();
                $$ = method;
@@ -1403,7 +1365,7 @@ func_declaration
 
                Method method = new Method ((Expression) ftype, (int) current_modifiers, (string) $2,
                                            (Parameters) current_local_parameters, (Attributes) current_attributes,/* (Attributes) currx ent_attributes,  */
-                                           (Expression) $6, member_location);
+                                           (ArrayList) $6, member_location);
                method.Block = end_block();
                $$ = method;
          }       
@@ -1479,33 +1441,51 @@ struct_member_declarator
        ;
        
 event_declaration
-       : EVENT identifier AS type logical_end_of_line
+       : EVENT identifier AS type opt_implement_clause logical_end_of_line
          {
                VariableDeclaration var = new VariableDeclaration ((string) $2, (Expression) $4, lexer.Location);
 
                Event e = new Event ((Expression) $4, var.identifier, 
                                     null, current_modifiers, null, null, 
-                                    current_attributes, lexer.Location);
+                                    current_attributes, (ArrayList) $5,
+                                    lexer.Location);
 
                CheckDef (current_container.AddEvent (e), e.Name, e.Location);
-
          }
-       | EVENT identifier opt_params logical_end_of_line
+       | EVENT identifier opt_params opt_implement_clause logical_end_of_line
          {
-               string delName = (string) $2;
-               delName = delName + "EventHandler";
-           Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate 
-                                               (current_container, TypeManager.system_void_expr, 
-                                            (int) current_modifiers, MakeName(delName), (Parameters) $3, 
-                                            (Attributes) current_attributes, lexer.Location);
-                                                 
-               del.Namespace = current_namespace;
-               CheckDef (current_container.AddDelegate (del), del.Name, lexer.Location);
-         
+               string delName = null;
+
+               if ($4 == null) {
+                       delName = (string) $2;
+                       delName = delName + "EventHandler";
+                       Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate 
+                                                       (current_container, TypeManager.system_void_expr, 
+                                                       (int) current_modifiers, MakeName(delName), (Parameters) $3, 
+                                                       (Attributes) current_attributes, lexer.Location);
+                                                         
+                       del.Namespace = current_namespace;
+                       CheckDef (current_container.AddDelegate (del), del.Name, lexer.Location);
+               } else {
+                       ArrayList impls = (ArrayList) $4;
+                       if (impls.Count > 1) {
+                               string expstr = "Event '" + ((Expression) impls[1]).ToString () +
+                                       "' can not be implemented with Event '" +
+                                       (string) $2 + "', since it's delegate type does not match " +
+                                       "with the delegate type of '" + ((Expression) impls[0]).ToString () + "'";
+                               Report.Error (31407, lexer.Location, expstr);
+                       }                       
+                       Expression impl = (Expression) impls[0];  
+                       delName = impl.ToString();
+                       delName = delName.Substring (delName.LastIndexOf(".") + 1);
+                       delName = delName + "EventHandler";
+               }
+               
                Event e = new Event (DecomposeQI (delName, lexer.Location),
                                         (string) $2, 
                                     null, current_modifiers, null, null, 
-                                    current_attributes, lexer.Location);
+                                    current_attributes, (ArrayList) $4, 
+                                    lexer.Location);
 
                CheckDef (current_container.AddEvent (e), e.Name, e.Location);
          }
@@ -1513,7 +1493,7 @@ event_declaration
        
 enum_declaration
        : ENUM identifier opt_type_spec logical_end_of_line
-         opt_enum_member_declarations
+         opt_enum_member_declarations // FIXME: BC30280: Enum must contain atleast one member
          { 
                Location enum_location = lexer.Location;
                string full_name = MakeName ((string) $2);
@@ -1657,88 +1637,138 @@ interface_member_declarations
        ;
 
 interface_member_declaration
+       : opt_attributes
+         opt_modifiers
+         { 
+               current_attributes = (Attributes) $1;
+               current_modifiers = ((int)$2) | Modifiers.ABSTRACT; 
+         }
+         interface_member_declarator
+         {
+               $$ = $3;
+         }
+       ;
+       
+interface_member_declarator
        : interface_method_declaration          
          { 
-               InterfaceMethod m = (InterfaceMethod) $1;
-
+               Method m = (Method) $1;
                CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
          }
        | interface_property_declaration        
-         { 
-               InterfaceProperty p = (InterfaceProperty) $1;
-               
-               CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
-          }
        | interface_event_declaration 
-          { 
-               InterfaceEvent e = (InterfaceEvent) $1;
-
-               CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
-         }
        ;
 
-opt_new
-       : /* empty */   { $$ = false; }
-       | NEW           { $$ = true; }
-       ;
-       
 interface_method_declaration
-       : SUB identifier
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS logical_end_of_line
+       : SUB identifier opt_params logical_end_of_line
          {
-               $$ = new InterfaceMethod (TypeManager.system_void_expr, (string) $2, false,
-                                         (Parameters) $4, current_attributes, lexer.Location);
-         }
-       | FUNCTION identifier opt_type_character
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS AS type
-         {
-               if ($3 != null && $3 != $8)
-                       Report.Error (-1, lexer.Location, "Type character conflicts with declared type."); // TODO: Correct error number and message text
+               Method method = new Method (TypeManager.system_void_expr, (int) current_modifiers, (string) $2,
+                                           (Parameters) $3, current_attributes, null, lexer.Location);
                
-               $$ = new InterfaceMethod (
-                                         (Expression) $8, (string) $2, false, (Parameters) $5,
-                                         current_attributes, lexer.Location);
+               $$ = method;
          }
-       | FUNCTION identifier type_character
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+       | FUNCTION identifier opt_type_character opt_params opt_type_with_ranks logical_end_of_line
          {
-               $$ = new InterfaceMethod (
-                                         (Expression) $3, (string) $2, false, (Parameters) $5,
-                                         current_attributes, lexer.Location);
+               Expression ftype = ($5 == null) ? (($3 == null) ? TypeManager.  
+                       system_object_expr : (Expression) $3 ) : (Expression) $5;
+               
+               Method method = new Method ((Expression) ftype, (int) current_modifiers, 
+                                               (string) $2,(Parameters) $4, current_attributes, null, 
+                                               lexer.Location);
+               
+               $$ = method;
          }
        ;
 
 interface_property_declaration
-       : opt_modifiers PROPERTY identifier
-         OPEN_PARENS
-         opt_formal_parameter_list
-         CLOSE_PARENS opt_type_spec logical_end_of_line
+       : PROPERTY identifier opt_type_character opt_property_parameters opt_type_spec logical_end_of_line
          {
-               // FIXME we MUST pass property parameters
-               $$ = new InterfaceProperty ((Expression) $6, (string) $2, false,
-                                           true, true, current_attributes,
-                                           lexer.Location);
+               Expression ftype = ($5 == null) ? (($3 == null) ? 
+                               TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $5;
+
+               current_local_parameters = (Parameters) $4;
+               if (current_local_parameters != Parameters.EmptyReadOnlyParameters) { 
+                       get_parameters = current_local_parameters.Copy (lexer.Location);
+                       set_parameters = current_local_parameters.Copy (lexer.Location);
+                       
+                       Parameter implicit_value_parameter = new Parameter (
+                                       ftype, "Value", Parameter.Modifier.NONE, null);
+                       
+                       set_parameters.AppendParameter (implicit_value_parameter);
+               }
+               else
+               {
+                       get_parameters = Parameters.EmptyReadOnlyParameters;
+                       set_parameters = new Parameters (null, null ,lexer.Location); 
+                       
+                       Parameter implicit_value_parameter = new Parameter (
+                                       ftype, "Value", Parameter.Modifier.NONE, null);
+                       
+                       set_parameters.AppendParameter (implicit_value_parameter);
+               }
+               lexer.PropertyParsing = true;
+               
+               Accessor get_block = new Accessor (null, null); 
+               Accessor set_block = new Accessor (null, null); 
+                               
+               Property prop = new Property ((Expression) ftype, (string) $2, current_modifiers,
+                                        get_block, set_block, current_attributes, lexer.Location,
+                                        null, get_parameters, set_parameters, null);
+    
+               CheckDef (current_interface.AddProperty (prop), prop.Name, lexer.Location);
+               
+               get_implicit_value_parameter_type = null;
+               set_implicit_value_parameter_type = null;
+               get_parameters = null;
+               set_parameters = null;
+               current_local_parameters = null;                        
          }
        ;
        
 interface_event_declaration
-       : opt_attributes opt_new EVENT type identifier logical_end_of_line
+       : EVENT identifier AS type logical_end_of_line
          {
-               $$ = new InterfaceEvent ((Expression) $4, (string) $5, (bool) $2, (Attributes) $1,
-                                        lexer.Location);
+               VariableDeclaration var = new VariableDeclaration ((string) $2, (Expression) $4, lexer.Location);
+
+               Event e = new Event ((Expression) $4, var.identifier, 
+                                    null, current_modifiers, null, null, 
+                                    current_attributes, lexer.Location);
+
+               CheckDef (current_interface.AddEvent (e), e.Name, e.Location);
+
+         }
+       | EVENT identifier opt_params logical_end_of_line
+         {
+               string delName = (string) $2;
+               delName = delName + "EventHandler";
+               int delModifiers = (current_modifiers & ~Modifiers.ABSTRACT);
+           Mono.MonoBASIC.Delegate del = new Mono.MonoBASIC.Delegate 
+                                               (current_container, TypeManager.system_void_expr, 
+                                            (int) delModifiers, MakeName(delName), (Parameters) $3, 
+                                            (Attributes) current_attributes, lexer.Location);
+                                                 
+               del.Namespace = current_namespace;
+               CheckDef (current_interface.AddDelegate (del), del.Name, lexer.Location);
+         
+               Event e = new Event (DecomposeQI (delName, lexer.Location),
+                                        (string) $2, 
+                                    null, current_modifiers, null, null, 
+                                    current_attributes, lexer.Location);
+
+               CheckDef (current_interface.AddEvent (e), e.Name, e.Location);
          }
        ;
 
- property_declaration
-       : abstruct_propery_declaration
-       | non_abstruct_propery_declaration 
+property_declaration
+       : abstract_propery_declaration
+       | non_abstract_propery_declaration 
        ;
        
-abstruct_propery_declaration
-       : MUSTOVERRIDE PROPERTY identifier opt_type_character opt_property_parameters AS type logical_end_of_line
+abstract_propery_declaration
+       : MUSTOVERRIDE PROPERTY identifier opt_type_character opt_property_parameters opt_type_spec logical_end_of_line
          {     
-               Expression ftype = ($7 == null) ? (($4 == null) ? 
-                               TypeManager.system_object_expr : (Expression) $4 ) : (Expression) $7;
+               Expression ftype = ($6 == null) ? (($4 == null) ? 
+                               TypeManager.system_object_expr : (Expression) $4 ) : (Expression) $6;
 
                if (current_container is Module)
                        Report.Error (30503, "Properties in a Module cannot be declared 'MustOverride'.");
@@ -1752,6 +1782,11 @@ abstruct_propery_declaration
                if (current_local_parameters != Parameters.EmptyReadOnlyParameters) { 
                        get_parameters = current_local_parameters.Copy (lexer.Location);
                        set_parameters = current_local_parameters.Copy (lexer.Location);
+                       
+                       Parameter implicit_value_parameter = new Parameter (
+                                       ftype, "Value", Parameter.Modifier.NONE, null);
+                       
+                       set_parameters.AppendParameter (implicit_value_parameter);
                }
                else
                {
@@ -1786,12 +1821,12 @@ abstruct_propery_declaration
        ;
        
        
- non_abstruct_propery_declaration
-         : PROPERTY identifier opt_type_character opt_property_parameters AS type opt_implement_clause logical_end_of_line
+ non_abstract_propery_declaration
+         : PROPERTY identifier opt_type_character opt_property_parameters opt_type_spec opt_implement_clause logical_end_of_line
          {
                get_implicit_value_parameter_type  = 
-                       ($6 == null) ? (($3 == null) ? 
-                               TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $6;
+                       ($5 == null) ? (($3 == null) ? 
+                               TypeManager.system_object_expr : (Expression) $3 ) : (Expression) $5;
                get_implicit_value_parameter_name = (string) $2;
                
                current_local_parameters = (Parameters) $4;
@@ -1814,7 +1849,7 @@ abstruct_propery_declaration
                lexer.PropertyParsing = false;
 
                Property prop;
-               Pair pair = (Pair) $10;
+               Pair pair = (Pair) $9;
                
                Accessor get_block = null;
                Accessor set_block = null;
@@ -1833,10 +1868,10 @@ abstruct_propery_declaration
                if ((current_container is Struct) && (current_modifiers == 0))
                        current_modifiers = Modifiers.PUBLIC;                           
                        
-               prop = new Property ((Expression) /*$6*/ get_implicit_value_parameter_type, 
+               prop = new Property ((Expression) get_implicit_value_parameter_type, 
                                         (string) $2, current_modifiers, get_block, set_block,
                                     current_attributes, loc, set_implicit_value_parameter_name, 
-                                    get_parameters, set_parameters, (Expression) $7);
+                                    get_parameters, set_parameters, (ArrayList) $6);
                
                CheckDef (current_container.AddProperty (prop), prop.Name, loc);
                get_implicit_value_parameter_type = null;
@@ -1863,10 +1898,26 @@ opt_implement_clause
          {
                $$ = null;
          }
-       | IMPLEMENTS qualified_identifier
+       | IMPLEMENTS implement_clause_list
          {
-               $$ = DecomposeQI ((string)$2, lexer.Location);
+               $$ = $2;
+         }
+       ;
+       
+implement_clause_list
+       : qualified_identifier
+         {
+           ArrayList impl_list = new ArrayList ();
+           impl_list.Add (DecomposeQI ((string)$1, lexer.Location));
+               $$ = impl_list;
+         }     
+       | implement_clause_list COMMA qualified_identifier
+         {
+               ArrayList impl_list = (ArrayList) $1;
+               impl_list.Add (DecomposeQI ((string)$3, lexer.Location));
+               $$ = impl_list;
          }     
+         
        ;
        
 accessor_declarations
@@ -1980,7 +2031,6 @@ field_declaration
          variable_declarators logical_end_of_line
          {               
                int mod = (int) current_modifiers;
-               
 
                VariableDeclaration.FixupTypes ((ArrayList) $2);
                VariableDeclaration.FixupArrayTypes ((ArrayList) $2);
@@ -2111,11 +2161,6 @@ opt_evt_handler
          }
        ;       
 
-opt_empty_parens
-       : /* empty */
-       | OPEN_PARENS CLOSE_PARENS
-       ;       
-
 constructor_declaration
        : SUB NEW opt_params logical_end_of_line
          {
@@ -2317,6 +2362,7 @@ opt_raise_event_args
                $$ = $2;
          }
        ;
+
 label_name
        : identifier
        | LITERAL_INTEGER
@@ -2326,7 +2372,17 @@ label_name
        ;
 
 labeled_statement
-       : label_name COLON opt_logical_end_of_line 
+       : label_name COLON
+         {
+               LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
+
+               if (!current_block.AddLabel ((string) $1, labeled)){
+                       Location l = lexer.Location;
+                       Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
+               }       
+               current_block.AddStatement (labeled);
+         }
+       | label_name COLON
          {
                LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
 
@@ -3169,22 +3225,9 @@ array_creation_expression
          }
        ;       
 
-/*delegate_creation_expression
-       : NEW type OPEN_PARENS ADDRESSOF expression CLOSE_PARENS
-         {
-           ArrayList args = new ArrayList();
-               Argument arg = new Argument ((Expression) $5, Argument.AType.Expression);
-               args.Add (arg);
-         
-               New n = new New ((Expression) $2, (ArrayList) args, lexer.Location);
-               $$ = n;
-         }
-       ;*/
-
 new_expression
        : object_creation_expression
        | array_creation_expression
-       //| delegate_creation_expression
        ;
 
 declaration_statement
@@ -3610,24 +3653,27 @@ dim_specifiers
          }     
        ;
        
-/* Expressions */
 primary_expression
        : literal
          {
-               // 7.5.1: Literals
+               //TODO
          }
-
+       | parenthesized_expression
+       | this_access
+       | base_access
        | qualified_identifier
          {
                string name = (string) $1;
                $$ = DecomposeQI (name, lexer.Location);
          }
-       | parenthesized_expression
+       //FIXME: address_of_expression is apparently missing here
+       | get_type_expression
+         {
+               // TODO
+         }
        | member_access
        | invocation_expression
        //| element_access
-       | this_access
-       | base_access
        | new_expression
        | cast_expression
        ;
@@ -3805,16 +3851,9 @@ variable_reference
        : expression {/* note ("section 5.4"); */  $$ = $1;  }
        ;
 
-negation_expression
-       : NOT expression 
-         {
-               $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
-         }
-       ;
                
 expression
-       : conditional_expression { $$ = $1; }
-       | negation_expression
+       : conditional_xor_expression { $$ = $1; }
        /*| assignment_expression*/
        ;
 
@@ -3836,24 +3875,19 @@ this_access
          }
        ;
 
-unary_expression
-       : primary_expression
-       /*| NOT prefixed_unary_expression
-         {
-               $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
-         }
-       | cast_expression */
-       ;
-       
 cast_expression
-        : cast_operator OPEN_PARENS expression CLOSE_PARENS
+        : DIRECTCAST OPEN_PARENS expression COMMA type CLOSE_PARENS
          {
-                 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
-         }     
+               // TODO
+         } 
        | CTYPE OPEN_PARENS expression COMMA type CLOSE_PARENS
          {
                  $$ = new Cast ((Expression) $5, (Expression) $3, lexer.Location);
-         }                       
+         }     
+        | cast_operator OPEN_PARENS expression CLOSE_PARENS
+         {
+                 $$ = new Cast ((Expression) $1, (Expression) $3, lexer.Location);
+         }     
        ;
        
 cast_operator
@@ -3870,19 +3904,32 @@ cast_operator
        | CSNG          { $$ = TypeManager.system_single_expr;          }
        | CSTR          { $$ = TypeManager.system_string_expr;  }
        ;
+
+get_type_expression
+       : GETTYPE OPEN_PARENS type CLOSE_PARENS
+         {
+               //TODO
+         }
+       ;
+       
+exponentiation_expression
+       : primary_expression
+       | exponentiation_expression OP_EXP primary_expression
+         {
+               //TODO
+         }                             
+       ;
        
-       //
-       // The idea to split this out is from Rhys' grammar
-       // to solve the problem with casts.
-       //
 prefixed_unary_expression
-       : unary_expression
+       : exponentiation_expression
        | PLUS prefixed_unary_expression
          {
+               //FIXME: Is this rule correctly defined ?
                $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
          }
        | MINUS prefixed_unary_expression
          {
+               //FIXME: Is this rule correctly defined ?
                $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
          }
        ;
@@ -3899,112 +3946,123 @@ multiplicative_expression
                $$ = new Binary (Binary.Operator.Division,
                                 (Expression) $1, (Expression) $3, lexer.Location);
          }
-       | multiplicative_expression OP_IDIV prefixed_unary_expression
-         {
+       ;
+
+integer_division_expression
+       : multiplicative_expression
+       | integer_division_expression OP_IDIV multiplicative_expression
+          {
+               //FIXME: Is this right ?
                $$ = new Binary (Binary.Operator.Division,
-                                (Expression) $1, (Expression) $3, lexer.Location);
-         }       
-       | multiplicative_expression MOD prefixed_unary_expression
+                          (Expression) $1, (Expression) $3, lexer.Location);
+          }
+       ;
+
+mod_expression
+       : integer_division_expression
+       | mod_expression MOD integer_division_expression
          {
-               $$ = new Binary (Binary.Operator.Modulus,
-                                (Expression) $1, (Expression) $3, lexer.Location);
+             $$ = new Binary (Binary.Operator.Modulus,
+                              (Expression) $1, (Expression) $3, lexer.Location);
          }
        ;
-
+       
 additive_expression
-       : multiplicative_expression
-       | additive_expression PLUS multiplicative_expression
+       : mod_expression
+       | additive_expression PLUS mod_expression
          {
                $$ = new Binary (Binary.Operator.Addition,
                                 (Expression) $1, (Expression) $3, lexer.Location);
          }
-       | additive_expression MINUS multiplicative_expression
+       | additive_expression MINUS mod_expression
          {
                $$ = new Binary (Binary.Operator.Subtraction,
                                 (Expression) $1, (Expression) $3, lexer.Location);
          }
-       | additive_expression OP_CONCAT multiplicative_expression
+       ;
+
+concat_expression
+       : additive_expression
+       | concat_expression OP_CONCAT additive_expression
+          {
+             // FIXME: This should only work for String expressions
+             // We probably need to use something from the runtime
+             $$ = new Binary (Binary.Operator.Addition,
+                              (Expression) $1, (Expression) $3, lexer.Location);
+         }     
+       ;
+
+shift_expression
+       : concat_expression
+       | shift_expression OP_SHIFT_LEFT concat_expression
          {
-               // FIXME: This should only work for String expressions
-               // We probably need to use something from the runtime
-               $$ = new Binary (Binary.Operator.Addition,
-                                (Expression) $1, (Expression) $3, lexer.Location);
-         }       
+               // TODO
+         }
+       | shift_expression OP_SHIFT_RIGHT concat_expression
+         {
+               //TODO
+         }
        ;
 
 relational_expression
-       : additive_expression
-       | relational_expression OP_LT additive_expression
+       : shift_expression
+       | relational_expression ASSIGN shift_expression
+         {
+               $$ = new Binary (Binary.Operator.Equality,
+                                (Expression) $1, (Expression) $3, lexer.Location);
+         }
+       | relational_expression OP_NE shift_expression
+         {
+               $$ = new Binary (Binary.Operator.Inequality, 
+                                (Expression) $1, (Expression) $3, lexer.Location);
+         }       
+       | relational_expression OP_LT shift_expression
          {
                $$ = new Binary (Binary.Operator.LessThan,
                                 (Expression) $1, (Expression) $3, lexer.Location);
          }
-       | relational_expression OP_GT additive_expression
+       | relational_expression OP_GT shift_expression
          {
                $$ = new Binary (Binary.Operator.GreaterThan,
                                 (Expression) $1, (Expression) $3, lexer.Location);
          }
-       | relational_expression OP_LE additive_expression
+       | relational_expression OP_LE shift_expression
          {
                $$ = new Binary (Binary.Operator.LessThanOrEqual,
                                 (Expression) $1, (Expression) $3, lexer.Location);
          }
-       | relational_expression OP_GE additive_expression
+       | relational_expression OP_GE shift_expression
          {
                $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
                                 (Expression) $1, (Expression) $3, lexer.Location);
          }
-       | relational_expression IS unary_expression
+       | relational_expression IS shift_expression
          {
-               $$ = new Binary (Binary.Operator.Equality,
-                       (Expression) $1, (Expression) $3, lexer.Location);
+               //FIXME: Is this rule correctly defined ?
          }
-       | relational_expression AS type_name
+       | TYPEOF shift_expression IS namespace_or_type_name
          {
-               $$ = new As ((Expression) $1, (Expression) $3, lexer.Location);
+                 //FIXME: Is this rule correctly defined ?
          }
        ;
 
-equality_expression
+negation_expression
        : relational_expression
-       | equality_expression ASSIGN relational_expression
-         {
-               $$ = new Binary (Binary.Operator.Equality,
-                                (Expression) $1, (Expression) $3, lexer.Location);
-         }
-       | equality_expression OP_NE relational_expression
-         {
-               $$ = new Binary (Binary.Operator.Inequality, 
-                                (Expression) $1, (Expression) $3, lexer.Location);
-         }       
-       ;
-
-and_expression
-       : equality_expression
-       | and_expression AND equality_expression
-         {
-               $$ = new Binary (Binary.Operator.BitwiseAnd,
-                                (Expression) $1, (Expression) $3, lexer.Location);
-         }
-       ;
-
-exclusive_or_expression
-       : and_expression
-       | exclusive_or_expression OP_XOR and_expression
+       | NOT negation_expression 
          {
-               $$ = new Binary (Binary.Operator.ExclusiveOr,
-                                (Expression) $1, (Expression) $3, lexer.Location);
+               //FIXME: Is this rule correctly defined ?
+               $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
          }
        ;
-
+       
 conditional_and_expression
-       : exclusive_or_expression
-       | conditional_and_expression AND exclusive_or_expression
+       : negation_expression
+       | conditional_and_expression AND negation_expression
          {
                $$ = new Binary (Binary.Operator.LogicalAnd,
                                 (Expression) $1, (Expression) $3, lexer.Location);
          }
-       | conditional_and_expression ANDALSO exclusive_or_expression
+       | conditional_and_expression ANDALSO negation_expression
          {     // FIXME: this is likely to be broken
                $$ = new Binary (Binary.Operator.LogicalAnd,
                                 (Expression) $1, (Expression) $3, lexer.Location);
@@ -4025,8 +4083,13 @@ conditional_or_expression
          }
        ;
 
-conditional_expression
+conditional_xor_expression
        : conditional_or_expression
+       | conditional_xor_expression XOR conditional_or_expression
+       {
+             $$ = new Binary (Binary.Operator.ExclusiveOr,
+                              (Expression) $1, (Expression) $3, lexer.Location);
+       }
        ;
 
 assignment_expression
@@ -4044,70 +4107,23 @@ assignment_expression
                n.isDelegate = true;
                $$ = new Assign ((Expression) $1, (Expression) n, lexer.Location);
          }
-       | prefixed_unary_expression OP_MULT_ASSIGN expression
-         {
-               Location l = lexer.Location;
-
-               $$ = new CompoundAssign (
-                       Binary.Operator.Multiply, (Expression) $1, (Expression) $3, l);
-         }
-       | prefixed_unary_expression OP_DIV_ASSIGN expression
-         {
-               Location l = lexer.Location;
-
-               $$ = new CompoundAssign (
-                       Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
-         }
-       | prefixed_unary_expression OP_IDIV_ASSIGN expression
-         {
-               Location l = lexer.Location;
-
-               $$ = new CompoundAssign (
-                       Binary.Operator.Division, (Expression) $1, (Expression) $3, l);
-         }       
-       | prefixed_unary_expression OP_ADD_ASSIGN expression
-         {
-               Location l = lexer.Location;
-
-               $$ = new CompoundAssign (
-                       Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
-         }
-       | prefixed_unary_expression OP_SUB_ASSIGN expression
-         {
-               Location l = lexer.Location;
-
-               $$ = new CompoundAssign (
-                       Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, l);
-         }
-       | prefixed_unary_expression OP_CONCAT_ASSIGN expression
-         {
-               Location l = lexer.Location;
-
-               $$ = new CompoundAssign (
-                       Binary.Operator.Addition, (Expression) $1, (Expression) $3, l);
-         }               
        ;
 
-/*constant_expression
+constant_expression
        : expression
        ;
-*/
 
 boolean_expression
        : expression
        ;
 
 type
-       : type_name {   /* class_type */
-               /*
-                  This does interfaces, delegates, struct_types, class_types,
-                  parent classes, and more! 4.2
-                */
+       : namespace_or_type_name 
+         {     
                $$ = DecomposeQI ((string) $1, lexer.Location); 
          }
        | builtin_types 
-       /*| array_type 
-        | pointer_type */
+       //| array_type 
        ;
 
 type_list
@@ -4127,37 +4143,45 @@ type_list
          }
        ;
 
-type_name
-       : namespace_or_type_name
-       ;
-       
 namespace_or_type_name
        : qualified_identifier
        ;
 
-/* Built-in / Integral types */
 builtin_types
        : OBJECT        { $$ = TypeManager.system_object_expr; }
-       | STRING        { $$ = TypeManager.system_string_expr; }
+       | primitive_type
+       ;
+
+primitive_type
+       : numeric_type
        | BOOLEAN       { $$ = TypeManager.system_boolean_expr; }
-       | DECIMAL       { $$ = TypeManager.system_decimal_expr; }
-       | SINGLE        { $$ = TypeManager.system_single_expr; }
-       | DOUBLE        { $$ = TypeManager.system_double_expr; }
        | DATE          { $$ = TypeManager.system_date_expr; }
-       | integral_type
+       | CHAR          { $$ = TypeManager.system_char_expr; }
+       | STRING        { $$ = TypeManager.system_string_expr; }
+       ;
+       
+
+numeric_type
+       : integral_type
+       | floating_point_type
+       | DECIMAL       { $$ = TypeManager.system_decimal_expr; }
        ;
 
 integral_type
        :
        | BYTE          { $$ = TypeManager.system_byte_expr; }
        | SHORT         { $$ = TypeManager.system_int16_expr; }
-       | LONG          { $$ = TypeManager.system_int64_expr; }
        | INTEGER       { $$ = TypeManager.system_int32_expr; }
-       | CHAR          { $$ = TypeManager.system_char_expr; }
+       | LONG          { $$ = TypeManager.system_int64_expr; }
+       ;
+       
+floating_point_type
+       : SINGLE        { $$ = TypeManager.system_single_expr; }
+       | DOUBLE        { $$ = TypeManager.system_double_expr; }
        ;
 
 interface_type
-       : type_name
+       : namespace_or_type_name
        ;
        
 pp_directive