3 // cs-parser.jay: The Parser for the C# compiler
5 // Author: Miguel de Icaza (miguel@gnu.org)
7 // Licensed under the terms of the GNU GPL
9 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (1) Get rid of the *Collections.cs, that is an idea I took from System.CodeDOM
13 // And come to think of it, it is not that great, it duplicates a lot of code
14 // for something which is not really needed. We still have piles of typecasts
15 // anwyays (due to the nature of the stack being a collection of Objects).
17 // (2) Figure out why error productions dont work. `type-declaration' is a
18 // great spot to put an `error' because you can reproduce it with this input:
21 // (3) Move Modifier checking from each object into the parser itself, that will
22 // get rid of the global "error" symbol that we use now to report errors.
23 // We still need to pass a pointer to the tree.ErrorHandler, but that is a
31 using System.Collections;
37 public class CSharpParser : GenericParser {
38 Namespace current_namespace;
39 TypeContainer current_container;
42 // Current block is used to add statements as we find
49 // Current interface is used by the various declaration
50 // productions in the interface declaration to "add"
51 // the interfaces as we find them.
53 Interface current_interface;
56 // This is used by the unary_expression code to resolve
57 // a name against a parameter.
59 Parameters current_local_parameters;
62 // Using during property parsing to describe the implicit
63 // value parameter that is passed to the "set" and "get"accesor
64 // methods (properties and indexers).
66 string implicit_value_parameter_type;
67 Parameters indexer_parameters;
70 // Used to determine if we are parsing the get/set pair
71 // of an indexer or a property
76 // An out-of-band stack.
82 %token NONE /* This token is never returned by our lexer */
83 %token ERROR // This is used not by the parser, but by the tokenizer.
87 *These are the C# keywords
168 /* C# keywords which are not really keywords */
172 /* C# single character operators/punctuation. */
173 %token OPEN_BRACE "{"
174 %token CLOSE_BRACE "}"
175 %token OPEN_BRACKET "["
176 %token CLOSE_BRACKET "]"
177 %token OPEN_PARENS "("
178 %token CLOSE_PARENS ")"
191 %token BITWISE_AND "&"
192 %token BITWISE_OR "|"
199 /* C# multi-character operators. */
202 %token OP_SHIFT_LEFT "<<"
203 %token OP_SHIFT_RIGHT ">>"
210 %token OP_MULT_ASSIGN "*="
211 %token OP_DIV_ASSIGN "/="
212 %token OP_MOD_ASSIGN "%="
213 %token OP_ADD_ASSIGN "+="
214 %token OP_SUB_ASSIGN "-="
215 %token OP_SHIFT_LEFT_ASSIGN "<<="
216 %token OP_SHIFT_RIGHT_ASSIGN ">>="
217 %token OP_AND_ASSIGN "&="
218 %token OP_XOR_ASSIGN "^="
219 %token OP_OR_ASSIGN "|="
223 %token LITERAL_INTEGER "int literal"
224 %token LITERAL_FLOAT "float literal"
225 %token LITERAL_DOUBLE "double literal"
226 %token LITERAL_DECIMAL "decimal literal"
227 %token LITERAL_CHARACTER "character literal"
228 %token LITERAL_STRING "string literal"
232 /* Add precedence rules to solve dangling else s/r conflict */
241 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
243 %left STAR DIV PERCENT
244 %right BANG CARRET UMINUS
245 %nonassoc OP_INC OP_DEC
247 %left OPEN_BRACKET OPEN_BRACE
251 %start compilation_unit
252 /*%start namespace_declaration */
256 : opt_using_directives opt_namespace_member_declarations opt_EOF
258 // Check that using comes only before namespace elements
269 | using_directives using_directive
273 : using_alias_directive
274 | using_namespace_directive
277 using_alias_directive
278 : USING IDENTIFIER ASSIGN
279 namespace_or_type_name SEMICOLON
281 current_namespace.UsingAlias ((string) $2, (string) $4);
285 using_namespace_directive
286 : USING namespace_name SEMICOLON
288 current_namespace.Using ((string) $2);
292 // namespace_declarations
293 // : namespace_declaration
294 // | namespace_declarations namespace_declaration
296 namespace_declaration
297 : NAMESPACE qualified_identifier
299 current_namespace = RootContext.Tree.RecordNamespace (current_namespace, name, (string) $2);
301 namespace_body opt_semicolon
303 current_namespace = current_namespace.Parent;
319 | qualified_identifier DOT IDENTIFIER {
320 $$ = (($1).ToString ()) + "." + ($3.ToString ()); }
325 : namespace_or_type_name
331 opt_namespace_member_declarations
342 opt_namespace_member_declarations
344 | namespace_member_declarations
347 namespace_member_declarations
348 : namespace_member_declaration
349 | namespace_member_declarations namespace_member_declaration
352 namespace_member_declaration
359 Class c = (Class) $1;
360 mod_flags = c.ModFlags;
362 } else if ($1 is Struct){
363 Struct s = (Struct) $1;
364 mod_flags = s.ModFlags;
369 if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
370 error (1527, "Namespace elements cant be explicitly " +
371 "declared private or protected in `" + name + "'");
374 | namespace_declaration
380 | interface_declaration
382 | delegate_declaration
389 : /* empty */ { $$ = null; }
390 | attribute_section opt_attributes
395 attrs = (Attributes) $2;
396 attrs.AddAttribute ((AttributeSection) $1);
398 attrs = new Attributes ((AttributeSection) $1);
405 : OPEN_BRACKET attribute_target_specifier attribute_list CLOSE_BRACKET
407 string target = null;
410 target = (string) $2;
412 $$ = new AttributeSection (target, (ArrayList) $3);
414 | OPEN_BRACKET attribute_list CLOSE_BRACKET
416 $$ = new AttributeSection (null, (ArrayList) $2);
420 attribute_target_specifier
421 : attribute_target COLON
430 CheckAttributeTarget ((string) $1);
433 | EVENT { $$ = "event"; }
434 | RETURN { $$ = "return"; }
440 ArrayList attrs = new ArrayList ();
446 | attribute_list COMMA attribute
448 ArrayList attrs = (ArrayList) $1;
460 opt_attribute_arguments
462 $$ = new Attribute ((string) $1, (ArrayList) $3, (Location) $2);
467 : type_name { /* reserved attribute name or identifier: 17.4 */ }
470 opt_attribute_arguments
471 : /* empty */ { $$ = null; }
472 | OPEN_PARENS attribute_arguments CLOSE_PARENS
480 : positional_argument_list
482 ArrayList args = new ArrayList ();
487 | positional_argument_list COMMA named_argument_list
489 ArrayList args = new ArrayList ();
495 | named_argument_list
497 ArrayList args = new ArrayList ();
506 positional_argument_list
509 ArrayList args = new ArrayList ();
510 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
514 | positional_argument_list COMMA expression
516 ArrayList args = (ArrayList) $1;
517 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
526 ArrayList args = new ArrayList ();
531 | named_argument_list COMMA named_argument
533 ArrayList args = (ArrayList) $1;
541 : IDENTIFIER ASSIGN expression
543 $$ = new DictionaryEntry (
545 new Argument ((Expression) $3, Argument.AType.Expression));
551 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
554 opt_class_member_declarations
556 | class_member_declarations
559 class_member_declarations
560 : class_member_declaration
561 | class_member_declarations
562 class_member_declaration
565 class_member_declaration
566 : constant_declaration // done
567 | field_declaration // done
568 | method_declaration // done
569 | property_declaration // done
570 | event_declaration // done
571 | indexer_declaration // done
572 | operator_declaration // done
573 | constructor_declaration // done
574 | destructor_declaration // done
584 string full_struct_name = MakeName ((string) $4);
586 new_struct = new Struct (current_container, full_struct_name, (int) $2,
587 (Attributes) $1, lexer.Location);
588 current_container = new_struct;
589 current_container.Namespace = current_namespace;
590 RootContext.Tree.RecordStruct (full_struct_name, new_struct);
592 opt_struct_interfaces
596 Struct new_struct = (Struct) current_container;
598 current_container = current_container.Parent;
599 CheckDef (current_container.AddStruct (new_struct), new_struct.Name);
604 opt_struct_interfaces
611 | struct_interfaces struct_interface
619 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
622 opt_struct_member_declarations
624 | struct_member_declarations
627 struct_member_declarations
628 : struct_member_declaration
629 | struct_member_declarations struct_member_declaration
632 struct_member_declaration
633 : constant_declaration
636 | property_declaration
638 | indexer_declaration
639 | operator_declaration
640 | constructor_declaration
644 * This is only included so we can flag error 575:
645 * destructors only allowed on class types
647 | destructor_declaration
658 foreach (VariableDeclaration constant in (ArrayList) $5){
659 Const c = new Const (
660 (string) $4, (string) constant.identifier,
661 (Expression) constant.expression_or_array_initializer, (int) $2, (Attributes) $1,
664 CheckDef (current_container.AddConstant (c), c.Name);
670 : constant_declarator
672 ArrayList constants = new ArrayList ();
676 | constant_declarators COMMA constant_declarator
678 ArrayList constants = (ArrayList) $1;
685 : IDENTIFIER ASSIGN constant_expression
687 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
698 string type = (string) $3;
701 foreach (VariableDeclaration var in (ArrayList) $4){
702 Field field = new Field (type, mod, var.identifier,
703 var.expression_or_array_initializer, (Attributes) $1, var.Location);
705 CheckDef (current_container.AddField (field), field.Name);
711 : variable_declarator
713 ArrayList decl = new ArrayList ();
717 | variable_declarators COMMA variable_declarator
719 ArrayList decls = (ArrayList) $1;
726 : IDENTIFIER ASSIGN variable_initializer
728 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
732 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
751 Method method = (Method) $1;
752 Block b = (Block) $2;
755 if ((method.ModFlags & (Modifiers.EXTERN | Modifiers.ABSTRACT)) == 0){
757 501, lexer.Location, "`" +
758 current_container.Name + "." + method.Name + "'" +
759 "must declare a body because it is not marked abstract or extern");
763 method.Block = (Block) $2;
764 CheckDef (current_container.AddMethod (method), method.Name);
766 current_local_parameters = null;
780 1585, lexer.Location, "Member modifier `" +
781 Modifiers.Name (i) + "' must precede member type and name");
794 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
796 Method method = new Method ((string) $3, (int) $2, (string) $4,
797 (Parameters) $6, (Attributes) $1, lexer.Location);
799 current_local_parameters = (Parameters) $6;
807 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
809 Method method = new Method ("System.Void", (int) $2, (string) $4,
810 (Parameters) $6, (Attributes) $1, lexer.Location);
812 current_local_parameters = (Parameters) $6;
819 | SEMICOLON { $$ = null; }
822 opt_formal_parameter_list
823 : /* empty */ { $$ = Parameters.GetEmptyReadOnlyParameters (); }
824 | formal_parameter_list
827 formal_parameter_list
830 ArrayList pars_list = (ArrayList) $1;
832 Parameter [] pars = new Parameter [pars_list.Count];
833 pars_list.CopyTo (pars);
835 $$ = new Parameters (pars, null, lexer.Location);
837 | fixed_parameters COMMA parameter_array
839 ArrayList pars_list = (ArrayList) $1;
841 Parameter [] pars = new Parameter [pars_list.Count];
842 pars_list.CopyTo (pars);
844 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
848 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
855 ArrayList pars = new ArrayList ();
860 | fixed_parameters COMMA fixed_parameter
862 ArrayList pars = (ArrayList) $1;
871 opt_parameter_modifier
875 $$ = new Parameter ((string) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
879 opt_parameter_modifier
880 : /* empty */ { $$ = Parameter.Modifier.NONE; }
885 : REF { $$ = Parameter.Modifier.REF; }
886 | OUT { $$ = Parameter.Modifier.OUT; }
890 : opt_attributes PARAMS type IDENTIFIER
892 $$ = new Parameter ((string) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
893 note ("type must be a single-dimension array type");
898 : qualified_identifier
907 implicit_value_parameter_type = (string) $3;
909 lexer.PropertyParsing = true;
913 accessor_declarations
915 lexer.PropertyParsing = false;
920 Pair pair = (Pair) $7;
921 Block get_block = null;
922 Block set_block = null;
924 if (pair.First != null)
925 get_block = (Block) pair.First;
926 if (pair.Second != null)
927 set_block = (Block) pair.Second;
929 prop = new Property ((string) $3, (string) $4, (int) $2, get_block, set_block,
930 (Attributes) $1, (Location) $6);
932 CheckDef (current_container.AddProperty (prop), prop.Name);
933 implicit_value_parameter_type = null;
937 accessor_declarations
938 : get_accessor_declaration opt_set_accessor_declaration
940 $$ = new Pair ($1, $2);
942 | set_accessor_declaration opt_get_accessor_declaration
944 $$ = new Pair ($2, $1);
948 opt_get_accessor_declaration
949 : /* empty */ { $$ = null; }
950 | get_accessor_declaration
953 opt_set_accessor_declaration
954 : /* empty */ { $$ = null; }
955 | set_accessor_declaration
958 get_accessor_declaration
961 // If this is not the case, then current_local_parameters has already
962 // been set in indexer_declaration
963 if (parsing_indexer == false)
964 current_local_parameters = null;
966 current_local_parameters = indexer_parameters;
967 lexer.PropertyParsing = false;
972 current_local_parameters = null;
973 lexer.PropertyParsing = true;
977 set_accessor_declaration
981 Parameter implicit_value_parameter = new Parameter (
982 implicit_value_parameter_type, "value",
983 Parameter.Modifier.NONE, null);
985 if (parsing_indexer == false) {
986 args = new Parameter [1];
987 args [0] = implicit_value_parameter;
989 Parameter [] fp = indexer_parameters.FixedParameters;
990 int count = fp.Length;
992 args = new Parameter [count + 1];
995 args [count] = implicit_value_parameter;
998 current_local_parameters = new Parameters (args, null, lexer.Location);
999 lexer.PropertyParsing = false;
1004 current_local_parameters = null;
1005 lexer.PropertyParsing = true;
1011 | SEMICOLON { $$ = new Block (null); }
1014 interface_declaration
1017 INTERFACE IDENTIFIER
1019 Interface new_interface;
1020 string full_interface_name = MakeName ((string) $4);
1022 new_interface = new Interface (current_container, full_interface_name, (int) $2,
1023 (Attributes) $1, lexer.Location);
1024 if (current_interface != null) {
1025 Location l = lexer.Location;
1026 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1028 current_interface = new_interface;
1029 new_interface.Namespace = current_namespace;
1030 RootContext.Tree.RecordInterface (full_interface_name, new_interface);
1035 Interface new_interface = (Interface) current_interface;
1038 new_interface.Bases = (ArrayList) $6;
1040 current_interface = null;
1041 CheckDef (current_container.AddInterface (new_interface), new_interface.Name);
1046 : /* empty */ { $$ = null; }
1051 : COLON interface_type_list { $$ = $2; }
1057 ArrayList interfaces = new ArrayList ();
1059 interfaces.Add ($1);
1062 | interface_type_list COMMA interface_type
1064 ArrayList interfaces = (ArrayList) $1;
1065 interfaces.Add ($3);
1072 opt_interface_member_declarations
1076 opt_interface_member_declarations
1078 | interface_member_declarations
1081 interface_member_declarations
1082 : interface_member_declaration
1083 | interface_member_declarations interface_member_declaration
1086 interface_member_declaration
1087 : interface_method_declaration
1089 InterfaceMethod m = (InterfaceMethod) $1;
1091 CheckDef (current_interface.AddMethod (m), m.Name);
1093 | interface_property_declaration
1095 InterfaceProperty p = (InterfaceProperty) $1;
1097 CheckDef (current_interface.AddProperty (p), p.Name);
1099 | interface_event_declaration
1101 InterfaceEvent e = (InterfaceEvent) $1;
1103 CheckDef (current_interface.AddEvent (e), e.Name);
1105 | interface_indexer_declaration
1107 InterfaceIndexer i = (InterfaceIndexer) $1;
1109 CheckDef (current_interface.AddIndexer (i), "indexer");
1114 : /* empty */ { $$ = false; }
1115 | NEW { $$ = true; }
1118 interface_method_declaration
1119 : opt_attributes opt_new type IDENTIFIER
1120 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1123 $$ = new InterfaceMethod ((string) $3, (string) $4, (bool) $2,
1124 (Parameters) $6, (Attributes) $1, lexer.Location);
1126 | opt_attributes opt_new VOID IDENTIFIER
1127 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1130 $$ = new InterfaceMethod ("System.Void", (string) $4, (bool) $2, (Parameters) $6,
1131 (Attributes) $1, lexer.Location);
1135 interface_property_declaration
1140 { lexer.PropertyParsing = true; }
1142 { lexer.PropertyParsing = false; }
1147 $$ = new InterfaceProperty ((string) $3, (string) $4, (bool) $2,
1148 (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
1154 : opt_attributes GET SEMICOLON { $$ = 1; }
1155 | opt_attributes SET SEMICOLON { $$ = 2; }
1156 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1158 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1162 interface_event_declaration
1163 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1165 $$ = new InterfaceEvent ((string) $4, (string) $5, (bool) $2, (Attributes) $1);
1169 interface_indexer_declaration
1170 : opt_attributes opt_new type THIS
1171 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1173 { lexer.PropertyParsing = true; }
1175 { lexer.PropertyParsing = false; }
1178 int a_flags = (int) $10;
1180 bool do_get = (a_flags & 1) == 1;
1181 bool do_set = (a_flags & 2) == 2;
1183 $$ = new InterfaceIndexer ((string) $3, (Parameters) $6, do_get, do_set,
1184 (bool) $2, (Attributes) $1, lexer.Location);
1188 operator_declaration
1189 : opt_attributes opt_modifiers operator_declarator block
1191 OperatorDeclaration decl = (OperatorDeclaration) $3;
1193 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1194 decl.arg2type, decl.arg2name, (Block) $4, (Attributes) $1, decl.location);
1196 // Note again, checking is done in semantic analysis
1197 current_container.AddOperator (op);
1199 current_local_parameters = null;
1204 : type OPERATOR overloadable_operator
1205 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1207 Operator.OpType op = (Operator.OpType) $3;
1208 CheckUnaryOperator (op);
1210 if (op == Operator.OpType.Addition)
1211 op = Operator.OpType.UnaryPlus;
1213 if (op == Operator.OpType.Subtraction)
1214 op = Operator.OpType.UnaryNegation;
1216 Parameter [] pars = new Parameter [1];
1218 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1220 current_local_parameters = new Parameters (pars, null, lexer.Location);
1222 $$ = new OperatorDeclaration (op, (string) $1, (string) $5, (string) $6,
1223 null, null, lexer.Location);
1225 | type OPERATOR overloadable_operator
1227 type IDENTIFIER COMMA
1231 CheckBinaryOperator ((Operator.OpType) $3);
1233 Parameter [] pars = new Parameter [2];
1235 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1236 pars [1] = new Parameter ((string) $8, (string) $9, Parameter.Modifier.NONE, null);
1238 current_local_parameters = new Parameters (pars, null, lexer.Location);
1240 $$ = new OperatorDeclaration ((Operator.OpType) $3, (string) $1, (string) $5, (string) $6,
1241 (string) $8, (string) $9, lexer.Location);
1243 | conversion_operator_declarator
1246 overloadable_operator
1248 : BANG { $$ = Operator.OpType.LogicalNot; }
1249 | TILDE { $$ = Operator.OpType.OnesComplement; }
1250 | OP_INC { $$ = Operator.OpType.Increment; }
1251 | OP_DEC { $$ = Operator.OpType.Decrement; }
1252 | TRUE { $$ = Operator.OpType.True; }
1253 | FALSE { $$ = Operator.OpType.False; }
1254 // Unary and binary:
1255 | PLUS { $$ = Operator.OpType.Addition; }
1256 | MINUS { $$ = Operator.OpType.Subtraction; }
1258 | STAR { $$ = Operator.OpType.Multiply; }
1259 | DIV { $$ = Operator.OpType.Division; }
1260 | PERCENT { $$ = Operator.OpType.Modulus; }
1261 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1262 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1263 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1264 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1265 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1266 | OP_EQ { $$ = Operator.OpType.Equality; }
1267 | OP_NE { $$ = Operator.OpType.Inequality; }
1268 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1269 | OP_LT { $$ = Operator.OpType.LessThan; }
1270 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1271 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1274 conversion_operator_declarator
1275 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1277 Parameter [] pars = new Parameter [1];
1279 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1281 current_local_parameters = new Parameters (pars, null, lexer.Location);
1283 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (string) $3, (string) $5, (string) $6,
1284 null, null, lexer.Location);
1286 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1288 Parameter [] pars = new Parameter [1];
1290 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1292 current_local_parameters = new Parameters (pars, null, lexer.Location);
1294 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (string) $3, (string) $5, (string) $6,
1295 null, null, lexer.Location);
1299 syntax_error (lexer.Location, "'operator' expected");
1303 syntax_error (lexer.Location, "'operator' expected");
1307 constructor_declaration
1310 constructor_declarator
1313 Constructor c = (Constructor) $3;
1314 c.Block = (Block) $4;
1315 c.ModFlags = (int) $2;
1316 c.OptAttributes = (Attributes) $1;
1318 if ((c.ModFlags & Modifiers.STATIC) != 0){
1319 if ((c.ModFlags & Modifiers.Accessibility) != 0) {
1320 Location l = lexer.Location;
1321 Report.Error (515, l, "Access modifiers are not allowed on static constructors");
1324 if (c.Initializer != null){
1325 Location l = lexer.Location;
1326 Report.Error (514, l, "Static constructors can not have an explicit this or base constructor invocations");
1329 if (!c.Parameters.Empty){
1330 Location l = lexer.Location;
1331 Report.Error (132, l, "Static constructors should not have parameters");
1335 CheckDef (current_container.AddConstructor (c), c.Name);
1337 current_local_parameters = null;
1341 constructor_declarator
1343 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1345 oob_stack.Push (lexer.Location);
1347 current_local_parameters = (Parameters) $3;
1349 opt_constructor_initializer
1351 Location l = (Location) oob_stack.Pop ();
1352 $$ = new Constructor ((string) $1, (Parameters) $3, (ConstructorInitializer) $6, l);
1356 opt_constructor_initializer
1357 : /* empty */ { $$ = null; }
1358 | constructor_initializer
1361 constructor_initializer
1362 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1364 $$ = new ConstructorBaseInitializer ((ArrayList) $4, lexer.Location);
1366 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1368 $$ = new ConstructorThisInitializer ((ArrayList) $4, lexer.Location);
1372 destructor_declaration
1373 : opt_attributes TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1375 if ((string) $3 != current_container.Basename){
1376 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1377 } else if (!(current_container is Class)){
1378 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1380 Location l = lexer.Location;
1382 Method d = new Method (
1383 "System.Void", 0, "Finalize",
1384 new Parameters (null, null, l), (Attributes) $1, l);
1386 d.Block = (Block) $6;
1387 CheckDef (current_container.AddMethod (d), d.Name);
1395 EVENT type variable_declarators SEMICOLON
1397 foreach (VariableDeclaration var in (ArrayList) $5) {
1399 Event e = new Event ((string) $4, var.identifier, var.expression_or_array_initializer,
1400 (int) $2, null, null, (Attributes) $1, lexer.Location);
1402 CheckDef (current_container.AddEvent (e), e.Name);
1408 EVENT type member_name
1411 implicit_value_parameter_type = (string) $4;
1412 lexer.EventParsing = true;
1414 event_accessor_declarations
1416 lexer.EventParsing = false;
1420 Pair pair = (Pair) $8;
1421 Block add_block = null;
1422 Block rem_block = null;
1424 if (pair.First != null)
1425 add_block = (Block) pair.First;
1426 if (pair.Second != null)
1427 rem_block = (Block) pair.Second;
1429 Event e = new Event ((string) $4, (string) $5, null, (int) $2, add_block, rem_block,
1430 (Attributes) $1, lexer.Location);
1432 CheckDef (current_container.AddEvent (e), e.Name);
1433 implicit_value_parameter_type = null;
1437 event_accessor_declarations
1438 : add_accessor_declaration remove_accessor_declaration
1440 $$ = new Pair ($1, $2);
1442 | remove_accessor_declaration add_accessor_declaration
1444 $$ = new Pair ($2, $1);
1448 add_accessor_declaration
1449 : opt_attributes ADD
1451 Parameter [] args = new Parameter [1];
1452 Parameter implicit_value_parameter = new Parameter (
1453 implicit_value_parameter_type, "value",
1454 Parameter.Modifier.NONE, null);
1456 args [0] = implicit_value_parameter;
1458 current_local_parameters = new Parameters (args, null, lexer.Location);
1459 lexer.EventParsing = false;
1464 lexer.EventParsing = true;
1468 remove_accessor_declaration
1469 : opt_attributes REMOVE
1471 Parameter [] args = new Parameter [1];
1472 Parameter implicit_value_parameter = new Parameter (
1473 implicit_value_parameter_type, "value",
1474 Parameter.Modifier.NONE, null);
1476 args [0] = implicit_value_parameter;
1478 current_local_parameters = new Parameters (args, null, lexer.Location);
1479 lexer.EventParsing = false;
1484 lexer.EventParsing = true;
1489 : opt_attributes opt_modifiers indexer_declarator
1492 IndexerDeclaration decl = (IndexerDeclaration) $3;
1494 implicit_value_parameter_type = decl.type;
1496 lexer.PropertyParsing = true;
1497 parsing_indexer = true;
1499 indexer_parameters = decl.param_list;
1500 $$ = lexer.Location;
1502 accessor_declarations
1504 lexer.PropertyParsing = false;
1505 parsing_indexer = false;
1509 // The signature is computed from the signature of the indexer. Look
1510 // at section 3.6 on the spec
1513 IndexerDeclaration decl = (IndexerDeclaration) $3;
1514 Pair pair = (Pair) $6;
1515 Block get_block = null;
1516 Block set_block = null;
1518 if (pair.First != null)
1519 get_block = (Block) pair.First;
1520 if (pair.Second != null)
1521 set_block = (Block) pair.Second;
1523 indexer = new Indexer (decl.type, decl.interface_type, (int) $2, decl.param_list,
1524 get_block, set_block, (Attributes) $1, (Location) $5);
1526 // Note that there is no equivalent of CheckDef for this case
1527 // We shall handle this in semantic analysis
1529 current_container.AddIndexer (indexer);
1531 current_local_parameters = null;
1532 implicit_value_parameter_type = null;
1533 indexer_parameters = null;
1538 : type THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1540 $$ = new IndexerDeclaration ((string) $1, null, (Parameters) $4);
1542 | type qualified_identifier DOT THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1544 $$ = new IndexerDeclaration ((string) $1, (string) $2, (Parameters) $6);
1556 string full_name = MakeName ((string) $4);
1557 Enum e = new Enum (current_container, (string) $5, (int) $2, full_name, (Attributes) $1, lexer.Location);
1559 foreach (VariableDeclaration ev in (ArrayList) $6){
1560 CheckDef (e.AddEnumMember (ev.identifier,
1561 (Expression) ev.expression_or_array_initializer,
1562 (Location) ev.Location),
1566 CheckDef (current_container.AddEnum (e), name);
1571 : /* empty */ { $$ = "System.Int32"; }
1572 | COLON type { $$ = $2; }
1576 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1582 opt_enum_member_declarations
1583 : /* empty */ { $$ = new ArrayList (); }
1584 | enum_member_declarations opt_comma { $$ = $1; }
1587 enum_member_declarations
1588 : enum_member_declaration
1590 ArrayList l = new ArrayList ();
1595 | enum_member_declarations COMMA enum_member_declaration
1597 ArrayList l = (ArrayList) $1;
1605 enum_member_declaration
1606 : opt_attributes IDENTIFIER
1608 $$ = new VariableDeclaration ((string) $2, null, lexer.Location);
1610 | opt_attributes IDENTIFIER
1612 $$ = lexer.Location;
1616 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location);
1620 delegate_declaration
1624 IDENTIFIER OPEN_PARENS
1625 opt_formal_parameter_list
1629 Delegate del = new Delegate ((string) $4, (int) $2,
1630 MakeName ((string) $5), (Parameters) $7,
1631 (Attributes) $1, lexer.Location);
1633 CheckDef (current_container.AddDelegate (del), del.Name);
1638 IDENTIFIER OPEN_PARENS
1639 opt_formal_parameter_list
1643 Delegate del = new Delegate ("System.Void", (int) $2, (string) $5, (Parameters) $7,
1644 (Attributes) $1, lexer.Location);
1646 CheckDef (current_container.AddDelegate (del), del.Name);
1651 : namespace_or_type_name
1654 namespace_or_type_name
1655 : qualified_identifier
1659 * Before you think of adding a return_type, notice that we have been
1660 * using two rules in the places where it matters (one rule using type
1661 * and another identical one that uses VOID as the return type). This
1662 * gets rid of a shift/reduce couple
1665 : type_name { /* class_type */
1667 This does interfaces, delegates, struct_types, class_types,
1668 parent classes, and more! 4.2
1682 // Note that here only unmanaged types are allowed but we
1683 // can't perform checks during this phase - we do it during
1684 // semantic analysis.
1686 $$ = (string) $1 + "*";
1690 $$ = "System.Void*";
1697 $$ = new SimpleName ((string) $1, lexer.Location);
1699 | non_expression_type rank_specifier
1701 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1703 | expression rank_specifiers
1705 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1712 ArrayList types = new ArrayList ();
1717 | type_list COMMA type
1719 ArrayList types = (ArrayList) $1;
1727 * replaces all the productions for isolating the various
1728 * simple types, but we need this to reuse it easily in local_variable_type
1731 : OBJECT { $$ = "System.Object"; }
1732 | STRING { $$ = "System.String"; }
1733 | BOOL { $$ = "System.Boolean"; }
1734 | DECIMAL { $$ = "System.Decimal"; }
1735 | FLOAT { $$ = "System.Single"; }
1736 | DOUBLE { $$ = "System.Double"; }
1741 : SBYTE { $$ = "System.SByte"; }
1742 | BYTE { $$ = "System.Byte"; }
1743 | SHORT { $$ = "System.Int16"; }
1744 | USHORT { $$ = "System.UInt16"; }
1745 | INT { $$ = "System.Int32"; }
1746 | UINT { $$ = "System.UInt32"; }
1747 | LONG { $$ = "System.Int64"; }
1748 | ULONG { $$ = "System.UInt64"; }
1749 | CHAR { $$ = "System.Char"; }
1757 : type rank_specifiers
1759 $$ = (string) $1 + (string) $2;
1764 // Expressions, section 7.5
1772 | qualified_identifier
1774 string name = (string) $1;
1777 $$ = DecomposeQI (name, lexer.Location);
1779 | parenthesized_expression
1781 | invocation_expression
1785 | post_increment_expression
1786 | post_decrement_expression
1790 | checked_expression
1791 | unchecked_expression
1798 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
1799 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
1800 | NULL { $$ = NullLiteral.Null; }
1804 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
1805 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
1806 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
1811 object v = lexer.Value;
1814 // FIXME: Possible optimization would be to
1815 // compute the *Literal objects directly in the scanner
1818 $$ = new IntLiteral ((Int32) v);
1820 $$ = new UIntLiteral ((UInt32) v);
1822 $$ = new LongLiteral ((Int64) v);
1823 else if (v is ulong)
1824 $$ = new ULongLiteral ((UInt64) v);
1826 Console.WriteLine ("OOPS. Unexpected result from scanner");
1831 : TRUE { $$ = new BoolLiteral (true); }
1832 | FALSE { $$ = new BoolLiteral (false); }
1835 parenthesized_expression
1836 : OPEN_PARENS expression CLOSE_PARENS
1841 : primary_expression DOT IDENTIFIER
1843 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
1845 | predefined_type DOT IDENTIFIER
1847 $$ = new SimpleName ((string) $1 + "." + (string) $3, lexer.Location);
1855 invocation_expression
1856 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
1859 Location l = lexer.Location;
1860 Report.Error (1, l, "THIS IS CRAZY");
1862 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
1867 : /* empty */ { $$ = null; }
1874 ArrayList list = new ArrayList ();
1878 | argument_list COMMA argument
1880 ArrayList list = (ArrayList) $1;
1889 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
1891 | REF variable_reference
1893 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
1895 | OUT variable_reference
1897 $$ = new Argument ((Expression) $2, Argument.AType.Out);
1902 : expression { note ("section 5.4"); $$ = $1; }
1906 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
1908 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
1910 | primary_expression rank_specifiers
1912 // So the super-trick is that primary_expression
1913 // can only be either a SimpleName or a MemberAccess.
1914 // The MemberAccess case arises when you have a fully qualified type-name like :
1916 // SimpleName is when you have
1919 Expression expr = (Expression) $1;
1920 if (!(expr is SimpleName || expr is MemberAccess)) {
1921 Location l = lexer.Location;
1922 Report.Error (-1, l, "Invalid Type definition");
1923 $$ = "System.Object";
1927 // So we extract the string corresponding to the SimpleName
1930 $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
1937 ArrayList list = new ArrayList ();
1941 | expression_list COMMA expression
1943 ArrayList list = (ArrayList) $1;
1952 $$ = new This (lexer.Location);
1957 : BASE DOT IDENTIFIER
1959 $$ = new BaseAccess ((string) $3, lexer.Location);
1961 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
1963 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
1967 post_increment_expression
1968 : primary_expression OP_INC
1970 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
1971 (Expression) $1, lexer.Location);
1975 post_decrement_expression
1976 : primary_expression OP_DEC
1978 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
1979 (Expression) $1, lexer.Location);
1984 : object_or_delegate_creation_expression
1985 | array_creation_expression
1988 object_or_delegate_creation_expression
1989 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
1991 $$ = new New ((string) $2, (ArrayList) $4, lexer.Location);
1995 array_creation_expression
1996 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
1998 opt_array_initializer
2000 $$ = new ArrayCreation ((string) $2, (ArrayList) $4, (string) $6, (ArrayList) $7,
2003 | NEW type rank_specifiers array_initializer
2005 $$ = new ArrayCreation ((string) $2, (string) $3, (ArrayList) $4, lexer.Location);
2025 | rank_specifiers rank_specifier
2027 $$ = (string) $2 + (string) $1;
2032 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2034 $$ = "[" + (string) $2 + "]";
2054 | dim_separators COMMA
2056 $$ = (string) $1 + ",";
2060 opt_array_initializer
2072 : OPEN_BRACE CLOSE_BRACE
2074 ArrayList list = new ArrayList ();
2077 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2079 $$ = (ArrayList) $2;
2083 variable_initializer_list
2084 : variable_initializer
2086 ArrayList list = new ArrayList ();
2090 | variable_initializer_list COMMA variable_initializer
2092 ArrayList list = (ArrayList) $1;
2099 : TYPEOF OPEN_PARENS type CLOSE_PARENS
2101 $$ = new TypeOf ((string) $3, lexer.Location);
2106 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2107 $$ = new SizeOf ((string) $3);
2109 note ("Verify type is unmanaged");
2110 note ("if (5.8) builtin, yield constant expression");
2115 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2117 $$ = new CheckedExpr ((Expression) $3);
2121 unchecked_expression
2122 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2124 $$ = new UnCheckedExpr ((Expression) $3);
2129 : primary_expression
2130 | BANG prefixed_unary_expression
2132 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2134 | TILDE prefixed_unary_expression
2136 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2138 | OPEN_PARENS expression CLOSE_PARENS unary_expression
2140 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2142 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2144 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2149 // The idea to split this out is from Rhys' grammar
2150 // to solve the problem with casts.
2152 prefixed_unary_expression
2154 | PLUS prefixed_unary_expression
2156 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2158 | MINUS prefixed_unary_expression
2160 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2162 | OP_INC prefixed_unary_expression
2164 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2165 (Expression) $2, lexer.Location);
2167 | OP_DEC prefixed_unary_expression
2169 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2170 (Expression) $2, lexer.Location);
2172 | STAR prefixed_unary_expression
2174 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2176 | BITWISE_AND prefixed_unary_expression
2178 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2182 pre_increment_expression
2183 : OP_INC prefixed_unary_expression
2185 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2186 (Expression) $2, lexer.Location);
2190 pre_decrement_expression
2191 : OP_DEC prefixed_unary_expression
2193 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2194 (Expression) $2, lexer.Location);
2198 multiplicative_expression
2199 : prefixed_unary_expression
2200 | multiplicative_expression STAR prefixed_unary_expression
2202 $$ = new Binary (Binary.Operator.Multiply,
2203 (Expression) $1, (Expression) $3, lexer.Location);
2205 | multiplicative_expression DIV prefixed_unary_expression
2207 $$ = new Binary (Binary.Operator.Division,
2208 (Expression) $1, (Expression) $3, lexer.Location);
2210 | multiplicative_expression PERCENT prefixed_unary_expression
2212 $$ = new Binary (Binary.Operator.Modulus,
2213 (Expression) $1, (Expression) $3, lexer.Location);
2218 : multiplicative_expression
2219 | additive_expression PLUS multiplicative_expression
2221 $$ = new Binary (Binary.Operator.Addition,
2222 (Expression) $1, (Expression) $3, lexer.Location);
2224 | additive_expression MINUS multiplicative_expression
2226 $$ = new Binary (Binary.Operator.Subtraction,
2227 (Expression) $1, (Expression) $3, lexer.Location);
2232 : additive_expression
2233 | shift_expression OP_SHIFT_LEFT additive_expression
2235 $$ = new Binary (Binary.Operator.LeftShift,
2236 (Expression) $1, (Expression) $3, lexer.Location);
2238 | shift_expression OP_SHIFT_RIGHT additive_expression
2240 $$ = new Binary (Binary.Operator.RightShift,
2241 (Expression) $1, (Expression) $3, lexer.Location);
2245 relational_expression
2247 | relational_expression OP_LT shift_expression
2249 $$ = new Binary (Binary.Operator.LessThan,
2250 (Expression) $1, (Expression) $3, lexer.Location);
2252 | relational_expression OP_GT shift_expression
2254 $$ = new Binary (Binary.Operator.GreaterThan,
2255 (Expression) $1, (Expression) $3, lexer.Location);
2257 | relational_expression OP_LE shift_expression
2259 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2260 (Expression) $1, (Expression) $3, lexer.Location);
2262 | relational_expression OP_GE shift_expression
2264 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2265 (Expression) $1, (Expression) $3, lexer.Location);
2267 | relational_expression IS type
2269 $$ = new Is ((Expression) $1, (string) $3, lexer.Location);
2271 | relational_expression AS type
2273 $$ = new As ((Expression) $1, (string) $3, lexer.Location);
2278 : relational_expression
2279 | equality_expression OP_EQ relational_expression
2281 $$ = new Binary (Binary.Operator.Equality,
2282 (Expression) $1, (Expression) $3, lexer.Location);
2284 | equality_expression OP_NE relational_expression
2286 $$ = new Binary (Binary.Operator.Inequality,
2287 (Expression) $1, (Expression) $3, lexer.Location);
2292 : equality_expression
2293 | and_expression BITWISE_AND equality_expression
2295 $$ = new Binary (Binary.Operator.BitwiseAnd,
2296 (Expression) $1, (Expression) $3, lexer.Location);
2300 exclusive_or_expression
2302 | exclusive_or_expression CARRET and_expression
2304 $$ = new Binary (Binary.Operator.ExclusiveOr,
2305 (Expression) $1, (Expression) $3, lexer.Location);
2309 inclusive_or_expression
2310 : exclusive_or_expression
2311 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2313 $$ = new Binary (Binary.Operator.BitwiseOr,
2314 (Expression) $1, (Expression) $3, lexer.Location);
2318 conditional_and_expression
2319 : inclusive_or_expression
2320 | conditional_and_expression OP_AND inclusive_or_expression
2322 $$ = new Binary (Binary.Operator.LogicalAnd,
2323 (Expression) $1, (Expression) $3, lexer.Location);
2327 conditional_or_expression
2328 : conditional_and_expression
2329 | conditional_or_expression OP_OR conditional_and_expression
2331 $$ = new Binary (Binary.Operator.LogicalOr,
2332 (Expression) $1, (Expression) $3, lexer.Location);
2336 conditional_expression
2337 : conditional_or_expression
2338 | conditional_or_expression INTERR expression COLON expression
2340 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2344 assignment_expression
2345 : prefixed_unary_expression ASSIGN expression
2347 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2349 | prefixed_unary_expression OP_MULT_ASSIGN expression
2351 Location l = lexer.Location;
2353 $$ = new Assign ((Expression) $1,
2354 new Binary (Binary.Operator.Multiply,
2356 (Expression) $3, l), l);
2358 | prefixed_unary_expression OP_DIV_ASSIGN expression
2360 Location l = lexer.Location;
2362 $$ = new Assign ((Expression) $1,
2363 new Binary (Binary.Operator.Division,
2365 (Expression) $3, l), l);
2367 | prefixed_unary_expression OP_MOD_ASSIGN expression
2369 Location l = lexer.Location;
2371 $$ = new Assign ((Expression) $1,
2372 new Binary (Binary.Operator.Modulus,
2374 (Expression) $3, l), l);
2376 | prefixed_unary_expression OP_ADD_ASSIGN expression
2378 Location l = lexer.Location;
2380 $$ = new Assign ((Expression) $1,
2381 new Binary (Binary.Operator.Addition,
2383 (Expression) $3, l), l);
2385 | prefixed_unary_expression OP_SUB_ASSIGN expression
2387 Location l = lexer.Location;
2389 $$ = new Assign ((Expression) $1,
2390 new Binary (Binary.Operator.Subtraction,
2392 (Expression) $3, l), l);
2394 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2396 Location l = lexer.Location;
2398 $$ = new Assign ((Expression) $1,
2399 new Binary (Binary.Operator.LeftShift,
2401 (Expression) $3, l), l);
2403 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2405 Location l = lexer.Location;
2407 $$ = new Assign ((Expression) $1,
2408 new Binary (Binary.Operator.RightShift,
2410 (Expression) $3, l), l);
2412 | prefixed_unary_expression OP_AND_ASSIGN expression
2414 Location l = lexer.Location;
2416 $$ = new Assign ((Expression) $1,
2417 new Binary (Binary.Operator.BitwiseAnd,
2419 (Expression) $3, l), l);
2421 | prefixed_unary_expression OP_OR_ASSIGN expression
2423 Location l = lexer.Location;
2425 $$ = new Assign ((Expression) $1,
2426 new Binary (Binary.Operator.BitwiseOr,
2428 (Expression) $3, l), l);
2430 | prefixed_unary_expression OP_XOR_ASSIGN expression
2432 Location l = lexer.Location;
2434 $$ = new Assign ((Expression) $1,
2435 new Binary (Binary.Operator.ExclusiveOr,
2437 (Expression) $3, l), l);
2442 : conditional_expression
2443 | assignment_expression
2465 name = MakeName ((string) $4);
2467 new_class = new Class (current_container, name, (int) $2,
2468 (Attributes) $1, lexer.Location);
2469 current_container = new_class;
2470 current_container.Namespace = current_namespace;
2471 RootContext.Tree.RecordClass (name, new_class);
2477 Class new_class = (Class) current_container;
2480 new_class.Bases = (ArrayList) $6;
2482 current_container = current_container.Parent;
2483 CheckDef (current_container.AddClass (new_class), new_class.Name);
2490 : /* empty */ { $$ = (int) 0; }
2496 | modifiers modifier
2501 if ((m1 & m2) != 0) {
2502 Location l = lexer.Location;
2503 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
2505 $$ = (int) (m1 | m2);
2510 : NEW { $$ = Modifiers.NEW; }
2511 | PUBLIC { $$ = Modifiers.PUBLIC; }
2512 | PROTECTED { $$ = Modifiers.PROTECTED; }
2513 | INTERNAL { $$ = Modifiers.INTERNAL; }
2514 | PRIVATE { $$ = Modifiers.PRIVATE; }
2515 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
2516 | SEALED { $$ = Modifiers.SEALED; }
2517 | STATIC { $$ = Modifiers.STATIC; }
2518 | READONLY { $$ = Modifiers.READONLY; }
2519 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
2520 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
2521 | EXTERN { $$ = Modifiers.EXTERN; }
2522 | VOLATILE { $$ = Modifiers.VOLATILE; }
2526 : /* empty */ { $$ = null; }
2527 | class_base { $$ = $1; }
2531 : COLON type_list { $$ = $2; }
2539 // A block is "contained" on the following places:
2541 // property_declaration as part of the accessor body (get/set)
2542 // operator_declaration
2543 // constructor_declaration
2544 // destructor_declaration
2545 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
2550 current_block = new Block (current_block);
2552 opt_statement_list CLOSE_BRACE
2554 while (current_block.Implicit)
2555 current_block = current_block.Parent;
2557 current_block = current_block.Parent;
2568 | statement_list statement
2572 : declaration_statement
2574 if ((Block) $1 != current_block){
2575 current_block.AddStatement ((Statement) $1);
2576 current_block = (Block) $1;
2579 | embedded_statement
2581 Statement s = (Statement) $1;
2584 current_block.AddStatement ((Statement) $1);
2592 | expression_statement
2593 | selection_statement
2594 | iteration_statement
2598 | unchecked_statement
2607 $$ = new EmptyStatement ();
2614 LabeledStatement labeled = new LabeledStatement ((string) $1);
2616 if (!current_block.AddLabel ((string) $1, labeled)){
2617 Location l = lexer.Location;
2618 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
2620 current_block.AddStatement (labeled);
2625 declaration_statement
2626 : local_variable_declaration SEMICOLON
2628 DictionaryEntry de = (DictionaryEntry) $1;
2630 $$ = declare_local_variables ((string) de.Key, (ArrayList) de.Value, lexer.Location);
2633 | local_constant_declaration SEMICOLON
2635 DictionaryEntry de = (DictionaryEntry) $1;
2637 $$ = declare_local_constant ((string) de.Key, (VariableDeclaration) de.Value);
2642 * The following is from Rhys' grammar:
2643 * > Types in local variable declarations must be recognized as
2644 * > expressions to prevent reduce/reduce errors in the grammar.
2645 * > The expressions are converted into types during semantic analysis.
2648 : primary_expression opt_rank_specifier
2650 // FIXME: Do something smart here regarding the composition of the type.
2652 // Ok, the above "primary_expression" is there to get rid of
2653 // both reduce/reduce and shift/reduces in the grammar, it should
2654 // really just be "type_name". If you use type_name, a reduce/reduce
2655 // creeps up. If you use qualified_identifier (which is all we need
2656 // really) two shift/reduces appear.
2659 // So the super-trick is that primary_expression
2660 // can only be either a SimpleName or a MemberAccess.
2661 // The MemberAccess case arises when you have a fully qualified type-name like :
2663 // SimpleName is when you have
2666 Expression expr = (Expression) $1;
2667 if (!(expr is SimpleName || expr is MemberAccess)) {
2668 Location l = lexer.Location;
2669 Report.Error (-1, l, "Invalid Type definition");
2670 $$ = "System.Object";
2674 // So we extract the string corresponding to the SimpleName
2677 $$ = GetQualifiedIdentifier (expr) + (string) $2;
2679 | builtin_types opt_rank_specifier
2681 $$ = (string) $1 + (string) $2;
2685 local_variable_pointer_type
2686 : primary_expression STAR
2688 Expression expr = (Expression) $1;
2689 if (!(expr is SimpleName || expr is MemberAccess)) {
2690 Location l = lexer.Location;
2691 Report.Error (-1, l, "Invalid Type definition");
2692 $$ = "System.Object";
2695 $$ = GetQualifiedIdentifier (expr) + "*";
2697 | builtin_types STAR
2699 $$ = (string) $1 + "*";
2703 $$ = "System.Void*";
2705 | local_variable_pointer_type STAR
2707 $$ = (string) $1 + "*";
2711 local_variable_declaration
2712 : local_variable_type variable_declarators
2714 $$ = new DictionaryEntry ($1, $2);
2716 | local_variable_pointer_type opt_rank_specifier variable_declarators
2718 $$ = new DictionaryEntry ((string) $1 + (string) $2, $3);
2722 local_constant_declaration
2723 : CONST local_variable_type constant_declarator
2725 $$ = new DictionaryEntry ($2, $3);
2729 expression_statement
2730 : statement_expression SEMICOLON
2737 // We have to do the wrapping here and not in the case above,
2738 // because statement_expression is used for example in for_statement
2740 statement_expression
2741 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2742 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2743 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2744 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2745 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2746 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2747 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2749 Report.Error (1002, lexer.Location, "Expecting `;'");
2753 object_creation_expression
2754 : object_or_delegate_creation_expression
2755 { note ("complain if this is a delegate maybe?"); }
2764 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
2767 $$ = new If ((Expression) $3, (Statement) $5);
2769 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
2770 embedded_statement ELSE embedded_statement
2772 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7);
2777 : SWITCH OPEN_PARENS
2779 oob_stack.Push (lexer.Location);
2781 expression CLOSE_PARENS
2784 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
2798 : /* empty */ { $$ = new ArrayList (); }
2805 ArrayList sections = new ArrayList ();
2810 | switch_sections switch_section
2812 ArrayList sections = (ArrayList) $1;
2822 current_block = new Block (current_block);
2826 while (current_block.Implicit)
2827 current_block = current_block.Parent;
2828 $$ = new SwitchSection ((ArrayList) $1, current_block);
2829 current_block = current_block.Parent;
2836 ArrayList labels = new ArrayList ();
2841 | switch_labels switch_label
2843 ArrayList labels = (ArrayList) ($1);
2851 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
2852 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
2863 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
2865 $$ = new While ((Expression) $3, (Statement) $5);
2870 : DO embedded_statement
2871 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
2873 $$ = new Do ((Statement) $2, (Expression) $5);
2879 opt_for_initializer SEMICOLON
2881 Block assign_block = new Block (current_block);
2882 current_block = assign_block;
2884 if ($3 is DictionaryEntry){
2885 DictionaryEntry de = (DictionaryEntry) $3;
2887 string type = (string) de.Key;
2888 ArrayList var_declarators = (ArrayList) de.Value;
2890 foreach (VariableDeclaration decl in var_declarators){
2892 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
2894 Report.Error (128, decl.Location,
2895 "A local variable `" + decl.identifier + "' is already" +
2896 "defined in this scope");
2899 Location l = lexer.Location;
2901 if (decl.expression_or_array_initializer is Expression){
2902 expr = (Expression) decl.expression_or_array_initializer;
2906 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
2908 string base_type = type.Substring (0, type.IndexOf ("["));
2909 string rank = type.Substring (type.IndexOf ("["));
2911 expr = new ArrayCreation (base_type, rank, init, decl.Location);
2914 LocalVariableReference var;
2915 var = new LocalVariableReference (
2916 assign_block, decl.identifier, l);
2918 Assign a = new Assign (var, expr, decl.Location);
2920 assign_block.AddStatement (new StatementExpression (a));
2927 opt_for_condition SEMICOLON
2928 opt_for_iterator CLOSE_PARENS
2931 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10);
2933 current_block.AddStatement (f);
2934 while (current_block.Implicit)
2935 current_block = current_block.Parent;
2937 current_block = current_block.Parent;
2942 : /* empty */ { $$ = new EmptyStatement (); }
2947 : local_variable_declaration
2948 | statement_expression_list
2952 : /* empty */ { $$ = null; }
2953 | boolean_expression
2957 : /* empty */ { $$ = new EmptyStatement (); }
2962 : statement_expression_list
2965 statement_expression_list
2966 : statement_expression
2968 Block b = new Block (null, true);
2970 b.AddStatement ((Statement) $1);
2973 | statement_expression_list COMMA statement_expression
2975 Block b = (Block) $1;
2977 b.AddStatement ((Statement) $3);
2983 : FOREACH OPEN_PARENS type IDENTIFIER IN
2985 oob_stack.Push (lexer.Location);
2987 expression CLOSE_PARENS
2989 Block foreach_block = new Block (current_block, true);
2990 LocalVariableReference v;
2991 Location l = lexer.Location;
2993 foreach_block.AddVariable ((string) $3, (string) $4, current_local_parameters, l);
2994 v = new LocalVariableReference (foreach_block, (string) $4, l);
2996 current_block.AddStatement (foreach_block);
2997 current_block = foreach_block;
2999 oob_stack.Push (foreach_block);
3004 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3005 Block foreach_block = (Block) oob_stack.Pop ();
3006 Location l = (Location) oob_stack.Pop ();
3008 $$ = new Foreach ((string) $3, v, (Expression) $7, (Statement) $10, l);
3014 | continue_statement
3023 $$ = new Break (lexer.Location);
3028 : CONTINUE SEMICOLON
3030 $$ = new Continue (lexer.Location);
3035 : GOTO IDENTIFIER SEMICOLON
3037 $$ = new Goto (current_block, (string) $2, lexer.Location);
3039 | GOTO CASE constant_expression SEMICOLON
3041 $$ = new GotoCase ((Expression) $3, lexer.Location);
3043 | GOTO DEFAULT SEMICOLON
3045 $$ = new GotoDefault (lexer.Location);
3050 : RETURN opt_expression SEMICOLON
3052 $$ = new Return ((Expression) $2, lexer.Location);
3057 : THROW opt_expression SEMICOLON
3059 $$ = new Throw ((Expression) $2, lexer.Location);
3069 : TRY block catch_clauses
3072 ArrayList s = new ArrayList ();
3074 foreach (Catch cc in (ArrayList) $3) {
3075 if (cc.Type == null)
3081 // Now s contains the list of specific catch clauses
3082 // and g contains the general one.
3084 $$ = new Try ((Block) $2, s, g, null);
3086 | TRY block opt_catch_clauses FINALLY block
3089 ArrayList s = new ArrayList ();
3091 foreach (Catch cc in (ArrayList) $3) {
3092 if (cc.Type == null)
3098 $$ = new Try ((Block) $2, s, g, (Block) $5);
3102 Report.Error (1524, lexer.Location, "Expected catch or finally");
3107 : /* empty */ { $$ = null; }
3114 ArrayList l = new ArrayList ();
3119 | catch_clauses catch_clause
3121 ArrayList l = (ArrayList) $1;
3129 : /* empty */ { $$ = null; }
3134 : CATCH opt_catch_args
3136 string type = null, id = null;
3139 DictionaryEntry cc = (DictionaryEntry) $2;
3140 type = (string) cc.Key;
3141 id = (string) cc.Value;
3144 ArrayList one = new ArrayList ();
3145 Location loc = lexer.Location;
3147 one.Add (new VariableDeclaration (id, null, loc));
3150 current_block = new Block (current_block);
3151 Block b = declare_local_variables (type, one, loc);
3158 string type = null, id = null;
3161 DictionaryEntry cc = (DictionaryEntry) $2;
3162 type = (string) cc.Key;
3163 id = (string) cc.Value;
3166 while (current_block != (Block) $1)
3167 current_block = current_block.Parent;
3172 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3177 : /* empty */ { $$ = null; }
3182 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3184 $$ = new DictionaryEntry ($2, $3);
3191 $$ = new Checked ((Block) $2);
3198 $$ = new Unchecked ((Block) $2);
3205 $$ = new Unsafe ((Block) $2);
3210 : LOCK OPEN_PARENS expression CLOSE_PARENS
3216 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
3221 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
3223 Block assign_block = new Block (current_block);
3224 current_block = assign_block;
3226 oob_stack.Push (lexer.Location);
3228 if ($3 is DictionaryEntry){
3229 DictionaryEntry de = (DictionaryEntry) $3;
3230 Location l = lexer.Location;
3232 string type = (string) de.Key;
3233 ArrayList var_declarators = (ArrayList) de.Value;
3235 foreach (VariableDeclaration decl in var_declarators){
3236 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
3238 Report.Error (128, decl.Location,
3239 "A local variable `" + decl.identifier + "' is already" +
3240 "defined in this scope");
3244 ArrayList vars = new ArrayList ();
3246 foreach (VariableDeclaration decl in var_declarators){
3249 if (decl.expression_or_array_initializer is Expression){
3250 expr = (Expression) decl.expression_or_array_initializer;
3254 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3256 string base_type = type.Substring (0, type.IndexOf ("["));
3257 string rank = type.Substring (type.IndexOf ("["));
3259 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3262 LocalVariableReference var;
3265 var = new LocalVariableReference (assign_block, decl.identifier, l);
3266 vi = var.VariableInfo;
3269 // This is so that it is not a warning on using variables
3272 vars.Add (new DictionaryEntry (var, expr));
3274 // Assign a = new Assign (var, expr, decl.Location);
3275 // assign_block.AddStatement (new StatementExpression (a));
3277 $3 = new DictionaryEntry (type, vars);
3282 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
3283 current_block.AddStatement (u);
3284 while (current_block.Implicit)
3285 current_block = current_block.Parent;
3287 current_block = current_block.Parent;
3291 resource_acquisition
3292 : local_variable_declaration
3299 // A class used to pass around variable declarations and constants
3301 public class VariableDeclaration {
3302 public string identifier;
3303 public object expression_or_array_initializer;
3304 public Location Location;
3306 public VariableDeclaration (string id, object eoai, Location l){
3307 this.identifier = id;
3308 this.expression_or_array_initializer = eoai;
3314 // A class used to hold info about an indexer declarator
3317 public class IndexerDeclaration {
3319 public string interface_type;
3320 public Parameters param_list;
3322 public IndexerDeclaration (string type, string interface_type, Parameters param_list)
3325 this.interface_type = interface_type;
3326 this.param_list = param_list;
3331 // A class used to hold info about an operator declarator
3334 public class OperatorDeclaration {
3335 public Operator.OpType optype;
3336 public string ret_type;
3337 public string arg1type;
3338 public string arg1name;
3339 public string arg2type;
3340 public string arg2name;
3341 public Location location;
3343 public OperatorDeclaration (Operator.OpType op, string ret_type, string arg1type, string arg1name,
3344 string arg2type, string arg2name, Location location)
3347 this.ret_type = ret_type;
3348 this.arg1type = arg1type;
3349 this.arg1name = arg1name;
3350 this.arg2type = arg2type;
3351 this.arg2name = arg2name;
3352 this.location = location;
3358 // Given the @class_name name, it creates a fully qualified name
3359 // based on the containing declaration space
3362 MakeName (string class_name)
3364 string ns = current_namespace.Name;
3365 string container_name = current_container.Name;
3367 if (container_name == ""){
3369 return ns + "." + class_name;
3373 return container_name + "." + class_name;
3377 // Used to report back to the user the result of a declaration
3378 // in the current declaration space
3381 CheckDef (AdditionResult result, string name)
3383 if (result == AdditionResult.Success)
3386 Location l = lexer.Location;
3389 case AdditionResult.NameExists:
3390 Report.Error (102, l, "The namespace `" + current_container.Name +
3391 "' already contains a definition for `"+
3397 // This is handled only for static Constructors, because
3398 // in reality we handle these by the semantic analysis later
3400 case AdditionResult.MethodExists:
3402 111, l, "Class `"+current_container.Name+
3403 "' already defines a member called '" +
3404 name + "' with the same parameter types (more than one default constructor)");
3407 case AdditionResult.EnclosingClash:
3408 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
3411 case AdditionResult.NotAConstructor:
3412 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
3418 CheckDef (bool result, string name)
3422 CheckDef (AdditionResult.NameExists, name);
3426 SimpleLookup (string name, Location loc)
3429 // we need to check against current_block not being null
3430 // as `expression' is allowed in argument_lists, which
3431 // do not exist inside a block.
3433 if (current_block != null){
3434 if (current_block.IsVariableDefined (name))
3435 return new LocalVariableReference (current_block, name, loc);
3438 if (current_local_parameters != null){
3440 Parameter par = current_local_parameters.GetParameterByName (name, out idx);
3442 return new ParameterReference (current_local_parameters, idx, name);
3448 Expression DecomposeQI (string name, Location loc)
3452 if (name.IndexOf ('.') == -1){
3453 o = SimpleLookup (name, loc);
3455 return new SimpleName (name, loc);
3458 int pos = name.LastIndexOf (".");
3459 string left = name.Substring (0, pos);
3460 string right = name.Substring (pos + 1);
3462 o = DecomposeQI (left, loc);
3463 return new MemberAccess (o, right, loc);
3468 // This method is used to get at the complete string representation of
3469 // a fully-qualified type name, hiding inside a MemberAccess ;-)
3470 // This is necessary because local_variable_type admits primary_expression
3471 // as the type of the variable. So we do some extra checking
3473 string GetQualifiedIdentifier (Expression expr)
3475 if (expr is SimpleName)
3476 return ((SimpleName)expr).Name;
3477 else if (expr is MemberAccess)
3478 return GetQualifiedIdentifier (((MemberAccess)expr).Expr) + "." + ((MemberAccess) expr).Identifier;
3480 throw new Exception ("Expr has to be either SimpleName or MemberAccess! (" + expr + ")");
3484 Block declare_local_variables (string type, ArrayList variable_declarators, Location loc)
3486 Block implicit_block;
3487 ArrayList inits = null;
3490 // We use the `Used' property to check whether statements
3491 // have been added to the current block. If so, we need
3492 // to create another block to contain the new declaration
3493 // otherwise, as an optimization, we use the same block to
3494 // add the declaration.
3496 // FIXME: A further optimization is to check if the statements
3497 // that were added were added as part of the initialization
3498 // below. In which case, no other statements have been executed
3499 // and we might be able to reduce the number of blocks for
3500 // situations like this:
3502 // int j = 1; int k = j + 1;
3504 if (current_block.Used)
3505 implicit_block = new Block (current_block, true);
3507 implicit_block = current_block;
3509 foreach (VariableDeclaration decl in variable_declarators){
3511 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location)) {
3512 if (decl.expression_or_array_initializer != null){
3514 inits = new ArrayList ();
3518 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3519 "' is already defined in this scope");
3524 return implicit_block;
3526 foreach (VariableDeclaration decl in inits){
3530 if (decl.expression_or_array_initializer is Expression){
3531 expr = (Expression) decl.expression_or_array_initializer;
3534 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3536 string base_type = type.Substring (0, type.IndexOf ("["));
3537 string rank = type.Substring (type.IndexOf ("["));
3539 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3543 LocalVariableReference var;
3544 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
3546 assign = new Assign (var, expr, decl.Location);
3548 implicit_block.AddStatement (new StatementExpression (assign));
3551 return implicit_block;
3554 Block declare_local_constant (string type, VariableDeclaration decl)
3556 Block implicit_block;
3558 if (current_block.Used)
3559 implicit_block = new Block (current_block, true);
3561 implicit_block = current_block;
3563 if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
3564 current_local_parameters, decl.Location))){
3565 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3566 "' is already defined in this scope");
3569 return implicit_block;
3572 void CheckAttributeTarget (string a)
3576 case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
3580 Location l = lexer.Location;
3581 Report.Error (658, l, "Invalid attribute target");
3587 void CheckUnaryOperator (Operator.OpType op)
3591 case Operator.OpType.LogicalNot:
3592 case Operator.OpType.OnesComplement:
3593 case Operator.OpType.Increment:
3594 case Operator.OpType.Decrement:
3595 case Operator.OpType.True:
3596 case Operator.OpType.False:
3597 case Operator.OpType.Addition:
3598 case Operator.OpType.Subtraction:
3603 Location l = lexer.Location;
3604 Report.Error (1019, l, "Overloadable unary operator expected");
3610 void CheckBinaryOperator (Operator.OpType op)
3614 case Operator.OpType.Addition:
3615 case Operator.OpType.Subtraction:
3616 case Operator.OpType.Multiply:
3617 case Operator.OpType.Division:
3618 case Operator.OpType.Modulus:
3619 case Operator.OpType.BitwiseAnd:
3620 case Operator.OpType.BitwiseOr:
3621 case Operator.OpType.ExclusiveOr:
3622 case Operator.OpType.LeftShift:
3623 case Operator.OpType.RightShift:
3624 case Operator.OpType.Equality:
3625 case Operator.OpType.Inequality:
3626 case Operator.OpType.GreaterThan:
3627 case Operator.OpType.LessThan:
3628 case Operator.OpType.GreaterThanOrEqual:
3629 case Operator.OpType.LessThanOrEqual:
3633 Location l = lexer.Location;
3634 Report.Error (1020, l, "Overloadable binary operator expected");
3640 void syntax_error (Location l, string msg)
3642 Report.Error (1003, l, "Syntax error, " + msg);
3645 void output (string s)
3647 Console.WriteLine (s);
3650 void note (string s)
3652 // Used to put annotations
3657 public Tokenizer Lexer {
3663 public CSharpParser (string name, System.IO.Stream input, ArrayList defines)
3665 current_namespace = new Namespace (null, "");
3668 current_container = RootContext.Tree.Types;
3669 current_container.Namespace = current_namespace;
3670 oob_stack = new Stack ();
3672 lexer = new Tokenizer (input, name, defines);
3675 public override int parse ()
3677 StringBuilder value = new StringBuilder ();
3681 if (yacc_verbose_flag)
3682 yyparse (lexer, new yydebug.yyDebugSimple ());
3685 } catch (Exception e){
3686 // Console.WriteLine ("Fatal error: " + name);
3687 // Console.WriteLine (lexer.location);
3690 // Please do not remove this, it is used during debugging
3693 Console.WriteLine (lexer.location + " : Parsing error ");
3694 Console.WriteLine (e);
3698 return global_errors;