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;
761 const int extern_abstract = (Modifiers.EXTERN | Modifiers.ABSTRACT);
764 if ((method.ModFlags & extern_abstract) == 0){
766 501, lexer.Location, current_container.MakeName (method.Name) +
767 "must declare a body because it is not marked abstract or extern");
770 if ((method.ModFlags & Modifiers.EXTERN) != 0){
772 179, lexer.Location, current_container.MakeName (method.Name) +
773 " is declared extern, but has a body");
777 method.Block = (Block) $2;
778 CheckDef (current_container.AddMethod (method), method.Name);
780 current_local_parameters = null;
794 1585, lexer.Location, "Member modifier `" +
795 Modifiers.Name (i) + "' must precede member type and name");
808 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
810 Method method = new Method ((string) $3, (int) $2, (string) $4,
811 (Parameters) $6, (Attributes) $1, lexer.Location);
813 current_local_parameters = (Parameters) $6;
821 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
823 Method method = new Method ("System.Void", (int) $2, (string) $4,
824 (Parameters) $6, (Attributes) $1, lexer.Location);
826 current_local_parameters = (Parameters) $6;
833 | SEMICOLON { $$ = null; }
836 opt_formal_parameter_list
837 : /* empty */ { $$ = Parameters.GetEmptyReadOnlyParameters (); }
838 | formal_parameter_list
841 formal_parameter_list
844 ArrayList pars_list = (ArrayList) $1;
846 Parameter [] pars = new Parameter [pars_list.Count];
847 pars_list.CopyTo (pars);
849 $$ = new Parameters (pars, null, lexer.Location);
851 | fixed_parameters COMMA parameter_array
853 ArrayList pars_list = (ArrayList) $1;
855 Parameter [] pars = new Parameter [pars_list.Count];
856 pars_list.CopyTo (pars);
858 $$ = new Parameters (pars, (Parameter) $3, lexer.Location);
862 $$ = new Parameters (null, (Parameter) $1, lexer.Location);
869 ArrayList pars = new ArrayList ();
874 | fixed_parameters COMMA fixed_parameter
876 ArrayList pars = (ArrayList) $1;
885 opt_parameter_modifier
889 $$ = new Parameter ((string) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
893 opt_parameter_modifier
894 : /* empty */ { $$ = Parameter.Modifier.NONE; }
899 : REF { $$ = Parameter.Modifier.REF; }
900 | OUT { $$ = Parameter.Modifier.OUT; }
904 : opt_attributes PARAMS type IDENTIFIER
906 $$ = new Parameter ((string) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
907 note ("type must be a single-dimension array type");
912 : qualified_identifier
921 implicit_value_parameter_type = (string) $3;
923 lexer.PropertyParsing = true;
927 accessor_declarations
929 lexer.PropertyParsing = false;
934 Pair pair = (Pair) $7;
935 Block get_block = null;
936 Block set_block = null;
938 if (pair.First != null)
939 get_block = (Block) pair.First;
940 if (pair.Second != null)
941 set_block = (Block) pair.Second;
943 prop = new Property ((string) $3, (string) $4, (int) $2, get_block, set_block,
944 (Attributes) $1, (Location) $6);
946 CheckDef (current_container.AddProperty (prop), prop.Name);
947 implicit_value_parameter_type = null;
951 accessor_declarations
952 : get_accessor_declaration opt_set_accessor_declaration
954 $$ = new Pair ($1, $2);
956 | set_accessor_declaration opt_get_accessor_declaration
958 $$ = new Pair ($2, $1);
962 opt_get_accessor_declaration
963 : /* empty */ { $$ = null; }
964 | get_accessor_declaration
967 opt_set_accessor_declaration
968 : /* empty */ { $$ = null; }
969 | set_accessor_declaration
972 get_accessor_declaration
975 // If this is not the case, then current_local_parameters has already
976 // been set in indexer_declaration
977 if (parsing_indexer == false)
978 current_local_parameters = null;
980 current_local_parameters = indexer_parameters;
981 lexer.PropertyParsing = false;
986 current_local_parameters = null;
987 lexer.PropertyParsing = true;
991 set_accessor_declaration
995 Parameter implicit_value_parameter = new Parameter (
996 implicit_value_parameter_type, "value",
997 Parameter.Modifier.NONE, null);
999 if (parsing_indexer == false) {
1000 args = new Parameter [1];
1001 args [0] = implicit_value_parameter;
1003 Parameter [] fp = indexer_parameters.FixedParameters;
1004 int count = fp.Length;
1006 args = new Parameter [count + 1];
1008 fp.CopyTo (args, 0);
1009 args [count] = implicit_value_parameter;
1012 current_local_parameters = new Parameters (args, null, lexer.Location);
1013 lexer.PropertyParsing = false;
1018 current_local_parameters = null;
1019 lexer.PropertyParsing = true;
1025 | SEMICOLON { $$ = new Block (null); }
1028 interface_declaration
1031 INTERFACE IDENTIFIER
1033 Interface new_interface;
1034 string full_interface_name = MakeName ((string) $4);
1036 new_interface = new Interface (current_container, full_interface_name, (int) $2,
1037 (Attributes) $1, lexer.Location);
1038 if (current_interface != null) {
1039 Location l = lexer.Location;
1040 Report.Error (-2, l, "Internal compiler error: interface inside interface");
1042 current_interface = new_interface;
1043 new_interface.Namespace = current_namespace;
1044 RootContext.Tree.RecordInterface (full_interface_name, new_interface);
1049 Interface new_interface = (Interface) current_interface;
1052 new_interface.Bases = (ArrayList) $6;
1054 current_interface = null;
1055 CheckDef (current_container.AddInterface (new_interface), new_interface.Name);
1060 : /* empty */ { $$ = null; }
1065 : COLON interface_type_list { $$ = $2; }
1071 ArrayList interfaces = new ArrayList ();
1073 interfaces.Add ($1);
1076 | interface_type_list COMMA interface_type
1078 ArrayList interfaces = (ArrayList) $1;
1079 interfaces.Add ($3);
1086 opt_interface_member_declarations
1090 opt_interface_member_declarations
1092 | interface_member_declarations
1095 interface_member_declarations
1096 : interface_member_declaration
1097 | interface_member_declarations interface_member_declaration
1100 interface_member_declaration
1101 : interface_method_declaration
1103 InterfaceMethod m = (InterfaceMethod) $1;
1105 CheckDef (current_interface.AddMethod (m), m.Name);
1107 | interface_property_declaration
1109 InterfaceProperty p = (InterfaceProperty) $1;
1111 CheckDef (current_interface.AddProperty (p), p.Name);
1113 | interface_event_declaration
1115 InterfaceEvent e = (InterfaceEvent) $1;
1117 CheckDef (current_interface.AddEvent (e), e.Name);
1119 | interface_indexer_declaration
1121 InterfaceIndexer i = (InterfaceIndexer) $1;
1123 CheckDef (current_interface.AddIndexer (i), "indexer");
1128 : /* empty */ { $$ = false; }
1129 | NEW { $$ = true; }
1132 interface_method_declaration
1133 : opt_attributes opt_new type IDENTIFIER
1134 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1137 $$ = new InterfaceMethod ((string) $3, (string) $4, (bool) $2,
1138 (Parameters) $6, (Attributes) $1, lexer.Location);
1140 | opt_attributes opt_new VOID IDENTIFIER
1141 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1144 $$ = new InterfaceMethod ("System.Void", (string) $4, (bool) $2, (Parameters) $6,
1145 (Attributes) $1, lexer.Location);
1149 interface_property_declaration
1154 { lexer.PropertyParsing = true; }
1156 { lexer.PropertyParsing = false; }
1161 $$ = new InterfaceProperty ((string) $3, (string) $4, (bool) $2,
1162 (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
1168 : opt_attributes GET SEMICOLON { $$ = 1; }
1169 | opt_attributes SET SEMICOLON { $$ = 2; }
1170 | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
1172 | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
1176 interface_event_declaration
1177 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1179 $$ = new InterfaceEvent ((string) $4, (string) $5, (bool) $2, (Attributes) $1);
1183 interface_indexer_declaration
1184 : opt_attributes opt_new type THIS
1185 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1187 { lexer.PropertyParsing = true; }
1189 { lexer.PropertyParsing = false; }
1192 int a_flags = (int) $10;
1194 bool do_get = (a_flags & 1) == 1;
1195 bool do_set = (a_flags & 2) == 2;
1197 $$ = new InterfaceIndexer ((string) $3, (Parameters) $6, do_get, do_set,
1198 (bool) $2, (Attributes) $1, lexer.Location);
1202 operator_declaration
1203 : opt_attributes opt_modifiers operator_declarator block
1205 OperatorDeclaration decl = (OperatorDeclaration) $3;
1207 Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
1208 decl.arg2type, decl.arg2name, (Block) $4, (Attributes) $1, decl.location);
1210 // Note again, checking is done in semantic analysis
1211 current_container.AddOperator (op);
1213 current_local_parameters = null;
1218 : type OPERATOR overloadable_operator
1219 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1221 Operator.OpType op = (Operator.OpType) $3;
1222 CheckUnaryOperator (op);
1224 if (op == Operator.OpType.Addition)
1225 op = Operator.OpType.UnaryPlus;
1227 if (op == Operator.OpType.Subtraction)
1228 op = Operator.OpType.UnaryNegation;
1230 Parameter [] pars = new Parameter [1];
1232 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1234 current_local_parameters = new Parameters (pars, null, lexer.Location);
1236 $$ = new OperatorDeclaration (op, (string) $1, (string) $5, (string) $6,
1237 null, null, lexer.Location);
1239 | type OPERATOR overloadable_operator
1241 type IDENTIFIER COMMA
1245 CheckBinaryOperator ((Operator.OpType) $3);
1247 Parameter [] pars = new Parameter [2];
1249 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1250 pars [1] = new Parameter ((string) $8, (string) $9, Parameter.Modifier.NONE, null);
1252 current_local_parameters = new Parameters (pars, null, lexer.Location);
1254 $$ = new OperatorDeclaration ((Operator.OpType) $3, (string) $1, (string) $5, (string) $6,
1255 (string) $8, (string) $9, lexer.Location);
1257 | conversion_operator_declarator
1260 overloadable_operator
1262 : BANG { $$ = Operator.OpType.LogicalNot; }
1263 | TILDE { $$ = Operator.OpType.OnesComplement; }
1264 | OP_INC { $$ = Operator.OpType.Increment; }
1265 | OP_DEC { $$ = Operator.OpType.Decrement; }
1266 | TRUE { $$ = Operator.OpType.True; }
1267 | FALSE { $$ = Operator.OpType.False; }
1268 // Unary and binary:
1269 | PLUS { $$ = Operator.OpType.Addition; }
1270 | MINUS { $$ = Operator.OpType.Subtraction; }
1272 | STAR { $$ = Operator.OpType.Multiply; }
1273 | DIV { $$ = Operator.OpType.Division; }
1274 | PERCENT { $$ = Operator.OpType.Modulus; }
1275 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1276 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1277 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1278 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1279 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1280 | OP_EQ { $$ = Operator.OpType.Equality; }
1281 | OP_NE { $$ = Operator.OpType.Inequality; }
1282 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1283 | OP_LT { $$ = Operator.OpType.LessThan; }
1284 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1285 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1288 conversion_operator_declarator
1289 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1291 Parameter [] pars = new Parameter [1];
1293 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1295 current_local_parameters = new Parameters (pars, null, lexer.Location);
1297 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (string) $3, (string) $5, (string) $6,
1298 null, null, lexer.Location);
1300 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1302 Parameter [] pars = new Parameter [1];
1304 pars [0] = new Parameter ((string) $5, (string) $6, Parameter.Modifier.NONE, null);
1306 current_local_parameters = new Parameters (pars, null, lexer.Location);
1308 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (string) $3, (string) $5, (string) $6,
1309 null, null, lexer.Location);
1313 syntax_error (lexer.Location, "'operator' expected");
1317 syntax_error (lexer.Location, "'operator' expected");
1321 constructor_declaration
1324 constructor_declarator
1327 Constructor c = (Constructor) $3;
1328 c.Block = (Block) $4;
1329 c.ModFlags = (int) $2;
1330 c.OptAttributes = (Attributes) $1;
1332 if ((c.ModFlags & Modifiers.STATIC) != 0){
1333 if ((c.ModFlags & Modifiers.Accessibility) != 0) {
1334 Location l = lexer.Location;
1335 Report.Error (515, l, "Access modifiers are not allowed on static constructors");
1338 if (c.Initializer != null){
1339 Location l = lexer.Location;
1340 Report.Error (514, l, "Static constructors can not have an explicit this or base constructor invocations");
1343 if (!c.Parameters.Empty){
1344 Location l = lexer.Location;
1345 Report.Error (132, l, "Static constructors should not have parameters");
1349 CheckDef (current_container.AddConstructor (c), c.Name);
1351 current_local_parameters = null;
1355 constructor_declarator
1357 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1359 oob_stack.Push (lexer.Location);
1361 current_local_parameters = (Parameters) $3;
1363 opt_constructor_initializer
1365 Location l = (Location) oob_stack.Pop ();
1366 $$ = new Constructor ((string) $1, (Parameters) $3, (ConstructorInitializer) $6, l);
1370 opt_constructor_initializer
1371 : /* empty */ { $$ = null; }
1372 | constructor_initializer
1375 constructor_initializer
1376 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
1378 $$ = new ConstructorBaseInitializer ((ArrayList) $4, lexer.Location);
1380 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
1382 $$ = new ConstructorThisInitializer ((ArrayList) $4, lexer.Location);
1386 destructor_declaration
1387 : opt_attributes TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
1389 if ((string) $3 != current_container.Basename){
1390 Report.Error (574, lexer.Location, "Name of destructor must match name of class");
1391 } else if (!(current_container is Class)){
1392 Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
1394 Location l = lexer.Location;
1396 Method d = new Method (
1397 "System.Void", 0, "Finalize",
1398 new Parameters (null, null, l), (Attributes) $1, l);
1400 d.Block = (Block) $6;
1401 CheckDef (current_container.AddMethod (d), d.Name);
1409 EVENT type variable_declarators SEMICOLON
1411 foreach (VariableDeclaration var in (ArrayList) $5) {
1413 Event e = new Event ((string) $4, var.identifier, var.expression_or_array_initializer,
1414 (int) $2, null, null, (Attributes) $1, lexer.Location);
1416 CheckDef (current_container.AddEvent (e), e.Name);
1422 EVENT type member_name
1425 implicit_value_parameter_type = (string) $4;
1426 lexer.EventParsing = true;
1428 event_accessor_declarations
1430 lexer.EventParsing = false;
1434 Pair pair = (Pair) $8;
1435 Block add_block = null;
1436 Block rem_block = null;
1438 if (pair.First != null)
1439 add_block = (Block) pair.First;
1440 if (pair.Second != null)
1441 rem_block = (Block) pair.Second;
1443 Event e = new Event ((string) $4, (string) $5, null, (int) $2, add_block, rem_block,
1444 (Attributes) $1, lexer.Location);
1446 CheckDef (current_container.AddEvent (e), e.Name);
1447 implicit_value_parameter_type = null;
1451 event_accessor_declarations
1452 : add_accessor_declaration remove_accessor_declaration
1454 $$ = new Pair ($1, $2);
1456 | remove_accessor_declaration add_accessor_declaration
1458 $$ = new Pair ($2, $1);
1462 add_accessor_declaration
1463 : opt_attributes ADD
1465 Parameter [] args = new Parameter [1];
1466 Parameter implicit_value_parameter = new Parameter (
1467 implicit_value_parameter_type, "value",
1468 Parameter.Modifier.NONE, null);
1470 args [0] = implicit_value_parameter;
1472 current_local_parameters = new Parameters (args, null, lexer.Location);
1473 lexer.EventParsing = false;
1478 lexer.EventParsing = true;
1482 remove_accessor_declaration
1483 : opt_attributes REMOVE
1485 Parameter [] args = new Parameter [1];
1486 Parameter implicit_value_parameter = new Parameter (
1487 implicit_value_parameter_type, "value",
1488 Parameter.Modifier.NONE, null);
1490 args [0] = implicit_value_parameter;
1492 current_local_parameters = new Parameters (args, null, lexer.Location);
1493 lexer.EventParsing = false;
1498 lexer.EventParsing = true;
1503 : opt_attributes opt_modifiers indexer_declarator
1506 IndexerDeclaration decl = (IndexerDeclaration) $3;
1508 implicit_value_parameter_type = decl.type;
1510 lexer.PropertyParsing = true;
1511 parsing_indexer = true;
1513 indexer_parameters = decl.param_list;
1514 $$ = lexer.Location;
1516 accessor_declarations
1518 lexer.PropertyParsing = false;
1519 parsing_indexer = false;
1523 // The signature is computed from the signature of the indexer. Look
1524 // at section 3.6 on the spec
1527 IndexerDeclaration decl = (IndexerDeclaration) $3;
1528 Pair pair = (Pair) $6;
1529 Block get_block = null;
1530 Block set_block = null;
1532 if (pair.First != null)
1533 get_block = (Block) pair.First;
1534 if (pair.Second != null)
1535 set_block = (Block) pair.Second;
1537 indexer = new Indexer (decl.type, decl.interface_type, (int) $2, decl.param_list,
1538 get_block, set_block, (Attributes) $1, (Location) $5);
1540 // Note that there is no equivalent of CheckDef for this case
1541 // We shall handle this in semantic analysis
1543 current_container.AddIndexer (indexer);
1545 current_local_parameters = null;
1546 implicit_value_parameter_type = null;
1547 indexer_parameters = null;
1552 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1554 Parameters pars = (Parameters) $4;
1556 if (pars.FixedParameters == null){
1557 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1560 $$ = new IndexerDeclaration ((string) $1, null, pars);
1562 | type qualified_identifier DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
1564 Parameters pars = (Parameters) $6;
1566 if (pars.FixedParameters == null){
1567 Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
1569 $$ = new IndexerDeclaration ((string) $1, (string) $2, pars);
1581 string full_name = MakeName ((string) $4);
1582 Enum e = new Enum (current_container, (string) $5, (int) $2, full_name, (Attributes) $1, lexer.Location);
1584 foreach (VariableDeclaration ev in (ArrayList) $6){
1585 CheckDef (e.AddEnumMember (ev.identifier,
1586 (Expression) ev.expression_or_array_initializer,
1587 (Location) ev.Location),
1591 CheckDef (current_container.AddEnum (e), name);
1596 : /* empty */ { $$ = "System.Int32"; }
1597 | COLON type { $$ = $2; }
1601 : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
1607 opt_enum_member_declarations
1608 : /* empty */ { $$ = new ArrayList (); }
1609 | enum_member_declarations opt_comma { $$ = $1; }
1612 enum_member_declarations
1613 : enum_member_declaration
1615 ArrayList l = new ArrayList ();
1620 | enum_member_declarations COMMA enum_member_declaration
1622 ArrayList l = (ArrayList) $1;
1630 enum_member_declaration
1631 : opt_attributes IDENTIFIER
1633 $$ = new VariableDeclaration ((string) $2, null, lexer.Location);
1635 | opt_attributes IDENTIFIER
1637 $$ = lexer.Location;
1641 $$ = new VariableDeclaration ((string) $2, $5, lexer.Location);
1645 delegate_declaration
1649 IDENTIFIER OPEN_PARENS
1650 opt_formal_parameter_list
1654 Delegate del = new Delegate ((string) $4, (int) $2,
1655 MakeName ((string) $5), (Parameters) $7,
1656 (Attributes) $1, lexer.Location);
1658 CheckDef (current_container.AddDelegate (del), del.Name);
1663 IDENTIFIER OPEN_PARENS
1664 opt_formal_parameter_list
1668 Delegate del = new Delegate ("System.Void", (int) $2, (string) $5, (Parameters) $7,
1669 (Attributes) $1, lexer.Location);
1671 CheckDef (current_container.AddDelegate (del), del.Name);
1676 : namespace_or_type_name
1679 namespace_or_type_name
1680 : qualified_identifier
1684 * Before you think of adding a return_type, notice that we have been
1685 * using two rules in the places where it matters (one rule using type
1686 * and another identical one that uses VOID as the return type). This
1687 * gets rid of a shift/reduce couple
1690 : type_name { /* class_type */
1692 This does interfaces, delegates, struct_types, class_types,
1693 parent classes, and more! 4.2
1707 // Note that here only unmanaged types are allowed but we
1708 // can't perform checks during this phase - we do it during
1709 // semantic analysis.
1711 $$ = (string) $1 + "*";
1715 $$ = "System.Void*";
1722 $$ = new SimpleName ((string) $1, lexer.Location);
1724 | non_expression_type rank_specifier
1726 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1728 | non_expression_type STAR
1730 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1732 | expression rank_specifiers
1734 $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
1738 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
1745 ArrayList types = new ArrayList ();
1750 | type_list COMMA type
1752 ArrayList types = (ArrayList) $1;
1760 * replaces all the productions for isolating the various
1761 * simple types, but we need this to reuse it easily in local_variable_type
1764 : OBJECT { $$ = "System.Object"; }
1765 | STRING { $$ = "System.String"; }
1766 | BOOL { $$ = "System.Boolean"; }
1767 | DECIMAL { $$ = "System.Decimal"; }
1768 | FLOAT { $$ = "System.Single"; }
1769 | DOUBLE { $$ = "System.Double"; }
1774 : SBYTE { $$ = "System.SByte"; }
1775 | BYTE { $$ = "System.Byte"; }
1776 | SHORT { $$ = "System.Int16"; }
1777 | USHORT { $$ = "System.UInt16"; }
1778 | INT { $$ = "System.Int32"; }
1779 | UINT { $$ = "System.UInt32"; }
1780 | LONG { $$ = "System.Int64"; }
1781 | ULONG { $$ = "System.UInt64"; }
1782 | CHAR { $$ = "System.Char"; }
1790 : type rank_specifiers
1792 $$ = (string) $1 + (string) $2;
1797 // Expressions, section 7.5
1805 | qualified_identifier
1807 string name = (string) $1;
1810 $$ = DecomposeQI (name, lexer.Location);
1812 | parenthesized_expression
1814 | invocation_expression
1818 | post_increment_expression
1819 | post_decrement_expression
1823 | checked_expression
1824 | unchecked_expression
1831 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); }
1832 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); }
1833 | NULL { $$ = NullLiteral.Null; }
1837 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); }
1838 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); }
1839 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); }
1844 object v = lexer.Value;
1847 // FIXME: Possible optimization would be to
1848 // compute the *Literal objects directly in the scanner
1851 $$ = new IntLiteral ((Int32) v);
1853 $$ = new UIntLiteral ((UInt32) v);
1855 $$ = new LongLiteral ((Int64) v);
1856 else if (v is ulong)
1857 $$ = new ULongLiteral ((UInt64) v);
1859 Console.WriteLine ("OOPS. Unexpected result from scanner");
1864 : TRUE { $$ = new BoolLiteral (true); }
1865 | FALSE { $$ = new BoolLiteral (false); }
1868 parenthesized_expression
1869 : OPEN_PARENS expression CLOSE_PARENS
1874 : primary_expression DOT IDENTIFIER
1876 $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
1878 | predefined_type DOT IDENTIFIER
1880 $$ = new SimpleName ((string) $1 + "." + (string) $3, lexer.Location);
1888 invocation_expression
1889 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
1892 Location l = lexer.Location;
1893 Report.Error (1, l, "THIS IS CRAZY");
1895 $$ = new Invocation ((Expression) $1, (ArrayList) $3, lexer.Location);
1900 : /* empty */ { $$ = null; }
1907 ArrayList list = new ArrayList ();
1911 | argument_list COMMA argument
1913 ArrayList list = (ArrayList) $1;
1922 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
1924 | REF variable_reference
1926 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
1928 | OUT variable_reference
1930 $$ = new Argument ((Expression) $2, Argument.AType.Out);
1935 : expression { note ("section 5.4"); $$ = $1; }
1939 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
1941 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3, lexer.Location);
1943 | primary_expression rank_specifiers
1945 // So the super-trick is that primary_expression
1946 // can only be either a SimpleName or a MemberAccess.
1947 // The MemberAccess case arises when you have a fully qualified type-name like :
1949 // SimpleName is when you have
1952 Expression expr = (Expression) $1;
1953 if (!(expr is SimpleName || expr is MemberAccess)) {
1954 Location l = lexer.Location;
1955 Report.Error (-1, l, "Invalid Type definition");
1956 $$ = "System.Object";
1960 // So we extract the string corresponding to the SimpleName
1963 $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
1970 ArrayList list = new ArrayList ();
1974 | expression_list COMMA expression
1976 ArrayList list = (ArrayList) $1;
1985 $$ = new This (lexer.Location);
1990 : BASE DOT IDENTIFIER
1992 $$ = new BaseAccess ((string) $3, lexer.Location);
1994 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
1996 $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
2000 post_increment_expression
2001 : primary_expression OP_INC
2003 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
2004 (Expression) $1, lexer.Location);
2008 post_decrement_expression
2009 : primary_expression OP_DEC
2011 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
2012 (Expression) $1, lexer.Location);
2017 : object_or_delegate_creation_expression
2018 | array_creation_expression
2021 object_or_delegate_creation_expression
2022 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
2024 $$ = new New ((string) $2, (ArrayList) $4, lexer.Location);
2028 array_creation_expression
2029 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
2031 opt_array_initializer
2033 $$ = new ArrayCreation ((string) $2, (ArrayList) $4, (string) $6, (ArrayList) $7,
2036 | NEW type rank_specifiers array_initializer
2038 $$ = new ArrayCreation ((string) $2, (string) $3, (ArrayList) $4, lexer.Location);
2042 Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
2062 | rank_specifiers rank_specifier
2064 $$ = (string) $2 + (string) $1;
2069 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
2071 $$ = "[" + (string) $2 + "]";
2091 | dim_separators COMMA
2093 $$ = (string) $1 + ",";
2097 opt_array_initializer
2109 : OPEN_BRACE CLOSE_BRACE
2111 ArrayList list = new ArrayList ();
2114 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
2116 $$ = (ArrayList) $2;
2120 variable_initializer_list
2121 : variable_initializer
2123 ArrayList list = new ArrayList ();
2127 | variable_initializer_list COMMA variable_initializer
2129 ArrayList list = (ArrayList) $1;
2136 : TYPEOF OPEN_PARENS type CLOSE_PARENS
2138 $$ = new TypeOf ((string) $3, lexer.Location);
2143 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
2144 $$ = new SizeOf ((string) $3);
2146 note ("Verify type is unmanaged");
2147 note ("if (5.8) builtin, yield constant expression");
2152 : CHECKED OPEN_PARENS expression CLOSE_PARENS
2154 $$ = new CheckedExpr ((Expression) $3);
2158 unchecked_expression
2159 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
2161 $$ = new UnCheckedExpr ((Expression) $3);
2166 : primary_expression
2167 | BANG prefixed_unary_expression
2169 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, lexer.Location);
2171 | TILDE prefixed_unary_expression
2173 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, lexer.Location);
2175 | OPEN_PARENS expression CLOSE_PARENS unary_expression
2177 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2179 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
2181 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
2186 // The idea to split this out is from Rhys' grammar
2187 // to solve the problem with casts.
2189 prefixed_unary_expression
2191 | PLUS prefixed_unary_expression
2193 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, lexer.Location);
2195 | MINUS prefixed_unary_expression
2197 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, lexer.Location);
2199 | OP_INC prefixed_unary_expression
2201 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2202 (Expression) $2, lexer.Location);
2204 | OP_DEC prefixed_unary_expression
2206 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2207 (Expression) $2, lexer.Location);
2209 | STAR prefixed_unary_expression
2211 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, lexer.Location);
2213 | BITWISE_AND prefixed_unary_expression
2215 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, lexer.Location);
2219 pre_increment_expression
2220 : OP_INC prefixed_unary_expression
2222 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
2223 (Expression) $2, lexer.Location);
2227 pre_decrement_expression
2228 : OP_DEC prefixed_unary_expression
2230 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
2231 (Expression) $2, lexer.Location);
2235 multiplicative_expression
2236 : prefixed_unary_expression
2237 | multiplicative_expression STAR prefixed_unary_expression
2239 $$ = new Binary (Binary.Operator.Multiply,
2240 (Expression) $1, (Expression) $3, lexer.Location);
2242 | multiplicative_expression DIV prefixed_unary_expression
2244 $$ = new Binary (Binary.Operator.Division,
2245 (Expression) $1, (Expression) $3, lexer.Location);
2247 | multiplicative_expression PERCENT prefixed_unary_expression
2249 $$ = new Binary (Binary.Operator.Modulus,
2250 (Expression) $1, (Expression) $3, lexer.Location);
2255 : multiplicative_expression
2256 | additive_expression PLUS multiplicative_expression
2258 $$ = new Binary (Binary.Operator.Addition,
2259 (Expression) $1, (Expression) $3, lexer.Location);
2261 | additive_expression MINUS multiplicative_expression
2263 $$ = new Binary (Binary.Operator.Subtraction,
2264 (Expression) $1, (Expression) $3, lexer.Location);
2269 : additive_expression
2270 | shift_expression OP_SHIFT_LEFT additive_expression
2272 $$ = new Binary (Binary.Operator.LeftShift,
2273 (Expression) $1, (Expression) $3, lexer.Location);
2275 | shift_expression OP_SHIFT_RIGHT additive_expression
2277 $$ = new Binary (Binary.Operator.RightShift,
2278 (Expression) $1, (Expression) $3, lexer.Location);
2282 relational_expression
2284 | relational_expression OP_LT shift_expression
2286 $$ = new Binary (Binary.Operator.LessThan,
2287 (Expression) $1, (Expression) $3, lexer.Location);
2289 | relational_expression OP_GT shift_expression
2291 $$ = new Binary (Binary.Operator.GreaterThan,
2292 (Expression) $1, (Expression) $3, lexer.Location);
2294 | relational_expression OP_LE shift_expression
2296 $$ = new Binary (Binary.Operator.LessThanOrEqual,
2297 (Expression) $1, (Expression) $3, lexer.Location);
2299 | relational_expression OP_GE shift_expression
2301 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
2302 (Expression) $1, (Expression) $3, lexer.Location);
2304 | relational_expression IS type
2306 $$ = new Is ((Expression) $1, (string) $3, lexer.Location);
2308 | relational_expression AS type
2310 $$ = new As ((Expression) $1, (string) $3, lexer.Location);
2315 : relational_expression
2316 | equality_expression OP_EQ relational_expression
2318 $$ = new Binary (Binary.Operator.Equality,
2319 (Expression) $1, (Expression) $3, lexer.Location);
2321 | equality_expression OP_NE relational_expression
2323 $$ = new Binary (Binary.Operator.Inequality,
2324 (Expression) $1, (Expression) $3, lexer.Location);
2329 : equality_expression
2330 | and_expression BITWISE_AND equality_expression
2332 $$ = new Binary (Binary.Operator.BitwiseAnd,
2333 (Expression) $1, (Expression) $3, lexer.Location);
2337 exclusive_or_expression
2339 | exclusive_or_expression CARRET and_expression
2341 $$ = new Binary (Binary.Operator.ExclusiveOr,
2342 (Expression) $1, (Expression) $3, lexer.Location);
2346 inclusive_or_expression
2347 : exclusive_or_expression
2348 | inclusive_or_expression BITWISE_OR exclusive_or_expression
2350 $$ = new Binary (Binary.Operator.BitwiseOr,
2351 (Expression) $1, (Expression) $3, lexer.Location);
2355 conditional_and_expression
2356 : inclusive_or_expression
2357 | conditional_and_expression OP_AND inclusive_or_expression
2359 $$ = new Binary (Binary.Operator.LogicalAnd,
2360 (Expression) $1, (Expression) $3, lexer.Location);
2364 conditional_or_expression
2365 : conditional_and_expression
2366 | conditional_or_expression OP_OR conditional_and_expression
2368 $$ = new Binary (Binary.Operator.LogicalOr,
2369 (Expression) $1, (Expression) $3, lexer.Location);
2373 conditional_expression
2374 : conditional_or_expression
2375 | conditional_or_expression INTERR expression COLON expression
2377 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5, lexer.Location);
2381 assignment_expression
2382 : prefixed_unary_expression ASSIGN expression
2384 $$ = new Assign ((Expression) $1, (Expression) $3, lexer.Location);
2386 | prefixed_unary_expression OP_MULT_ASSIGN expression
2388 Location l = lexer.Location;
2390 $$ = new Assign ((Expression) $1,
2391 new Binary (Binary.Operator.Multiply,
2393 (Expression) $3, l), l);
2395 | prefixed_unary_expression OP_DIV_ASSIGN expression
2397 Location l = lexer.Location;
2399 $$ = new Assign ((Expression) $1,
2400 new Binary (Binary.Operator.Division,
2402 (Expression) $3, l), l);
2404 | prefixed_unary_expression OP_MOD_ASSIGN expression
2406 Location l = lexer.Location;
2408 $$ = new Assign ((Expression) $1,
2409 new Binary (Binary.Operator.Modulus,
2411 (Expression) $3, l), l);
2413 | prefixed_unary_expression OP_ADD_ASSIGN expression
2415 Location l = lexer.Location;
2417 $$ = new Assign ((Expression) $1,
2418 new Binary (Binary.Operator.Addition,
2420 (Expression) $3, l), l);
2422 | prefixed_unary_expression OP_SUB_ASSIGN expression
2424 Location l = lexer.Location;
2426 $$ = new Assign ((Expression) $1,
2427 new Binary (Binary.Operator.Subtraction,
2429 (Expression) $3, l), l);
2431 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
2433 Location l = lexer.Location;
2435 $$ = new Assign ((Expression) $1,
2436 new Binary (Binary.Operator.LeftShift,
2438 (Expression) $3, l), l);
2440 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
2442 Location l = lexer.Location;
2444 $$ = new Assign ((Expression) $1,
2445 new Binary (Binary.Operator.RightShift,
2447 (Expression) $3, l), l);
2449 | prefixed_unary_expression OP_AND_ASSIGN expression
2451 Location l = lexer.Location;
2453 $$ = new Assign ((Expression) $1,
2454 new Binary (Binary.Operator.BitwiseAnd,
2456 (Expression) $3, l), l);
2458 | prefixed_unary_expression OP_OR_ASSIGN expression
2460 Location l = lexer.Location;
2462 $$ = new Assign ((Expression) $1,
2463 new Binary (Binary.Operator.BitwiseOr,
2465 (Expression) $3, l), l);
2467 | prefixed_unary_expression OP_XOR_ASSIGN expression
2469 Location l = lexer.Location;
2471 $$ = new Assign ((Expression) $1,
2472 new Binary (Binary.Operator.ExclusiveOr,
2474 (Expression) $3, l), l);
2479 : conditional_expression
2480 | assignment_expression
2502 name = MakeName ((string) $4);
2504 new_class = new Class (current_container, name, (int) $2,
2505 (Attributes) $1, lexer.Location);
2506 current_container = new_class;
2507 current_container.Namespace = current_namespace;
2508 RootContext.Tree.RecordClass (name, new_class);
2514 Class new_class = (Class) current_container;
2517 new_class.Bases = (ArrayList) $6;
2519 current_container = current_container.Parent;
2520 CheckDef (current_container.AddClass (new_class), new_class.Name);
2527 : /* empty */ { $$ = (int) 0; }
2533 | modifiers modifier
2538 if ((m1 & m2) != 0) {
2539 Location l = lexer.Location;
2540 Report.Error (1004, l, "Duplicate modifier: `" + Modifiers.Name (m2) + "'");
2542 $$ = (int) (m1 | m2);
2547 : NEW { $$ = Modifiers.NEW; }
2548 | PUBLIC { $$ = Modifiers.PUBLIC; }
2549 | PROTECTED { $$ = Modifiers.PROTECTED; }
2550 | INTERNAL { $$ = Modifiers.INTERNAL; }
2551 | PRIVATE { $$ = Modifiers.PRIVATE; }
2552 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
2553 | SEALED { $$ = Modifiers.SEALED; }
2554 | STATIC { $$ = Modifiers.STATIC; }
2555 | READONLY { $$ = Modifiers.READONLY; }
2556 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
2557 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
2558 | EXTERN { $$ = Modifiers.EXTERN; }
2559 | VOLATILE { $$ = Modifiers.VOLATILE; }
2560 | UNSAFE { $$ = Modifiers.UNSAFE; }
2564 : /* empty */ { $$ = null; }
2565 | class_base { $$ = $1; }
2569 : COLON type_list { $$ = $2; }
2577 // A block is "contained" on the following places:
2579 // property_declaration as part of the accessor body (get/set)
2580 // operator_declaration
2581 // constructor_declaration
2582 // destructor_declaration
2583 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
2588 current_block = new Block (current_block);
2590 opt_statement_list CLOSE_BRACE
2592 while (current_block.Implicit)
2593 current_block = current_block.Parent;
2595 current_block = current_block.Parent;
2606 | statement_list statement
2610 : declaration_statement
2612 if ((Block) $1 != current_block){
2613 current_block.AddStatement ((Statement) $1);
2614 current_block = (Block) $1;
2617 | embedded_statement
2619 Statement s = (Statement) $1;
2622 current_block.AddStatement ((Statement) $1);
2630 | expression_statement
2631 | selection_statement
2632 | iteration_statement
2636 | unchecked_statement
2645 $$ = new EmptyStatement ();
2652 LabeledStatement labeled = new LabeledStatement ((string) $1);
2654 if (!current_block.AddLabel ((string) $1, labeled)){
2655 Location l = lexer.Location;
2656 Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
2658 current_block.AddStatement (labeled);
2663 declaration_statement
2664 : local_variable_declaration SEMICOLON
2666 DictionaryEntry de = (DictionaryEntry) $1;
2668 $$ = declare_local_variables ((string) de.Key, (ArrayList) de.Value, lexer.Location);
2671 | local_constant_declaration SEMICOLON
2673 DictionaryEntry de = (DictionaryEntry) $1;
2675 $$ = declare_local_constant ((string) de.Key, (VariableDeclaration) de.Value);
2680 * The following is from Rhys' grammar:
2681 * > Types in local variable declarations must be recognized as
2682 * > expressions to prevent reduce/reduce errors in the grammar.
2683 * > The expressions are converted into types during semantic analysis.
2686 : primary_expression opt_rank_specifier
2688 // FIXME: Do something smart here regarding the composition of the type.
2690 // Ok, the above "primary_expression" is there to get rid of
2691 // both reduce/reduce and shift/reduces in the grammar, it should
2692 // really just be "type_name". If you use type_name, a reduce/reduce
2693 // creeps up. If you use qualified_identifier (which is all we need
2694 // really) two shift/reduces appear.
2697 // So the super-trick is that primary_expression
2698 // can only be either a SimpleName or a MemberAccess.
2699 // The MemberAccess case arises when you have a fully qualified type-name like :
2701 // SimpleName is when you have
2704 Expression expr = (Expression) $1;
2705 if (!(expr is SimpleName || expr is MemberAccess)) {
2706 Location l = lexer.Location;
2707 Report.Error (-1, l, "Invalid Type definition");
2708 $$ = "System.Object";
2712 // So we extract the string corresponding to the SimpleName
2715 $$ = GetQualifiedIdentifier (expr) + (string) $2;
2717 | builtin_types opt_rank_specifier
2719 $$ = (string) $1 + (string) $2;
2723 local_variable_pointer_type
2724 : primary_expression STAR
2726 Expression expr = (Expression) $1;
2727 if (!(expr is SimpleName || expr is MemberAccess)) {
2728 Location l = lexer.Location;
2729 Report.Error (-1, l, "Invalid Type definition");
2730 $$ = "System.Object";
2733 $$ = GetQualifiedIdentifier (expr) + "*";
2735 | builtin_types STAR
2737 $$ = (string) $1 + "*";
2741 $$ = "System.Void*";
2743 | local_variable_pointer_type STAR
2745 $$ = (string) $1 + "*";
2749 local_variable_declaration
2750 : local_variable_type variable_declarators
2752 $$ = new DictionaryEntry ($1, $2);
2754 | local_variable_pointer_type opt_rank_specifier variable_declarators
2756 $$ = new DictionaryEntry ((string) $1 + (string) $2, $3);
2760 local_constant_declaration
2761 : CONST local_variable_type constant_declarator
2763 $$ = new DictionaryEntry ($2, $3);
2767 expression_statement
2768 : statement_expression SEMICOLON
2775 // We have to do the wrapping here and not in the case above,
2776 // because statement_expression is used for example in for_statement
2778 statement_expression
2779 : invocation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2780 | object_creation_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2781 | assignment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2782 | post_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2783 | post_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2784 | pre_increment_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2785 | pre_decrement_expression { $$ = new StatementExpression ((ExpressionStatement) $1); }
2787 Report.Error (1002, lexer.Location, "Expecting `;'");
2791 object_creation_expression
2792 : object_or_delegate_creation_expression
2793 { note ("complain if this is a delegate maybe?"); }
2802 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
2805 $$ = new If ((Expression) $3, (Statement) $5);
2807 if (RootContext.WarningLevel >= 3){
2808 if ($5 is EmptyStatement)
2809 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
2813 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
2814 embedded_statement ELSE embedded_statement
2816 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7);
2821 : SWITCH OPEN_PARENS
2823 oob_stack.Push (lexer.Location);
2825 expression CLOSE_PARENS
2828 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
2844 Report.Error (1522, lexer.Location, "Empty switch block");
2852 ArrayList sections = new ArrayList ();
2857 | switch_sections switch_section
2859 ArrayList sections = (ArrayList) $1;
2869 current_block = new Block (current_block);
2873 while (current_block.Implicit)
2874 current_block = current_block.Parent;
2875 $$ = new SwitchSection ((ArrayList) $1, current_block);
2876 current_block = current_block.Parent;
2883 ArrayList labels = new ArrayList ();
2888 | switch_labels switch_label
2890 ArrayList labels = (ArrayList) ($1);
2898 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
2899 | DEFAULT COLON { $$ = new SwitchLabel (null, lexer.Location); }
2902 1523, lexer.Location,
2903 "The keyword case or default must precede code in switch block");
2915 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
2917 $$ = new While ((Expression) $3, (Statement) $5);
2919 if (RootContext.WarningLevel >= 3){
2920 if ($5 is EmptyStatement)
2921 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
2927 : DO embedded_statement
2928 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
2930 $$ = new Do ((Statement) $2, (Expression) $5);
2936 opt_for_initializer SEMICOLON
2938 Block assign_block = new Block (current_block);
2939 current_block = assign_block;
2941 if ($3 is DictionaryEntry){
2942 DictionaryEntry de = (DictionaryEntry) $3;
2944 string type = (string) de.Key;
2945 ArrayList var_declarators = (ArrayList) de.Value;
2947 foreach (VariableDeclaration decl in var_declarators){
2949 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
2951 Report.Error (128, decl.Location,
2952 "A local variable `" + decl.identifier + "' is already" +
2953 "defined in this scope");
2956 Location l = lexer.Location;
2958 if (decl.expression_or_array_initializer is Expression){
2959 expr = (Expression) decl.expression_or_array_initializer;
2963 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
2965 string base_type = type.Substring (0, type.IndexOf ("["));
2966 string rank = type.Substring (type.IndexOf ("["));
2968 expr = new ArrayCreation (base_type, rank, init, decl.Location);
2971 LocalVariableReference var;
2972 var = new LocalVariableReference (
2973 assign_block, decl.identifier, l);
2975 Assign a = new Assign (var, expr, decl.Location);
2977 assign_block.AddStatement (new StatementExpression (a));
2984 opt_for_condition SEMICOLON
2985 opt_for_iterator CLOSE_PARENS
2988 For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10);
2990 if (RootContext.WarningLevel >= 3){
2991 if ($10 is EmptyStatement)
2992 Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
2995 current_block.AddStatement (f);
2996 while (current_block.Implicit)
2997 current_block = current_block.Parent;
2999 current_block = current_block.Parent;
3004 : /* empty */ { $$ = new EmptyStatement (); }
3009 : local_variable_declaration
3010 | statement_expression_list
3014 : /* empty */ { $$ = null; }
3015 | boolean_expression
3019 : /* empty */ { $$ = new EmptyStatement (); }
3024 : statement_expression_list
3027 statement_expression_list
3028 : statement_expression
3030 Block b = new Block (null, true);
3032 b.AddStatement ((Statement) $1);
3035 | statement_expression_list COMMA statement_expression
3037 Block b = (Block) $1;
3039 b.AddStatement ((Statement) $3);
3045 : FOREACH OPEN_PARENS type IDENTIFIER IN
3047 oob_stack.Push (lexer.Location);
3049 expression CLOSE_PARENS
3051 Block foreach_block = new Block (current_block, true);
3052 LocalVariableReference v;
3053 Location l = lexer.Location;
3055 foreach_block.AddVariable ((string) $3, (string) $4, current_local_parameters, l);
3056 v = new LocalVariableReference (foreach_block, (string) $4, l);
3058 current_block.AddStatement (foreach_block);
3059 current_block = foreach_block;
3061 oob_stack.Push (foreach_block);
3066 LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
3067 Block foreach_block = (Block) oob_stack.Pop ();
3068 Location l = (Location) oob_stack.Pop ();
3070 $$ = new Foreach ((string) $3, v, (Expression) $7, (Statement) $10, l);
3076 | continue_statement
3085 $$ = new Break (lexer.Location);
3090 : CONTINUE SEMICOLON
3092 $$ = new Continue (lexer.Location);
3097 : GOTO IDENTIFIER SEMICOLON
3099 $$ = new Goto (current_block, (string) $2, lexer.Location);
3101 | GOTO CASE constant_expression SEMICOLON
3103 $$ = new GotoCase ((Expression) $3, lexer.Location);
3105 | GOTO DEFAULT SEMICOLON
3107 $$ = new GotoDefault (lexer.Location);
3112 : RETURN opt_expression SEMICOLON
3114 $$ = new Return ((Expression) $2, lexer.Location);
3119 : THROW opt_expression SEMICOLON
3121 $$ = new Throw ((Expression) $2, lexer.Location);
3131 : TRY block catch_clauses
3134 ArrayList s = new ArrayList ();
3136 foreach (Catch cc in (ArrayList) $3) {
3137 if (cc.Type == null)
3143 // Now s contains the list of specific catch clauses
3144 // and g contains the general one.
3146 $$ = new Try ((Block) $2, s, g, null);
3148 | TRY block opt_catch_clauses FINALLY block
3151 ArrayList s = new ArrayList ();
3153 foreach (Catch cc in (ArrayList) $3) {
3154 if (cc.Type == null)
3160 $$ = new Try ((Block) $2, s, g, (Block) $5);
3164 Report.Error (1524, lexer.Location, "Expected catch or finally");
3169 : /* empty */ { $$ = null; }
3176 ArrayList l = new ArrayList ();
3181 | catch_clauses catch_clause
3183 ArrayList l = (ArrayList) $1;
3191 : /* empty */ { $$ = null; }
3196 : CATCH opt_catch_args
3198 string type = null, id = null;
3201 DictionaryEntry cc = (DictionaryEntry) $2;
3202 type = (string) cc.Key;
3203 id = (string) cc.Value;
3206 ArrayList one = new ArrayList ();
3207 Location loc = lexer.Location;
3209 one.Add (new VariableDeclaration (id, null, loc));
3212 current_block = new Block (current_block);
3213 Block b = declare_local_variables (type, one, loc);
3220 string type = null, id = null;
3223 DictionaryEntry cc = (DictionaryEntry) $2;
3224 type = (string) cc.Key;
3225 id = (string) cc.Value;
3228 while (current_block != (Block) $1)
3229 current_block = current_block.Parent;
3234 $$ = new Catch (type, id , (Block) $4, lexer.Location);
3239 : /* empty */ { $$ = null; }
3244 : OPEN_PARENS type opt_identifier CLOSE_PARENS
3246 $$ = new DictionaryEntry ($2, $3);
3253 $$ = new Checked ((Block) $2);
3260 $$ = new Unchecked ((Block) $2);
3267 if (!RootContext.Unsafe){
3268 Report.Error (227, lexer.Location,
3269 "Unsafe code can only be used if --unsafe is used");
3272 $$ = new Unsafe ((Block) $3);
3277 : LOCK OPEN_PARENS expression CLOSE_PARENS
3283 $$ = new Lock ((Expression) $3, (Statement) $6, lexer.Location);
3288 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
3290 Block assign_block = new Block (current_block);
3291 current_block = assign_block;
3293 oob_stack.Push (lexer.Location);
3295 if ($3 is DictionaryEntry){
3296 DictionaryEntry de = (DictionaryEntry) $3;
3297 Location l = lexer.Location;
3299 string type = (string) de.Key;
3300 ArrayList var_declarators = (ArrayList) de.Value;
3302 foreach (VariableDeclaration decl in var_declarators){
3303 if (!current_block.AddVariable (type, decl.identifier, current_local_parameters,
3305 Report.Error (128, decl.Location,
3306 "A local variable `" + decl.identifier + "' is already" +
3307 "defined in this scope");
3311 ArrayList vars = new ArrayList ();
3313 foreach (VariableDeclaration decl in var_declarators){
3316 if (decl.expression_or_array_initializer is Expression){
3317 expr = (Expression) decl.expression_or_array_initializer;
3321 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3323 string base_type = type.Substring (0, type.IndexOf ("["));
3324 string rank = type.Substring (type.IndexOf ("["));
3326 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3329 LocalVariableReference var;
3332 var = new LocalVariableReference (assign_block, decl.identifier, l);
3333 vi = var.VariableInfo;
3336 // This is so that it is not a warning on using variables
3339 vars.Add (new DictionaryEntry (var, expr));
3341 // Assign a = new Assign (var, expr, decl.Location);
3342 // assign_block.AddStatement (new StatementExpression (a));
3344 $3 = new DictionaryEntry (type, vars);
3349 Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
3350 current_block.AddStatement (u);
3351 while (current_block.Implicit)
3352 current_block = current_block.Parent;
3354 current_block = current_block.Parent;
3358 resource_acquisition
3359 : local_variable_declaration
3366 // A class used to pass around variable declarations and constants
3368 public class VariableDeclaration {
3369 public string identifier;
3370 public object expression_or_array_initializer;
3371 public Location Location;
3373 public VariableDeclaration (string id, object eoai, Location l){
3374 this.identifier = id;
3375 this.expression_or_array_initializer = eoai;
3381 // A class used to hold info about an indexer declarator
3384 public class IndexerDeclaration {
3386 public string interface_type;
3387 public Parameters param_list;
3389 public IndexerDeclaration (string type, string interface_type, Parameters param_list)
3392 this.interface_type = interface_type;
3393 this.param_list = param_list;
3398 // A class used to hold info about an operator declarator
3401 public class OperatorDeclaration {
3402 public Operator.OpType optype;
3403 public string ret_type;
3404 public string arg1type;
3405 public string arg1name;
3406 public string arg2type;
3407 public string arg2name;
3408 public Location location;
3410 public OperatorDeclaration (Operator.OpType op, string ret_type, string arg1type, string arg1name,
3411 string arg2type, string arg2name, Location location)
3414 this.ret_type = ret_type;
3415 this.arg1type = arg1type;
3416 this.arg1name = arg1name;
3417 this.arg2type = arg2type;
3418 this.arg2name = arg2name;
3419 this.location = location;
3425 // Given the @class_name name, it creates a fully qualified name
3426 // based on the containing declaration space
3429 MakeName (string class_name)
3431 string ns = current_namespace.Name;
3432 string container_name = current_container.Name;
3434 if (container_name == ""){
3436 return ns + "." + class_name;
3440 return container_name + "." + class_name;
3444 // Used to report back to the user the result of a declaration
3445 // in the current declaration space
3448 CheckDef (AdditionResult result, string name)
3450 if (result == AdditionResult.Success)
3453 Location l = lexer.Location;
3456 case AdditionResult.NameExists:
3457 Report.Error (102, l, "The namespace `" + current_container.Name +
3458 "' already contains a definition for `"+
3464 // This is handled only for static Constructors, because
3465 // in reality we handle these by the semantic analysis later
3467 case AdditionResult.MethodExists:
3469 111, l, "Class `"+current_container.Name+
3470 "' already defines a member called '" +
3471 name + "' with the same parameter types (more than one default constructor)");
3474 case AdditionResult.EnclosingClash:
3475 Report.Error (542, l, "Member names cannot be the same as their enclosing type");
3478 case AdditionResult.NotAConstructor:
3479 Report.Error (1520, l, "Class, struct, or interface method must have a return type");
3485 CheckDef (bool result, string name)
3489 CheckDef (AdditionResult.NameExists, name);
3493 SimpleLookup (string name, Location loc)
3496 // we need to check against current_block not being null
3497 // as `expression' is allowed in argument_lists, which
3498 // do not exist inside a block.
3500 if (current_block != null){
3501 if (current_block.IsVariableDefined (name))
3502 return new LocalVariableReference (current_block, name, loc);
3505 if (current_local_parameters != null){
3507 Parameter par = current_local_parameters.GetParameterByName (name, out idx);
3509 return new ParameterReference (current_local_parameters, idx, name);
3515 Expression DecomposeQI (string name, Location loc)
3519 if (name.IndexOf ('.') == -1){
3520 o = SimpleLookup (name, loc);
3522 return new SimpleName (name, loc);
3525 int pos = name.LastIndexOf (".");
3526 string left = name.Substring (0, pos);
3527 string right = name.Substring (pos + 1);
3529 o = DecomposeQI (left, loc);
3530 return new MemberAccess (o, right, loc);
3535 // This method is used to get at the complete string representation of
3536 // a fully-qualified type name, hiding inside a MemberAccess ;-)
3537 // This is necessary because local_variable_type admits primary_expression
3538 // as the type of the variable. So we do some extra checking
3540 string GetQualifiedIdentifier (Expression expr)
3542 if (expr is SimpleName)
3543 return ((SimpleName)expr).Name;
3544 else if (expr is MemberAccess)
3545 return GetQualifiedIdentifier (((MemberAccess)expr).Expr) + "." + ((MemberAccess) expr).Identifier;
3547 throw new Exception ("Expr has to be either SimpleName or MemberAccess! (" + expr + ")");
3551 Block declare_local_variables (string type, ArrayList variable_declarators, Location loc)
3553 Block implicit_block;
3554 ArrayList inits = null;
3557 // We use the `Used' property to check whether statements
3558 // have been added to the current block. If so, we need
3559 // to create another block to contain the new declaration
3560 // otherwise, as an optimization, we use the same block to
3561 // add the declaration.
3563 // FIXME: A further optimization is to check if the statements
3564 // that were added were added as part of the initialization
3565 // below. In which case, no other statements have been executed
3566 // and we might be able to reduce the number of blocks for
3567 // situations like this:
3569 // int j = 1; int k = j + 1;
3571 if (current_block.Used)
3572 implicit_block = new Block (current_block, true);
3574 implicit_block = current_block;
3576 foreach (VariableDeclaration decl in variable_declarators){
3578 if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location)) {
3579 if (decl.expression_or_array_initializer != null){
3581 inits = new ArrayList ();
3585 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3586 "' is already defined in this scope");
3591 return implicit_block;
3593 foreach (VariableDeclaration decl in inits){
3597 if (decl.expression_or_array_initializer is Expression){
3598 expr = (Expression) decl.expression_or_array_initializer;
3601 ArrayList init = (ArrayList) decl.expression_or_array_initializer;
3603 string base_type = type.Substring (0, type.IndexOf ("["));
3604 string rank = type.Substring (type.IndexOf ("["));
3606 expr = new ArrayCreation (base_type, rank, init, decl.Location);
3610 LocalVariableReference var;
3611 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
3613 assign = new Assign (var, expr, decl.Location);
3615 implicit_block.AddStatement (new StatementExpression (assign));
3618 return implicit_block;
3621 Block declare_local_constant (string type, VariableDeclaration decl)
3623 Block implicit_block;
3625 if (current_block.Used)
3626 implicit_block = new Block (current_block, true);
3628 implicit_block = current_block;
3630 if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
3631 current_local_parameters, decl.Location))){
3632 Report.Error (128, decl.Location, "A local variable `" + decl.identifier +
3633 "' is already defined in this scope");
3636 return implicit_block;
3639 void CheckAttributeTarget (string a)
3643 case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
3647 Location l = lexer.Location;
3648 Report.Error (658, l, "Invalid attribute target");
3654 void CheckUnaryOperator (Operator.OpType op)
3658 case Operator.OpType.LogicalNot:
3659 case Operator.OpType.OnesComplement:
3660 case Operator.OpType.Increment:
3661 case Operator.OpType.Decrement:
3662 case Operator.OpType.True:
3663 case Operator.OpType.False:
3664 case Operator.OpType.Addition:
3665 case Operator.OpType.Subtraction:
3670 Location l = lexer.Location;
3671 Report.Error (1019, l, "Overloadable unary operator expected");
3677 void CheckBinaryOperator (Operator.OpType op)
3681 case Operator.OpType.Addition:
3682 case Operator.OpType.Subtraction:
3683 case Operator.OpType.Multiply:
3684 case Operator.OpType.Division:
3685 case Operator.OpType.Modulus:
3686 case Operator.OpType.BitwiseAnd:
3687 case Operator.OpType.BitwiseOr:
3688 case Operator.OpType.ExclusiveOr:
3689 case Operator.OpType.LeftShift:
3690 case Operator.OpType.RightShift:
3691 case Operator.OpType.Equality:
3692 case Operator.OpType.Inequality:
3693 case Operator.OpType.GreaterThan:
3694 case Operator.OpType.LessThan:
3695 case Operator.OpType.GreaterThanOrEqual:
3696 case Operator.OpType.LessThanOrEqual:
3700 Location l = lexer.Location;
3701 Report.Error (1020, l, "Overloadable binary operator expected");
3707 void syntax_error (Location l, string msg)
3709 Report.Error (1003, l, "Syntax error, " + msg);
3712 void output (string s)
3714 Console.WriteLine (s);
3717 void note (string s)
3719 // Used to put annotations
3724 public Tokenizer Lexer {
3730 public CSharpParser (string name, System.IO.Stream input, ArrayList defines)
3732 current_namespace = new Namespace (null, "");
3735 current_container = RootContext.Tree.Types;
3736 current_container.Namespace = current_namespace;
3737 oob_stack = new Stack ();
3739 lexer = new Tokenizer (input, name, defines);
3742 public override int parse ()
3744 StringBuilder value = new StringBuilder ();
3748 if (yacc_verbose_flag)
3749 yyparse (lexer, new yydebug.yyDebugSimple ());
3752 } catch (Exception e){
3753 // Console.WriteLine ("Fatal error: " + name);
3754 // Console.WriteLine (lexer.location);
3757 // Please do not remove this, it is used during debugging
3760 Console.WriteLine (lexer.location + " : Parsing error ");
3761 Console.WriteLine (e);
3765 return global_errors;