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, lexer.Location);
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){
371 1527, lexer.Location,
372 "Namespace elements cant be explicitly " +
373 "declared private or protected in `" + name + "'");
376 | namespace_declaration
382 | interface_declaration
384 | delegate_declaration
386 // Enable this when we have handled all errors, because this acts as a generic fallback
389 // Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
397 : /* empty */ { $$ = null; }
398 | attribute_section opt_attributes
403 attrs = (Attributes) $2;
404 attrs.AddAttribute ((AttributeSection) $1);
406 attrs = new Attributes ((AttributeSection) $1);
413 : OPEN_BRACKET attribute_target_specifier attribute_list CLOSE_BRACKET
415 string target = null;
418 target = (string) $2;
420 $$ = new AttributeSection (target, (ArrayList) $3);
422 | OPEN_BRACKET attribute_list CLOSE_BRACKET
424 $$ = new AttributeSection (null, (ArrayList) $2);
428 attribute_target_specifier
429 : attribute_target COLON
438 CheckAttributeTarget ((string) $1);
441 | EVENT { $$ = "event"; }
442 | RETURN { $$ = "return"; }
448 ArrayList attrs = new ArrayList ();
454 | attribute_list COMMA attribute
456 ArrayList attrs = (ArrayList) $1;
468 opt_attribute_arguments
470 $$ = new Attribute ((string) $1, (ArrayList) $3, (Location) $2);
475 : type_name { /* reserved attribute name or identifier: 17.4 */ }
478 opt_attribute_arguments
479 : /* empty */ { $$ = null; }
480 | OPEN_PARENS attribute_arguments CLOSE_PARENS
488 : positional_argument_list
490 ArrayList args = new ArrayList ();
495 | positional_argument_list COMMA named_argument_list
497 ArrayList args = new ArrayList ();
503 | named_argument_list
505 ArrayList args = new ArrayList ();
514 positional_argument_list
517 ArrayList args = new ArrayList ();
518 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
522 | positional_argument_list COMMA expression
524 ArrayList args = (ArrayList) $1;
525 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
534 ArrayList args = new ArrayList ();
539 | named_argument_list COMMA named_argument
541 ArrayList args = (ArrayList) $1;
549 : IDENTIFIER ASSIGN expression
551 $$ = new DictionaryEntry (
553 new Argument ((Expression) $3, Argument.AType.Expression));
559 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
562 opt_class_member_declarations
564 | class_member_declarations
567 class_member_declarations
568 : class_member_declaration
569 | class_member_declarations
570 class_member_declaration
573 class_member_declaration
574 : constant_declaration // done
575 | field_declaration // done
576 | method_declaration // done
577 | property_declaration // done
578 | event_declaration // done
579 | indexer_declaration // done
580 | operator_declaration // done
581 | constructor_declaration // done
582 | destructor_declaration // done
592 string full_struct_name = MakeName ((string) $4);
594 new_struct = new Struct (current_container, full_struct_name, (int) $2,
595 (Attributes) $1, lexer.Location);
596 current_container = new_struct;
597 current_container.Namespace = current_namespace;
598 RootContext.Tree.RecordStruct (full_struct_name, new_struct);
600 opt_struct_interfaces
604 Struct new_struct = (Struct) current_container;
606 current_container = current_container.Parent;
607 CheckDef (current_container.AddStruct (new_struct), new_struct.Name);
612 opt_struct_interfaces
619 | struct_interfaces struct_interface
627 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
630 opt_struct_member_declarations
632 | struct_member_declarations
635 struct_member_declarations
636 : struct_member_declaration
637 | struct_member_declarations struct_member_declaration
640 struct_member_declaration
641 : constant_declaration
644 | property_declaration
646 | indexer_declaration
647 | operator_declaration
648 | constructor_declaration
652 * This is only included so we can flag error 575:
653 * destructors only allowed on class types
655 | destructor_declaration
666 foreach (VariableDeclaration constant in (ArrayList) $5){
667 Const c = new Const (
668 (string) $4, (string) constant.identifier,
669 (Expression) constant.expression_or_array_initializer, (int) $2, (Attributes) $1,
672 CheckDef (current_container.AddConstant (c), c.Name);
678 : constant_declarator
680 ArrayList constants = new ArrayList ();
684 | constant_declarators COMMA constant_declarator
686 ArrayList constants = (ArrayList) $1;
693 : IDENTIFIER ASSIGN constant_expression
695 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
706 string type = (string) $3;
709 foreach (VariableDeclaration var in (ArrayList) $4){
710 Field field = new Field (type, mod, var.identifier,
711 var.expression_or_array_initializer, (Attributes) $1, var.Location);
713 CheckDef (current_container.AddField (field), field.Name);
719 : variable_declarator
721 ArrayList decl = new ArrayList ();
725 | variable_declarators COMMA variable_declarator
727 ArrayList decls = (ArrayList) $1;
734 : IDENTIFIER ASSIGN variable_initializer
736 $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
740 $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
759 Method method = (Method) $1;
760 Block b = (Block) $2;
763 if ((method.ModFlags & (Modifiers.EXTERN | Modifiers.ABSTRACT)) == 0){
765 501, lexer.Location, "`" +
766 current_container.Name + "." + method.Name + "'" +
767 "must declare a body because it is not marked abstract or extern");
771 method.Block = (Block) $2;
772 CheckDef (current_container.AddMethod (method), method.Name);
774 current_local_parameters = null;
788 1585, lexer.Location, "Member modifier `" +
789 Modifiers.Name (i) + "' must precede member type and name");
802 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
804 Method method = new Method ((string) $3, (int) $2, (string) $4,
805 (Parameters) $6, (Attributes) $1, lexer.Location);
807 current_local_parameters = (Parameters) $6;
815 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
817 Method method = new Method ("System.Void", (int) $2, (string) $4,
818 (Parameters) $6, (Attributes) $1, lexer.Location);
820 current_local_parameters = (Parameters) $6;
827 | SEMICOLON { $$ = null; }
830 opt_formal_parameter_list
831 : /* empty */ { $$ = Parameters.GetEmptyReadOnlyParameters (); }
832 | formal_parameter_list
835 formal_parameter_list
838 ArrayList pars_list = (ArrayList) $1;
840 Parameter [] pars = new Parameter [pars_list.Count];
841 pars_list.CopyTo (pars);
843 $$ = new Parameters (pars, null, lexer.Location);
845 | fixed_parameters COMMA parameter_array
847 ArrayList pars_list = (ArrayList) $1;
849 Parameter [] pars = new Parameter [pars_list.Count];
850 pars_list.CopyTo (pars);
852 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
856 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
863 ArrayList pars = new ArrayList ();
868 | fixed_parameters COMMA fixed_parameter
870 ArrayList pars = (ArrayList) $1;
879 opt_parameter_modifier
883 $$ = new Parameter ((string) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
887 opt_parameter_modifier
888 : /* empty */ { $$ = Parameter.Modifier.NONE; }
893 : REF { $$ = Parameter.Modifier.REF; }
894 | OUT { $$ = Parameter.Modifier.OUT; }
898 : opt_attributes PARAMS type IDENTIFIER
900 $$ = new Parameter ((string) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
901 note ("type must be a single-dimension array type");
906 : qualified_identifier
915 implicit_value_parameter_type = (string) $3;
917 lexer.PropertyParsing = true;
921 accessor_declarations
923 lexer.PropertyParsing = false;
928 Pair pair = (Pair) $7;
929 Block get_block = null;
930 Block set_block = null;
932 if (pair.First != null)
933 get_block = (Block) pair.First;
934 if (pair.Second != null)
935 set_block = (Block) pair.Second;
937 prop = new Property ((string) $3, (string) $4, (int) $2, get_block, set_block,
938 (Attributes) $1, (Location) $6);
940 CheckDef (current_container.AddProperty (prop), prop.Name);
941 implicit_value_parameter_type = null;
945 accessor_declarations
946 : get_accessor_declaration opt_set_accessor_declaration
948 $$ = new Pair ($1, $2);
950 | set_accessor_declaration opt_get_accessor_declaration
952 $$ = new Pair ($2, $1);
956 opt_get_accessor_declaration
957 : /* empty */ { $$ = null; }
958 | get_accessor_declaration
961 opt_set_accessor_declaration
962 : /* empty */ { $$ = null; }
963 | set_accessor_declaration
966 get_accessor_declaration
969 // If this is not the case, then current_local_parameters has already
970 // been set in indexer_declaration
971 if (parsing_indexer == false)
972 current_local_parameters = null;
974 current_local_parameters = indexer_parameters;
975 lexer.PropertyParsing = false;
980 current_local_parameters = null;
981 lexer.PropertyParsing = true;
985 set_accessor_declaration
989 Parameter implicit_value_parameter = new Parameter (
990 implicit_value_parameter_type, "value",
991 Parameter.Modifier.NONE, null);
993 if (parsing_indexer == false) {
994 args = new Parameter [1];
995 args [0] = implicit_value_parameter;
997 Parameter [] fp = indexer_parameters.FixedParameters;
998 int count = fp.Length;
1000 args = new Parameter [count + 1];
1002 fp.CopyTo (args, 0);
1003 args [count] = implicit_value_parameter;
1006 current_local_parameters = new Parameters (args, null, lexer.Location);
1007 lexer.PropertyParsing = false;
1012 current_local_parameters = null;
1013 lexer.PropertyParsing = true;
1019 | SEMICOLON { $$ = new Block (null); }
1022 interface_declaration
1025 INTERFACE IDENTIFIER
1027 Interface new_interface;
1028 string full_interface_name = MakeName ((string) $4);
1030 new_interface = new Interface (current_container, full_interface_name, (int) $2,
1031 (Attributes) $1, lexer.Location);
1032 if (current_interface != null) {
1033 Location l = lexer.Location;
1034 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1036 current_interface = new_interface;
1037 new_interface.Namespace = current_namespace;
1038 RootContext.Tree.RecordInterface (full_interface_name, new_interface);
1043 Interface new_interface = (Interface) current_interface;
1046 new_interface.Bases = (ArrayList) $6;
1048 current_interface = null;
1049 CheckDef (current_container.AddInterface (new_interface), new_interface.Name);
1054 : /* empty */ { $$ = null; }
1059 : COLON interface_type_list { $$ = $2; }
1065 ArrayList interfaces = new ArrayList ();
1067 interfaces.Add ($1);
1070 | interface_type_list COMMA interface_type
1072 ArrayList interfaces = (ArrayList) $1;
1073 interfaces.Add ($3);
1080 opt_interface_member_declarations
1084 opt_interface_member_declarations
1086 | interface_member_declarations
1089 interface_member_declarations
1090 : interface_member_declaration
1091 | interface_member_declarations interface_member_declaration
1094 interface_member_declaration
1095 : interface_method_declaration
1097 InterfaceMethod m = (InterfaceMethod) $1;
1099 CheckDef (current_interface.AddMethod (m), m.Name);
1101 | interface_property_declaration
1103 InterfaceProperty p = (InterfaceProperty) $1;
1105 CheckDef (current_interface.AddProperty (p), p.Name);
1107 | interface_event_declaration
1109 InterfaceEvent e = (InterfaceEvent) $1;
1111 CheckDef (current_interface.AddEvent (e), e.Name);
1113 | interface_indexer_declaration
1115 InterfaceIndexer i = (InterfaceIndexer) $1;
1117 CheckDef (current_interface.AddIndexer (i), "indexer");
1122 : /* empty */ { $$ = false; }
1123 | NEW { $$ = true; }
1126 interface_method_declaration
1127 : opt_attributes opt_new type IDENTIFIER
1128 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1131 $$ = new InterfaceMethod ((string) $3, (string) $4, (bool) $2,
1132 (Parameters) $6, (Attributes) $1, lexer.Location);
1134 | opt_attributes opt_new VOID IDENTIFIER
1135 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1138 $$ = new InterfaceMethod ("System.Void", (string) $4, (bool) $2, (Parameters) $6,
1139 (Attributes) $1, lexer.Location);
1143 interface_property_declaration
1148 { lexer.PropertyParsing = true; }
1150 { lexer.PropertyParsing = false; }
1155 $$ = new InterfaceProperty ((string) $3, (string) $4, (bool) $2,
1156 (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
1162 : opt_attributes GET SEMICOLON { $$ = 1; }
1163 | opt_attributes SET SEMICOLON { $$ = 2; }
1164 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1166 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1170 interface_event_declaration
1171 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1173 $$ = new InterfaceEvent ((string) $4, (string) $5, (bool) $2, (Attributes) $1);
1177 interface_indexer_declaration
1178 : opt_attributes opt_new type THIS
1179 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1181 { lexer.PropertyParsing = true; }
1183 { lexer.PropertyParsing = false; }
1186 int a_flags = (int) $10;
1188 bool do_get = (a_flags & 1) == 1;
1189 bool do_set = (a_flags & 2) == 2;
1191 $$ = new InterfaceIndexer ((string) $3, (Parameters) $6, do_get, do_set,
1192 (bool) $2, (Attributes) $1, lexer.Location);
1196 operator_declaration
1197 : opt_attributes opt_modifiers operator_declarator block
1199 OperatorDeclaration decl = (OperatorDeclaration) $3;
1201 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1202 decl.arg2type, decl.arg2name, (Block) $4, (Attributes) $1, decl.location);
1204 // Note again, checking is done in semantic analysis
1205 current_container.AddOperator (op);
1207 current_local_parameters = null;
1212 : type OPERATOR overloadable_operator
1213 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1215 Operator.OpType op = (Operator.OpType) $3;
1216 CheckUnaryOperator (op);
1218 if (op == Operator.OpType.Addition)
1219 op = Operator.OpType.UnaryPlus;
1221 if (op == Operator.OpType.Subtraction)
1222 op = Operator.OpType.UnaryNegation;
1224 Parameter [] pars = new Parameter [1];
1226 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1228 current_local_parameters = new Parameters (pars, null, lexer.Location);
1230 $$ = new OperatorDeclaration (op, (string) $1, (string) $5, (string) $6,
1231 null, null, lexer.Location);
1233 | type OPERATOR overloadable_operator
1235 type IDENTIFIER COMMA
1239 CheckBinaryOperator ((Operator.OpType) $3);
1241 Parameter [] pars = new Parameter [2];
1243 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1244 pars [1] = new Parameter ((string) $8, (string) $9, Parameter.Modifier.NONE, null);
1246 current_local_parameters = new Parameters (pars, null, lexer.Location);
1248 $$ = new OperatorDeclaration ((Operator.OpType) $3, (string) $1, (string) $5, (string) $6,
1249 (string) $8, (string) $9, lexer.Location);
1251 | conversion_operator_declarator
1254 overloadable_operator
1256 : BANG { $$ = Operator.OpType.LogicalNot; }
1257 | TILDE { $$ = Operator.OpType.OnesComplement; }
1258 | OP_INC { $$ = Operator.OpType.Increment; }
1259 | OP_DEC { $$ = Operator.OpType.Decrement; }
1260 | TRUE { $$ = Operator.OpType.True; }
1261 | FALSE { $$ = Operator.OpType.False; }
1262 // Unary and binary:
1263 | PLUS { $$ = Operator.OpType.Addition; }
1264 | MINUS { $$ = Operator.OpType.Subtraction; }
1266 | STAR { $$ = Operator.OpType.Multiply; }
1267 | DIV { $$ = Operator.OpType.Division; }
1268 | PERCENT { $$ = Operator.OpType.Modulus; }
1269 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1270 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1271 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1272 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1273 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1274 | OP_EQ { $$ = Operator.OpType.Equality; }
1275 | OP_NE { $$ = Operator.OpType.Inequality; }
1276 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1277 | OP_LT { $$ = Operator.OpType.LessThan; }
1278 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1279 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1282 conversion_operator_declarator
1283 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1285 Parameter [] pars = new Parameter [1];
1287 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1289 current_local_parameters = new Parameters (pars, null, lexer.Location);
1291 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (string) $3, (string) $5, (string) $6,
1292 null, null, lexer.Location);
1294 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1296 Parameter [] pars = new Parameter [1];
1298 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1300 current_local_parameters = new Parameters (pars, null, lexer.Location);
1302 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (string) $3, (string) $5, (string) $6,
1303 null, null, lexer.Location);
1307 syntax_error (lexer.Location, "'operator' expected");
1311 syntax_error (lexer.Location, "'operator' expected");
1315 constructor_declaration
1318 constructor_declarator
1321 Constructor c = (Constructor) $3;
1322 c.Block = (Block) $4;
1323 c.ModFlags = (int) $2;
1324 c.OptAttributes = (Attributes) $1;
1326 if ((c.ModFlags & Modifiers.STATIC) != 0){
1327 if ((c.ModFlags & Modifiers.Accessibility) != 0) {
1328 Location l = lexer.Location;
1329 Report.Error (515, l, "Access modifiers are not allowed on static constructors");
1332 if (c.Initializer != null){
1333 Location l = lexer.Location;
1334 Report.Error (514, l, "Static constructors can not have an explicit this or base constructor invocations");
1337 if (!c.Parameters.Empty){
1338 Location l = lexer.Location;
1339 Report.Error (132, l, "Static constructors should not have parameters");
1343 CheckDef (current_container.AddConstructor (c), c.Name);
1345 current_local_parameters = null;
1349 constructor_declarator
1351 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1353 oob_stack.Push (lexer.Location);
1355 current_local_parameters = (Parameters) $3;
1357 opt_constructor_initializer
1359 Location l = (Location) oob_stack.Pop ();
1360 $$ = new Constructor ((string) $1, (Parameters) $3, (ConstructorInitializer) $6, l);
1364 opt_constructor_initializer
1365 : /* empty */ { $$ = null; }
1366 | constructor_initializer
1369 constructor_initializer
1370 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1372 $$ = new ConstructorBaseInitializer ((ArrayList) $4, lexer.Location);
1374 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1376 $$ = new ConstructorThisInitializer ((ArrayList) $4, lexer.Location);
1380 destructor_declaration
1381 : opt_attributes TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1383 if ((string) $3 != current_container.Basename){
1384 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1385 } else if (!(current_container is Class)){
1386 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1388 Location l = lexer.Location;
1390 Method d = new Method (
1391 "System.Void", 0, "Finalize",
1392 new Parameters (null, null, l), (Attributes) $1, l);
1394 d.Block = (Block) $6;
1395 CheckDef (current_container.AddMethod (d), d.Name);
1403 EVENT type variable_declarators SEMICOLON
1405 foreach (VariableDeclaration var in (ArrayList) $5) {
1407 Event e = new Event ((string) $4, var.identifier, var.expression_or_array_initializer,
1408 (int) $2, null, null, (Attributes) $1, lexer.Location);
1410 CheckDef (current_container.AddEvent (e), e.Name);
1416 EVENT type member_name
1419 implicit_value_parameter_type = (string) $4;
1420 lexer.EventParsing = true;
1422 event_accessor_declarations
1424 lexer.EventParsing = false;
1428 Pair pair = (Pair) $8;
1429 Block add_block = null;
1430 Block rem_block = null;
1432 if (pair.First != null)
1433 add_block = (Block) pair.First;
1434 if (pair.Second != null)
1435 rem_block = (Block) pair.Second;
1437 Event e = new Event ((string) $4, (string) $5, null, (int) $2, add_block, rem_block,
1438 (Attributes) $1, lexer.Location);
1440 CheckDef (current_container.AddEvent (e), e.Name);
1441 implicit_value_parameter_type = null;
1445 event_accessor_declarations
1446 : add_accessor_declaration remove_accessor_declaration
1448 $$ = new Pair ($1, $2);
1450 | remove_accessor_declaration add_accessor_declaration
1452 $$ = new Pair ($2, $1);
1456 add_accessor_declaration
1457 : opt_attributes ADD
1459 Parameter [] args = new Parameter [1];
1460 Parameter implicit_value_parameter = new Parameter (
1461 implicit_value_parameter_type, "value",
1462 Parameter.Modifier.NONE, null);
1464 args [0] = implicit_value_parameter;
1466 current_local_parameters = new Parameters (args, null, lexer.Location);
1467 lexer.EventParsing = false;
1472 lexer.EventParsing = true;
1476 remove_accessor_declaration
1477 : opt_attributes REMOVE
1479 Parameter [] args = new Parameter [1];
1480 Parameter implicit_value_parameter = new Parameter (
1481 implicit_value_parameter_type, "value",
1482 Parameter.Modifier.NONE, null);
1484 args [0] = implicit_value_parameter;
1486 current_local_parameters = new Parameters (args, null, lexer.Location);
1487 lexer.EventParsing = false;
1492 lexer.EventParsing = true;
1497 : opt_attributes opt_modifiers indexer_declarator
1500 IndexerDeclaration decl = (IndexerDeclaration) $3;
1502 implicit_value_parameter_type = decl.type;
1504 lexer.PropertyParsing = true;
1505 parsing_indexer = true;
1507 indexer_parameters = decl.param_list;
1508 $$ = lexer.Location;
1510 accessor_declarations
1512 lexer.PropertyParsing = false;
1513 parsing_indexer = false;
1517 // The signature is computed from the signature of the indexer. Look
1518 // at section 3.6 on the spec
1521 IndexerDeclaration decl = (IndexerDeclaration) $3;
1522 Pair pair = (Pair) $6;
1523 Block get_block = null;
1524 Block set_block = null;
1526 if (pair.First != null)
1527 get_block = (Block) pair.First;
1528 if (pair.Second != null)
1529 set_block = (Block) pair.Second;
1531 indexer = new Indexer (decl.type, decl.interface_type, (int) $2, decl.param_list,
1532 get_block, set_block, (Attributes) $1, (Location) $5);
1534 // Note that there is no equivalent of CheckDef for this case
1535 // We shall handle this in semantic analysis
1537 current_container.AddIndexer (indexer);
1539 current_local_parameters = null;
1540 implicit_value_parameter_type = null;
1541 indexer_parameters = null;
1546 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1548 Parameters pars = (Parameters) $4;
1550 if (pars.FixedParameters == null){
1551 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1554 $$ = new IndexerDeclaration ((string) $1, null, pars);
1556 | type qualified_identifier DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1558 Parameters pars = (Parameters) $6;
1560 if (pars.FixedParameters == null){
1561 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1563 $$ = new IndexerDeclaration ((string) $1, (string) $2, pars);
1575 string full_name = MakeName ((string) $4);
1576 Enum e = new Enum (current_container, (string) $5, (int) $2, full_name, (Attributes) $1, lexer.Location);
1578 foreach (VariableDeclaration ev in (ArrayList) $6){
1579 CheckDef (e.AddEnumMember (ev.identifier,
1580 (Expression) ev.expression_or_array_initializer,
1581 (Location) ev.Location),
1585 CheckDef (current_container.AddEnum (e), name);
1590 : /* empty */ { $$ = "System.Int32"; }
1591 | COLON type { $$ = $2; }
1595 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1601 opt_enum_member_declarations
1602 : /* empty */ { $$ = new ArrayList (); }
1603 | enum_member_declarations opt_comma { $$ = $1; }
1606 enum_member_declarations
1607 : enum_member_declaration
1609 ArrayList l = new ArrayList ();
1614 | enum_member_declarations COMMA enum_member_declaration
1616 ArrayList l = (ArrayList) $1;
1624 enum_member_declaration
1625 : opt_attributes IDENTIFIER
1627 $$ = new VariableDeclaration ((string) $2, null, lexer.Location);
1629 | opt_attributes IDENTIFIER
1631 $$ = lexer.Location;
1635 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location);
1639 delegate_declaration
1643 IDENTIFIER OPEN_PARENS
1644 opt_formal_parameter_list
1648 Delegate del = new Delegate ((string) $4, (int) $2,
1649 MakeName ((string) $5), (Parameters) $7,
1650 (Attributes) $1, lexer.Location);
1652 CheckDef (current_container.AddDelegate (del), del.Name);
1657 IDENTIFIER OPEN_PARENS
1658 opt_formal_parameter_list
1662 Delegate del = new Delegate ("System.Void", (int) $2, (string) $5, (Parameters) $7,
1663 (Attributes) $1, lexer.Location);
1665 CheckDef (current_container.AddDelegate (del), del.Name);
1670 : namespace_or_type_name
1673 namespace_or_type_name
1674 : qualified_identifier
1678 * Before you think of adding a return_type, notice that we have been
1679 * using two rules in the places where it matters (one rule using type
1680 * and another identical one that uses VOID as the return type). This
1681 * gets rid of a shift/reduce couple
1684 : type_name { /* class_type */
1686 This does interfaces, delegates, struct_types, class_types,
1687 parent classes, and more! 4.2
1701 // Note that here only unmanaged types are allowed but we
1702 // can't perform checks during this phase - we do it during
1703 // semantic analysis.
1705 $$ = (string) $1 + "*";
1709 $$ = "System.Void*";
1716 $$ = new SimpleName ((string) $1, lexer.Location);
1718 | non_expression_type rank_specifier
1720 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1722 | expression rank_specifiers
1724 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1731 ArrayList types = new ArrayList ();
1736 | type_list COMMA type
1738 ArrayList types = (ArrayList) $1;
1746 * replaces all the productions for isolating the various
1747 * simple types, but we need this to reuse it easily in local_variable_type
1750 : OBJECT { $$ = "System.Object"; }
1751 | STRING { $$ = "System.String"; }
1752 | BOOL { $$ = "System.Boolean"; }
1753 | DECIMAL { $$ = "System.Decimal"; }
1754 | FLOAT { $$ = "System.Single"; }
1755 | DOUBLE { $$ = "System.Double"; }
1760 : SBYTE { $$ = "System.SByte"; }
1761 | BYTE { $$ = "System.Byte"; }
1762 | SHORT { $$ = "System.Int16"; }
1763 | USHORT { $$ = "System.UInt16"; }
1764 | INT { $$ = "System.Int32"; }
1765 | UINT { $$ = "System.UInt32"; }
1766 | LONG { $$ = "System.Int64"; }
1767 | ULONG { $$ = "System.UInt64"; }
1768 | CHAR { $$ = "System.Char"; }
1776 : type rank_specifiers
1778 $$ = (string) $1 + (string) $2;
1783 // Expressions, section 7.5
1791 | qualified_identifier
1793 string name = (string) $1;
1796 $$ = DecomposeQI (name, lexer.Location);
1798 | parenthesized_expression
1800 | invocation_expression
1804 | post_increment_expression
1805 | post_decrement_expression
1809 | checked_expression
1810 | unchecked_expression
1817 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
1818 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
1819 | NULL { $$ = NullLiteral.Null; }
1823 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
1824 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
1825 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
1830 object v = lexer.Value;
1833 // FIXME: Possible optimization would be to
1834 // compute the *Literal objects directly in the scanner
1837 $$ = new IntLiteral ((Int32) v);
1839 $$ = new UIntLiteral ((UInt32) v);
1841 $$ = new LongLiteral ((Int64) v);
1842 else if (v is ulong)
1843 $$ = new ULongLiteral ((UInt64) v);
1845 Console.WriteLine ("OOPS. Unexpected result from scanner");
1850 : TRUE { $$ = new BoolLiteral (true); }
1851 | FALSE { $$ = new BoolLiteral (false); }
1854 parenthesized_expression
1855 : OPEN_PARENS expression CLOSE_PARENS
1860 : primary_expression DOT IDENTIFIER
1862 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
1864 | predefined_type DOT IDENTIFIER
1866 $$ = new SimpleName ((string) $1 + "." + (string) $3, lexer.Location);
1874 invocation_expression
1875 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
1878 Location l = lexer.Location;
1879 Report.Error (1, l, "THIS IS CRAZY");
1881 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
1886 : /* empty */ { $$ = null; }
1893 ArrayList list = new ArrayList ();
1897 | argument_list COMMA argument
1899 ArrayList list = (ArrayList) $1;
1908 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
1910 | REF variable_reference
1912 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
1914 | OUT variable_reference
1916 $$ = new Argument ((Expression) $2, Argument.AType.Out);
1921 : expression { note ("section 5.4"); $$ = $1; }
1925 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
1927 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
1929 | primary_expression rank_specifiers
1931 // So the super-trick is that primary_expression
1932 // can only be either a SimpleName or a MemberAccess.
1933 // The MemberAccess case arises when you have a fully qualified type-name like :
1935 // SimpleName is when you have
1938 Expression expr = (Expression) $1;
1939 if (!(expr is SimpleName || expr is MemberAccess)) {
1940 Location l = lexer.Location;
1941 Report.Error (-1, l, "Invalid Type definition");
1942 $$ = "System.Object";
1946 // So we extract the string corresponding to the SimpleName
1949 $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
1956 ArrayList list = new ArrayList ();
1960 | expression_list COMMA expression
1962 ArrayList list = (ArrayList) $1;
1971 $$ = new This (lexer.Location);
1976 : BASE DOT IDENTIFIER
1978 $$ = new BaseAccess ((string) $3, lexer.Location);
1980 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
1982 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
1986 post_increment_expression
1987 : primary_expression OP_INC
1989 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
1990 (Expression) $1, lexer.Location);
1994 post_decrement_expression
1995 : primary_expression OP_DEC
1997 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
1998 (Expression) $1, lexer.Location);
2003 : object_or_delegate_creation_expression
2004 | array_creation_expression
2007 object_or_delegate_creation_expression
2008 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2010 $$ = new New ((string) $2, (ArrayList) $4, lexer.Location);
2014 array_creation_expression
2015 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2017 opt_array_initializer
2019 $$ = new ArrayCreation ((string) $2, (ArrayList) $4, (string) $6, (ArrayList) $7,
2022 | NEW type rank_specifiers array_initializer
2024 $$ = new ArrayCreation ((string) $2, (string) $3, (ArrayList) $4, lexer.Location);
2028 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2048 | rank_specifiers rank_specifier
2050 $$ = (string) $2 + (string) $1;
2055 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2057 $$ = "[" + (string) $2 + "]";
2077 | dim_separators COMMA
2079 $$ = (string) $1 + ",";
2083 opt_array_initializer
2095 : OPEN_BRACE CLOSE_BRACE
2097 ArrayList list = new ArrayList ();
2100 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2102 $$ = (ArrayList) $2;
2106 variable_initializer_list
2107 : variable_initializer
2109 ArrayList list = new ArrayList ();
2113 | variable_initializer_list COMMA variable_initializer
2115 ArrayList list = (ArrayList) $1;
2122 : TYPEOF OPEN_PARENS type CLOSE_PARENS
2124 $$ = new TypeOf ((string) $3, lexer.Location);
2129 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2130 $$ = new SizeOf ((string) $3);
2132 note ("Verify type is unmanaged");
2133 note ("if (5.8) builtin, yield constant expression");
2138 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2140 $$ = new CheckedExpr ((Expression) $3);
2144 unchecked_expression
2145 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2147 $$ = new UnCheckedExpr ((Expression) $3);
2152 : primary_expression
2153 | BANG prefixed_unary_expression
2155 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2157 | TILDE prefixed_unary_expression
2159 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2161 | OPEN_PARENS expression CLOSE_PARENS unary_expression
2163 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2165 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2167 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2172 // The idea to split this out is from Rhys' grammar
2173 // to solve the problem with casts.
2175 prefixed_unary_expression
2177 | PLUS prefixed_unary_expression
2179 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2181 | MINUS prefixed_unary_expression
2183 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2185 | OP_INC prefixed_unary_expression
2187 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2188 (Expression) $2, lexer.Location);
2190 | OP_DEC prefixed_unary_expression
2192 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2193 (Expression) $2, lexer.Location);
2195 | STAR prefixed_unary_expression
2197 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2199 | BITWISE_AND prefixed_unary_expression
2201 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2205 pre_increment_expression
2206 : OP_INC prefixed_unary_expression
2208 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2209 (Expression) $2, lexer.Location);
2213 pre_decrement_expression
2214 : OP_DEC prefixed_unary_expression
2216 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2217 (Expression) $2, lexer.Location);
2221 multiplicative_expression
2222 : prefixed_unary_expression
2223 | multiplicative_expression STAR prefixed_unary_expression
2225 $$ = new Binary (Binary.Operator.Multiply,
2226 (Expression) $1, (Expression) $3, lexer.Location);
2228 | multiplicative_expression DIV prefixed_unary_expression
2230 $$ = new Binary (Binary.Operator.Division,
2231 (Expression) $1, (Expression) $3, lexer.Location);
2233 | multiplicative_expression PERCENT prefixed_unary_expression
2235 $$ = new Binary (Binary.Operator.Modulus,
2236 (Expression) $1, (Expression) $3, lexer.Location);
2241 : multiplicative_expression
2242 | additive_expression PLUS multiplicative_expression
2244 $$ = new Binary (Binary.Operator.Addition,
2245 (Expression) $1, (Expression) $3, lexer.Location);
2247 | additive_expression MINUS multiplicative_expression
2249 $$ = new Binary (Binary.Operator.Subtraction,
2250 (Expression) $1, (Expression) $3, lexer.Location);
2255 : additive_expression
2256 | shift_expression OP_SHIFT_LEFT additive_expression
2258 $$ = new Binary (Binary.Operator.LeftShift,
2259 (Expression) $1, (Expression) $3, lexer.Location);
2261 | shift_expression OP_SHIFT_RIGHT additive_expression
2263 $$ = new Binary (Binary.Operator.RightShift,
2264 (Expression) $1, (Expression) $3, lexer.Location);
2268 relational_expression
2270 | relational_expression OP_LT shift_expression
2272 $$ = new Binary (Binary.Operator.LessThan,
2273 (Expression) $1, (Expression) $3, lexer.Location);
2275 | relational_expression OP_GT shift_expression
2277 $$ = new Binary (Binary.Operator.GreaterThan,
2278 (Expression) $1, (Expression) $3, lexer.Location);
2280 | relational_expression OP_LE shift_expression
2282 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2283 (Expression) $1, (Expression) $3, lexer.Location);
2285 | relational_expression OP_GE shift_expression
2287 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2288 (Expression) $1, (Expression) $3, lexer.Location);
2290 | relational_expression IS type
2292 $$ = new Is ((Expression) $1, (string) $3, lexer.Location);
2294 | relational_expression AS type
2296 $$ = new As ((Expression) $1, (string) $3, lexer.Location);
2301 : relational_expression
2302 | equality_expression OP_EQ relational_expression
2304 $$ = new Binary (Binary.Operator.Equality,
2305 (Expression) $1, (Expression) $3, lexer.Location);
2307 | equality_expression OP_NE relational_expression
2309 $$ = new Binary (Binary.Operator.Inequality,
2310 (Expression) $1, (Expression) $3, lexer.Location);
2315 : equality_expression
2316 | and_expression BITWISE_AND equality_expression
2318 $$ = new Binary (Binary.Operator.BitwiseAnd,
2319 (Expression) $1, (Expression) $3, lexer.Location);
2323 exclusive_or_expression
2325 | exclusive_or_expression CARRET and_expression
2327 $$ = new Binary (Binary.Operator.ExclusiveOr,
2328 (Expression) $1, (Expression) $3, lexer.Location);
2332 inclusive_or_expression
2333 : exclusive_or_expression
2334 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2336 $$ = new Binary (Binary.Operator.BitwiseOr,
2337 (Expression) $1, (Expression) $3, lexer.Location);
2341 conditional_and_expression
2342 : inclusive_or_expression
2343 | conditional_and_expression OP_AND inclusive_or_expression
2345 $$ = new Binary (Binary.Operator.LogicalAnd,
2346 (Expression) $1, (Expression) $3, lexer.Location);
2350 conditional_or_expression
2351 : conditional_and_expression
2352 | conditional_or_expression OP_OR conditional_and_expression
2354 $$ = new Binary (Binary.Operator.LogicalOr,
2355 (Expression) $1, (Expression) $3, lexer.Location);
2359 conditional_expression
2360 : conditional_or_expression
2361 | conditional_or_expression INTERR expression COLON expression
2363 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2367 assignment_expression
2368 : prefixed_unary_expression ASSIGN expression
2370 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2372 | prefixed_unary_expression OP_MULT_ASSIGN expression
2374 Location l = lexer.Location;
2376 $$ = new Assign ((Expression) $1,
2377 new Binary (Binary.Operator.Multiply,
2379 (Expression) $3, l), l);
2381 | prefixed_unary_expression OP_DIV_ASSIGN expression
2383 Location l = lexer.Location;
2385 $$ = new Assign ((Expression) $1,
2386 new Binary (Binary.Operator.Division,
2388 (Expression) $3, l), l);
2390 | prefixed_unary_expression OP_MOD_ASSIGN expression
2392 Location l = lexer.Location;
2394 $$ = new Assign ((Expression) $1,
2395 new Binary (Binary.Operator.Modulus,
2397 (Expression) $3, l), l);
2399 | prefixed_unary_expression OP_ADD_ASSIGN expression
2401 Location l = lexer.Location;
2403 $$ = new Assign ((Expression) $1,
2404 new Binary (Binary.Operator.Addition,
2406 (Expression) $3, l), l);
2408 | prefixed_unary_expression OP_SUB_ASSIGN expression
2410 Location l = lexer.Location;
2412 $$ = new Assign ((Expression) $1,
2413 new Binary (Binary.Operator.Subtraction,
2415 (Expression) $3, l), l);
2417 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2419 Location l = lexer.Location;
2421 $$ = new Assign ((Expression) $1,
2422 new Binary (Binary.Operator.LeftShift,
2424 (Expression) $3, l), l);
2426 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2428 Location l = lexer.Location;
2430 $$ = new Assign ((Expression) $1,
2431 new Binary (Binary.Operator.RightShift,
2433 (Expression) $3, l), l);
2435 | prefixed_unary_expression OP_AND_ASSIGN expression
2437 Location l = lexer.Location;
2439 $$ = new Assign ((Expression) $1,
2440 new Binary (Binary.Operator.BitwiseAnd,
2442 (Expression) $3, l), l);
2444 | prefixed_unary_expression OP_OR_ASSIGN expression
2446 Location l = lexer.Location;
2448 $$ = new Assign ((Expression) $1,
2449 new Binary (Binary.Operator.BitwiseOr,
2451 (Expression) $3, l), l);
2453 | prefixed_unary_expression OP_XOR_ASSIGN expression
2455 Location l = lexer.Location;
2457 $$ = new Assign ((Expression) $1,
2458 new Binary (Binary.Operator.ExclusiveOr,
2460 (Expression) $3, l), l);
2465 : conditional_expression
2466 | assignment_expression
2488 name = MakeName ((string) $4);
2490 new_class = new Class (current_container, name, (int) $2,
2491 (Attributes) $1, lexer.Location);
2492 current_container = new_class;
2493 current_container.Namespace = current_namespace;
2494 RootContext.Tree.RecordClass (name, new_class);
2500 Class new_class = (Class) current_container;
2503 new_class.Bases = (ArrayList) $6;
2505 current_container = current_container.Parent;
2506 CheckDef (current_container.AddClass (new_class), new_class.Name);
2513 : /* empty */ { $$ = (int) 0; }
2519 | modifiers modifier
2524 if ((m1 & m2) != 0) {
2525 Location l = lexer.Location;
2526 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
2528 $$ = (int) (m1 | m2);
2533 : NEW { $$ = Modifiers.NEW; }
2534 | PUBLIC { $$ = Modifiers.PUBLIC; }
2535 | PROTECTED { $$ = Modifiers.PROTECTED; }
2536 | INTERNAL { $$ = Modifiers.INTERNAL; }
2537 | PRIVATE { $$ = Modifiers.PRIVATE; }
2538 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
2539 | SEALED { $$ = Modifiers.SEALED; }
2540 | STATIC { $$ = Modifiers.STATIC; }
2541 | READONLY { $$ = Modifiers.READONLY; }
2542 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
2543 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
2544 | EXTERN { $$ = Modifiers.EXTERN; }
2545 | VOLATILE { $$ = Modifiers.VOLATILE; }
2549 : /* empty */ { $$ = null; }
2550 | class_base { $$ = $1; }
2554 : COLON type_list { $$ = $2; }
2562 // A block is "contained" on the following places:
2564 // property_declaration as part of the accessor body (get/set)
2565 // operator_declaration
2566 // constructor_declaration
2567 // destructor_declaration
2568 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
2573 current_block = new Block (current_block);
2575 opt_statement_list CLOSE_BRACE
2577 while (current_block.Implicit)
2578 current_block = current_block.Parent;
2580 current_block = current_block.Parent;
2591 | statement_list statement
2595 : declaration_statement
2597 if ((Block) $1 != current_block){
2598 current_block.AddStatement ((Statement) $1);
2599 current_block = (Block) $1;
2602 | embedded_statement
2604 Statement s = (Statement) $1;
2607 current_block.AddStatement ((Statement) $1);
2615 | expression_statement
2616 | selection_statement
2617 | iteration_statement
2621 | unchecked_statement
2630 $$ = new EmptyStatement ();
2637 LabeledStatement labeled = new LabeledStatement ((string) $1);
2639 if (!current_block.AddLabel ((string) $1, labeled)){
2640 Location l = lexer.Location;
2641 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
2643 current_block.AddStatement (labeled);
2648 declaration_statement
2649 : local_variable_declaration SEMICOLON
2651 DictionaryEntry de = (DictionaryEntry) $1;
2653 $$ = declare_local_variables ((string) de.Key, (ArrayList) de.Value, lexer.Location);
2656 | local_constant_declaration SEMICOLON
2658 DictionaryEntry de = (DictionaryEntry) $1;
2660 $$ = declare_local_constant ((string) de.Key, (VariableDeclaration) de.Value);
2665 * The following is from Rhys' grammar:
2666 * > Types in local variable declarations must be recognized as
2667 * > expressions to prevent reduce/reduce errors in the grammar.
2668 * > The expressions are converted into types during semantic analysis.
2671 : primary_expression opt_rank_specifier
2673 // FIXME: Do something smart here regarding the composition of the type.
2675 // Ok, the above "primary_expression" is there to get rid of
2676 // both reduce/reduce and shift/reduces in the grammar, it should
2677 // really just be "type_name". If you use type_name, a reduce/reduce
2678 // creeps up. If you use qualified_identifier (which is all we need
2679 // really) two shift/reduces appear.
2682 // So the super-trick is that primary_expression
2683 // can only be either a SimpleName or a MemberAccess.
2684 // The MemberAccess case arises when you have a fully qualified type-name like :
2686 // SimpleName is when you have
2689 Expression expr = (Expression) $1;
2690 if (!(expr is SimpleName || expr is MemberAccess)) {
2691 Location l = lexer.Location;
2692 Report.Error (-1, l, "Invalid Type definition");
2693 $$ = "System.Object";
2697 // So we extract the string corresponding to the SimpleName
2700 $$ = GetQualifiedIdentifier (expr) + (string) $2;
2702 | builtin_types opt_rank_specifier
2704 $$ = (string) $1 + (string) $2;
2708 local_variable_pointer_type
2709 : primary_expression STAR
2711 Expression expr = (Expression) $1;
2712 if (!(expr is SimpleName || expr is MemberAccess)) {
2713 Location l = lexer.Location;
2714 Report.Error (-1, l, "Invalid Type definition");
2715 $$ = "System.Object";
2718 $$ = GetQualifiedIdentifier (expr) + "*";
2720 | builtin_types STAR
2722 $$ = (string) $1 + "*";
2726 $$ = "System.Void*";
2728 | local_variable_pointer_type STAR
2730 $$ = (string) $1 + "*";
2734 local_variable_declaration
2735 : local_variable_type variable_declarators
2737 $$ = new DictionaryEntry ($1, $2);
2739 | local_variable_pointer_type opt_rank_specifier variable_declarators
2741 $$ = new DictionaryEntry ((string) $1 + (string) $2, $3);
2745 local_constant_declaration
2746 : CONST local_variable_type constant_declarator
2748 $$ = new DictionaryEntry ($2, $3);
2752 expression_statement
2753 : statement_expression SEMICOLON
2760 // We have to do the wrapping here and not in the case above,
2761 // because statement_expression is used for example in for_statement
2763 statement_expression
2764 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2765 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2766 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2767 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2768 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2769 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2770 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2772 Report.Error (1002, lexer.Location, "Expecting `;'");
2776 object_creation_expression
2777 : object_or_delegate_creation_expression
2778 { note ("complain if this is a delegate maybe?"); }
2787 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
2790 $$ = new If ((Expression) $3, (Statement) $5);
2792 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
2793 embedded_statement ELSE embedded_statement
2795 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7);
2800 : SWITCH OPEN_PARENS
2802 oob_stack.Push (lexer.Location);
2804 expression CLOSE_PARENS
2807 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
2823 Report.Error (1522, lexer.Location, "Empty switch block");
2831 ArrayList sections = new ArrayList ();
2836 | switch_sections switch_section
2838 ArrayList sections = (ArrayList) $1;
2848 current_block = new Block (current_block);
2852 while (current_block.Implicit)
2853 current_block = current_block.Parent;
2854 $$ = new SwitchSection ((ArrayList) $1, current_block);
2855 current_block = current_block.Parent;
2862 ArrayList labels = new ArrayList ();
2867 | switch_labels switch_label
2869 ArrayList labels = (ArrayList) ($1);
2877 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
2878 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
2881 1523, lexer.Location,
2882 "The keyword case or default must precede code in switch block");
2894 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
2896 $$ = new While ((Expression) $3, (Statement) $5);
2901 : DO embedded_statement
2902 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
2904 $$ = new Do ((Statement) $2, (Expression) $5);
2910 opt_for_initializer SEMICOLON
2912 Block assign_block = new Block (current_block);
2913 current_block = assign_block;
2915 if ($3 is DictionaryEntry){
2916 DictionaryEntry de = (DictionaryEntry) $3;
2918 string type = (string) de.Key;
2919 ArrayList var_declarators = (ArrayList) de.Value;
2921 foreach (VariableDeclaration decl in var_declarators){
2923 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
2925 Report.Error (128, decl.Location,
2926 "A local variable `" + decl.identifier + "' is already" +
2927 "defined in this scope");
2930 Location l = lexer.Location;
2932 if (decl.expression_or_array_initializer is Expression){
2933 expr = (Expression) decl.expression_or_array_initializer;
2937 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
2939 string base_type = type.Substring (0, type.IndexOf ("["));
2940 string rank = type.Substring (type.IndexOf ("["));
2942 expr = new ArrayCreation (base_type, rank, init, decl.Location);
2945 LocalVariableReference var;
2946 var = new LocalVariableReference (
2947 assign_block, decl.identifier, l);
2949 Assign a = new Assign (var, expr, decl.Location);
2951 assign_block.AddStatement (new StatementExpression (a));
2958 opt_for_condition SEMICOLON
2959 opt_for_iterator CLOSE_PARENS
2962 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10);
2964 current_block.AddStatement (f);
2965 while (current_block.Implicit)
2966 current_block = current_block.Parent;
2968 current_block = current_block.Parent;
2973 : /* empty */ { $$ = new EmptyStatement (); }
2978 : local_variable_declaration
2979 | statement_expression_list
2983 : /* empty */ { $$ = null; }
2984 | boolean_expression
2988 : /* empty */ { $$ = new EmptyStatement (); }
2993 : statement_expression_list
2996 statement_expression_list
2997 : statement_expression
2999 Block b = new Block (null, true);
3001 b.AddStatement ((Statement) $1);
3004 | statement_expression_list COMMA statement_expression
3006 Block b = (Block) $1;
3008 b.AddStatement ((Statement) $3);
3014 : FOREACH OPEN_PARENS type IDENTIFIER IN
3016 oob_stack.Push (lexer.Location);
3018 expression CLOSE_PARENS
3020 Block foreach_block = new Block (current_block, true);
3021 LocalVariableReference v;
3022 Location l = lexer.Location;
3024 foreach_block.AddVariable ((string) $3, (string) $4, current_local_parameters, l);
3025 v = new LocalVariableReference (foreach_block, (string) $4, l);
3027 current_block.AddStatement (foreach_block);
3028 current_block = foreach_block;
3030 oob_stack.Push (foreach_block);
3035 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3036 Block foreach_block = (Block) oob_stack.Pop ();
3037 Location l = (Location) oob_stack.Pop ();
3039 $$ = new Foreach ((string) $3, v, (Expression) $7, (Statement) $10, l);
3045 | continue_statement
3054 $$ = new Break (lexer.Location);
3059 : CONTINUE SEMICOLON
3061 $$ = new Continue (lexer.Location);
3066 : GOTO IDENTIFIER SEMICOLON
3068 $$ = new Goto (current_block, (string) $2, lexer.Location);
3070 | GOTO CASE constant_expression SEMICOLON
3072 $$ = new GotoCase ((Expression) $3, lexer.Location);
3074 | GOTO DEFAULT SEMICOLON
3076 $$ = new GotoDefault (lexer.Location);
3081 : RETURN opt_expression SEMICOLON
3083 $$ = new Return ((Expression) $2, lexer.Location);
3088 : THROW opt_expression SEMICOLON
3090 $$ = new Throw ((Expression) $2, lexer.Location);
3100 : TRY block catch_clauses
3103 ArrayList s = new ArrayList ();
3105 foreach (Catch cc in (ArrayList) $3) {
3106 if (cc.Type == null)
3112 // Now s contains the list of specific catch clauses
3113 // and g contains the general one.
3115 $$ = new Try ((Block) $2, s, g, null);
3117 | TRY block opt_catch_clauses FINALLY block
3120 ArrayList s = new ArrayList ();
3122 foreach (Catch cc in (ArrayList) $3) {
3123 if (cc.Type == null)
3129 $$ = new Try ((Block) $2, s, g, (Block) $5);
3133 Report.Error (1524, lexer.Location, "Expected catch or finally");
3138 : /* empty */ { $$ = null; }
3145 ArrayList l = new ArrayList ();
3150 | catch_clauses catch_clause
3152 ArrayList l = (ArrayList) $1;
3160 : /* empty */ { $$ = null; }
3165 : CATCH opt_catch_args
3167 string type = null, id = null;
3170 DictionaryEntry cc = (DictionaryEntry) $2;
3171 type = (string) cc.Key;
3172 id = (string) cc.Value;
3175 ArrayList one = new ArrayList ();
3176 Location loc = lexer.Location;
3178 one.Add (new VariableDeclaration (id, null, loc));
3181 current_block = new Block (current_block);
3182 Block b = declare_local_variables (type, one, loc);
3189 string type = null, id = null;
3192 DictionaryEntry cc = (DictionaryEntry) $2;
3193 type = (string) cc.Key;
3194 id = (string) cc.Value;
3197 while (current_block != (Block) $1)
3198 current_block = current_block.Parent;
3203 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3208 : /* empty */ { $$ = null; }
3213 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3215 $$ = new DictionaryEntry ($2, $3);
3222 $$ = new Checked ((Block) $2);
3229 $$ = new Unchecked ((Block) $2);
3236 $$ = new Unsafe ((Block) $2);
3241 : LOCK OPEN_PARENS expression CLOSE_PARENS
3247 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
3252 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
3254 Block assign_block = new Block (current_block);
3255 current_block = assign_block;
3257 oob_stack.Push (lexer.Location);
3259 if ($3 is DictionaryEntry){
3260 DictionaryEntry de = (DictionaryEntry) $3;
3261 Location l = lexer.Location;
3263 string type = (string) de.Key;
3264 ArrayList var_declarators = (ArrayList) de.Value;
3266 foreach (VariableDeclaration decl in var_declarators){
3267 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
3269 Report.Error (128, decl.Location,
3270 "A local variable `" + decl.identifier + "' is already" +
3271 "defined in this scope");
3275 ArrayList vars = new ArrayList ();
3277 foreach (VariableDeclaration decl in var_declarators){
3280 if (decl.expression_or_array_initializer is Expression){
3281 expr = (Expression) decl.expression_or_array_initializer;
3285 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3287 string base_type = type.Substring (0, type.IndexOf ("["));
3288 string rank = type.Substring (type.IndexOf ("["));
3290 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3293 LocalVariableReference var;
3296 var = new LocalVariableReference (assign_block, decl.identifier, l);
3297 vi = var.VariableInfo;
3300 // This is so that it is not a warning on using variables
3303 vars.Add (new DictionaryEntry (var, expr));
3305 // Assign a = new Assign (var, expr, decl.Location);
3306 // assign_block.AddStatement (new StatementExpression (a));
3308 $3 = new DictionaryEntry (type, vars);
3313 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
3314 current_block.AddStatement (u);
3315 while (current_block.Implicit)
3316 current_block = current_block.Parent;
3318 current_block = current_block.Parent;
3322 resource_acquisition
3323 : local_variable_declaration
3330 // A class used to pass around variable declarations and constants
3332 public class VariableDeclaration {
3333 public string identifier;
3334 public object expression_or_array_initializer;
3335 public Location Location;
3337 public VariableDeclaration (string id, object eoai, Location l){
3338 this.identifier = id;
3339 this.expression_or_array_initializer = eoai;
3345 // A class used to hold info about an indexer declarator
3348 public class IndexerDeclaration {
3350 public string interface_type;
3351 public Parameters param_list;
3353 public IndexerDeclaration (string type, string interface_type, Parameters param_list)
3356 this.interface_type = interface_type;
3357 this.param_list = param_list;
3362 // A class used to hold info about an operator declarator
3365 public class OperatorDeclaration {
3366 public Operator.OpType optype;
3367 public string ret_type;
3368 public string arg1type;
3369 public string arg1name;
3370 public string arg2type;
3371 public string arg2name;
3372 public Location location;
3374 public OperatorDeclaration (Operator.OpType op, string ret_type, string arg1type, string arg1name,
3375 string arg2type, string arg2name, Location location)
3378 this.ret_type = ret_type;
3379 this.arg1type = arg1type;
3380 this.arg1name = arg1name;
3381 this.arg2type = arg2type;
3382 this.arg2name = arg2name;
3383 this.location = location;
3389 // Given the @class_name name, it creates a fully qualified name
3390 // based on the containing declaration space
3393 MakeName (string class_name)
3395 string ns = current_namespace.Name;
3396 string container_name = current_container.Name;
3398 if (container_name == ""){
3400 return ns + "." + class_name;
3404 return container_name + "." + class_name;
3408 // Used to report back to the user the result of a declaration
3409 // in the current declaration space
3412 CheckDef (AdditionResult result, string name)
3414 if (result == AdditionResult.Success)
3417 Location l = lexer.Location;
3420 case AdditionResult.NameExists:
3421 Report.Error (102, l, "The namespace `" + current_container.Name +
3422 "' already contains a definition for `"+
3428 // This is handled only for static Constructors, because
3429 // in reality we handle these by the semantic analysis later
3431 case AdditionResult.MethodExists:
3433 111, l, "Class `"+current_container.Name+
3434 "' already defines a member called '" +
3435 name + "' with the same parameter types (more than one default constructor)");
3438 case AdditionResult.EnclosingClash:
3439 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
3442 case AdditionResult.NotAConstructor:
3443 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
3449 CheckDef (bool result, string name)
3453 CheckDef (AdditionResult.NameExists, name);
3457 SimpleLookup (string name, Location loc)
3460 // we need to check against current_block not being null
3461 // as `expression' is allowed in argument_lists, which
3462 // do not exist inside a block.
3464 if (current_block != null){
3465 if (current_block.IsVariableDefined (name))
3466 return new LocalVariableReference (current_block, name, loc);
3469 if (current_local_parameters != null){
3471 Parameter par = current_local_parameters.GetParameterByName (name, out idx);
3473 return new ParameterReference (current_local_parameters, idx, name);
3479 Expression DecomposeQI (string name, Location loc)
3483 if (name.IndexOf ('.') == -1){
3484 o = SimpleLookup (name, loc);
3486 return new SimpleName (name, loc);
3489 int pos = name.LastIndexOf (".");
3490 string left = name.Substring (0, pos);
3491 string right = name.Substring (pos + 1);
3493 o = DecomposeQI (left, loc);
3494 return new MemberAccess (o, right, loc);
3499 // This method is used to get at the complete string representation of
3500 // a fully-qualified type name, hiding inside a MemberAccess ;-)
3501 // This is necessary because local_variable_type admits primary_expression
3502 // as the type of the variable. So we do some extra checking
3504 string GetQualifiedIdentifier (Expression expr)
3506 if (expr is SimpleName)
3507 return ((SimpleName)expr).Name;
3508 else if (expr is MemberAccess)
3509 return GetQualifiedIdentifier (((MemberAccess)expr).Expr) + "." + ((MemberAccess) expr).Identifier;
3511 throw new Exception ("Expr has to be either SimpleName or MemberAccess! (" + expr + ")");
3515 Block declare_local_variables (string type, ArrayList variable_declarators, Location loc)
3517 Block implicit_block;
3518 ArrayList inits = null;
3521 // We use the `Used' property to check whether statements
3522 // have been added to the current block. If so, we need
3523 // to create another block to contain the new declaration
3524 // otherwise, as an optimization, we use the same block to
3525 // add the declaration.
3527 // FIXME: A further optimization is to check if the statements
3528 // that were added were added as part of the initialization
3529 // below. In which case, no other statements have been executed
3530 // and we might be able to reduce the number of blocks for
3531 // situations like this:
3533 // int j = 1; int k = j + 1;
3535 if (current_block.Used)
3536 implicit_block = new Block (current_block, true);
3538 implicit_block = current_block;
3540 foreach (VariableDeclaration decl in variable_declarators){
3542 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location)) {
3543 if (decl.expression_or_array_initializer != null){
3545 inits = new ArrayList ();
3549 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3550 "' is already defined in this scope");
3555 return implicit_block;
3557 foreach (VariableDeclaration decl in inits){
3561 if (decl.expression_or_array_initializer is Expression){
3562 expr = (Expression) decl.expression_or_array_initializer;
3565 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3567 string base_type = type.Substring (0, type.IndexOf ("["));
3568 string rank = type.Substring (type.IndexOf ("["));
3570 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3574 LocalVariableReference var;
3575 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
3577 assign = new Assign (var, expr, decl.Location);
3579 implicit_block.AddStatement (new StatementExpression (assign));
3582 return implicit_block;
3585 Block declare_local_constant (string type, VariableDeclaration decl)
3587 Block implicit_block;
3589 if (current_block.Used)
3590 implicit_block = new Block (current_block, true);
3592 implicit_block = current_block;
3594 if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
3595 current_local_parameters, decl.Location))){
3596 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3597 "' is already defined in this scope");
3600 return implicit_block;
3603 void CheckAttributeTarget (string a)
3607 case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
3611 Location l = lexer.Location;
3612 Report.Error (658, l, "Invalid attribute target");
3618 void CheckUnaryOperator (Operator.OpType op)
3622 case Operator.OpType.LogicalNot:
3623 case Operator.OpType.OnesComplement:
3624 case Operator.OpType.Increment:
3625 case Operator.OpType.Decrement:
3626 case Operator.OpType.True:
3627 case Operator.OpType.False:
3628 case Operator.OpType.Addition:
3629 case Operator.OpType.Subtraction:
3634 Location l = lexer.Location;
3635 Report.Error (1019, l, "Overloadable unary operator expected");
3641 void CheckBinaryOperator (Operator.OpType op)
3645 case Operator.OpType.Addition:
3646 case Operator.OpType.Subtraction:
3647 case Operator.OpType.Multiply:
3648 case Operator.OpType.Division:
3649 case Operator.OpType.Modulus:
3650 case Operator.OpType.BitwiseAnd:
3651 case Operator.OpType.BitwiseOr:
3652 case Operator.OpType.ExclusiveOr:
3653 case Operator.OpType.LeftShift:
3654 case Operator.OpType.RightShift:
3655 case Operator.OpType.Equality:
3656 case Operator.OpType.Inequality:
3657 case Operator.OpType.GreaterThan:
3658 case Operator.OpType.LessThan:
3659 case Operator.OpType.GreaterThanOrEqual:
3660 case Operator.OpType.LessThanOrEqual:
3664 Location l = lexer.Location;
3665 Report.Error (1020, l, "Overloadable binary operator expected");
3671 void syntax_error (Location l, string msg)
3673 Report.Error (1003, l, "Syntax error, " + msg);
3676 void output (string s)
3678 Console.WriteLine (s);
3681 void note (string s)
3683 // Used to put annotations
3688 public Tokenizer Lexer {
3694 public CSharpParser (string name, System.IO.Stream input, ArrayList defines)
3696 current_namespace = new Namespace (null, "");
3699 current_container = RootContext.Tree.Types;
3700 current_container.Namespace = current_namespace;
3701 oob_stack = new Stack ();
3703 lexer = new Tokenizer (input, name, defines);
3706 public override int parse ()
3708 StringBuilder value = new StringBuilder ();
3712 if (yacc_verbose_flag)
3713 yyparse (lexer, new yydebug.yyDebugSimple ());
3716 } catch (Exception e){
3717 // Console.WriteLine ("Fatal error: " + name);
3718 // Console.WriteLine (lexer.location);
3721 // Please do not remove this, it is used during debugging
3724 Console.WriteLine (lexer.location + " : Parsing error ");
3725 Console.WriteLine (e);
3729 return global_errors;