3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnu.org)
6 // Ravi Pratap (ravi@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // Licensed under the terms of the GNU GPL
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004 Novell, Inc
15 // (1) Figure out why error productions dont work. `type-declaration' is a
16 // great spot to put an `error' because you can reproduce it with this input:
19 // Possible optimization:
20 // Run memory profiler with parsing only, and consider dropping
21 // arraylists where not needed. Some pieces can use linked lists.
29 using System.Collections;
34 public class CSharpParser {
35 NamespaceEntry current_namespace;
36 TypeContainer current_container;
37 DeclSpace current_class;
39 IAnonymousHost anonymous_host;
42 /// Current block is used to add statements as we find
47 Delegate current_delegate;
49 GenericMethod current_generic_method;
50 AnonymousMethodExpression current_anonymous_method;
53 /// This is used by the unary_expression code to resolve
54 /// a name against a parameter.
56 Parameters current_local_parameters;
59 /// Using during property parsing to describe the implicit
60 /// value parameter that is passed to the "set" and "get"accesor
61 /// methods (properties and indexers).
63 Expression implicit_value_parameter_type;
64 Parameters indexer_parameters;
67 /// Hack to help create non-typed array initializer
69 public static Expression current_array_type;
70 Expression pushed_current_array_type;
73 /// Used to determine if we are parsing the get/set pair
74 /// of an indexer or a property
78 bool parsing_anonymous_method;
81 /// An out-of-band stack.
83 static Stack oob_stack;
90 static public int yacc_verbose_flag;
92 // Name of the file we are parsing
101 /// Temporary Xml documentation cache.
102 /// For enum types, we need one more temporary store.
105 string enumTypeComment;
107 /// Current attribute target
108 string current_attr_target;
110 /// assembly and module attribute definitions are enabled
111 bool global_attrs_enabled = true;
112 bool has_get, has_set;
117 %token NONE /* This token is never returned by our lexer */
118 %token ERROR // This is used not by the parser, but by the tokenizer.
122 *These are the C# keywords
209 %token QUERY_FIRST_TOKEN
222 %token QUERY_LAST_TOKEN
224 /* C# keywords which are not really keywords */
231 /* C# single character operators/punctuation. */
232 %token OPEN_BRACE "{"
233 %token CLOSE_BRACE "}"
234 %token OPEN_BRACKET "["
235 %token CLOSE_BRACKET "]"
236 %token OPEN_PARENS "("
237 %token CLOSE_PARENS ")"
249 %token OP_GENERICS_LT "<"
251 %token OP_GENERICS_GT ">"
252 %token BITWISE_AND "&"
253 %token BITWISE_OR "|"
260 /* C# multi-character operators. */
261 %token DOUBLE_COLON "::"
264 %token OP_SHIFT_LEFT "<<"
265 %token OP_SHIFT_RIGHT ">>"
272 %token OP_MULT_ASSIGN "*="
273 %token OP_DIV_ASSIGN "/="
274 %token OP_MOD_ASSIGN "%="
275 %token OP_ADD_ASSIGN "+="
276 %token OP_SUB_ASSIGN "-="
277 %token OP_SHIFT_LEFT_ASSIGN "<<="
278 %token OP_SHIFT_RIGHT_ASSIGN ">>="
279 %token OP_AND_ASSIGN "&="
280 %token OP_XOR_ASSIGN "^="
281 %token OP_OR_ASSIGN "|="
283 %token OP_COALESCING "??"
286 %token LITERAL_INTEGER "int literal"
287 %token LITERAL_FLOAT "float literal"
288 %token LITERAL_DOUBLE "double literal"
289 %token LITERAL_DECIMAL "decimal literal"
290 %token LITERAL_CHARACTER "character literal"
291 %token LITERAL_STRING "string literal"
294 %token OPEN_PARENS_LAMBDA
295 %token CLOSE_PARENS_CAST
296 %token CLOSE_PARENS_NO_CAST
297 %token CLOSE_PARENS_OPEN_PARENS
298 %token CLOSE_PARENS_MINUS
299 %token DEFAULT_OPEN_PARENS
300 %token GENERIC_DIMENSION
303 /* Add precedence rules to solve dangling else s/r conflict */
312 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
314 %left STAR DIV PERCENT
315 %right BANG CARRET UMINUS
316 %nonassoc OP_INC OP_DEC
318 %left OPEN_BRACKET OPEN_BRACE
322 %start compilation_unit
326 : outer_declarations opt_EOF
327 | outer_declarations global_attributes opt_EOF
328 | global_attributes opt_EOF
329 | opt_EOF /* allow empty files */
335 Lexer.check_incorrect_doc_comment ();
339 Lexer.check_incorrect_doc_comment ();
345 | outer_declarations outer_declaration
349 : extern_alias_directive
351 | namespace_member_declaration
354 extern_alias_directives
355 : extern_alias_directive
356 | extern_alias_directives extern_alias_directive;
358 extern_alias_directive
359 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
361 LocatedToken lt = (LocatedToken) $2;
364 Report.Error (1003, lt.Location, "'alias' expected");
365 } else if (RootContext.Version == LanguageVersion.ISO_1) {
366 Report.FeatureIsNotISO1 (lt.Location, "external alias");
368 lt = (LocatedToken) $3;
369 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
376 | using_directives using_directive
380 : using_alias_directive
382 if (RootContext.Documentation != null)
383 Lexer.doc_state = XmlCommentState.Allowed;
385 | using_namespace_directive
387 if (RootContext.Documentation != null)
388 Lexer.doc_state = XmlCommentState.Allowed;
392 using_alias_directive
393 : USING IDENTIFIER ASSIGN
394 namespace_or_type_name SEMICOLON
396 LocatedToken lt = (LocatedToken) $2;
397 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
400 CheckIdentifierToken (yyToken, GetLocation ($2));
404 using_namespace_directive
405 : USING namespace_name SEMICOLON
407 current_namespace.Using ((MemberName) $2, (Location) $1);
412 // Strictly speaking, namespaces don't have attributes but
413 // we parse global attributes along with namespace declarations and then
416 namespace_declaration
417 : opt_attributes NAMESPACE namespace_or_type_name
419 MemberName name = (MemberName) $3;
422 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
425 if (name.TypeArguments != null)
426 syntax_error (lexer.Location, "namespace name expected");
428 current_namespace = new NamespaceEntry (
429 current_namespace, file, name.GetName ());
430 current_class = current_namespace.SlaveDeclSpace;
431 current_container = current_class.PartialContainer;
433 namespace_body opt_semicolon
435 current_namespace = current_namespace.Parent;
436 current_class = current_namespace.SlaveDeclSpace;
437 current_container = current_class.PartialContainer;
452 : namespace_or_type_name {
453 MemberName name = (MemberName) $1;
455 if (name.TypeArguments != null)
456 syntax_error (lexer.Location, "namespace name expected");
465 if (RootContext.Documentation != null)
466 Lexer.doc_state = XmlCommentState.Allowed;
472 : opt_extern_alias_directives
474 opt_namespace_member_declarations
478 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
481 | opt_extern_alias_directives
483 opt_namespace_member_declarations
486 Report.Error (1513, lexer.Location, "} expected");
495 opt_extern_alias_directives
497 | extern_alias_directives
500 opt_namespace_member_declarations
502 | namespace_member_declarations
505 namespace_member_declarations
506 : namespace_member_declaration
507 | namespace_member_declarations namespace_member_declaration
510 namespace_member_declaration
514 DeclSpace ds = (DeclSpace)$1;
516 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
517 Report.Error (1527, ds.Location,
518 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
521 current_namespace.DeclarationFound = true;
523 | namespace_declaration {
524 current_namespace.DeclarationFound = true;
527 | field_declaration {
528 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
530 | method_declaration {
531 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
538 | interface_declaration
540 | delegate_declaration
542 // Enable this when we have handled all errors, because this acts as a generic fallback
545 // Console.WriteLine ("Token=" + yyToken);
546 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
558 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
566 global_attrs_enabled = false;
571 global_attrs_enabled = false;
580 if (current_attr_target != String.Empty) {
581 ArrayList sect = (ArrayList) $1;
583 if (global_attrs_enabled) {
584 if (current_attr_target == "module") {
585 CodeGen.Module.AddAttributes (sect);
587 } else if (current_attr_target != null && current_attr_target.Length > 0) {
588 CodeGen.Assembly.AddAttributes (sect);
591 $$ = new Attributes (sect);
594 if (RootContext.Documentation != null) {
595 Lexer.check_incorrect_doc_comment ();
597 XmlCommentState.Allowed;
601 $$ = new Attributes (sect);
606 current_attr_target = null;
608 | attribute_sections attribute_section
610 if (current_attr_target != String.Empty) {
611 Attributes attrs = $1 as Attributes;
612 ArrayList sect = (ArrayList) $2;
614 if (global_attrs_enabled) {
615 if (current_attr_target == "module") {
616 CodeGen.Module.AddAttributes (sect);
618 } else if (current_attr_target == "assembly") {
619 CodeGen.Assembly.AddAttributes (sect);
623 attrs = new Attributes (sect);
625 attrs.AddAttributes (sect);
629 attrs = new Attributes (sect);
631 attrs.AddAttributes (sect);
637 current_attr_target = null;
642 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
646 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
652 attribute_target_specifier
653 : attribute_target COLON
655 current_attr_target = (string)$1;
663 LocatedToken lt = (LocatedToken) $1;
664 $$ = CheckAttributeTarget (lt.Value, lt.Location);
666 | EVENT { $$ = "event"; }
667 | RETURN { $$ = "return"; }
670 string name = yyNames [yyToken].ToLower ();
671 $$ = CheckAttributeTarget (name, GetLocation ($1));
678 ArrayList attrs = new ArrayList (4);
684 | attribute_list COMMA attribute
686 ArrayList attrs = (ArrayList) $1;
694 : attribute_name opt_attribute_arguments
696 MemberName mname = (MemberName) $1;
697 if (mname.IsGeneric) {
698 Report.Error (404, lexer.Location,
699 "'<' unexpected: attributes cannot be generic");
702 object [] arguments = (object []) $2;
703 MemberName left = mname.Left;
704 string identifier = mname.Name;
706 Expression left_expr = left == null ? null : left.GetTypeExpression ();
708 if (current_attr_target == String.Empty)
710 else if (current_attr_target == "assembly" || current_attr_target == "module")
711 // FIXME: supply "nameEscaped" parameter here.
712 $$ = new GlobalAttribute (current_namespace, current_attr_target,
713 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
715 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
720 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
723 opt_attribute_arguments
724 : /* empty */ { $$ = null; }
725 | OPEN_PARENS attribute_arguments CLOSE_PARENS
733 : opt_positional_argument_list
738 $$ = new object [] { $1, null };
741 | positional_argument_list COMMA named_argument_list
743 $$ = new object[] { $1, $3 };
745 | named_argument_list
747 $$ = new object [] { null, $1 };
752 opt_positional_argument_list
753 : /* empty */ { $$ = null; }
754 | positional_argument_list
757 positional_argument_list
760 ArrayList args = new ArrayList (4);
761 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
765 | positional_argument_list COMMA expression
767 ArrayList args = (ArrayList) $1;
768 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
777 ArrayList args = new ArrayList (4);
782 | named_argument_list COMMA named_argument
784 ArrayList args = (ArrayList) $1;
789 | named_argument_list COMMA expression
791 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
797 : IDENTIFIER ASSIGN expression
799 // FIXME: keep location
800 $$ = new DictionaryEntry (
801 ((LocatedToken) $1).Value,
802 new Argument ((Expression) $3, Argument.AType.Expression));
808 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
811 opt_class_member_declarations
813 | class_member_declarations
816 class_member_declarations
817 : class_member_declaration
818 | class_member_declarations
819 class_member_declaration
822 class_member_declaration
823 : constant_declaration // done
824 | field_declaration // done
825 | method_declaration // done
826 | property_declaration // done
827 | event_declaration // done
828 | indexer_declaration // done
829 | operator_declaration // done
830 | constructor_declaration // done
831 | destructor_declaration // done
841 lexer.ConstraintsParsing = true;
845 MemberName name = MakeName ((MemberName) $6);
846 push_current_class (new Struct (
847 current_namespace, current_class, name, (int) $2,
848 (Attributes) $1), $3);
851 opt_type_parameter_constraints_clauses
853 lexer.ConstraintsParsing = false;
856 current_container.AddBasesForPart (current_class, (ArrayList) $8);
858 current_class.SetParameterInfo ((ArrayList) $9);
860 if (RootContext.Documentation != null)
861 current_container.DocComment = Lexer.consume_doc_comment ();
865 if (RootContext.Documentation != null)
866 Lexer.doc_state = XmlCommentState.Allowed;
870 $$ = pop_current_class ();
872 | opt_attributes opt_modifiers opt_partial STRUCT error {
873 CheckIdentifierToken (yyToken, GetLocation ($5));
880 if (RootContext.Documentation != null)
881 Lexer.doc_state = XmlCommentState.Allowed;
883 opt_struct_member_declarations CLOSE_BRACE
886 opt_struct_member_declarations
888 | struct_member_declarations
891 struct_member_declarations
892 : struct_member_declaration
893 | struct_member_declarations struct_member_declaration
896 struct_member_declaration
897 : constant_declaration
900 | property_declaration
902 | indexer_declaration
903 | operator_declaration
904 | constructor_declaration
908 * This is only included so we can flag error 575:
909 * destructors only allowed on class types
911 | destructor_declaration
922 int modflags = (int) $2;
923 foreach (VariableDeclaration constant in (ArrayList) $5){
924 Location l = constant.Location;
925 if ((modflags & Modifiers.STATIC) != 0) {
926 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
930 Const c = new Const (
931 current_class, (Expression) $4, (string) constant.identifier,
932 (Expression) constant.expression_or_array_initializer, modflags,
935 if (RootContext.Documentation != null) {
936 c.DocComment = Lexer.consume_doc_comment ();
937 Lexer.doc_state = XmlCommentState.Allowed;
939 current_container.AddConstant (c);
945 : constant_declarator
947 ArrayList constants = new ArrayList (4);
952 | constant_declarators COMMA constant_declarator
955 ArrayList constants = (ArrayList) $1;
962 : IDENTIFIER ASSIGN constant_expression
964 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
968 // A const field requires a value to be provided
969 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
981 Expression type = (Expression) $3;
984 current_array_type = null;
986 foreach (VariableDeclaration var in (ArrayList) $4){
987 Field field = new Field (current_class, type, mod, var.identifier,
988 (Attributes) $1, var.Location);
990 field.Initializer = var.expression_or_array_initializer;
992 if (RootContext.Documentation != null) {
993 field.DocComment = Lexer.consume_doc_comment ();
994 Lexer.doc_state = XmlCommentState.Allowed;
996 current_container.AddField (field);
997 $$ = field; // FIXME: might be better if it points to the top item
1004 fixed_variable_declarators
1007 Expression type = (Expression) $4;
1010 current_array_type = null;
1012 foreach (VariableDeclaration var in (ArrayList) $5) {
1013 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1014 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1016 if (RootContext.Documentation != null) {
1017 field.DocComment = Lexer.consume_doc_comment ();
1018 Lexer.doc_state = XmlCommentState.Allowed;
1020 current_container.AddField (field);
1021 $$ = field; // FIXME: might be better if it points to the top item
1030 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1035 variable_declarators
1037 current_array_type = null;
1038 Report.Error (670, (Location) $3, "Fields cannot have void type");
1042 fixed_variable_declarators
1043 : fixed_variable_declarator
1045 ArrayList decl = new ArrayList (2);
1049 | fixed_variable_declarators COMMA fixed_variable_declarator
1051 ArrayList decls = (ArrayList) $1;
1057 fixed_variable_declarator
1058 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1060 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1062 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1064 Report.Error (443, lexer.Location, "Value or constant expected");
1065 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1069 variable_declarators
1070 : variable_declarator
1072 ArrayList decl = new ArrayList (4);
1077 | variable_declarators COMMA variable_declarator
1079 ArrayList decls = (ArrayList) $1;
1086 : IDENTIFIER ASSIGN variable_initializer
1088 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1092 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1094 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1096 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1097 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1102 variable_initializer
1111 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1113 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1117 $$ = new ArglistAccess ((Location) $1);
1121 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1128 anonymous_host = (IAnonymousHost) $1;
1129 if (RootContext.Documentation != null)
1130 Lexer.doc_state = XmlCommentState.NotAllowed;
1131 Lexer.VarParsing = true;
1135 Method method = (Method) $1;
1136 method.Block = (ToplevelBlock) $3;
1137 current_container.AddMethod (method);
1139 anonymous_host = null;
1140 current_generic_method = null;
1141 current_local_parameters = null;
1143 if (RootContext.Documentation != null)
1144 Lexer.doc_state = XmlCommentState.Allowed;
1145 Lexer.VarParsing = false;
1158 Report.Error (1585, lexer.Location,
1159 "Member modifier `{0}' must precede the member type and name",
1160 Modifiers.Name (i));
1169 // This rule is used to handle the cases where OPEN_PARENS_LAMBDA
1170 // is returned (type followed by an identifier), these are the
1171 // declarations (methods, overloads, constructors, etc) and a handful
1172 // of expressions ("using", "fixed") or "catch".
1176 | OPEN_PARENS_LAMBDA
1182 type namespace_or_type_name
1183 open_parens opt_formal_parameter_list CLOSE_PARENS
1185 lexer.ConstraintsParsing = true;
1187 opt_type_parameter_constraints_clauses
1189 lexer.ConstraintsParsing = false;
1191 MemberName name = (MemberName) $4;
1193 if ($9 != null && name.TypeArguments == null)
1194 Report.Error (80, lexer.Location,
1195 "Constraints are not allowed on non-generic declarations");
1199 GenericMethod generic = null;
1200 if (name.TypeArguments != null) {
1201 generic = new GenericMethod (current_namespace, current_class, name,
1202 (Expression) $3, (Parameters) $6);
1204 generic.SetParameterInfo ((ArrayList) $9);
1207 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1208 name, (Parameters) $6, (Attributes) $1);
1210 anonymous_host = method;
1211 current_local_parameters = (Parameters) $6;
1212 current_generic_method = generic;
1214 if (RootContext.Documentation != null)
1215 method.DocComment = Lexer.consume_doc_comment ();
1221 VOID namespace_or_type_name
1222 open_parens opt_formal_parameter_list CLOSE_PARENS
1224 lexer.ConstraintsParsing = true;
1226 opt_type_parameter_constraints_clauses
1228 lexer.ConstraintsParsing = false;
1230 MemberName name = (MemberName) $4;
1232 if ($9 != null && name.TypeArguments == null)
1233 Report.Error (80, lexer.Location,
1234 "Constraints are not allowed on non-generic declarations");
1237 GenericMethod generic = null;
1238 if (name.TypeArguments != null) {
1239 generic = new GenericMethod (current_namespace, current_class, name,
1240 TypeManager.system_void_expr, (Parameters) $6);
1242 generic.SetParameterInfo ((ArrayList) $9);
1245 method = new Method (current_class, generic, TypeManager.system_void_expr,
1246 (int) $2, false, name, (Parameters) $6, (Attributes) $1);
1248 anonymous_host = method;
1249 current_local_parameters = (Parameters) $6;
1250 current_generic_method = generic;
1252 if (RootContext.Documentation != null)
1253 method.DocComment = Lexer.consume_doc_comment ();
1260 modifiers namespace_or_type_name open_parens opt_formal_parameter_list CLOSE_PARENS
1262 MemberName name = (MemberName) $5;
1263 Report.Error (1585, name.Location,
1264 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1266 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1267 0, false, name, (Parameters) $6, (Attributes) $1);
1269 current_local_parameters = (Parameters) $6;
1271 if (RootContext.Documentation != null)
1272 method.DocComment = Lexer.consume_doc_comment ();
1280 | SEMICOLON { $$ = null; }
1283 opt_formal_parameter_list
1284 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1285 | formal_parameter_list
1288 formal_parameter_list
1291 ArrayList pars_list = (ArrayList) $1;
1293 Parameter [] pars = new Parameter [pars_list.Count];
1294 pars_list.CopyTo (pars);
1296 $$ = new Parameters (pars);
1298 | fixed_parameters COMMA parameter_array
1300 ArrayList pars_list = (ArrayList) $1;
1303 Parameter [] pars = new Parameter [pars_list.Count];
1304 pars_list.CopyTo (pars);
1306 $$ = new Parameters (pars);
1308 | fixed_parameters COMMA ARGLIST
1310 ArrayList pars_list = (ArrayList) $1;
1311 //pars_list.Add (new ArglistParameter (GetLocation ($3)));
1313 Parameter [] pars = new Parameter [pars_list.Count];
1314 pars_list.CopyTo (pars);
1316 $$ = new Parameters (pars, true);
1318 | parameter_array COMMA error
1321 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1324 | fixed_parameters COMMA parameter_array COMMA error
1327 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1330 | ARGLIST COMMA error
1332 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1335 | fixed_parameters COMMA ARGLIST COMMA error
1337 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1342 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1346 $$ = new Parameters (new Parameter[0], true);
1353 ArrayList pars = new ArrayList (4);
1358 | fixed_parameters COMMA fixed_parameter
1360 ArrayList pars = (ArrayList) $1;
1361 Parameter p = (Parameter)$3;
1363 if ((p.modFlags & Parameter.Modifier.This) != 0)
1364 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1373 opt_parameter_modifier
1377 LocatedToken lt = (LocatedToken) $4;
1378 $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1381 opt_parameter_modifier
1383 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1385 LocatedToken lt = (LocatedToken) $4;
1386 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1390 opt_parameter_modifier
1393 Report.Error (1001, GetLocation ($3), "Identifier expected");
1397 opt_parameter_modifier
1400 CheckIdentifierToken (yyToken, GetLocation ($4));
1404 opt_parameter_modifier
1410 LocatedToken lt = (LocatedToken) $4;
1411 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1416 opt_parameter_modifier
1417 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1418 | parameter_modifiers
1422 : parameter_modifier
1426 | parameter_modifiers parameter_modifier
1428 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1429 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1430 if (((Parameter.Modifier)$1 & p2) == p2) {
1431 Error_DuplicateParameterModifier (lexer.Location, p2);
1433 switch (mod & ~Parameter.Modifier.This) {
1434 case Parameter.Modifier.REF:
1435 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1437 case Parameter.Modifier.OUT:
1438 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1441 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1450 : REF { $$ = Parameter.Modifier.REF; }
1451 | OUT { $$ = Parameter.Modifier.OUT; }
1452 | THIS { $$ = Parameter.Modifier.This; }
1456 : opt_attributes PARAMS type IDENTIFIER
1458 LocatedToken lt = (LocatedToken) $4;
1459 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1461 | opt_attributes PARAMS PARAMS type IDENTIFIER
1463 Error_DuplicateParameterModifier (lexer.Location, Parameter.Modifier.PARAMS);
1466 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1468 Parameter.Modifier mod = (Parameter.Modifier)$3;
1469 if ((mod & Parameter.Modifier.This) != 0) {
1470 Report.Error (1104, lexer.Location, "The parameter modifiers `this' and `params' cannot be used altogether");
1472 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1476 | opt_attributes PARAMS type error {
1477 CheckIdentifierToken (yyToken, GetLocation ($4));
1482 property_declaration
1486 namespace_or_type_name
1488 if (RootContext.Documentation != null)
1489 tmpComment = Lexer.consume_doc_comment ();
1493 implicit_value_parameter_type = (Expression) $3;
1495 lexer.PropertyParsing = true;
1497 accessor_declarations
1499 lexer.PropertyParsing = false;
1500 has_get = has_set = false;
1508 Accessors accessors = (Accessors) $8;
1509 Accessor get_block = accessors.get_or_add;
1510 Accessor set_block = accessors.set_or_remove;
1512 MemberName name = (MemberName) $4;
1514 if (name.TypeArguments != null)
1515 syntax_error (lexer.Location, "a property can't have type arguments");
1517 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1518 name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse, current_block);
1520 current_container.AddProperty (prop);
1521 implicit_value_parameter_type = null;
1523 if (RootContext.Documentation != null)
1524 prop.DocComment = ConsumeStoredComment ();
1529 accessor_declarations
1530 : get_accessor_declaration
1532 $$ = new Accessors ((Accessor) $1, null);
1534 | get_accessor_declaration accessor_declarations
1536 Accessors accessors = (Accessors) $2;
1537 accessors.get_or_add = (Accessor) $1;
1540 | set_accessor_declaration
1542 $$ = new Accessors (null, (Accessor) $1);
1544 | set_accessor_declaration accessor_declarations
1546 Accessors accessors = (Accessors) $2;
1547 accessors.set_or_remove = (Accessor) $1;
1548 accessors.declared_in_reverse = true;
1553 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1558 get_accessor_declaration
1559 : opt_attributes opt_modifiers GET
1561 // If this is not the case, then current_local_parameters has already
1562 // been set in indexer_declaration
1563 if (parsing_indexer == false)
1564 current_local_parameters = null;
1566 current_local_parameters = indexer_parameters;
1567 lexer.PropertyParsing = false;
1569 anonymous_host = SimpleAnonymousHost.GetSimple ();
1574 Report.Error (1007, (Location) $3, "Property accessor already defined");
1577 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1579 current_local_parameters = null;
1580 lexer.PropertyParsing = true;
1582 SimpleAnonymousHost.Simple.Propagate (accessor);
1583 anonymous_host = null;
1585 if (RootContext.Documentation != null)
1586 if (Lexer.doc_state == XmlCommentState.Error)
1587 Lexer.doc_state = XmlCommentState.NotAllowed;
1593 set_accessor_declaration
1594 : opt_attributes opt_modifiers SET
1597 Parameter implicit_value_parameter = new Parameter (
1598 implicit_value_parameter_type, "value",
1599 Parameter.Modifier.NONE, null, (Location) $3);
1601 if (parsing_indexer == false) {
1602 args = new Parameter [1];
1603 args [0] = implicit_value_parameter;
1604 current_local_parameters = new Parameters (args);
1606 Parameter [] fpars = indexer_parameters.FixedParameters;
1609 int count = fpars.Length;
1611 args = new Parameter [count + 1];
1612 fpars.CopyTo (args, 0);
1613 args [count] = implicit_value_parameter;
1616 current_local_parameters = new Parameters (
1620 lexer.PropertyParsing = false;
1622 anonymous_host = SimpleAnonymousHost.GetSimple ();
1627 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1630 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1632 current_local_parameters = null;
1633 lexer.PropertyParsing = true;
1635 SimpleAnonymousHost.Simple.Propagate (accessor);
1636 anonymous_host = null;
1638 if (RootContext.Documentation != null
1639 && Lexer.doc_state == XmlCommentState.Error)
1640 Lexer.doc_state = XmlCommentState.NotAllowed;
1648 | SEMICOLON { $$ = null; }
1651 interface_declaration
1657 lexer.ConstraintsParsing = true;
1661 MemberName name = MakeName ((MemberName) $6);
1663 push_current_class (new Interface (
1664 current_namespace, current_class, name, (int) $2,
1665 (Attributes) $1), $3);
1668 opt_type_parameter_constraints_clauses
1670 lexer.ConstraintsParsing = false;
1673 current_container.AddBasesForPart (current_class, (ArrayList) $8);
1675 current_class.SetParameterInfo ((ArrayList) $9);
1677 if (RootContext.Documentation != null) {
1678 current_container.DocComment = Lexer.consume_doc_comment ();
1679 Lexer.doc_state = XmlCommentState.Allowed;
1684 if (RootContext.Documentation != null)
1685 Lexer.doc_state = XmlCommentState.Allowed;
1689 $$ = pop_current_class ();
1691 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1692 CheckIdentifierToken (yyToken, GetLocation ($5));
1698 opt_interface_member_declarations
1702 opt_interface_member_declarations
1704 | interface_member_declarations
1707 interface_member_declarations
1708 : interface_member_declaration
1709 | interface_member_declarations interface_member_declaration
1712 interface_member_declaration
1713 : interface_method_declaration
1718 Method m = (Method) $1;
1720 if (m.IsExplicitImpl)
1721 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1722 m.GetSignatureForError ());
1724 current_container.AddMethod (m);
1726 if (RootContext.Documentation != null)
1727 Lexer.doc_state = XmlCommentState.Allowed;
1729 | interface_property_declaration
1734 Property p = (Property) $1;
1736 if (p.IsExplicitImpl)
1737 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1738 p.GetSignatureForError ());
1740 current_container.AddProperty (p);
1742 if (RootContext.Documentation != null)
1743 Lexer.doc_state = XmlCommentState.Allowed;
1745 | interface_event_declaration
1748 Event e = (Event) $1;
1750 if (e.IsExplicitImpl)
1751 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1752 e.GetSignatureForError ());
1754 current_container.AddEvent (e);
1757 if (RootContext.Documentation != null)
1758 Lexer.doc_state = XmlCommentState.Allowed;
1760 | interface_indexer_declaration
1765 Indexer i = (Indexer) $1;
1767 if (i.IsExplicitImpl)
1768 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1769 i.GetSignatureForError ());
1771 current_container.AddIndexer (i);
1773 if (RootContext.Documentation != null)
1774 Lexer.doc_state = XmlCommentState.Allowed;
1776 | delegate_declaration
1779 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1780 ((MemberCore)$1).GetSignatureForError ());
1786 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1787 ((MemberCore)$1).GetSignatureForError ());
1790 | struct_declaration
1793 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1794 ((MemberCore)$1).GetSignatureForError ());
1800 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1801 ((MemberCore)$1).GetSignatureForError ());
1804 | interface_declaration
1807 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1808 ((MemberCore)$1).GetSignatureForError ());
1811 | constant_declaration
1813 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1821 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1826 interface_method_declaration_body
1829 lexer.ConstraintsParsing = false;
1831 opt_statement_list CLOSE_BRACE
1833 Report.Error (531, lexer.Location,
1834 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1840 interface_method_declaration
1841 : opt_attributes opt_new type namespace_or_type_name
1842 open_parens opt_formal_parameter_list CLOSE_PARENS
1844 lexer.ConstraintsParsing = true;
1846 opt_type_parameter_constraints_clauses
1848 // Refer to the name as $-1 in interface_method_declaration_body
1851 interface_method_declaration_body
1853 lexer.ConstraintsParsing = false;
1855 MemberName name = (MemberName) $4;
1857 if ($9 != null && name.TypeArguments == null)
1858 Report.Error (80, lexer.Location,
1859 "Constraints are not allowed on non-generic declarations");
1861 GenericMethod generic = null;
1862 if (name.TypeArguments != null) {
1863 generic = new GenericMethod (current_namespace, current_class, name,
1864 (Expression) $3, (Parameters) $6);
1866 generic.SetParameterInfo ((ArrayList) $9);
1869 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1870 (Parameters) $6, (Attributes) $1);
1871 if (RootContext.Documentation != null)
1872 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1874 | opt_attributes opt_new VOID namespace_or_type_name
1875 open_parens opt_formal_parameter_list CLOSE_PARENS
1877 lexer.ConstraintsParsing = true;
1879 opt_type_parameter_constraints_clauses
1883 interface_method_declaration_body
1885 lexer.ConstraintsParsing = false;
1887 MemberName name = (MemberName) $4;
1889 if ($9 != null && name.TypeArguments == null)
1890 Report.Error (80, lexer.Location,
1891 "Constraints are not allowed on non-generic declarations");
1893 GenericMethod generic = null;
1894 if (name.TypeArguments != null) {
1895 generic = new GenericMethod (current_namespace, current_class, name,
1896 TypeManager.system_void_expr, (Parameters) $6);
1898 generic.SetParameterInfo ((ArrayList) $9);
1901 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1902 true, name, (Parameters) $6, (Attributes) $1);
1903 if (RootContext.Documentation != null)
1904 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1908 interface_property_declaration
1913 { lexer.PropertyParsing = true; }
1914 accessor_declarations
1916 has_get = has_set = false;
1917 lexer.PropertyParsing = false;
1921 LocatedToken lt = (LocatedToken) $4;
1922 MemberName name = new MemberName (lt.Value, lt.Location);
1924 if ($3 == TypeManager.system_void_expr) {
1925 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1931 p = new Property (current_class, (Expression) $3, (int) $2, true,
1932 name, (Attributes) $1,
1935 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1939 Accessors accessor = (Accessors) $7;
1940 p = new Property (current_class, (Expression) $3, (int) $2, true,
1941 name, (Attributes) $1,
1942 accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
1944 if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
1945 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1950 if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
1951 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1956 if (RootContext.Documentation != null)
1957 p.DocComment = Lexer.consume_doc_comment ();
1964 CheckIdentifierToken (yyToken, GetLocation ($4));
1970 interface_event_declaration
1971 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1973 LocatedToken lt = (LocatedToken) $5;
1974 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1975 new MemberName (lt.Value, lt.Location),
1977 if (RootContext.Documentation != null)
1978 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1980 | opt_attributes opt_new EVENT type error {
1981 CheckIdentifierToken (yyToken, GetLocation ($5));
1984 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1985 LocatedToken lt = (LocatedToken) $5;
1986 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1989 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1991 lexer.EventParsing = true;
1993 event_accessor_declarations
1995 lexer.EventParsing = false;
1998 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2003 interface_indexer_declaration
2004 : opt_attributes opt_new type THIS
2005 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
2007 { lexer.PropertyParsing = true; }
2008 accessor_declarations
2010 has_get = has_set = false;
2011 lexer.PropertyParsing = false;
2017 i = new Indexer (current_class, (Expression) $3,
2018 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2019 (int) $2, true, (Parameters) $6, (Attributes) $1,
2022 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
2026 Accessors accessors = (Accessors) $10;
2027 i = new Indexer (current_class, (Expression) $3,
2028 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2029 (int) $2, true, (Parameters) $6, (Attributes) $1,
2030 accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
2032 if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
2033 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
2038 if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
2039 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
2044 if (RootContext.Documentation != null)
2045 i.DocComment = ConsumeStoredComment ();
2051 operator_declaration
2052 : opt_attributes opt_modifiers operator_declarator
2054 anonymous_host = SimpleAnonymousHost.GetSimple ();
2061 OperatorDeclaration decl = (OperatorDeclaration) $3;
2063 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
2065 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
2066 if (decl.arg2type != null)
2067 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
2069 Operator op = new Operator (
2070 current_class, decl.optype, decl.ret_type, (int) $2,
2071 new Parameters (param_list),
2072 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2074 if (RootContext.Documentation != null) {
2075 op.DocComment = tmpComment;
2076 Lexer.doc_state = XmlCommentState.Allowed;
2079 SimpleAnonymousHost.Simple.Propagate (op);
2080 anonymous_host = null;
2082 // Note again, checking is done in semantic analysis
2083 current_container.AddOperator (op);
2085 current_local_parameters = null;
2091 | SEMICOLON { $$ = null; }
2094 : type OPERATOR overloadable_operator
2095 open_parens opt_attributes opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2097 // TODO: wrong location
2098 if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE)
2099 Error_ParameterModifierNotValid ((Location) $2);
2101 LocatedToken lt = (LocatedToken) $8;
2102 Operator.OpType op = (Operator.OpType) $3;
2103 CheckUnaryOperator (op, lt.Location);
2105 if (op == Operator.OpType.Addition)
2106 op = Operator.OpType.UnaryPlus;
2108 if (op == Operator.OpType.Subtraction)
2109 op = Operator.OpType.UnaryNegation;
2111 Parameter [] pars = new Parameter [1];
2112 Expression type = (Expression) $7;
2114 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, (Attributes) $5, lt.Location);
2116 current_local_parameters = new Parameters (pars);
2118 if (RootContext.Documentation != null) {
2119 tmpComment = Lexer.consume_doc_comment ();
2120 Lexer.doc_state = XmlCommentState.NotAllowed;
2123 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2124 null, null, (Location) $2);
2126 | type OPERATOR overloadable_operator
2128 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
2129 opt_attributes opt_parameter_modifier type IDENTIFIER
2132 // TODO: wrong location
2133 if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE || (Parameter.Modifier)$11 != Parameter.Modifier.NONE)
2134 Error_ParameterModifierNotValid ((Location) $2);
2136 LocatedToken ltParam1 = (LocatedToken) $8;
2137 LocatedToken ltParam2 = (LocatedToken) $13;
2138 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2140 Parameter [] pars = new Parameter [2];
2142 Expression typeL = (Expression) $7;
2143 Expression typeR = (Expression) $12;
2145 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, (Attributes) $5, ltParam1.Location);
2146 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, (Attributes) $10, ltParam2.Location);
2148 current_local_parameters = new Parameters (pars);
2150 if (RootContext.Documentation != null) {
2151 tmpComment = Lexer.consume_doc_comment ();
2152 Lexer.doc_state = XmlCommentState.NotAllowed;
2155 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2156 typeL, ltParam1.Value,
2157 typeR, ltParam2.Value, (Location) $2);
2159 | conversion_operator_declarator
2160 | type OPERATOR overloadable_operator
2162 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
2163 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA error
2165 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2166 Operator.GetName ((Operator.OpType) $3));
2169 | type OPERATOR overloadable_operator
2170 open_parens CLOSE_PARENS
2172 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2173 Operator.GetName ((Operator.OpType) $3));
2178 overloadable_operator
2180 : BANG { $$ = Operator.OpType.LogicalNot; }
2181 | TILDE { $$ = Operator.OpType.OnesComplement; }
2182 | OP_INC { $$ = Operator.OpType.Increment; }
2183 | OP_DEC { $$ = Operator.OpType.Decrement; }
2184 | TRUE { $$ = Operator.OpType.True; }
2185 | FALSE { $$ = Operator.OpType.False; }
2186 // Unary and binary:
2187 | PLUS { $$ = Operator.OpType.Addition; }
2188 | MINUS { $$ = Operator.OpType.Subtraction; }
2190 | STAR { $$ = Operator.OpType.Multiply; }
2191 | DIV { $$ = Operator.OpType.Division; }
2192 | PERCENT { $$ = Operator.OpType.Modulus; }
2193 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2194 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2195 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2196 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2197 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2198 | OP_EQ { $$ = Operator.OpType.Equality; }
2199 | OP_NE { $$ = Operator.OpType.Inequality; }
2200 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2201 | OP_LT { $$ = Operator.OpType.LessThan; }
2202 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2203 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2206 conversion_operator_declarator
2207 : IMPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2209 // TODO: wrong location
2210 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2211 Error_ParameterModifierNotValid (GetLocation ($4));
2213 LocatedToken lt = (LocatedToken) $7;
2214 Parameter [] pars = new Parameter [1];
2216 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2218 current_local_parameters = new Parameters (pars);
2220 if (RootContext.Documentation != null) {
2221 tmpComment = Lexer.consume_doc_comment ();
2222 Lexer.doc_state = XmlCommentState.NotAllowed;
2225 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $6, lt.Value,
2226 null, null, (Location) $2);
2228 | EXPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2230 // TODO: wrong location
2231 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2232 Error_ParameterModifierNotValid (GetLocation ($4));
2234 LocatedToken lt = (LocatedToken) $7;
2235 Parameter [] pars = new Parameter [1];
2237 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2239 current_local_parameters = new Parameters (pars);
2241 if (RootContext.Documentation != null) {
2242 tmpComment = Lexer.consume_doc_comment ();
2243 Lexer.doc_state = XmlCommentState.NotAllowed;
2246 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $6, lt.Value,
2247 null, null, (Location) $2);
2251 syntax_error ((Location) $1, "'operator' expected");
2255 syntax_error ((Location) $1, "'operator' expected");
2259 constructor_declaration
2262 constructor_declarator
2265 Constructor c = (Constructor) $3;
2266 c.Block = (ToplevelBlock) $4;
2267 c.OptAttributes = (Attributes) $1;
2268 c.ModFlags = (int) $2;
2270 if (RootContext.Documentation != null)
2271 c.DocComment = ConsumeStoredComment ();
2273 if (c.Name == current_container.Basename){
2274 if ((c.ModFlags & Modifiers.STATIC) != 0){
2275 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2276 Report.Error (515, c.Location,
2277 "`{0}': access modifiers are not allowed on static constructors",
2278 c.GetSignatureForError ());
2281 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2283 if (c.Initializer != null){
2284 Report.Error (514, c.Location,
2285 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2286 c.GetSignatureForError ());
2289 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2292 // We let another layer check the validity of the constructor.
2293 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2296 current_container.AddConstructor (c);
2298 current_local_parameters = null;
2299 if (RootContext.Documentation != null)
2300 Lexer.doc_state = XmlCommentState.Allowed;
2304 constructor_declarator
2305 : constructor_header
2309 | constructor_header constructor_initializer
2311 ((Constructor)$1).Initializer = (ConstructorInitializer) $2;
2319 if (RootContext.Documentation != null) {
2320 tmpComment = Lexer.consume_doc_comment ();
2321 Lexer.doc_state = XmlCommentState.Allowed;
2324 open_parens opt_formal_parameter_list CLOSE_PARENS
2326 LocatedToken lt = (LocatedToken) $1;
2327 current_local_parameters = (Parameters) $4;
2328 current_block = new ToplevelBlock (null, current_local_parameters, null, lt.Location);
2330 $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
2333 anonymous_host = (IAnonymousHost) $$;
2339 | SEMICOLON { current_block = null; $$ = null; }
2342 constructor_initializer
2343 : COLON BASE open_parens opt_argument_list CLOSE_PARENS
2345 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2347 | COLON THIS open_parens opt_argument_list CLOSE_PARENS
2349 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2352 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2358 : /* EMPTY */ { $$ = 0; }
2359 | UNSAFE { $$ = Modifiers.UNSAFE; }
2360 | EXTERN { $$ = Modifiers.EXTERN; }
2363 destructor_declaration
2364 : opt_attributes opt_finalizer TILDE
2366 if (RootContext.Documentation != null) {
2367 tmpComment = Lexer.consume_doc_comment ();
2368 Lexer.doc_state = XmlCommentState.NotAllowed;
2371 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2373 LocatedToken lt = (LocatedToken) $5;
2374 if (lt.Value != current_container.MemberName.Name){
2375 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2376 } else if (current_container.Kind != Kind.Class){
2377 Report.Error (575, lt.Location, "Only class types can contain destructor");
2379 Location l = lt.Location;
2382 if (!RootContext.StdLib && current_container.Name == "System.Object")
2383 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2385 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2387 Method d = new Destructor (
2388 current_class, TypeManager.system_void_expr, m, "Finalize",
2389 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2390 if (RootContext.Documentation != null)
2391 d.DocComment = ConsumeStoredComment ();
2393 d.Block = (ToplevelBlock) $8;
2394 current_container.AddMethod (d);
2402 EVENT type variable_declarators SEMICOLON
2404 current_array_type = null;
2405 foreach (VariableDeclaration var in (ArrayList) $5) {
2407 MemberName name = new MemberName (var.identifier,
2410 EventField e = new EventField (
2411 current_class, (Expression) $4, (int) $2, false, name,
2414 e.Initializer = var.expression_or_array_initializer;
2416 current_container.AddEvent (e);
2418 if (RootContext.Documentation != null) {
2419 e.DocComment = Lexer.consume_doc_comment ();
2420 Lexer.doc_state = XmlCommentState.Allowed;
2426 EVENT type namespace_or_type_name
2429 implicit_value_parameter_type = (Expression) $4;
2430 lexer.EventParsing = true;
2432 event_accessor_declarations
2434 lexer.EventParsing = false;
2438 MemberName name = (MemberName) $5;
2441 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2442 current_container.Name, name.ToString ());
2445 Accessors accessors = (Accessors) $8;
2447 if (name.TypeArguments != null)
2448 syntax_error (lexer.Location, "an event can't have type arguments");
2450 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2451 // CS0073 is already reported, so no CS0065 here.
2454 Event e = new EventProperty (
2455 current_class, (Expression) $4, (int) $2, false, name,
2456 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2457 if (RootContext.Documentation != null) {
2458 e.DocComment = Lexer.consume_doc_comment ();
2459 Lexer.doc_state = XmlCommentState.Allowed;
2462 current_container.AddEvent (e);
2463 implicit_value_parameter_type = null;
2467 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2468 MemberName mn = (MemberName) $5;
2470 if (mn.Left != null)
2471 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2473 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2475 if (RootContext.Documentation != null)
2476 Lexer.doc_state = XmlCommentState.Allowed;
2480 event_accessor_declarations
2481 : add_accessor_declaration remove_accessor_declaration
2483 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2485 | remove_accessor_declaration add_accessor_declaration
2487 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2488 accessors.declared_in_reverse = true;
2491 | add_accessor_declaration { $$ = null; }
2492 | remove_accessor_declaration { $$ = null; }
2495 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2501 add_accessor_declaration
2502 : opt_attributes ADD
2504 Parameter [] args = new Parameter [1];
2505 Parameter implicit_value_parameter = new Parameter (
2506 implicit_value_parameter_type, "value",
2507 Parameter.Modifier.NONE, null, (Location) $2);
2509 args [0] = implicit_value_parameter;
2511 current_local_parameters = new Parameters (args);
2512 lexer.EventParsing = false;
2514 anonymous_host = SimpleAnonymousHost.GetSimple ();
2518 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2519 lexer.EventParsing = true;
2521 current_local_parameters = null;
2522 SimpleAnonymousHost.Simple.Propagate (accessor);
2523 anonymous_host = null;
2527 | opt_attributes ADD error {
2528 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2531 | opt_attributes modifiers ADD {
2532 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2537 remove_accessor_declaration
2538 : opt_attributes REMOVE
2540 Parameter [] args = new Parameter [1];
2541 Parameter implicit_value_parameter = new Parameter (
2542 implicit_value_parameter_type, "value",
2543 Parameter.Modifier.NONE, null, (Location) $2);
2545 args [0] = implicit_value_parameter;
2547 current_local_parameters = new Parameters (args);
2548 lexer.EventParsing = false;
2552 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2553 lexer.EventParsing = true;
2555 | opt_attributes REMOVE error {
2556 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2559 | opt_attributes modifiers REMOVE {
2560 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2566 : opt_attributes opt_modifiers indexer_declarator
2569 IndexerDeclaration decl = (IndexerDeclaration) $3;
2571 implicit_value_parameter_type = decl.type;
2573 lexer.PropertyParsing = true;
2574 parsing_indexer = true;
2576 indexer_parameters = decl.param_list;
2577 anonymous_host = SimpleAnonymousHost.GetSimple ();
2579 accessor_declarations
2581 lexer.PropertyParsing = false;
2582 has_get = has_set = false;
2583 parsing_indexer = false;
2590 // The signature is computed from the signature of the indexer. Look
2591 // at section 3.6 on the spec
2593 IndexerDeclaration decl = (IndexerDeclaration) $3;
2594 Accessors accessors = (Accessors) $6;
2595 Accessor get_block = accessors.get_or_add;
2596 Accessor set_block = accessors.set_or_remove;
2599 if (decl.interface_type != null)
2600 name = new MemberName (
2601 decl.interface_type, TypeContainer.DefaultIndexerName, decl.location);
2603 name = new MemberName (TypeContainer.DefaultIndexerName, decl.location);
2605 indexer = new Indexer (current_class, decl.type, name,
2606 (int) $2, false, decl.param_list, (Attributes) $1,
2607 get_block, set_block, accessors.declared_in_reverse);
2609 if (RootContext.Documentation != null)
2610 indexer.DocComment = ConsumeStoredComment ();
2612 current_container.AddIndexer (indexer);
2614 current_local_parameters = null;
2615 implicit_value_parameter_type = null;
2616 indexer_parameters = null;
2621 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2623 Parameters pars = (Parameters) $4;
2624 if (pars.HasArglist) {
2625 // "__arglist is not valid in this context"
2626 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2627 } else if (pars.Empty){
2628 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2630 if (RootContext.Documentation != null) {
2631 tmpComment = Lexer.consume_doc_comment ();
2632 Lexer.doc_state = XmlCommentState.Allowed;
2635 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2637 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2639 Parameters pars = (Parameters) $6;
2641 if (pars.HasArglist) {
2642 // "__arglist is not valid in this context"
2643 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2644 } else if (pars.Empty){
2645 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2648 MemberName name = (MemberName) $2;
2649 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2651 if (RootContext.Documentation != null) {
2652 tmpComment = Lexer.consume_doc_comment ();
2653 Lexer.doc_state = XmlCommentState.Allowed;
2663 if (RootContext.Documentation != null)
2664 enumTypeComment = Lexer.consume_doc_comment ();
2669 LocatedToken lt = (LocatedToken) $4;
2670 Location enum_location = lt.Location;
2672 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2673 Enum e = new Enum (current_namespace, current_class, (Expression) $5, (int) $2,
2674 name, (Attributes) $1);
2676 if (RootContext.Documentation != null)
2677 e.DocComment = enumTypeComment;
2680 EnumMember em = null;
2681 foreach (VariableDeclaration ev in (ArrayList) $7) {
2682 em = new EnumMember (
2683 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2684 ev.OptAttributes, ev.Location);
2686 // if (RootContext.Documentation != null)
2687 em.DocComment = ev.DocComment;
2689 e.AddEnumMember (em);
2692 current_container.AddTypeContainer (e);
2699 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2700 | COLON type { $$ = $2; }
2706 if (RootContext.Documentation != null)
2707 Lexer.doc_state = XmlCommentState.Allowed;
2709 opt_enum_member_declarations
2711 // here will be evaluated after CLOSE_BLACE is consumed.
2712 if (RootContext.Documentation != null)
2713 Lexer.doc_state = XmlCommentState.Allowed;
2721 opt_enum_member_declarations
2722 : /* empty */ { $$ = new ArrayList (4); }
2723 | enum_member_declarations opt_comma { $$ = $1; }
2726 enum_member_declarations
2727 : enum_member_declaration
2729 ArrayList l = new ArrayList (4);
2734 | enum_member_declarations COMMA enum_member_declaration
2736 ArrayList l = (ArrayList) $1;
2744 enum_member_declaration
2745 : opt_attributes IDENTIFIER
2747 VariableDeclaration vd = new VariableDeclaration (
2748 (LocatedToken) $2, null, (Attributes) $1);
2750 if (RootContext.Documentation != null) {
2751 vd.DocComment = Lexer.consume_doc_comment ();
2752 Lexer.doc_state = XmlCommentState.Allowed;
2757 | opt_attributes IDENTIFIER
2759 if (RootContext.Documentation != null) {
2760 tmpComment = Lexer.consume_doc_comment ();
2761 Lexer.doc_state = XmlCommentState.NotAllowed;
2766 VariableDeclaration vd = new VariableDeclaration (
2767 (LocatedToken) $2, $5, (Attributes) $1);
2769 if (RootContext.Documentation != null)
2770 vd.DocComment = ConsumeStoredComment ();
2776 delegate_declaration
2781 lexer.ConstraintsParsing = true;
2784 open_parens opt_formal_parameter_list CLOSE_PARENS
2786 MemberName name = MakeName ((MemberName) $6);
2787 Parameters p = (Parameters) $8;
2789 // TODO: wrong location
2790 Report.Error (1669, name.Location, "__arglist is not valid in this context");
2793 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2794 (int) $2, name, p, (Attributes) $1);
2796 if (RootContext.Documentation != null) {
2797 del.DocComment = Lexer.consume_doc_comment ();
2798 Lexer.doc_state = XmlCommentState.Allowed;
2801 current_container.AddDelegate (del);
2802 current_delegate = del;
2804 opt_type_parameter_constraints_clauses
2806 lexer.ConstraintsParsing = false;
2810 current_delegate.SetParameterInfo ((ArrayList) $11);
2811 $$ = current_delegate;
2813 current_delegate = null;
2820 lexer.CheckNullable (false);
2825 lexer.CheckNullable (true);
2830 namespace_or_type_name
2832 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2833 LocatedToken lt1 = (LocatedToken) $1;
2834 LocatedToken lt2 = (LocatedToken) $3;
2835 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2837 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2838 LocatedToken lt = (LocatedToken) $3;
2839 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2844 : IDENTIFIER opt_type_argument_list {
2845 LocatedToken lt = (LocatedToken) $1;
2846 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2850 opt_type_argument_list
2851 : /* empty */ { $$ = null; }
2852 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2855 if (RootContext.Version == LanguageVersion.ISO_1)
2856 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2860 $$ = new TypeArguments ((int) $1, lexer.Location);
2861 if (RootContext.Version == LanguageVersion.ISO_1)
2862 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2867 : opt_attributes type {
2868 TypeArguments type_args = new TypeArguments (lexer.Location);
2870 SimpleName sn = $2 as SimpleName;
2872 Report.Error (1031, lexer.Location, "Type expected");
2874 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2876 type_args.Add ((Expression) $2);
2879 | type_arguments COMMA opt_attributes type {
2880 TypeArguments type_args = (TypeArguments) $1;
2882 SimpleName sn = $4 as SimpleName;
2884 Report.Error (1031, lexer.Location, "Type expected");
2886 $4 = new TypeParameterName (sn.Name, (Attributes) $3, lexer.Location);
2888 type_args.Add ((Expression) $4);
2895 * Before you think of adding a return_type, notice that we have been
2896 * using two rules in the places where it matters (one rule using type
2897 * and another identical one that uses VOID as the return type). This
2898 * gets rid of a shift/reduce couple
2901 : namespace_or_type_name opt_nullable
2903 MemberName name = (MemberName) $1;
2904 $$ = name.GetTypeExpression ();
2907 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2909 | builtin_types opt_nullable
2912 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2918 $$ = new VarExpr (lexer.Location);
2926 // Note that here only unmanaged types are allowed but we
2927 // can't perform checks during this phase - we do it during
2928 // semantic analysis.
2930 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2934 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2939 : builtin_types opt_nullable
2942 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2944 | non_expression_type rank_specifier
2946 Location loc = GetLocation ($1);
2948 loc = lexer.Location;
2949 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2951 | non_expression_type STAR
2953 Location loc = GetLocation ($1);
2955 loc = lexer.Location;
2956 $$ = new ComposedCast ((Expression) $1, "*", loc);
2958 | expression rank_specifiers
2960 $$ = new ComposedCast ((Expression) $1, (string) $2);
2964 $$ = new ComposedCast ((Expression) $1, "*");
2968 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2969 // through this different path
2971 | multiplicative_expression STAR
2973 $$ = new ComposedCast ((Expression) $1, "*");
2980 ArrayList types = new ArrayList (4);
2985 | type_list COMMA type
2987 ArrayList types = (ArrayList) $1;
2995 * replaces all the productions for isolating the various
2996 * simple types, but we need this to reuse it easily in local_variable_type
2999 : OBJECT { $$ = TypeManager.system_object_expr; }
3000 | STRING { $$ = TypeManager.system_string_expr; }
3001 | BOOL { $$ = TypeManager.system_boolean_expr; }
3002 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
3003 | FLOAT { $$ = TypeManager.system_single_expr; }
3004 | DOUBLE { $$ = TypeManager.system_double_expr; }
3009 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
3010 | BYTE { $$ = TypeManager.system_byte_expr; }
3011 | SHORT { $$ = TypeManager.system_int16_expr; }
3012 | USHORT { $$ = TypeManager.system_uint16_expr; }
3013 | INT { $$ = TypeManager.system_int32_expr; }
3014 | UINT { $$ = TypeManager.system_uint32_expr; }
3015 | LONG { $$ = TypeManager.system_int64_expr; }
3016 | ULONG { $$ = TypeManager.system_uint64_expr; }
3017 | CHAR { $$ = TypeManager.system_char_expr; }
3018 | VOID { $$ = TypeManager.system_void_expr; }
3022 : type rank_specifiers opt_nullable
3024 string rank_specifiers = (string) $2;
3026 rank_specifiers += "?";
3028 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
3033 // Expressions, section 7.5
3042 MemberName mn = (MemberName) $1;
3043 $$ = mn.GetTypeExpression ();
3045 | IDENTIFIER DOUBLE_COLON IDENTIFIER
3047 LocatedToken lt1 = (LocatedToken) $1;
3048 LocatedToken lt2 = (LocatedToken) $3;
3049 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
3051 | parenthesized_expression
3052 | default_value_expression
3054 | invocation_expression
3058 | post_increment_expression
3059 | post_decrement_expression
3063 | checked_expression
3064 | unchecked_expression
3065 | pointer_member_access
3066 | anonymous_method_expression
3073 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3074 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
3075 | NULL { $$ = new NullLiteral (lexer.Location); }
3079 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3080 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3081 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3086 object v = lexer.Value;
3089 $$ = new IntLiteral ((int) v, lexer.Location);
3090 } else if (v is uint)
3091 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3093 $$ = new LongLiteral ((Int64) v, lexer.Location);
3094 else if (v is ulong)
3095 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3097 Console.WriteLine ("OOPS. Unexpected result from scanner");
3102 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3103 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3106 parenthesized_expression_0
3107 : OPEN_PARENS expression CLOSE_PARENS
3110 lexer.Deambiguate_CloseParens ($$);
3111 // After this, the next token returned is one of
3112 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
3113 // or CLOSE_PARENS_MINUS.
3115 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
3118 parenthesized_expression
3119 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
3123 | parenthesized_expression_0 CLOSE_PARENS
3127 | parenthesized_expression_0 CLOSE_PARENS_MINUS
3129 // If a parenthesized expression is followed by a minus, we need to wrap
3130 // the expression inside a ParenthesizedExpression for the CS0075 check
3131 // in Binary.DoResolve().
3132 $$ = new ParenthesizedExpression ((Expression) $1);
3137 : primary_expression DOT IDENTIFIER opt_type_argument_list
3139 LocatedToken lt = (LocatedToken) $3;
3140 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3142 | predefined_type DOT IDENTIFIER opt_type_argument_list
3144 LocatedToken lt = (LocatedToken) $3;
3145 // TODO: Location is wrong as some predefined types doesn't hold a location
3146 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3154 invocation_expression
3155 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3158 Report.Error (1, (Location) $2, "Parse error");
3160 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3162 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3164 $$ = new Invocation ((Expression) $1, new ArrayList ());
3166 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3168 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3170 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3172 ArrayList args = new ArrayList (1);
3174 $$ = new Invocation ((Expression) $1, args);
3176 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3178 ArrayList args = ((ArrayList) $4);
3180 $$ = new Invocation ((Expression) $1, args);
3184 opt_object_initializer
3185 : /* empty */ { $$ = null; }
3186 | OPEN_BRACE variable_declarators CLOSE_BRACE
3188 ArrayList vars = (ArrayList) $2;
3189 ArrayList inits = new ArrayList (vars.Count);
3190 foreach (VariableDeclaration variable in vars) {
3191 Initializer i = new Initializer (variable.identifier, variable.expression_or_array_initializer);
3198 opt_object_or_collection_initializer
3199 : /* empty */ { $$ = null; }
3200 | object_or_collection_initializer
3203 object_or_collection_initializer
3204 : object_initializer
3205 | collection_initializer
3209 : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
3214 $$ = new ObjectInitializer ((ArrayList)$2);
3216 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3218 $$ = new ObjectInitializer ((ArrayList) $2);
3222 opt_member_initializer_list
3223 : /* empty */ { $$ = null; }
3224 | member_initializer_list
3227 member_initializer_list
3228 : member_initializer
3230 ArrayList a = new ArrayList ();
3234 | member_initializer_list COMMA member_initializer
3236 ArrayList a = (ArrayList)$1;
3243 : IDENTIFIER ASSIGN initializer_value
3245 LocatedToken id = $1 as LocatedToken;
3246 IInitializable i = $3 as IInitializable;
3248 $$ = new Initializer (id.Value, i);
3250 $$ = new Initializer (id.Value, (Expression)$3);
3256 | object_or_collection_initializer
3259 collection_initializer
3260 : OPEN_BRACE element_initializer_list CLOSE_BRACE
3262 $$ = new CollectionInitializer ((ArrayList) $2);
3264 | OPEN_BRACE element_initializer_list COMMA CLOSE_BRACE
3266 $$ = new CollectionInitializer ((ArrayList) $2);
3270 element_initializer_list
3271 : element_initializer
3273 ArrayList a = new ArrayList ();
3277 | element_initializer_list COMMA element_initializer
3279 ArrayList a = $1 as ArrayList;
3286 : non_assignment_expression
3290 : /* empty */ { $$ = null; }
3297 ArrayList list = new ArrayList (4);
3301 | argument_list COMMA argument
3303 ArrayList list = (ArrayList) $1;
3307 | argument_list error {
3308 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3316 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3318 | non_simple_argument
3325 : REF variable_reference
3327 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3329 | OUT variable_reference
3331 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3333 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3335 ArrayList list = (ArrayList) $3;
3336 Argument[] args = new Argument [list.Count];
3337 list.CopyTo (args, 0);
3339 Expression expr = new Arglist (args, (Location) $1);
3340 $$ = new Argument (expr, Argument.AType.Expression);
3342 | ARGLIST OPEN_PARENS CLOSE_PARENS
3344 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3348 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3353 : expression { note ("section 5.4"); $$ = $1; }
3357 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3359 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3361 | primary_expression rank_specifiers
3363 // So the super-trick is that primary_expression
3364 // can only be either a SimpleName or a MemberAccess.
3365 // The MemberAccess case arises when you have a fully qualified type-name like :
3367 // SimpleName is when you have
3370 Expression expr = (Expression) $1;
3371 if (expr is ComposedCast){
3372 $$ = new ComposedCast (expr, (string) $2);
3373 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3374 Error_ExpectingTypeName (expr);
3375 $$ = TypeManager.system_object_expr;
3378 // So we extract the string corresponding to the SimpleName
3381 $$ = new ComposedCast (expr, (string) $2);
3383 current_array_type = (Expression)$$;
3390 ArrayList list = new ArrayList (4);
3394 | expression_list COMMA expression
3396 ArrayList list = (ArrayList) $1;
3405 $$ = new This (current_block, (Location) $1);
3410 : BASE DOT IDENTIFIER opt_type_argument_list
3412 LocatedToken lt = (LocatedToken) $3;
3413 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3415 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3417 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3420 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3425 post_increment_expression
3426 : primary_expression OP_INC
3428 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3429 (Expression) $1, (Location) $2);
3433 post_decrement_expression
3434 : primary_expression OP_DEC
3436 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3437 (Expression) $1, (Location) $2);
3442 : object_or_delegate_creation_expression
3443 | array_creation_expression
3444 | anonymous_type_expression
3447 object_or_delegate_creation_expression
3448 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3451 if (RootContext.Version < LanguageVersion.LINQ) {
3452 Error_ExpectingTypeName ((Expression) $2);
3456 $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (IInitializable) $6, (Location) $1);
3459 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3461 | NEW type object_or_collection_initializer
3463 if (RootContext.Version < LanguageVersion.LINQ) {
3464 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3468 $$ = new NewInitialize ((Expression) $2, new ArrayList (), (IInitializable) $3, (Location) $1);
3472 array_creation_expression
3473 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3475 opt_array_initializer
3477 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3479 | NEW type rank_specifiers array_initializer
3481 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3483 | NEW rank_specifiers array_initializer
3485 if (RootContext.Version < LanguageVersion.LINQ) {
3486 Report.Error (1031, (Location) $1, "Type expected");
3490 $$ = new ArrayCreation (new VarExpr((Location) $1), (string) $2, (ArrayList) $3, (Location) $1);
3494 Report.Error (1031, (Location) $1, "Type expected");
3499 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3504 anonymous_type_expression
3505 : NEW OPEN_BRACE anonymous_type_parameters CLOSE_BRACE
3507 if (RootContext.Version < LanguageVersion.LINQ) {
3508 Report.Error (1031, (Location) $1, "Type expected");
3512 $$ = new AnonymousType ((ArrayList) $3, current_container, lexer.Location);
3516 anonymous_type_parameters
3517 : anonymous_type_parameter
3519 ArrayList a = new ArrayList (4);
3523 | anonymous_type_parameters COMMA anonymous_type_parameter
3525 ArrayList a = (ArrayList) $1;
3531 anonymous_type_parameter
3532 : variable_declarator
3534 VariableDeclaration v = (VariableDeclaration) $1;
3535 Expression e = v.expression_or_array_initializer;
3537 e = new LocalVariableReference (current_block, v.identifier, lexer.Location);
3539 $$ = new AnonymousTypeParameter (e, v.identifier);
3543 MemberAccess ma = (MemberAccess) $1;
3544 $$ = new AnonymousTypeParameter (ma, ma.Identifier);
3559 opt_rank_specifier_or_nullable
3568 | opt_nullable rank_specifiers
3575 | opt_nullable rank_specifiers INTERR
3578 $$ = "?" + $2 + "?";
3585 : rank_specifier opt_rank_specifier
3587 $$ = (string) $2 + (string) $1;
3592 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3594 $$ = "[" + (string) $2 + "]";
3614 | dim_separators COMMA
3616 $$ = (string) $1 + ",";
3620 opt_array_initializer
3632 : OPEN_BRACE CLOSE_BRACE
3634 ArrayList list = new ArrayList (4);
3637 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3639 $$ = (ArrayList) $2;
3643 variable_initializer_list
3644 : variable_initializer
3646 ArrayList list = new ArrayList (4);
3650 | variable_initializer_list COMMA variable_initializer
3652 ArrayList list = (ArrayList) $1;
3661 pushed_current_array_type = current_array_type;
3662 lexer.TypeOfParsing = true;
3664 OPEN_PARENS type CLOSE_PARENS
3666 lexer.TypeOfParsing = false;
3667 Expression type = (Expression)$4;
3668 if (type == TypeManager.system_void_expr)
3669 $$ = new TypeOfVoid ((Location) $1);
3671 $$ = new TypeOf (type, (Location) $1);
3672 current_array_type = pushed_current_array_type;
3677 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3678 $$ = new SizeOf ((Expression) $3, (Location) $1);
3683 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3685 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3689 unchecked_expression
3690 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3692 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3696 pointer_member_access
3697 : primary_expression OP_PTR IDENTIFIER
3700 LocatedToken lt = (LocatedToken) $3;
3702 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3703 $$ = new MemberAccess (deref, lt.Value);
3707 anonymous_method_expression
3708 : DELEGATE opt_anonymous_method_signature
3710 start_anonymous (false, (Parameters) $2, (Location) $1);
3714 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
3718 opt_anonymous_method_signature
3719 : /* empty */ { $$ = null; }
3720 | anonymous_method_signature
3723 anonymous_method_signature
3724 : open_parens opt_anonymous_method_parameter_list CLOSE_PARENS
3727 $$ = Parameters.EmptyReadOnlyParameters;
3729 ArrayList par_list = (ArrayList) $2;
3730 Parameter [] pars = new Parameter [par_list.Count];
3731 par_list.CopyTo (pars);
3732 $$ = new Parameters (pars);
3737 opt_anonymous_method_parameter_list
3738 : /* empty */ { $$ = null; }
3739 | anonymous_method_parameter_list { $$ = $1; }
3742 anonymous_method_parameter_list
3743 : anonymous_method_parameter
3745 ArrayList a = new ArrayList (4);
3749 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3751 ArrayList a = (ArrayList) $1;
3757 anonymous_method_parameter
3758 : opt_parameter_modifier type IDENTIFIER {
3759 LocatedToken lt = (LocatedToken) $3;
3760 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3762 | PARAMS type IDENTIFIER {
3763 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3768 default_value_expression
3769 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3771 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3776 : primary_expression
3777 | BANG prefixed_unary_expression
3779 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3781 | TILDE prefixed_unary_expression
3783 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3789 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3791 $$ = new Cast ((Expression) $1, (Expression) $3);
3793 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3795 $$ = new Cast ((Expression) $1, (Expression) $3);
3797 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3799 $$ = new Cast ((Expression) $1, (Expression) $3);
3805 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3807 // TODO: wrong location
3808 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3813 // The idea to split this out is from Rhys' grammar
3814 // to solve the problem with casts.
3816 prefixed_unary_expression
3818 | PLUS prefixed_unary_expression
3820 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3822 | MINUS prefixed_unary_expression
3824 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3826 | OP_INC prefixed_unary_expression
3828 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3829 (Expression) $2, (Location) $1);
3831 | OP_DEC prefixed_unary_expression
3833 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3834 (Expression) $2, (Location) $1);
3836 | STAR prefixed_unary_expression
3838 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3840 | BITWISE_AND prefixed_unary_expression
3842 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3846 pre_increment_expression
3847 : OP_INC prefixed_unary_expression
3849 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3850 (Expression) $2, (Location) $1);
3854 pre_decrement_expression
3855 : OP_DEC prefixed_unary_expression
3857 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3858 (Expression) $2, (Location) $1);
3862 multiplicative_expression
3863 : prefixed_unary_expression
3864 | multiplicative_expression STAR prefixed_unary_expression
3866 $$ = new Binary (Binary.Operator.Multiply,
3867 (Expression) $1, (Expression) $3);
3869 | multiplicative_expression DIV prefixed_unary_expression
3871 $$ = new Binary (Binary.Operator.Division,
3872 (Expression) $1, (Expression) $3);
3874 | multiplicative_expression PERCENT prefixed_unary_expression
3876 $$ = new Binary (Binary.Operator.Modulus,
3877 (Expression) $1, (Expression) $3);
3882 : multiplicative_expression
3883 | additive_expression PLUS multiplicative_expression
3885 $$ = new Binary (Binary.Operator.Addition,
3886 (Expression) $1, (Expression) $3);
3888 | additive_expression MINUS multiplicative_expression
3890 $$ = new Binary (Binary.Operator.Subtraction,
3891 (Expression) $1, (Expression) $3);
3896 : additive_expression
3897 | shift_expression OP_SHIFT_LEFT additive_expression
3899 $$ = new Binary (Binary.Operator.LeftShift,
3900 (Expression) $1, (Expression) $3);
3902 | shift_expression OP_SHIFT_RIGHT additive_expression
3904 $$ = new Binary (Binary.Operator.RightShift,
3905 (Expression) $1, (Expression) $3);
3916 lexer.PutbackNullable ();
3921 nullable_type_or_conditional
3924 if (((bool) $2) && ($1 is ComposedCast))
3925 $$ = ((ComposedCast) $1).RemoveNullable ();
3931 relational_expression
3933 | relational_expression OP_LT shift_expression
3935 $$ = new Binary (Binary.Operator.LessThan,
3936 (Expression) $1, (Expression) $3);
3938 | relational_expression OP_GT shift_expression
3940 $$ = new Binary (Binary.Operator.GreaterThan,
3941 (Expression) $1, (Expression) $3);
3943 | relational_expression OP_LE shift_expression
3945 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3946 (Expression) $1, (Expression) $3);
3948 | relational_expression OP_GE shift_expression
3950 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3951 (Expression) $1, (Expression) $3);
3953 | relational_expression IS
3956 } nullable_type_or_conditional
3958 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
3960 | relational_expression AS
3963 } nullable_type_or_conditional
3965 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
3970 : relational_expression
3971 | equality_expression OP_EQ relational_expression
3973 $$ = new Binary (Binary.Operator.Equality,
3974 (Expression) $1, (Expression) $3);
3976 | equality_expression OP_NE relational_expression
3978 $$ = new Binary (Binary.Operator.Inequality,
3979 (Expression) $1, (Expression) $3);
3984 : equality_expression
3985 | and_expression BITWISE_AND equality_expression
3987 $$ = new Binary (Binary.Operator.BitwiseAnd,
3988 (Expression) $1, (Expression) $3);
3992 exclusive_or_expression
3994 | exclusive_or_expression CARRET and_expression
3996 $$ = new Binary (Binary.Operator.ExclusiveOr,
3997 (Expression) $1, (Expression) $3);
4001 inclusive_or_expression
4002 : exclusive_or_expression
4003 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4005 $$ = new Binary (Binary.Operator.BitwiseOr,
4006 (Expression) $1, (Expression) $3);
4010 conditional_and_expression
4011 : inclusive_or_expression
4012 | conditional_and_expression OP_AND inclusive_or_expression
4014 $$ = new Binary (Binary.Operator.LogicalAnd,
4015 (Expression) $1, (Expression) $3);
4019 conditional_or_expression
4020 : conditional_and_expression
4021 | conditional_or_expression OP_OR conditional_and_expression
4023 $$ = new Binary (Binary.Operator.LogicalOr,
4024 (Expression) $1, (Expression) $3);
4028 conditional_expression
4029 : conditional_or_expression
4030 | conditional_or_expression INTERR expression COLON expression
4032 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
4034 | conditional_or_expression OP_COALESCING expression
4036 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
4038 // We'll be resolved into a `parenthesized_expression_0' later on.
4039 | conditional_or_expression INTERR CLOSE_PARENS
4041 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
4042 lexer.PutbackCloseParens ();
4046 assignment_expression
4047 : prefixed_unary_expression ASSIGN expression
4049 $$ = new Assign ((Expression) $1, (Expression) $3);
4051 | prefixed_unary_expression OP_MULT_ASSIGN expression
4053 $$ = new CompoundAssign (
4054 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4056 | prefixed_unary_expression OP_DIV_ASSIGN expression
4058 $$ = new CompoundAssign (
4059 Binary.Operator.Division, (Expression) $1, (Expression) $3);
4061 | prefixed_unary_expression OP_MOD_ASSIGN expression
4063 $$ = new CompoundAssign (
4064 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4066 | prefixed_unary_expression OP_ADD_ASSIGN expression
4068 $$ = new CompoundAssign (
4069 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4071 | prefixed_unary_expression OP_SUB_ASSIGN expression
4073 $$ = new CompoundAssign (
4074 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4076 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4078 $$ = new CompoundAssign (
4079 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4081 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4083 $$ = new CompoundAssign (
4084 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4086 | prefixed_unary_expression OP_AND_ASSIGN expression
4088 $$ = new CompoundAssign (
4089 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4091 | prefixed_unary_expression OP_OR_ASSIGN expression
4093 $$ = new CompoundAssign (
4094 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4096 | prefixed_unary_expression OP_XOR_ASSIGN expression
4098 $$ = new CompoundAssign (
4099 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4103 implicitly_typed_lambda_parameter_list
4105 LocatedToken lt = (LocatedToken) $1;
4106 ArrayList a = new ArrayList (4);
4108 a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
4111 | implicitly_typed_lambda_parameter_list COMMA IDENTIFIER {
4112 LocatedToken lt = (LocatedToken) $3;
4113 ArrayList a = (ArrayList) $1;
4114 a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
4119 explicitly_typed_lambda_parameter_list
4120 : explicitly_typed_lambda_parameter
4122 ArrayList pars = new ArrayList (4);
4127 | explicitly_typed_lambda_parameter_list COMMA explicitly_typed_lambda_parameter
4129 ArrayList pars = (ArrayList) $1;
4136 explicitly_typed_lambda_parameter
4137 : parameter_modifier type IDENTIFIER
4139 LocatedToken lt = (LocatedToken) $3;
4141 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4145 LocatedToken lt = (LocatedToken) $2;
4147 $$ = new Parameter ((Expression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4151 lambda_parameter_list
4152 : implicitly_typed_lambda_parameter_list { $$ = $1; }
4153 | explicitly_typed_lambda_parameter_list { $$ = $1; }
4156 opt_lambda_parameter_list
4157 : /* empty */ { $$ = null; }
4158 | lambda_parameter_list {
4159 ArrayList pars_list = (ArrayList) $1;
4161 Parameter [] pars = new Parameter [pars_list.Count];
4162 pars_list.CopyTo (pars);
4163 $$ = new Parameters (pars);
4167 lambda_expression_body
4169 start_block (lexer.Location);
4173 Block b = end_block (lexer.Location);
4174 b.AddStatement (new ContextualReturn ((Expression) $2));
4185 Parameter [] pars = new Parameter [1];
4186 LocatedToken lt = (LocatedToken) $1;
4187 pars [0] = new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4189 Parameters parameters = new Parameters (pars);
4191 start_anonymous (true, parameters, (Location) $2);
4193 lambda_expression_body
4195 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
4197 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4199 start_anonymous (true, (Parameters) $2, (Location) $4);
4201 lambda_expression_body
4203 $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
4208 : assignment_expression
4209 | non_assignment_expression
4212 non_assignment_expression
4213 : conditional_expression
4235 lexer.ConstraintsParsing = true;
4239 MemberName name = MakeName ((MemberName) $6);
4240 int mod_flags = (int) $2;
4242 push_current_class (new Class (
4243 current_namespace, current_class, name,
4244 mod_flags, (Attributes) $1), $3);
4247 opt_type_parameter_constraints_clauses
4249 lexer.ConstraintsParsing = false;
4252 if (current_class.Name == "System.Object") {
4253 Report.Error (537, current_class.Location,
4254 "The class System.Object cannot have a base " +
4255 "class or implement an interface.");
4257 current_container.AddBasesForPart (current_class, (ArrayList) $8);
4260 current_class.SetParameterInfo ((ArrayList) $9);
4262 if (RootContext.Documentation != null) {
4263 current_container.DocComment = Lexer.consume_doc_comment ();
4264 Lexer.doc_state = XmlCommentState.Allowed;
4269 if (RootContext.Documentation != null)
4270 Lexer.doc_state = XmlCommentState.Allowed;
4274 $$ = pop_current_class ();
4282 { $$ = $1; } // location
4286 : /* empty */ { $$ = (int) 0; }
4292 | modifiers modifier
4297 if ((m1 & m2) != 0) {
4298 Location l = lexer.Location;
4299 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4301 $$ = (int) (m1 | m2);
4306 : NEW { $$ = Modifiers.NEW; }
4307 | PUBLIC { $$ = Modifiers.PUBLIC; }
4308 | PROTECTED { $$ = Modifiers.PROTECTED; }
4309 | INTERNAL { $$ = Modifiers.INTERNAL; }
4310 | PRIVATE { $$ = Modifiers.PRIVATE; }
4311 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4312 | SEALED { $$ = Modifiers.SEALED; }
4313 | STATIC { $$ = Modifiers.STATIC; }
4314 | READONLY { $$ = Modifiers.READONLY; }
4315 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4316 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4317 | EXTERN { $$ = Modifiers.EXTERN; }
4318 | VOLATILE { $$ = Modifiers.VOLATILE; }
4319 | UNSAFE { $$ = Modifiers.UNSAFE; }
4323 : /* empty */ { $$ = null; }
4324 | class_base { $$ = $1; }
4328 : COLON type_list { $$ = $2; }
4331 opt_type_parameter_constraints_clauses
4332 : /* empty */ { $$ = null; }
4333 | type_parameter_constraints_clauses
4337 type_parameter_constraints_clauses
4338 : type_parameter_constraints_clause {
4339 ArrayList constraints = new ArrayList (1);
4340 constraints.Add ($1);
4343 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4344 ArrayList constraints = (ArrayList) $1;
4345 Constraints new_constraint = (Constraints)$2;
4347 foreach (Constraints c in constraints) {
4348 if (new_constraint.TypeParameter == c.TypeParameter) {
4349 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4350 new_constraint.TypeParameter);
4354 constraints.Add (new_constraint);
4359 type_parameter_constraints_clause
4360 : WHERE IDENTIFIER COLON type_parameter_constraints {
4361 LocatedToken lt = (LocatedToken) $2;
4362 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4366 type_parameter_constraints
4367 : type_parameter_constraint {
4368 ArrayList constraints = new ArrayList (1);
4369 constraints.Add ($1);
4372 | type_parameter_constraints COMMA type_parameter_constraint {
4373 ArrayList constraints = (ArrayList) $1;
4375 constraints.Add ($3);
4380 type_parameter_constraint
4382 | NEW OPEN_PARENS CLOSE_PARENS {
4383 $$ = SpecialConstraint.Constructor;
4386 $$ = SpecialConstraint.ReferenceType;
4389 $$ = SpecialConstraint.ValueType;
4398 // A block is "contained" on the following places:
4400 // property_declaration as part of the accessor body (get/set)
4401 // operator_declaration
4402 // constructor_declaration
4403 // destructor_declaration
4404 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4409 start_block ((Location) $1);
4411 opt_statement_list CLOSE_BRACE
4413 $$ = end_block ((Location) $4);
4419 opt_statement_list CLOSE_BRACE
4421 $$ = end_block ((Location) $3);
4432 | statement_list statement
4436 : declaration_statement
4438 if ($1 != null && (Block) $1 != current_block){
4439 current_block.AddStatement ((Statement) $1);
4440 current_block = (Block) $1;
4443 | valid_declaration_statement
4445 current_block.AddStatement ((Statement) $1);
4450 valid_declaration_statement
4453 | expression_statement
4454 | selection_statement
4455 | iteration_statement
4459 | unchecked_statement
4467 : valid_declaration_statement
4468 | declaration_statement
4470 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4475 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4483 $$ = EmptyStatement.Value;
4490 LocatedToken lt = (LocatedToken) $1;
4491 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4493 if (current_block.AddLabel (labeled))
4494 current_block.AddStatement (labeled);
4499 declaration_statement
4500 : local_variable_declaration SEMICOLON
4502 current_array_type = null;
4504 DictionaryEntry de = (DictionaryEntry) $1;
4505 Expression e = (Expression) de.Key;
4507 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4511 | local_constant_declaration SEMICOLON
4513 current_array_type = null;
4515 DictionaryEntry de = (DictionaryEntry) $1;
4517 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4523 * The following is from Rhys' grammar:
4524 * > Types in local variable declarations must be recognized as
4525 * > expressions to prevent reduce/reduce errors in the grammar.
4526 * > The expressions are converted into types during semantic analysis.
4529 : primary_expression opt_rank_specifier_or_nullable
4531 // FIXME: Do something smart here regarding the composition of the type.
4533 // Ok, the above "primary_expression" is there to get rid of
4534 // both reduce/reduce and shift/reduces in the grammar, it should
4535 // really just be "type_name". If you use type_name, a reduce/reduce
4536 // creeps up. If you use namespace_or_type_name (which is all we need
4537 // really) two shift/reduces appear.
4540 // So the super-trick is that primary_expression
4541 // can only be either a SimpleName or a MemberAccess.
4542 // The MemberAccess case arises when you have a fully qualified type-name like :
4544 // SimpleName is when you have
4547 Expression expr = (Expression) $1;
4548 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4549 Error_ExpectingTypeName (expr);
4553 // So we extract the string corresponding to the SimpleName
4557 if ((string) $2 == "")
4560 $$ = new ComposedCast ((Expression) $1, (string) $2);
4563 | builtin_types opt_rank_specifier_or_nullable
4565 if ((string) $2 == "")
4568 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4572 local_variable_pointer_type
4573 : primary_expression STAR
4575 Expression expr = (Expression) $1;
4577 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4578 Error_ExpectingTypeName (expr);
4582 $$ = new ComposedCast ((Expression) $1, "*");
4584 | builtin_types STAR
4586 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4590 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4592 | local_variable_pointer_type STAR
4594 $$ = new ComposedCast ((Expression) $1, "*");
4598 local_variable_declaration
4599 : local_variable_type variable_declarators
4602 $$ = new DictionaryEntry ($1, $2);
4606 | VAR variable_declarators
4608 $$ = new DictionaryEntry (new VarExpr (lexer.Location), $2);
4610 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4615 if ((string) $2 == "")
4616 t = (Expression) $1;
4618 t = new ComposedCast ((Expression) $1, (string) $2);
4619 $$ = new DictionaryEntry (t, $3);
4625 local_constant_declaration
4626 : CONST local_variable_type constant_declarators
4629 $$ = new DictionaryEntry ($2, $3);
4635 expression_statement
4636 : statement_expression SEMICOLON { $$ = $1; }
4640 // We have to do the wrapping here and not in the case above,
4641 // because statement_expression is used for example in for_statement
4643 statement_expression
4646 Expression expr = (Expression) $1;
4647 ExpressionStatement s = expr as ExpressionStatement;
4649 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
4652 $$ = new StatementExpression (s);
4656 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4661 object_creation_expression
4662 : object_or_delegate_creation_expression
4663 { note ("complain if this is a delegate maybe?"); }
4672 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4675 Location l = (Location) $1;
4677 $$ = new If ((Expression) $3, (Statement) $5, l);
4679 // FIXME: location for warning should be loc property of $5.
4680 if ($5 == EmptyStatement.Value)
4681 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4684 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4685 embedded_statement ELSE embedded_statement
4687 Location l = (Location) $1;
4689 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4691 // FIXME: location for warning should be loc property of $5 and $7.
4692 if ($5 == EmptyStatement.Value)
4693 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4694 if ($7 == EmptyStatement.Value)
4695 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4700 : SWITCH OPEN_PARENS
4702 if (switch_stack == null)
4703 switch_stack = new Stack (2);
4704 switch_stack.Push (current_block);
4706 expression CLOSE_PARENS
4709 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4710 current_block = (Block) switch_stack.Pop ();
4726 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4727 $$ = new ArrayList ();
4735 ArrayList sections = new ArrayList (4);
4740 | switch_sections switch_section
4742 ArrayList sections = (ArrayList) $1;
4752 current_block = current_block.CreateSwitchBlock (lexer.Location);
4756 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4763 ArrayList labels = new ArrayList (4);
4768 | switch_labels switch_label
4770 ArrayList labels = (ArrayList) ($1);
4778 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4779 | DEFAULT_COLON { $$ = new SwitchLabel (null, (Location) $1); }
4782 1523, GetLocation ($1),
4783 "The keyword case or default must precede code in switch block");
4795 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4797 Location l = (Location) $1;
4798 $$ = new While ((Expression) $3, (Statement) $5, l);
4803 : DO embedded_statement
4804 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4806 Location l = (Location) $1;
4808 $$ = new Do ((Statement) $2, (Expression) $5, l);
4814 opt_for_initializer SEMICOLON
4816 Location l = lexer.Location;
4818 Block assign_block = current_block;
4820 if ($3 is DictionaryEntry){
4821 DictionaryEntry de = (DictionaryEntry) $3;
4823 Expression type = (Expression) de.Key;
4824 ArrayList var_declarators = (ArrayList) de.Value;
4826 foreach (VariableDeclaration decl in var_declarators){
4830 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4834 Expression expr = decl.expression_or_array_initializer;
4836 LocalVariableReference var;
4837 var = new LocalVariableReference (assign_block, decl.identifier, l);
4840 Assign a = new Assign (var, expr, decl.Location);
4842 assign_block.AddStatement (new StatementExpression (a));
4846 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4847 // This can be referred to as $5 below.
4853 opt_for_condition SEMICOLON
4854 opt_for_iterator CLOSE_PARENS
4857 Location l = (Location) $1;
4859 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4861 current_block.AddStatement (f);
4863 $$ = end_block (lexer.Location);
4868 : /* empty */ { $$ = EmptyStatement.Value; }
4873 : local_variable_declaration
4874 | statement_expression_list
4878 : /* empty */ { $$ = null; }
4879 | boolean_expression
4883 : /* empty */ { $$ = EmptyStatement.Value; }
4888 : statement_expression_list
4891 statement_expression_list
4892 : statement_expression
4894 // CHANGE: was `null'
4895 Statement s = (Statement) $1;
4896 Block b = new Block (current_block, s.loc, lexer.Location);
4901 | statement_expression_list COMMA statement_expression
4903 Block b = (Block) $1;
4905 b.AddStatement ((Statement) $3);
4911 : FOREACH open_parens type IN expression CLOSE_PARENS
4913 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4916 | FOREACH open_parens type IDENTIFIER IN
4917 expression CLOSE_PARENS
4919 start_block (lexer.Location);
4920 Block foreach_block = current_block;
4922 LocatedToken lt = (LocatedToken) $4;
4923 Location l = lt.Location;
4926 vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4928 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4930 // Get a writable reference to this read-only variable.
4932 // Note that the $$ here refers to the value of _this_ code block,
4933 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4934 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4941 LocalVariableReference v = (LocalVariableReference) $8;
4942 Location l = (Location) $1;
4945 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4946 current_block.AddStatement (f);
4949 $$ = end_block (lexer.Location);
4955 | continue_statement
4965 $$ = new Break ((Location) $1);
4970 : CONTINUE SEMICOLON
4972 $$ = new Continue ((Location) $1);
4977 : GOTO IDENTIFIER SEMICOLON
4979 LocatedToken lt = (LocatedToken) $2;
4980 $$ = new Goto (lt.Value, lt.Location);
4982 | GOTO CASE constant_expression SEMICOLON
4984 $$ = new GotoCase ((Expression) $3, (Location) $1);
4986 | GOTO DEFAULT SEMICOLON
4988 $$ = new GotoDefault ((Location) $1);
4993 : RETURN opt_expression SEMICOLON
4995 $$ = new Return ((Expression) $2, (Location) $1);
5000 : THROW opt_expression SEMICOLON
5002 $$ = new Throw ((Expression) $2, (Location) $1);
5007 : IDENTIFIER RETURN expression SEMICOLON
5009 LocatedToken lt = (LocatedToken) $1;
5010 string s = lt.Value;
5012 Report.Error (1003, lt.Location, "; expected");
5015 if (RootContext.Version == LanguageVersion.ISO_1){
5016 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
5019 if (anonymous_host == null){
5020 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
5023 anonymous_host.SetYields ();
5024 $$ = new Yield ((Expression) $3, lt.Location);
5027 | IDENTIFIER RETURN SEMICOLON
5029 Report.Error (1627, (Location) $2, "Expression expected after yield return");
5032 | IDENTIFIER BREAK SEMICOLON
5034 LocatedToken lt = (LocatedToken) $1;
5035 string s = lt.Value;
5037 Report.Error (1003, lt.Location, "; expected");
5040 if (RootContext.Version == LanguageVersion.ISO_1){
5041 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
5044 if (anonymous_host == null){
5045 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
5048 anonymous_host.SetYields ();
5049 $$ = new YieldBreak (lt.Location);
5060 : TRY block catch_clauses
5064 ArrayList c = (ArrayList)$3;
5065 for (int i = 0; i < c.Count; ++i) {
5066 Catch cc = (Catch) c [i];
5068 if (i != c.Count - 1)
5069 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
5076 // Now s contains the list of specific catch clauses
5077 // and g contains the general one.
5079 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
5081 | TRY block opt_catch_clauses FINALLY block
5084 ArrayList s = new ArrayList (4);
5085 ArrayList catch_list = (ArrayList) $3;
5087 if (catch_list != null){
5088 foreach (Catch cc in catch_list) {
5096 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
5100 Report.Error (1524, (Location) $1, "Expected catch or finally");
5106 : /* empty */ { $$ = null; }
5113 ArrayList l = new ArrayList (4);
5118 | catch_clauses catch_clause
5120 ArrayList l = (ArrayList) $1;
5128 : /* empty */ { $$ = null; }
5133 : CATCH opt_catch_args
5135 Expression type = null;
5138 DictionaryEntry cc = (DictionaryEntry) $2;
5139 type = (Expression) cc.Key;
5140 LocatedToken lt = (LocatedToken) cc.Value;
5143 ArrayList one = new ArrayList (4);
5145 one.Add (new VariableDeclaration (lt, null));
5147 start_block (lexer.Location);
5148 current_block = declare_local_variables (type, one, lt.Location);
5152 Expression type = null;
5154 Block var_block = null;
5157 DictionaryEntry cc = (DictionaryEntry) $2;
5158 type = (Expression) cc.Key;
5159 LocatedToken lt = (LocatedToken) cc.Value;
5163 var_block = end_block (lexer.Location);
5167 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5172 : /* empty */ { $$ = null; }
5177 : open_parens type opt_identifier CLOSE_PARENS
5179 $$ = new DictionaryEntry ($2, $3);
5187 $$ = new Checked ((Block) $2);
5194 $$ = new Unchecked ((Block) $2);
5201 RootContext.CheckUnsafeOption ((Location) $1);
5203 $$ = new Unsafe ((Block) $3);
5209 type fixed_pointer_declarators
5212 ArrayList list = (ArrayList) $4;
5213 Expression type = (Expression) $3;
5214 Location l = (Location) $1;
5215 int top = list.Count;
5217 start_block (lexer.Location);
5218 Block assign_block = current_block;
5220 for (int i = 0; i < top; i++){
5221 Pair p = (Pair) list [i];
5224 v = current_block.AddVariable (type, (string) p.First, l);
5228 if (type is VarExpr)
5229 v.VariableType = typeof(VarExpr); // Kinda lame. Avoids a problem in the VariableMap ctor
5231 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5239 Location l = (Location) $1;
5241 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5243 current_block.AddStatement (f);
5245 $$ = end_block (lexer.Location);
5249 fixed_pointer_declarators
5250 : fixed_pointer_declarator {
5251 ArrayList declarators = new ArrayList (4);
5253 declarators.Add ($1);
5256 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5258 ArrayList declarators = (ArrayList) $1;
5260 declarators.Add ($3);
5265 fixed_pointer_declarator
5266 : IDENTIFIER ASSIGN expression
5268 LocatedToken lt = (LocatedToken) $1;
5269 // FIXME: keep location
5270 $$ = new Pair (lt.Value, $3);
5274 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5280 : LOCK OPEN_PARENS expression CLOSE_PARENS
5286 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5291 : USING open_parens resource_acquisition CLOSE_PARENS
5293 start_block (lexer.Location);
5294 Block assign_block = current_block;
5296 if ($3 is DictionaryEntry){
5297 DictionaryEntry de = (DictionaryEntry) $3;
5298 Location l = (Location) $1;
5300 Expression type = (Expression) de.Key;
5301 ArrayList var_declarators = (ArrayList) de.Value;
5303 ArrayList vars = new ArrayList (4);
5305 foreach (VariableDeclaration decl in var_declarators){
5307 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5310 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5312 Expression expr = decl.expression_or_array_initializer;
5314 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5317 LocalVariableReference var;
5319 // Get a writable reference to this read-only variable.
5320 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5322 // This is so that it is not a warning on using variables
5325 vars.Add (new DictionaryEntry (var, expr));
5327 // Assign a = new Assign (var, expr, decl.Location);
5328 // assign_block.AddStatement (new StatementExpression (a));
5331 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5332 // It can be referred to as $5 below.
5333 $$ = new DictionaryEntry (type, vars);
5340 Using u = new Using ($5, (Statement) $6, (Location) $1);
5341 current_block.AddStatement (u);
5342 $$ = end_block (lexer.Location);
5346 resource_acquisition
5347 : local_variable_declaration
5355 : from_clause query_body
5357 lexer.QueryParsing = false;
5358 $$ = new Linq.QueryExpression (current_container, current_block, (Expression)$1, (Linq.AQueryClause)$2);
5359 end_block (lexer.Location);
5364 : FROM IDENTIFIER IN expression opt_join_clauses
5366 start_block (lexer.Location);
5367 LocatedToken lt = (LocatedToken) $2;
5369 LocalInfo vi = current_block.AddVariable (TypeManager.system_object_expr, lt.Value, lt.Location); // TODO: null is var type
5371 $$ = new LocalVariableReference (current_block, lt.Value, lt.Location, vi, false);
5375 | FROM type IDENTIFIER IN expression opt_join_clauses
5377 start_block (lexer.Location);
5378 LocatedToken lt = (LocatedToken) $3;
5380 Expression type = (Expression)$2;
5381 LocalInfo vi = current_block.AddVariable (type, lt.Value, lt.Location);
5382 $$ = new Linq.Cast (type, (Expression)$5, lt.Location);
5393 | join_clauses join_clause
5397 : JOIN join_clause_body
5398 | JOIN join_clause_body INTO IDENTIFIER
5399 | JOIN type join_clause_body
5400 | JOIN type join_clause_body INTO IDENTIFIER
5404 : IDENTIFIER IN expression ON expression EQUALS expression
5408 : opt_from_let_where_clauses opt_orderby_clause SELECT expression opt_query_continuation
5410 Linq.AQueryClause ret = new Linq.Select ((Expression)$4, GetLocation ($3));
5413 ((Linq.AQueryClause)$1).Next = ret;
5414 ret = (Linq.AQueryClause)$1;
5419 | opt_from_let_where_clauses opt_orderby_clause group_clause opt_query_continuation
5422 opt_from_let_where_clauses
5424 | from_let_where_clauses
5427 from_let_where_clauses
5428 : from_let_where_clause
5429 | from_let_where_clauses from_let_where_clause
5432 from_let_where_clause
5439 : LET IDENTIFIER ASSIGN expression
5443 : WHERE boolean_expression
5445 $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
5460 | orderings COMMA ordering
5465 | expression ASCENDING
5466 | expression DESCENDING
5471 : GROUP expression BY expression
5474 opt_query_continuation
5476 | query_continuation
5480 : INTO IDENTIFIER opt_join_clauses query_body
5486 // A class used to pass around variable declarations and constants
5488 public class VariableDeclaration {
5489 public string identifier;
5490 public Expression expression_or_array_initializer;
5491 public Location Location;
5492 public Attributes OptAttributes;
5493 public string DocComment;
5495 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5497 this.identifier = lt.Value;
5498 if (eoai is ArrayList) {
5499 if (CSharpParser.current_array_type == null)
5500 Report.Error (622, lt.Location,
5501 "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
5502 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5504 this.expression_or_array_initializer = (Expression)eoai;
5506 this.Location = lt.Location;
5507 this.OptAttributes = opt_attrs;
5510 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5516 // A class used to hold info about an indexer declarator
5518 public class IndexerDeclaration {
5519 public Expression type;
5520 public MemberName interface_type;
5521 public Parameters param_list;
5522 public Location location;
5524 public IndexerDeclaration (Expression type, MemberName interface_type,
5525 Parameters param_list, Location loc)
5528 this.interface_type = interface_type;
5529 this.param_list = param_list;
5530 this.location = loc;
5535 // We use this when we do not have an object in advance that is an IAnonymousHost
5537 public class SimpleAnonymousHost : IAnonymousHost {
5538 public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
5541 ArrayList anonymous_methods;
5543 public static SimpleAnonymousHost GetSimple () {
5544 Simple.yields = false;
5545 Simple.anonymous_methods = null;
5549 public void SetYields ()
5554 public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
5556 if (anonymous_methods == null)
5557 anonymous_methods = new ArrayList ();
5558 anonymous_methods.Add (anonymous);
5561 public void Propagate (IAnonymousHost real_host)
5564 real_host.SetYields ();
5565 if (anonymous_methods != null) {
5566 foreach (AnonymousMethodExpression ame in anonymous_methods)
5567 real_host.AddAnonymousMethod (ame);
5573 // A class used to hold info about an operator declarator
5575 public class OperatorDeclaration {
5576 public Operator.OpType optype;
5577 public Expression ret_type, arg1type, arg2type;
5578 public string arg1name, arg2name;
5579 public Location location;
5581 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5582 Expression arg1type, string arg1name,
5583 Expression arg2type, string arg2name, Location location)
5586 this.ret_type = ret_type;
5587 this.arg1type = arg1type;
5588 this.arg1name = arg1name;
5589 this.arg2type = arg2type;
5590 this.arg2name = arg2name;
5591 this.location = location;
5596 void Error_ExpectingTypeName (Expression expr)
5598 if (expr is Invocation){
5599 Report.Error (1002, expr.Location, "Expecting `;'");
5601 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5605 public static void Error_ParameterModifierNotValid (Location loc)
5607 Report.Error (631, loc, "The modifiers `ref' and `out' are not valid in this context");
5610 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5612 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5613 Parameter.GetModifierSignature (mod));
5616 void push_current_class (TypeContainer tc, object partial_token)
5618 if (partial_token != null)
5619 current_container = current_container.AddPartial (tc);
5621 current_container = current_container.AddTypeContainer (tc);
5625 DeclSpace pop_current_class ()
5627 DeclSpace retval = current_class;
5629 current_class = current_class.Parent;
5630 current_container = current_class.PartialContainer;
5636 // Given the @class_name name, it creates a fully qualified name
5637 // based on the containing declaration space
5640 MakeName (MemberName class_name)
5642 Namespace ns = current_namespace.NS;
5644 if (current_container.Name.Length == 0){
5645 if (ns.Name.Length != 0)
5646 return new MemberName (ns.MemberName, class_name);
5650 return new MemberName (current_container.MemberName, class_name);
5654 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5656 Block implicit_block;
5657 ArrayList inits = null;
5660 // We use the `Used' property to check whether statements
5661 // have been added to the current block. If so, we need
5662 // to create another block to contain the new declaration
5663 // otherwise, as an optimization, we use the same block to
5664 // add the declaration.
5666 // FIXME: A further optimization is to check if the statements
5667 // that were added were added as part of the initialization
5668 // below. In which case, no other statements have been executed
5669 // and we might be able to reduce the number of blocks for
5670 // situations like this:
5672 // int j = 1; int k = j + 1;
5674 if (current_block.Used)
5675 implicit_block = new Block (current_block, loc, Location.Null);
5677 implicit_block = current_block;
5679 foreach (VariableDeclaration decl in variable_declarators){
5681 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5682 if (decl.expression_or_array_initializer != null){
5684 inits = new ArrayList (4);
5691 return implicit_block;
5693 foreach (VariableDeclaration decl in inits){
5695 Expression expr = decl.expression_or_array_initializer;
5697 LocalVariableReference var;
5698 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5700 assign = new Assign (var, expr, decl.Location);
5702 implicit_block.AddStatement (new StatementExpression (assign));
5705 return implicit_block;
5708 Block declare_local_constants (Expression type, ArrayList declarators)
5710 Block implicit_block;
5712 if (current_block.Used)
5713 implicit_block = new Block (current_block);
5715 implicit_block = current_block;
5717 foreach (VariableDeclaration decl in declarators){
5718 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5721 return implicit_block;
5724 string CheckAttributeTarget (string a, Location l)
5727 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5731 Report.Warning (658, 1, l,
5732 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5733 return string.Empty;
5736 void CheckUnaryOperator (Operator.OpType op, Location l)
5740 case Operator.OpType.LogicalNot:
5741 case Operator.OpType.OnesComplement:
5742 case Operator.OpType.Increment:
5743 case Operator.OpType.Decrement:
5744 case Operator.OpType.True:
5745 case Operator.OpType.False:
5746 case Operator.OpType.Addition:
5747 case Operator.OpType.Subtraction:
5752 Report.Error (1019, l, "Overloadable unary operator expected");
5758 void CheckBinaryOperator (Operator.OpType op, Location l)
5762 case Operator.OpType.Addition:
5763 case Operator.OpType.Subtraction:
5764 case Operator.OpType.Multiply:
5765 case Operator.OpType.Division:
5766 case Operator.OpType.Modulus:
5767 case Operator.OpType.BitwiseAnd:
5768 case Operator.OpType.BitwiseOr:
5769 case Operator.OpType.ExclusiveOr:
5770 case Operator.OpType.LeftShift:
5771 case Operator.OpType.RightShift:
5772 case Operator.OpType.Equality:
5773 case Operator.OpType.Inequality:
5774 case Operator.OpType.GreaterThan:
5775 case Operator.OpType.LessThan:
5776 case Operator.OpType.GreaterThanOrEqual:
5777 case Operator.OpType.LessThanOrEqual:
5781 Report.Error (1020, l, "Overloadable binary operator expected");
5787 void syntax_error (Location l, string msg)
5789 Report.Error (1003, l, "Syntax error, " + msg);
5792 void note (string s)
5794 // Used to put annotations
5799 public Tokenizer Lexer {
5805 static CSharpParser ()
5807 oob_stack = new Stack ();
5810 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5812 this.name = file.Name;
5814 current_namespace = new NamespaceEntry (null, file, null);
5815 current_class = current_namespace.SlaveDeclSpace;
5816 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5818 lexer = new Tokenizer (reader, file, defines);
5821 public void parse ()
5823 int errors = Report.Errors;
5825 if (yacc_verbose_flag > 1)
5826 yyparse (lexer, new yydebug.yyDebugSimple ());
5829 Tokenizer tokenizer = lexer as Tokenizer;
5830 tokenizer.cleanup ();
5831 } catch (Exception e){
5833 // Removed for production use, use parser verbose to get the output.
5835 // Console.WriteLine (e);
5836 if (Report.Errors == errors)
5837 Report.Error (-25, lexer.Location, "Parsing error");
5838 if (yacc_verbose_flag > 0)
5839 Console.WriteLine (e);
5842 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5843 throw new InternalErrorException ("who set it?");
5846 static void CheckToken (int error, int yyToken, string msg, Location loc)
5848 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5849 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5851 Report.Error (error, loc, msg);
5854 void CheckIdentifierToken (int yyToken, Location loc)
5856 CheckToken (1041, yyToken, "Identifier expected", loc);
5859 string ConsumeStoredComment ()
5861 string s = tmpComment;
5863 Lexer.doc_state = XmlCommentState.Allowed;
5867 Location GetLocation (object obj)
5869 if (obj is MemberCore)
5870 return ((MemberCore) obj).Location;
5871 if (obj is MemberName)
5872 return ((MemberName) obj).Location;
5873 if (obj is LocatedToken)
5874 return ((LocatedToken) obj).Location;
5875 if (obj is Location)
5876 return (Location) obj;
5877 return lexer.Location;
5881 start_block (Location loc)
5883 if (current_block == null || parsing_anonymous_method) {
5884 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
5885 parsing_anonymous_method = false;
5887 current_block = new ExplicitBlock (current_block, loc, Location.Null);
5892 end_block (Location loc)
5894 Block retval = current_block.Explicit;
5895 retval.SetEndLocation (loc);
5896 current_block = retval.Parent;
5901 start_anonymous (bool lambda, Parameters parameters, Location loc)
5903 oob_stack.Push (current_anonymous_method);
5904 oob_stack.Push (current_local_parameters);
5906 current_local_parameters = parameters;
5908 ToplevelBlock top_current_block = current_block == null ? null : current_block.Toplevel;
5910 current_anonymous_method = lambda
5911 ? new LambdaExpression (
5912 current_anonymous_method, current_generic_method, current_container,
5913 parameters, top_current_block, loc)
5914 : new AnonymousMethodExpression (
5915 current_anonymous_method, current_generic_method, current_container,
5916 parameters, top_current_block, loc);
5918 // Force the next block to be created as a ToplevelBlock
5919 parsing_anonymous_method = true;
5923 * Completes the anonymous method processing, if lambda_expr is null, this
5924 * means that we have a Statement instead of an Expression embedded
5926 AnonymousMethodExpression
5927 end_anonymous (ToplevelBlock anon_block, Location loc)
5929 AnonymousMethodExpression retval;
5931 if (RootContext.Version == LanguageVersion.ISO_1){
5932 Report.FeatureIsNotISO1 (loc, "anonymous methods");
5935 current_anonymous_method.Block = anon_block;
5936 if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
5937 anonymous_host.AddAnonymousMethod (current_anonymous_method);
5939 retval = current_anonymous_method;
5942 current_local_parameters = (Parameters) oob_stack.Pop ();
5943 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();