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 */
230 /* C# single character operators/punctuation. */
231 %token OPEN_BRACE "{"
232 %token CLOSE_BRACE "}"
233 %token OPEN_BRACKET "["
234 %token CLOSE_BRACKET "]"
235 %token OPEN_PARENS "("
236 %token CLOSE_PARENS ")"
248 %token OP_GENERICS_LT "<"
250 %token OP_GENERICS_GT ">"
251 %token BITWISE_AND "&"
252 %token BITWISE_OR "|"
259 /* C# multi-character operators. */
260 %token DOUBLE_COLON "::"
263 %token OP_SHIFT_LEFT "<<"
264 %token OP_SHIFT_RIGHT ">>"
271 %token OP_MULT_ASSIGN "*="
272 %token OP_DIV_ASSIGN "/="
273 %token OP_MOD_ASSIGN "%="
274 %token OP_ADD_ASSIGN "+="
275 %token OP_SUB_ASSIGN "-="
276 %token OP_SHIFT_LEFT_ASSIGN "<<="
277 %token OP_SHIFT_RIGHT_ASSIGN ">>="
278 %token OP_AND_ASSIGN "&="
279 %token OP_XOR_ASSIGN "^="
280 %token OP_OR_ASSIGN "|="
282 %token OP_COALESCING "??"
285 %token LITERAL_INTEGER "int literal"
286 %token LITERAL_FLOAT "float literal"
287 %token LITERAL_DOUBLE "double literal"
288 %token LITERAL_DECIMAL "decimal literal"
289 %token LITERAL_CHARACTER "character literal"
290 %token LITERAL_STRING "string literal"
293 %token OPEN_PARENS_LAMBDA
294 %token CLOSE_PARENS_CAST
295 %token CLOSE_PARENS_NO_CAST
296 %token CLOSE_PARENS_OPEN_PARENS
297 %token CLOSE_PARENS_MINUS
298 %token DEFAULT_OPEN_PARENS
299 %token GENERIC_DIMENSION
302 /* Add precedence rules to solve dangling else s/r conflict */
311 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
313 %left STAR DIV PERCENT
314 %right BANG CARRET UMINUS
315 %nonassoc OP_INC OP_DEC
317 %left OPEN_BRACKET OPEN_BRACE
321 %start compilation_unit
325 : outer_declarations opt_EOF
326 | outer_declarations global_attributes opt_EOF
327 | global_attributes opt_EOF
328 | opt_EOF /* allow empty files */
334 Lexer.check_incorrect_doc_comment ();
338 Lexer.check_incorrect_doc_comment ();
344 | outer_declarations outer_declaration
348 : extern_alias_directive
350 | namespace_member_declaration
353 extern_alias_directives
354 : extern_alias_directive
355 | extern_alias_directives extern_alias_directive;
357 extern_alias_directive
358 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
360 LocatedToken lt = (LocatedToken) $2;
363 Report.Error (1003, lt.Location, "'alias' expected");
364 } else if (RootContext.Version == LanguageVersion.ISO_1) {
365 Report.FeatureIsNotISO1 (lt.Location, "external alias");
367 lt = (LocatedToken) $3;
368 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
375 | using_directives using_directive
379 : using_alias_directive
381 if (RootContext.Documentation != null)
382 Lexer.doc_state = XmlCommentState.Allowed;
384 | using_namespace_directive
386 if (RootContext.Documentation != null)
387 Lexer.doc_state = XmlCommentState.Allowed;
391 using_alias_directive
392 : USING IDENTIFIER ASSIGN
393 namespace_or_type_name SEMICOLON
395 LocatedToken lt = (LocatedToken) $2;
396 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
399 CheckIdentifierToken (yyToken, GetLocation ($2));
403 using_namespace_directive
404 : USING namespace_name SEMICOLON
406 current_namespace.Using ((MemberName) $2, (Location) $1);
411 // Strictly speaking, namespaces don't have attributes but
412 // we parse global attributes along with namespace declarations and then
415 namespace_declaration
416 : opt_attributes NAMESPACE namespace_or_type_name
418 MemberName name = (MemberName) $3;
421 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
424 if (name.TypeArguments != null)
425 syntax_error (lexer.Location, "namespace name expected");
427 current_namespace = new NamespaceEntry (
428 current_namespace, file, name.GetName ());
429 current_class = current_namespace.SlaveDeclSpace;
430 current_container = current_class.PartialContainer;
432 namespace_body opt_semicolon
434 current_namespace = current_namespace.Parent;
435 current_class = current_namespace.SlaveDeclSpace;
436 current_container = current_class.PartialContainer;
451 : namespace_or_type_name {
452 MemberName name = (MemberName) $1;
454 if (name.TypeArguments != null)
455 syntax_error (lexer.Location, "namespace name expected");
464 if (RootContext.Documentation != null)
465 Lexer.doc_state = XmlCommentState.Allowed;
471 : opt_extern_alias_directives
473 opt_namespace_member_declarations
477 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
480 | opt_extern_alias_directives
482 opt_namespace_member_declarations
485 Report.Error (1513, lexer.Location, "} expected");
494 opt_extern_alias_directives
496 | extern_alias_directives
499 opt_namespace_member_declarations
501 | namespace_member_declarations
504 namespace_member_declarations
505 : namespace_member_declaration
506 | namespace_member_declarations namespace_member_declaration
509 namespace_member_declaration
513 DeclSpace ds = (DeclSpace)$1;
515 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
516 Report.Error (1527, ds.Location,
517 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
520 current_namespace.DeclarationFound = true;
522 | namespace_declaration {
523 current_namespace.DeclarationFound = true;
526 | field_declaration {
527 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
529 | method_declaration {
530 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
537 | interface_declaration
539 | delegate_declaration
541 // Enable this when we have handled all errors, because this acts as a generic fallback
544 // Console.WriteLine ("Token=" + yyToken);
545 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
557 Attributes attrs = (Attributes)$1;
558 if (global_attrs_enabled) {
559 CodeGen.Assembly.AddAttributes (attrs.Attrs);
561 foreach (Attribute a in attrs.Attrs) {
562 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
573 global_attrs_enabled = false;
578 global_attrs_enabled = false;
587 if (current_attr_target != String.Empty) {
588 ArrayList sect = (ArrayList) $1;
590 if (global_attrs_enabled) {
591 if (current_attr_target == "module") {
592 CodeGen.Module.AddAttributes (sect);
594 } else if (current_attr_target != null && current_attr_target.Length > 0) {
595 CodeGen.Assembly.AddAttributes (sect);
598 $$ = new Attributes (sect);
601 if (RootContext.Documentation != null) {
602 Lexer.check_incorrect_doc_comment ();
604 XmlCommentState.Allowed;
608 $$ = new Attributes (sect);
613 current_attr_target = null;
615 | attribute_sections attribute_section
617 if (current_attr_target != String.Empty) {
618 Attributes attrs = $1 as Attributes;
619 ArrayList sect = (ArrayList) $2;
621 if (global_attrs_enabled) {
622 if (current_attr_target == "module") {
623 CodeGen.Module.AddAttributes (sect);
625 } else if (current_attr_target == "assembly") {
626 CodeGen.Assembly.AddAttributes (sect);
630 attrs = new Attributes (sect);
632 attrs.AddAttributes (sect);
636 attrs = new Attributes (sect);
638 attrs.AddAttributes (sect);
644 current_attr_target = null;
649 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
653 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
659 attribute_target_specifier
660 : attribute_target COLON
662 current_attr_target = (string)$1;
670 LocatedToken lt = (LocatedToken) $1;
671 $$ = CheckAttributeTarget (lt.Value, lt.Location);
673 | EVENT { $$ = "event"; }
674 | RETURN { $$ = "return"; }
677 string name = yyNames [yyToken].ToLower ();
678 $$ = CheckAttributeTarget (name, GetLocation ($1));
685 ArrayList attrs = new ArrayList (4);
691 | attribute_list COMMA attribute
693 ArrayList attrs = (ArrayList) $1;
701 : attribute_name opt_attribute_arguments
703 MemberName mname = (MemberName) $1;
704 if (mname.IsGeneric) {
705 Report.Error (404, lexer.Location,
706 "'<' unexpected: attributes cannot be generic");
709 object [] arguments = (object []) $2;
710 MemberName left = mname.Left;
711 string identifier = mname.Name;
713 Expression left_expr = left == null ? null : left.GetTypeExpression ();
715 if (current_attr_target == String.Empty)
717 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
718 // FIXME: supply "nameEscaped" parameter here.
719 $$ = new GlobalAttribute (current_namespace, current_attr_target,
720 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
722 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
727 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
730 opt_attribute_arguments
731 : /* empty */ { $$ = null; }
732 | OPEN_PARENS attribute_arguments CLOSE_PARENS
740 : opt_positional_argument_list
745 $$ = new object [] { $1, null };
748 | positional_argument_list COMMA named_argument_list
750 $$ = new object[] { $1, $3 };
752 | named_argument_list
754 $$ = new object [] { null, $1 };
759 opt_positional_argument_list
760 : /* empty */ { $$ = null; }
761 | positional_argument_list
764 positional_argument_list
767 ArrayList args = new ArrayList (4);
768 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
772 | positional_argument_list COMMA expression
774 ArrayList args = (ArrayList) $1;
775 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
784 ArrayList args = new ArrayList (4);
789 | named_argument_list COMMA named_argument
791 ArrayList args = (ArrayList) $1;
796 | named_argument_list COMMA expression
798 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
804 : IDENTIFIER ASSIGN expression
806 // FIXME: keep location
807 $$ = new DictionaryEntry (
808 ((LocatedToken) $1).Value,
809 new Argument ((Expression) $3, Argument.AType.Expression));
815 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
818 opt_class_member_declarations
820 | class_member_declarations
823 class_member_declarations
824 : class_member_declaration
825 | class_member_declarations
826 class_member_declaration
829 class_member_declaration
830 : constant_declaration // done
831 | field_declaration // done
832 | method_declaration // done
833 | property_declaration // done
834 | event_declaration // done
835 | indexer_declaration // done
836 | operator_declaration // done
837 | constructor_declaration // done
838 | destructor_declaration // done
848 lexer.ConstraintsParsing = true;
852 MemberName name = MakeName ((MemberName) $6);
853 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
856 opt_type_parameter_constraints_clauses
858 lexer.ConstraintsParsing = false;
860 current_class.SetParameterInfo ((ArrayList) $9);
862 if (RootContext.Documentation != null)
863 current_container.DocComment = Lexer.consume_doc_comment ();
867 if (RootContext.Documentation != null)
868 Lexer.doc_state = XmlCommentState.Allowed;
872 $$ = pop_current_class ();
874 | opt_attributes opt_modifiers opt_partial STRUCT error {
875 CheckIdentifierToken (yyToken, GetLocation ($5));
882 if (RootContext.Documentation != null)
883 Lexer.doc_state = XmlCommentState.Allowed;
885 opt_struct_member_declarations CLOSE_BRACE
888 opt_struct_member_declarations
890 | struct_member_declarations
893 struct_member_declarations
894 : struct_member_declaration
895 | struct_member_declarations struct_member_declaration
898 struct_member_declaration
899 : constant_declaration
902 | property_declaration
904 | indexer_declaration
905 | operator_declaration
906 | constructor_declaration
910 * This is only included so we can flag error 575:
911 * destructors only allowed on class types
913 | destructor_declaration
924 int modflags = (int) $2;
925 foreach (VariableDeclaration constant in (ArrayList) $5){
926 Location l = constant.Location;
927 if ((modflags & Modifiers.STATIC) != 0) {
928 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
932 Const c = new Const (
933 current_class, (Expression) $4, (string) constant.identifier,
934 (Expression) constant.expression_or_array_initializer, modflags,
937 if (RootContext.Documentation != null) {
938 c.DocComment = Lexer.consume_doc_comment ();
939 Lexer.doc_state = XmlCommentState.Allowed;
941 current_container.AddConstant (c);
947 : constant_declarator
949 ArrayList constants = new ArrayList (4);
954 | constant_declarators COMMA constant_declarator
957 ArrayList constants = (ArrayList) $1;
964 : IDENTIFIER ASSIGN constant_expression
966 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
970 // A const field requires a value to be provided
971 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
983 Expression type = (Expression) $3;
986 current_array_type = null;
988 foreach (VariableDeclaration var in (ArrayList) $4){
989 Field field = new Field (current_class, type, mod, var.identifier,
990 (Attributes) $1, var.Location);
992 field.Initializer = var.expression_or_array_initializer;
994 if (RootContext.Documentation != null) {
995 field.DocComment = Lexer.consume_doc_comment ();
996 Lexer.doc_state = XmlCommentState.Allowed;
998 current_container.AddField (field);
999 $$ = field; // FIXME: might be better if it points to the top item
1006 fixed_variable_declarators
1009 Expression type = (Expression) $4;
1012 current_array_type = null;
1014 foreach (VariableDeclaration var in (ArrayList) $5) {
1015 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1016 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1018 if (RootContext.Documentation != null) {
1019 field.DocComment = Lexer.consume_doc_comment ();
1020 Lexer.doc_state = XmlCommentState.Allowed;
1022 current_container.AddField (field);
1023 $$ = field; // FIXME: might be better if it points to the top item
1032 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1037 variable_declarators
1039 current_array_type = null;
1040 Report.Error (670, (Location) $3, "Fields cannot have void type");
1044 fixed_variable_declarators
1045 : fixed_variable_declarator
1047 ArrayList decl = new ArrayList (2);
1051 | fixed_variable_declarators COMMA fixed_variable_declarator
1053 ArrayList decls = (ArrayList) $1;
1059 fixed_variable_declarator
1060 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1062 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1064 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1066 Report.Error (443, lexer.Location, "Value or constant expected");
1067 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1071 variable_declarators
1072 : variable_declarator
1074 ArrayList decl = new ArrayList (4);
1079 | variable_declarators COMMA variable_declarator
1081 ArrayList decls = (ArrayList) $1;
1088 : IDENTIFIER ASSIGN variable_initializer
1090 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1094 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1096 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1098 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1099 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1104 variable_initializer
1113 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1115 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1119 $$ = new ArglistAccess ((Location) $1);
1123 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1130 anonymous_host = (IAnonymousHost) $1;
1131 if (RootContext.Documentation != null)
1132 Lexer.doc_state = XmlCommentState.NotAllowed;
1136 Method method = (Method) $1;
1137 method.Block = (ToplevelBlock) $3;
1138 current_container.AddMethod (method);
1140 anonymous_host = null;
1141 current_generic_method = null;
1142 current_local_parameters = null;
1144 if (RootContext.Documentation != null)
1145 Lexer.doc_state = XmlCommentState.Allowed;
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
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 ();
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 member_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) $7, (Attributes) $1);
1269 current_local_parameters = (Parameters) $7;
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; }
1454 if (RootContext.Version <= LanguageVersion.ISO_2)
1455 Report.FeatureIsNotISO1 (GetLocation ($1), "extension methods");
1456 $$ = Parameter.Modifier.This;
1461 : opt_attributes PARAMS type IDENTIFIER
1463 LocatedToken lt = (LocatedToken) $4;
1464 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1466 | opt_attributes PARAMS PARAMS type IDENTIFIER
1468 Error_DuplicateParameterModifier (lexer.Location, Parameter.Modifier.PARAMS);
1471 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1473 Parameter.Modifier mod = (Parameter.Modifier)$3;
1474 if ((mod & Parameter.Modifier.This) != 0) {
1475 Report.Error (1104, lexer.Location, "The parameter modifiers `this' and `params' cannot be used altogether");
1477 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1481 | opt_attributes PARAMS type error {
1482 CheckIdentifierToken (yyToken, GetLocation ($4));
1487 property_declaration
1491 namespace_or_type_name
1493 if (RootContext.Documentation != null)
1494 tmpComment = Lexer.consume_doc_comment ();
1498 implicit_value_parameter_type = (Expression) $3;
1500 lexer.PropertyParsing = true;
1502 accessor_declarations
1504 lexer.PropertyParsing = false;
1505 has_get = has_set = false;
1513 Accessors accessors = (Accessors) $8;
1514 Accessor get_block = accessors.get_or_add;
1515 Accessor set_block = accessors.set_or_remove;
1517 MemberName name = (MemberName) $4;
1519 if (name.TypeArguments != null)
1520 syntax_error (lexer.Location, "a property can't have type arguments");
1522 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1523 name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse, current_block);
1525 current_container.AddProperty (prop);
1526 implicit_value_parameter_type = null;
1528 if (RootContext.Documentation != null)
1529 prop.DocComment = ConsumeStoredComment ();
1534 accessor_declarations
1535 : get_accessor_declaration
1537 $$ = new Accessors ((Accessor) $1, null);
1539 | get_accessor_declaration accessor_declarations
1541 Accessors accessors = (Accessors) $2;
1542 accessors.get_or_add = (Accessor) $1;
1545 | set_accessor_declaration
1547 $$ = new Accessors (null, (Accessor) $1);
1549 | set_accessor_declaration accessor_declarations
1551 Accessors accessors = (Accessors) $2;
1552 accessors.set_or_remove = (Accessor) $1;
1553 accessors.declared_in_reverse = true;
1558 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1563 get_accessor_declaration
1564 : opt_attributes opt_modifiers GET
1566 // If this is not the case, then current_local_parameters has already
1567 // been set in indexer_declaration
1568 if (parsing_indexer == false)
1569 current_local_parameters = null;
1571 current_local_parameters = indexer_parameters;
1572 lexer.PropertyParsing = false;
1574 anonymous_host = SimpleAnonymousHost.GetSimple ();
1579 Report.Error (1007, (Location) $3, "Property accessor already defined");
1582 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1584 current_local_parameters = null;
1585 lexer.PropertyParsing = true;
1587 SimpleAnonymousHost.Simple.Propagate (accessor);
1588 anonymous_host = null;
1590 if (RootContext.Documentation != null)
1591 if (Lexer.doc_state == XmlCommentState.Error)
1592 Lexer.doc_state = XmlCommentState.NotAllowed;
1598 set_accessor_declaration
1599 : opt_attributes opt_modifiers SET
1602 Parameter implicit_value_parameter = new Parameter (
1603 implicit_value_parameter_type, "value",
1604 Parameter.Modifier.NONE, null, (Location) $3);
1606 if (parsing_indexer == false) {
1607 args = new Parameter [1];
1608 args [0] = implicit_value_parameter;
1609 current_local_parameters = new Parameters (args);
1611 Parameter [] fpars = indexer_parameters.FixedParameters;
1614 int count = fpars.Length;
1616 args = new Parameter [count + 1];
1617 fpars.CopyTo (args, 0);
1618 args [count] = implicit_value_parameter;
1621 current_local_parameters = new Parameters (
1625 lexer.PropertyParsing = false;
1627 anonymous_host = SimpleAnonymousHost.GetSimple ();
1632 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1635 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1637 current_local_parameters = null;
1638 lexer.PropertyParsing = true;
1640 SimpleAnonymousHost.Simple.Propagate (accessor);
1641 anonymous_host = null;
1643 if (RootContext.Documentation != null
1644 && Lexer.doc_state == XmlCommentState.Error)
1645 Lexer.doc_state = XmlCommentState.NotAllowed;
1653 | SEMICOLON { $$ = null; }
1656 interface_declaration
1662 lexer.ConstraintsParsing = true;
1666 MemberName name = MakeName ((MemberName) $6);
1667 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1670 opt_type_parameter_constraints_clauses
1672 lexer.ConstraintsParsing = false;
1674 current_class.SetParameterInfo ((ArrayList) $9);
1676 if (RootContext.Documentation != null) {
1677 current_container.DocComment = Lexer.consume_doc_comment ();
1678 Lexer.doc_state = XmlCommentState.Allowed;
1683 if (RootContext.Documentation != null)
1684 Lexer.doc_state = XmlCommentState.Allowed;
1688 $$ = pop_current_class ();
1690 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1691 CheckIdentifierToken (yyToken, GetLocation ($5));
1697 opt_interface_member_declarations
1701 opt_interface_member_declarations
1703 | interface_member_declarations
1706 interface_member_declarations
1707 : interface_member_declaration
1708 | interface_member_declarations interface_member_declaration
1711 interface_member_declaration
1712 : interface_method_declaration
1717 Method m = (Method) $1;
1719 if (m.IsExplicitImpl)
1720 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1721 m.GetSignatureForError ());
1723 current_container.AddMethod (m);
1725 if (RootContext.Documentation != null)
1726 Lexer.doc_state = XmlCommentState.Allowed;
1728 | interface_property_declaration
1733 Property p = (Property) $1;
1735 if (p.IsExplicitImpl)
1736 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1737 p.GetSignatureForError ());
1739 current_container.AddProperty (p);
1741 if (RootContext.Documentation != null)
1742 Lexer.doc_state = XmlCommentState.Allowed;
1744 | interface_event_declaration
1747 Event e = (Event) $1;
1749 if (e.IsExplicitImpl)
1750 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1751 e.GetSignatureForError ());
1753 current_container.AddEvent (e);
1756 if (RootContext.Documentation != null)
1757 Lexer.doc_state = XmlCommentState.Allowed;
1759 | interface_indexer_declaration
1764 Indexer i = (Indexer) $1;
1766 if (i.IsExplicitImpl)
1767 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1768 i.GetSignatureForError ());
1770 current_container.AddIndexer (i);
1772 if (RootContext.Documentation != null)
1773 Lexer.doc_state = XmlCommentState.Allowed;
1775 | delegate_declaration
1778 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1779 ((MemberCore)$1).GetSignatureForError ());
1785 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1786 ((MemberCore)$1).GetSignatureForError ());
1789 | struct_declaration
1792 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1793 ((MemberCore)$1).GetSignatureForError ());
1799 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1800 ((MemberCore)$1).GetSignatureForError ());
1803 | interface_declaration
1806 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1807 ((MemberCore)$1).GetSignatureForError ());
1810 | constant_declaration
1812 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1820 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1825 interface_method_declaration_body
1828 lexer.ConstraintsParsing = false;
1830 opt_statement_list CLOSE_BRACE
1832 Report.Error (531, lexer.Location,
1833 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1839 interface_method_declaration
1840 : opt_attributes opt_new type namespace_or_type_name
1841 open_parens opt_formal_parameter_list CLOSE_PARENS
1843 lexer.ConstraintsParsing = true;
1845 opt_type_parameter_constraints_clauses
1847 // Refer to the name as $-1 in interface_method_declaration_body
1850 interface_method_declaration_body
1852 lexer.ConstraintsParsing = false;
1854 MemberName name = (MemberName) $4;
1856 if ($9 != null && name.TypeArguments == null)
1857 Report.Error (80, lexer.Location,
1858 "Constraints are not allowed on non-generic declarations");
1860 GenericMethod generic = null;
1861 if (name.TypeArguments != null) {
1862 generic = new GenericMethod (current_namespace, current_class, name,
1863 (Expression) $3, (Parameters) $6);
1865 generic.SetParameterInfo ((ArrayList) $9);
1868 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1869 (Parameters) $6, (Attributes) $1);
1870 if (RootContext.Documentation != null)
1871 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1873 | opt_attributes opt_new VOID namespace_or_type_name
1874 open_parens opt_formal_parameter_list CLOSE_PARENS
1876 lexer.ConstraintsParsing = true;
1878 opt_type_parameter_constraints_clauses
1882 interface_method_declaration_body
1884 lexer.ConstraintsParsing = false;
1886 MemberName name = (MemberName) $4;
1888 if ($9 != null && name.TypeArguments == null)
1889 Report.Error (80, lexer.Location,
1890 "Constraints are not allowed on non-generic declarations");
1892 GenericMethod generic = null;
1893 if (name.TypeArguments != null) {
1894 generic = new GenericMethod (current_namespace, current_class, name,
1895 TypeManager.system_void_expr, (Parameters) $6);
1897 generic.SetParameterInfo ((ArrayList) $9);
1900 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1901 true, name, (Parameters) $6, (Attributes) $1);
1902 if (RootContext.Documentation != null)
1903 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1907 interface_property_declaration
1913 lexer.PropertyParsing = true;
1914 implicit_value_parameter_type = (Expression)$3;
1916 accessor_declarations
1918 has_get = has_set = false;
1919 lexer.PropertyParsing = false;
1920 implicit_value_parameter_type = null;
1924 LocatedToken lt = (LocatedToken) $4;
1925 MemberName name = new MemberName (lt.Value, lt.Location);
1927 if ($3 == TypeManager.system_void_expr) {
1928 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1934 p = new Property (current_class, (Expression) $3, (int) $2, true,
1935 name, (Attributes) $1,
1938 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1942 Accessors accessor = (Accessors) $7;
1943 p = new Property (current_class, (Expression) $3, (int) $2, true,
1944 name, (Attributes) $1,
1945 accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
1947 if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
1948 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1953 if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
1954 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1959 if (RootContext.Documentation != null)
1960 p.DocComment = Lexer.consume_doc_comment ();
1967 CheckIdentifierToken (yyToken, GetLocation ($4));
1973 interface_event_declaration
1974 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1976 LocatedToken lt = (LocatedToken) $5;
1977 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1978 new MemberName (lt.Value, lt.Location),
1980 if (RootContext.Documentation != null)
1981 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1983 | opt_attributes opt_new EVENT type error {
1984 CheckIdentifierToken (yyToken, GetLocation ($5));
1987 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1988 LocatedToken lt = (LocatedToken) $5;
1989 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1992 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1994 implicit_value_parameter_type = (Expression) $4;
1995 lexer.EventParsing = true;
1997 event_accessor_declarations
1999 lexer.EventParsing = false;
2000 implicit_value_parameter_type = null;
2003 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2008 interface_indexer_declaration
2009 : opt_attributes opt_new type THIS
2010 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
2013 lexer.PropertyParsing = true;
2014 implicit_value_parameter_type = (Expression)$3;
2016 accessor_declarations
2018 has_get = has_set = false;
2019 lexer.PropertyParsing = false;
2020 implicit_value_parameter_type = null;
2026 i = new Indexer (current_class, (Expression) $3,
2027 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2028 (int) $2, true, (Parameters) $6, (Attributes) $1,
2031 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
2035 Accessors accessors = (Accessors) $10;
2036 i = new Indexer (current_class, (Expression) $3,
2037 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2038 (int) $2, true, (Parameters) $6, (Attributes) $1,
2039 accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
2041 if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
2042 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
2047 if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
2048 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
2053 if (RootContext.Documentation != null)
2054 i.DocComment = ConsumeStoredComment ();
2060 operator_declaration
2061 : opt_attributes opt_modifiers operator_declarator
2063 anonymous_host = SimpleAnonymousHost.GetSimple ();
2070 OperatorDeclaration decl = (OperatorDeclaration) $3;
2072 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
2074 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
2075 if (decl.arg2type != null)
2076 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
2078 Operator op = new Operator (
2079 current_class, decl.optype, decl.ret_type, (int) $2,
2080 new Parameters (param_list),
2081 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2083 if (RootContext.Documentation != null) {
2084 op.DocComment = tmpComment;
2085 Lexer.doc_state = XmlCommentState.Allowed;
2088 SimpleAnonymousHost.Simple.Propagate (op);
2089 anonymous_host = null;
2091 // Note again, checking is done in semantic analysis
2092 current_container.AddOperator (op);
2094 current_local_parameters = null;
2100 | SEMICOLON { $$ = null; }
2103 : type OPERATOR overloadable_operator
2104 open_parens opt_attributes opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2106 // TODO: wrong location
2107 if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE)
2108 Error_ParameterModifierNotValid ((Location) $2);
2110 LocatedToken lt = (LocatedToken) $8;
2111 Operator.OpType op = (Operator.OpType) $3;
2112 CheckUnaryOperator (op, lt.Location);
2114 if (op == Operator.OpType.Addition)
2115 op = Operator.OpType.UnaryPlus;
2117 if (op == Operator.OpType.Subtraction)
2118 op = Operator.OpType.UnaryNegation;
2120 Parameter [] pars = new Parameter [1];
2121 Expression type = (Expression) $7;
2123 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, (Attributes) $5, lt.Location);
2125 current_local_parameters = new Parameters (pars);
2127 if (RootContext.Documentation != null) {
2128 tmpComment = Lexer.consume_doc_comment ();
2129 Lexer.doc_state = XmlCommentState.NotAllowed;
2132 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2133 null, null, (Location) $2);
2135 | type OPERATOR overloadable_operator
2137 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
2138 opt_attributes opt_parameter_modifier type IDENTIFIER
2141 // TODO: wrong location
2142 if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE || (Parameter.Modifier)$11 != Parameter.Modifier.NONE)
2143 Error_ParameterModifierNotValid ((Location) $2);
2145 LocatedToken ltParam1 = (LocatedToken) $8;
2146 LocatedToken ltParam2 = (LocatedToken) $13;
2147 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2149 Parameter [] pars = new Parameter [2];
2151 Expression typeL = (Expression) $7;
2152 Expression typeR = (Expression) $12;
2154 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, (Attributes) $5, ltParam1.Location);
2155 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, (Attributes) $10, ltParam2.Location);
2157 current_local_parameters = new Parameters (pars);
2159 if (RootContext.Documentation != null) {
2160 tmpComment = Lexer.consume_doc_comment ();
2161 Lexer.doc_state = XmlCommentState.NotAllowed;
2164 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2165 typeL, ltParam1.Value,
2166 typeR, ltParam2.Value, (Location) $2);
2168 | conversion_operator_declarator
2169 | type OPERATOR overloadable_operator
2171 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
2172 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA error
2174 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2175 Operator.GetName ((Operator.OpType) $3));
2178 | type OPERATOR overloadable_operator
2179 open_parens CLOSE_PARENS
2181 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2182 Operator.GetName ((Operator.OpType) $3));
2187 overloadable_operator
2189 : BANG { $$ = Operator.OpType.LogicalNot; }
2190 | TILDE { $$ = Operator.OpType.OnesComplement; }
2191 | OP_INC { $$ = Operator.OpType.Increment; }
2192 | OP_DEC { $$ = Operator.OpType.Decrement; }
2193 | TRUE { $$ = Operator.OpType.True; }
2194 | FALSE { $$ = Operator.OpType.False; }
2195 // Unary and binary:
2196 | PLUS { $$ = Operator.OpType.Addition; }
2197 | MINUS { $$ = Operator.OpType.Subtraction; }
2199 | STAR { $$ = Operator.OpType.Multiply; }
2200 | DIV { $$ = Operator.OpType.Division; }
2201 | PERCENT { $$ = Operator.OpType.Modulus; }
2202 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2203 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2204 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2205 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2206 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2207 | OP_EQ { $$ = Operator.OpType.Equality; }
2208 | OP_NE { $$ = Operator.OpType.Inequality; }
2209 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2210 | OP_LT { $$ = Operator.OpType.LessThan; }
2211 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2212 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2215 conversion_operator_declarator
2216 : IMPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2218 // TODO: wrong location
2219 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2220 Error_ParameterModifierNotValid (GetLocation ($4));
2222 LocatedToken lt = (LocatedToken) $7;
2223 Parameter [] pars = new Parameter [1];
2225 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2227 current_local_parameters = new Parameters (pars);
2229 if (RootContext.Documentation != null) {
2230 tmpComment = Lexer.consume_doc_comment ();
2231 Lexer.doc_state = XmlCommentState.NotAllowed;
2234 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $6, lt.Value,
2235 null, null, (Location) $2);
2237 | EXPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2239 // TODO: wrong location
2240 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2241 Error_ParameterModifierNotValid (GetLocation ($4));
2243 LocatedToken lt = (LocatedToken) $7;
2244 Parameter [] pars = new Parameter [1];
2246 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2248 current_local_parameters = new Parameters (pars);
2250 if (RootContext.Documentation != null) {
2251 tmpComment = Lexer.consume_doc_comment ();
2252 Lexer.doc_state = XmlCommentState.NotAllowed;
2255 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $6, lt.Value,
2256 null, null, (Location) $2);
2260 syntax_error ((Location) $1, "'operator' expected");
2264 syntax_error ((Location) $1, "'operator' expected");
2268 constructor_declaration
2271 constructor_declarator
2274 Constructor c = (Constructor) $3;
2275 c.Block = (ToplevelBlock) $4;
2276 c.OptAttributes = (Attributes) $1;
2277 c.ModFlags = (int) $2;
2279 if (RootContext.Documentation != null)
2280 c.DocComment = ConsumeStoredComment ();
2282 if (c.Name == current_container.Basename){
2283 if ((c.ModFlags & Modifiers.STATIC) != 0){
2284 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2285 Report.Error (515, c.Location,
2286 "`{0}': access modifiers are not allowed on static constructors",
2287 c.GetSignatureForError ());
2290 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2292 if (c.Initializer != null){
2293 Report.Error (514, c.Location,
2294 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2295 c.GetSignatureForError ());
2298 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2301 // We let another layer check the validity of the constructor.
2302 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2305 current_container.AddConstructor (c);
2307 current_local_parameters = null;
2308 if (RootContext.Documentation != null)
2309 Lexer.doc_state = XmlCommentState.Allowed;
2313 constructor_declarator
2314 : constructor_header
2318 | constructor_header constructor_initializer
2320 ((Constructor)$1).Initializer = (ConstructorInitializer) $2;
2328 if (RootContext.Documentation != null) {
2329 tmpComment = Lexer.consume_doc_comment ();
2330 Lexer.doc_state = XmlCommentState.Allowed;
2333 open_parens opt_formal_parameter_list CLOSE_PARENS
2335 LocatedToken lt = (LocatedToken) $1;
2336 current_local_parameters = (Parameters) $4;
2337 current_block = new ToplevelBlock (null, current_local_parameters, null, lt.Location);
2339 $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
2342 anonymous_host = (IAnonymousHost) $$;
2348 | SEMICOLON { current_block = null; $$ = null; }
2351 constructor_initializer
2352 : COLON BASE open_parens opt_argument_list CLOSE_PARENS
2354 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2356 | COLON THIS open_parens opt_argument_list CLOSE_PARENS
2358 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2361 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2367 : /* EMPTY */ { $$ = 0; }
2368 | UNSAFE { $$ = Modifiers.UNSAFE; }
2369 | EXTERN { $$ = Modifiers.EXTERN; }
2372 destructor_declaration
2373 : opt_attributes opt_finalizer TILDE
2375 if (RootContext.Documentation != null) {
2376 tmpComment = Lexer.consume_doc_comment ();
2377 Lexer.doc_state = XmlCommentState.NotAllowed;
2380 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2382 LocatedToken lt = (LocatedToken) $5;
2383 if (lt.Value != current_container.MemberName.Name){
2384 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2385 } else if (current_container.Kind != Kind.Class){
2386 Report.Error (575, lt.Location, "Only class types can contain destructor");
2388 Location l = lt.Location;
2391 if (!RootContext.StdLib && current_container.Name == "System.Object")
2392 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2394 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2396 Method d = new Destructor (
2397 current_class, TypeManager.system_void_expr, m, "Finalize",
2398 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2399 if (RootContext.Documentation != null)
2400 d.DocComment = ConsumeStoredComment ();
2402 d.Block = (ToplevelBlock) $8;
2403 current_container.AddMethod (d);
2411 EVENT type variable_declarators SEMICOLON
2413 current_array_type = null;
2414 foreach (VariableDeclaration var in (ArrayList) $5) {
2416 MemberName name = new MemberName (var.identifier,
2419 EventField e = new EventField (
2420 current_class, (Expression) $4, (int) $2, false, name,
2423 e.Initializer = var.expression_or_array_initializer;
2425 current_container.AddEvent (e);
2427 if (RootContext.Documentation != null) {
2428 e.DocComment = Lexer.consume_doc_comment ();
2429 Lexer.doc_state = XmlCommentState.Allowed;
2435 EVENT type namespace_or_type_name
2438 implicit_value_parameter_type = (Expression) $4;
2439 lexer.EventParsing = true;
2441 event_accessor_declarations
2443 lexer.EventParsing = false;
2447 MemberName name = (MemberName) $5;
2450 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2451 current_container.Name, name.ToString ());
2454 Accessors accessors = (Accessors) $8;
2456 if (name.TypeArguments != null)
2457 syntax_error (lexer.Location, "an event can't have type arguments");
2459 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2460 // CS0073 is already reported, so no CS0065 here.
2463 Event e = new EventProperty (
2464 current_class, (Expression) $4, (int) $2, false, name,
2465 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2466 if (RootContext.Documentation != null) {
2467 e.DocComment = Lexer.consume_doc_comment ();
2468 Lexer.doc_state = XmlCommentState.Allowed;
2471 current_container.AddEvent (e);
2472 implicit_value_parameter_type = null;
2476 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2477 MemberName mn = (MemberName) $5;
2479 if (mn.Left != null)
2480 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2482 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2484 if (RootContext.Documentation != null)
2485 Lexer.doc_state = XmlCommentState.Allowed;
2489 event_accessor_declarations
2490 : add_accessor_declaration remove_accessor_declaration
2492 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2494 | remove_accessor_declaration add_accessor_declaration
2496 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2497 accessors.declared_in_reverse = true;
2500 | add_accessor_declaration { $$ = null; }
2501 | remove_accessor_declaration { $$ = null; }
2504 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2510 add_accessor_declaration
2511 : opt_attributes ADD
2513 Parameter [] args = new Parameter [1];
2514 Parameter implicit_value_parameter = new Parameter (
2515 implicit_value_parameter_type, "value",
2516 Parameter.Modifier.NONE, null, (Location) $2);
2518 args [0] = implicit_value_parameter;
2520 current_local_parameters = new Parameters (args);
2521 lexer.EventParsing = false;
2523 anonymous_host = SimpleAnonymousHost.GetSimple ();
2527 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2528 lexer.EventParsing = true;
2530 current_local_parameters = null;
2531 SimpleAnonymousHost.Simple.Propagate (accessor);
2532 anonymous_host = null;
2536 | opt_attributes ADD error {
2537 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2540 | opt_attributes modifiers ADD {
2541 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2546 remove_accessor_declaration
2547 : opt_attributes REMOVE
2549 Parameter [] args = new Parameter [1];
2550 Parameter implicit_value_parameter = new Parameter (
2551 implicit_value_parameter_type, "value",
2552 Parameter.Modifier.NONE, null, (Location) $2);
2554 args [0] = implicit_value_parameter;
2556 current_local_parameters = new Parameters (args);
2557 lexer.EventParsing = false;
2561 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2562 lexer.EventParsing = true;
2564 | opt_attributes REMOVE error {
2565 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2568 | opt_attributes modifiers REMOVE {
2569 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2575 : opt_attributes opt_modifiers indexer_declarator
2578 IndexerDeclaration decl = (IndexerDeclaration) $3;
2580 implicit_value_parameter_type = decl.type;
2582 lexer.PropertyParsing = true;
2583 parsing_indexer = true;
2585 indexer_parameters = decl.param_list;
2586 anonymous_host = SimpleAnonymousHost.GetSimple ();
2588 accessor_declarations
2590 lexer.PropertyParsing = false;
2591 has_get = has_set = false;
2592 parsing_indexer = false;
2599 // The signature is computed from the signature of the indexer. Look
2600 // at section 3.6 on the spec
2602 IndexerDeclaration decl = (IndexerDeclaration) $3;
2603 Location loc = decl.location;
2604 Accessors accessors = (Accessors) $6;
2605 Accessor get_block = accessors.get_or_add;
2606 Accessor set_block = accessors.set_or_remove;
2609 if (decl.interface_type != null)
2610 name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);
2612 name = new MemberName (TypeContainer.DefaultIndexerName, loc);
2614 indexer = new Indexer (current_class, decl.type, name,
2615 (int) $2, false, decl.param_list, (Attributes) $1,
2616 get_block, set_block, accessors.declared_in_reverse);
2618 if (RootContext.Documentation != null)
2619 indexer.DocComment = ConsumeStoredComment ();
2621 current_container.AddIndexer (indexer);
2623 current_local_parameters = null;
2624 implicit_value_parameter_type = null;
2625 indexer_parameters = null;
2630 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2632 Parameters pars = (Parameters) $4;
2633 if (pars.HasArglist) {
2634 // "__arglist is not valid in this context"
2635 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2636 } else if (pars.Empty){
2637 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2639 if (RootContext.Documentation != null) {
2640 tmpComment = Lexer.consume_doc_comment ();
2641 Lexer.doc_state = XmlCommentState.Allowed;
2644 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2646 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2648 Parameters pars = (Parameters) $6;
2650 if (pars.HasArglist) {
2651 // "__arglist is not valid in this context"
2652 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2653 } else if (pars.Empty){
2654 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2657 MemberName name = (MemberName) $2;
2658 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2660 if (RootContext.Documentation != null) {
2661 tmpComment = Lexer.consume_doc_comment ();
2662 Lexer.doc_state = XmlCommentState.Allowed;
2672 if (RootContext.Documentation != null)
2673 enumTypeComment = Lexer.consume_doc_comment ();
2678 LocatedToken lt = (LocatedToken) $4;
2679 Location enum_location = lt.Location;
2681 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2682 Enum e = new Enum (current_namespace, current_class, (Expression) $5, (int) $2,
2683 name, (Attributes) $1);
2685 if (RootContext.Documentation != null)
2686 e.DocComment = enumTypeComment;
2689 EnumMember em = null;
2690 foreach (VariableDeclaration ev in (ArrayList) $7) {
2691 em = new EnumMember (
2692 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2693 ev.OptAttributes, ev.Location);
2695 // if (RootContext.Documentation != null)
2696 em.DocComment = ev.DocComment;
2698 e.AddEnumMember (em);
2701 current_container.AddTypeContainer (e);
2708 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2709 | COLON type { $$ = $2; }
2715 if (RootContext.Documentation != null)
2716 Lexer.doc_state = XmlCommentState.Allowed;
2718 opt_enum_member_declarations
2720 // here will be evaluated after CLOSE_BLACE is consumed.
2721 if (RootContext.Documentation != null)
2722 Lexer.doc_state = XmlCommentState.Allowed;
2730 opt_enum_member_declarations
2731 : /* empty */ { $$ = new ArrayList (4); }
2732 | enum_member_declarations opt_comma { $$ = $1; }
2735 enum_member_declarations
2736 : enum_member_declaration
2738 ArrayList l = new ArrayList (4);
2743 | enum_member_declarations COMMA enum_member_declaration
2745 ArrayList l = (ArrayList) $1;
2753 enum_member_declaration
2754 : opt_attributes IDENTIFIER
2756 VariableDeclaration vd = new VariableDeclaration (
2757 (LocatedToken) $2, null, (Attributes) $1);
2759 if (RootContext.Documentation != null) {
2760 vd.DocComment = Lexer.consume_doc_comment ();
2761 Lexer.doc_state = XmlCommentState.Allowed;
2766 | opt_attributes IDENTIFIER
2768 if (RootContext.Documentation != null) {
2769 tmpComment = Lexer.consume_doc_comment ();
2770 Lexer.doc_state = XmlCommentState.NotAllowed;
2775 VariableDeclaration vd = new VariableDeclaration (
2776 (LocatedToken) $2, $5, (Attributes) $1);
2778 if (RootContext.Documentation != null)
2779 vd.DocComment = ConsumeStoredComment ();
2785 delegate_declaration
2790 lexer.ConstraintsParsing = true;
2793 open_parens opt_formal_parameter_list CLOSE_PARENS
2795 MemberName name = MakeName ((MemberName) $6);
2796 Parameters p = (Parameters) $8;
2798 // TODO: wrong location
2799 Report.Error (1669, name.Location, "__arglist is not valid in this context");
2802 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2803 (int) $2, name, p, (Attributes) $1);
2805 if (RootContext.Documentation != null) {
2806 del.DocComment = Lexer.consume_doc_comment ();
2807 Lexer.doc_state = XmlCommentState.Allowed;
2810 current_container.AddDelegate (del);
2811 current_delegate = del;
2813 opt_type_parameter_constraints_clauses
2815 lexer.ConstraintsParsing = false;
2819 current_delegate.SetParameterInfo ((ArrayList) $11);
2820 $$ = current_delegate;
2822 current_delegate = null;
2829 lexer.CheckNullable (false);
2834 lexer.CheckNullable (true);
2839 namespace_or_type_name
2840 : IDENTIFIER opt_type_argument_list
2842 LocatedToken lt = (LocatedToken) $1;
2843 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2845 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2846 LocatedToken lt1 = (LocatedToken) $1;
2847 LocatedToken lt2 = (LocatedToken) $3;
2848 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2850 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2851 LocatedToken lt = (LocatedToken) $3;
2852 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2857 : IDENTIFIER opt_type_parameter_list
2859 LocatedToken lt = (LocatedToken) $1;
2860 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2862 | namespace_or_type_name DOT IDENTIFIER opt_type_parameter_list
2864 LocatedToken lt = (LocatedToken) $3;
2865 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2870 : IDENTIFIER opt_type_parameter_list
2872 LocatedToken lt = (LocatedToken) $1;
2873 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2878 // Generics arguments (any type, without attributes)
2881 opt_type_argument_list
2882 : /* empty */ { $$ = null; }
2883 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2885 if (RootContext.Version == LanguageVersion.ISO_1)
2886 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2893 // Generics parameters (identifiers only, with attributes), used in type, method declarations
2896 opt_type_parameter_list
2897 : /* empty */ { $$ = null; }
2898 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2900 if (RootContext.Version == LanguageVersion.ISO_1)
2901 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2910 TypeArguments type_args = new TypeArguments (lexer.Location);
2911 type_args.Add ((Expression) $1);
2914 | type_arguments COMMA type_argument
2916 TypeArguments type_args = (TypeArguments) $1;
2917 type_args.Add ((Expression) $3);
2927 | attribute_sections type
2929 SimpleName sn = $2 as SimpleName;
2931 Error_TypeExpected (GetLocation ($2));
2933 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2939 * Before you think of adding a return_type, notice that we have been
2940 * using two rules in the places where it matters (one rule using type
2941 * and another identical one that uses VOID as the return type). This
2942 * gets rid of a shift/reduce couple
2945 : namespace_or_type_name opt_nullable
2947 MemberName name = (MemberName) $1;
2948 $$ = name.GetTypeExpression ();
2951 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2953 | builtin_types opt_nullable
2956 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2966 // Note that here only unmanaged types are allowed but we
2967 // can't perform checks during this phase - we do it during
2968 // semantic analysis.
2970 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2974 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2979 : builtin_types opt_nullable
2982 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2984 | non_expression_type rank_specifier
2986 Location loc = GetLocation ($1);
2988 loc = lexer.Location;
2989 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2991 | non_expression_type STAR
2993 Location loc = GetLocation ($1);
2995 loc = lexer.Location;
2996 $$ = new ComposedCast ((Expression) $1, "*", loc);
2998 | expression rank_specifiers
3000 $$ = new ComposedCast ((Expression) $1, (string) $2);
3004 $$ = new ComposedCast ((Expression) $1, "*");
3008 // We need this because the parser will happily go and reduce IDENTIFIER STAR
3009 // through this different path
3011 | multiplicative_expression STAR
3013 $$ = new ComposedCast ((Expression) $1, "*");
3020 ArrayList types = new ArrayList (4);
3025 | type_list COMMA type
3027 ArrayList types = (ArrayList) $1;
3035 * replaces all the productions for isolating the various
3036 * simple types, but we need this to reuse it easily in local_variable_type
3039 : OBJECT { $$ = TypeManager.system_object_expr; }
3040 | STRING { $$ = TypeManager.system_string_expr; }
3041 | BOOL { $$ = TypeManager.system_boolean_expr; }
3042 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
3043 | FLOAT { $$ = TypeManager.system_single_expr; }
3044 | DOUBLE { $$ = TypeManager.system_double_expr; }
3049 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
3050 | BYTE { $$ = TypeManager.system_byte_expr; }
3051 | SHORT { $$ = TypeManager.system_int16_expr; }
3052 | USHORT { $$ = TypeManager.system_uint16_expr; }
3053 | INT { $$ = TypeManager.system_int32_expr; }
3054 | UINT { $$ = TypeManager.system_uint32_expr; }
3055 | LONG { $$ = TypeManager.system_int64_expr; }
3056 | ULONG { $$ = TypeManager.system_uint64_expr; }
3057 | CHAR { $$ = TypeManager.system_char_expr; }
3058 | VOID { $$ = TypeManager.system_void_expr; }
3062 : type rank_specifiers opt_nullable
3064 string rank_specifiers = (string) $2;
3066 rank_specifiers += "?";
3068 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
3073 // Expressions, section 7.5
3082 MemberName mn = (MemberName) $1;
3083 $$ = mn.GetTypeExpression ();
3085 | IDENTIFIER DOUBLE_COLON IDENTIFIER
3087 LocatedToken lt1 = (LocatedToken) $1;
3088 LocatedToken lt2 = (LocatedToken) $3;
3089 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
3091 | parenthesized_expression
3092 | default_value_expression
3094 | invocation_expression
3098 | post_increment_expression
3099 | post_decrement_expression
3103 | checked_expression
3104 | unchecked_expression
3105 | pointer_member_access
3106 | anonymous_method_expression
3113 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3114 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
3115 | NULL { $$ = new NullLiteral (lexer.Location); }
3119 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3120 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3121 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3126 object v = lexer.Value;
3129 $$ = new IntLiteral ((int) v, lexer.Location);
3130 } else if (v is uint)
3131 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3133 $$ = new LongLiteral ((Int64) v, lexer.Location);
3134 else if (v is ulong)
3135 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3137 Console.WriteLine ("OOPS. Unexpected result from scanner");
3142 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3143 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3146 parenthesized_expression_0
3147 : OPEN_PARENS expression CLOSE_PARENS
3150 lexer.Deambiguate_CloseParens ($$);
3151 // After this, the next token returned is one of
3152 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
3153 // or CLOSE_PARENS_MINUS.
3155 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
3158 parenthesized_expression
3159 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
3163 | parenthesized_expression_0 CLOSE_PARENS
3167 | parenthesized_expression_0 CLOSE_PARENS_MINUS
3169 // If a parenthesized expression is followed by a minus, we need to wrap
3170 // the expression inside a ParenthesizedExpression for the CS0075 check
3171 // in Binary.DoResolve().
3172 $$ = new ParenthesizedExpression ((Expression) $1);
3177 : primary_expression DOT IDENTIFIER opt_type_argument_list
3179 LocatedToken lt = (LocatedToken) $3;
3180 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3182 | predefined_type DOT IDENTIFIER opt_type_argument_list
3184 LocatedToken lt = (LocatedToken) $3;
3185 // TODO: Location is wrong as some predefined types doesn't hold a location
3186 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3194 invocation_expression
3195 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3198 Report.Error (1, (Location) $2, "Parse error");
3200 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3202 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3204 $$ = new Invocation ((Expression) $1, new ArrayList ());
3206 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3208 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3210 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3212 ArrayList args = new ArrayList (1);
3214 $$ = new Invocation ((Expression) $1, args);
3216 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3218 ArrayList args = ((ArrayList) $4);
3220 $$ = new Invocation ((Expression) $1, args);
3224 opt_object_or_collection_initializer
3225 : /* empty */ { $$ = null; }
3226 | object_or_collection_initializer
3229 object_or_collection_initializer
3230 : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
3233 $$ = CollectionOrObjectInitializers.Empty;
3235 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3237 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3239 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3243 opt_member_initializer_list
3244 : /* empty */ { $$ = null; }
3245 | member_initializer_list
3251 member_initializer_list
3252 : member_initializer
3254 ArrayList a = new ArrayList ();
3258 | member_initializer_list COMMA member_initializer
3260 ArrayList a = (ArrayList)$1;
3267 : IDENTIFIER ASSIGN initializer_value
3269 LocatedToken lt = $1 as LocatedToken;
3270 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3272 | non_assignment_expression
3274 $$ = new CollectionElementInitializer ((Expression)$1);
3276 | OPEN_BRACE expression_list CLOSE_BRACE
3278 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3280 | OPEN_BRACE CLOSE_BRACE
3282 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3288 | object_or_collection_initializer
3292 : /* empty */ { $$ = null; }
3299 ArrayList list = new ArrayList (4);
3303 | argument_list COMMA argument
3305 ArrayList list = (ArrayList) $1;
3309 | argument_list error {
3310 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3318 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3320 | non_simple_argument
3327 : REF variable_reference
3329 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3331 | OUT variable_reference
3333 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3335 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3337 ArrayList list = (ArrayList) $3;
3338 Argument[] args = new Argument [list.Count];
3339 list.CopyTo (args, 0);
3341 Expression expr = new Arglist (args, (Location) $1);
3342 $$ = new Argument (expr, Argument.AType.Expression);
3344 | ARGLIST OPEN_PARENS CLOSE_PARENS
3346 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3350 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3355 : expression { note ("section 5.4"); $$ = $1; }
3359 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3361 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3363 | primary_expression rank_specifiers
3365 // So the super-trick is that primary_expression
3366 // can only be either a SimpleName or a MemberAccess.
3367 // The MemberAccess case arises when you have a fully qualified type-name like :
3369 // SimpleName is when you have
3372 Expression expr = (Expression) $1;
3373 if (expr is ComposedCast){
3374 $$ = new ComposedCast (expr, (string) $2);
3375 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3376 Error_ExpectingTypeName (expr);
3377 $$ = TypeManager.system_object_expr;
3380 // So we extract the string corresponding to the SimpleName
3383 $$ = new ComposedCast (expr, (string) $2);
3385 current_array_type = (Expression)$$;
3392 ArrayList list = new ArrayList (4);
3396 | expression_list COMMA expression
3398 ArrayList list = (ArrayList) $1;
3407 $$ = new This (current_block, (Location) $1);
3412 : BASE DOT IDENTIFIER opt_type_argument_list
3414 LocatedToken lt = (LocatedToken) $3;
3415 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3417 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3419 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3422 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3427 post_increment_expression
3428 : primary_expression OP_INC
3430 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3431 (Expression) $1, (Location) $2);
3435 post_decrement_expression
3436 : primary_expression OP_DEC
3438 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3439 (Expression) $1, (Location) $2);
3444 : object_or_delegate_creation_expression
3445 | array_creation_expression
3446 | anonymous_type_expression
3449 object_or_delegate_creation_expression
3450 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3453 if (RootContext.Version <= LanguageVersion.ISO_2)
3454 Report.FeatureIsNotISO1 (GetLocation ($1), "object initializers");
3456 $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (CollectionOrObjectInitializers) $6, (Location) $1);
3459 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3461 | NEW type object_or_collection_initializer
3463 if (RootContext.Version <= LanguageVersion.ISO_2)
3464 Report.FeatureIsNotISO1 (GetLocation ($1), "collection initializers");
3466 $$ = new NewInitialize ((Expression) $2, null, (CollectionOrObjectInitializers) $3, (Location) $1);
3470 array_creation_expression
3471 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3473 opt_array_initializer
3475 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3477 | NEW type rank_specifiers array_initializer
3479 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3481 | NEW rank_specifiers array_initializer
3483 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
3487 Report.Error (1031, (Location) $1, "Type expected");
3492 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3497 anonymous_type_expression
3498 : NEW OPEN_BRACE anonymous_type_parameters CLOSE_BRACE
3500 if (RootContext.Version <= LanguageVersion.ISO_2)
3501 Report.FeatureIsNotISO1 (GetLocation ($1), "anonymous types");
3503 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3507 anonymous_type_parameters
3509 | anonymous_type_parameter
3511 ArrayList a = new ArrayList (4);
3515 | anonymous_type_parameters COMMA anonymous_type_parameter
3517 ArrayList a = (ArrayList) $1;
3523 anonymous_type_parameter
3524 : IDENTIFIER ASSIGN variable_initializer
3526 LocatedToken lt = (LocatedToken)$1;
3527 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3531 LocatedToken lt = (LocatedToken)$1;
3532 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3533 lt.Value, lt.Location);
3537 MemberAccess ma = (MemberAccess) $1;
3538 $$ = new AnonymousTypeParameter (ma, ma.Identifier, ma.Location);
3542 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3543 "Anonymous type members must be a member assignment, simple name or member access expression");
3558 opt_rank_specifier_or_nullable
3567 | opt_nullable rank_specifiers
3574 | opt_nullable rank_specifiers INTERR
3577 $$ = "?" + $2 + "?";
3584 : rank_specifier opt_rank_specifier
3586 $$ = (string) $2 + (string) $1;
3591 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3593 $$ = "[" + (string) $2 + "]";
3613 | dim_separators COMMA
3615 $$ = (string) $1 + ",";
3619 opt_array_initializer
3631 : OPEN_BRACE CLOSE_BRACE
3633 ArrayList list = new ArrayList (4);
3636 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3638 $$ = (ArrayList) $2;
3642 variable_initializer_list
3643 : variable_initializer
3645 ArrayList list = new ArrayList (4);
3649 | variable_initializer_list COMMA variable_initializer
3651 ArrayList list = (ArrayList) $1;
3660 pushed_current_array_type = current_array_type;
3661 lexer.TypeOfParsing = true;
3663 OPEN_PARENS typeof_type_expression CLOSE_PARENS
3665 lexer.TypeOfParsing = false;
3666 Expression type = (Expression)$4;
3667 if (type == TypeManager.system_void_expr)
3668 $$ = new TypeOfVoid ((Location) $1);
3670 $$ = new TypeOf (type, (Location) $1);
3671 current_array_type = pushed_current_array_type;
3675 typeof_type_expression
3682 $$ = new UnboundTypeExpression ((MemberName)$1, lexer.Location);
3687 : IDENTIFIER GENERIC_DIMENSION
3689 if (RootContext.Version == LanguageVersion.ISO_1)
3690 Report.FeatureIsNotISO1 (lexer.Location, "generics");
3692 LocatedToken lt = (LocatedToken) $1;
3693 TypeArguments ta = new TypeArguments ((int)$2, lt.Location);
3695 $$ = new MemberName (lt.Value, ta, lt.Location);
3697 | IDENTIFIER DOUBLE_COLON IDENTIFIER GENERIC_DIMENSION
3699 LocatedToken lt = (LocatedToken) $1;
3700 MemberName left = new MemberName (lt.Value, lt.Location);
3701 lt = (LocatedToken) $3;
3702 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3704 $$ = new MemberName (left, lt.Value, ta, lt.Location);
3706 | unbound_type_name DOT IDENTIFIER GENERIC_DIMENSION
3708 LocatedToken lt = (LocatedToken) $3;
3709 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3711 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3713 | namespace_or_type_name DOT IDENTIFIER GENERIC_DIMENSION
3715 LocatedToken lt = (LocatedToken) $3;
3716 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3718 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3724 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3725 $$ = new SizeOf ((Expression) $3, (Location) $1);
3730 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3732 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3736 unchecked_expression
3737 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3739 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3743 pointer_member_access
3744 : primary_expression OP_PTR IDENTIFIER
3747 LocatedToken lt = (LocatedToken) $3;
3749 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3750 $$ = new MemberAccess (deref, lt.Value);
3754 anonymous_method_expression
3755 : DELEGATE opt_anonymous_method_signature
3757 start_anonymous (false, (Parameters) $2, (Location) $1);
3761 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
3765 opt_anonymous_method_signature
3766 : /* empty */ { $$ = null; }
3767 | anonymous_method_signature
3770 anonymous_method_signature
3771 : open_parens opt_anonymous_method_parameter_list CLOSE_PARENS
3774 $$ = Parameters.EmptyReadOnlyParameters;
3776 ArrayList par_list = (ArrayList) $2;
3777 Parameter [] pars = new Parameter [par_list.Count];
3778 par_list.CopyTo (pars);
3779 $$ = new Parameters (pars);
3784 opt_anonymous_method_parameter_list
3785 : /* empty */ { $$ = null; }
3786 | anonymous_method_parameter_list { $$ = $1; }
3789 anonymous_method_parameter_list
3790 : anonymous_method_parameter
3792 ArrayList a = new ArrayList (4);
3796 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3798 ArrayList a = (ArrayList) $1;
3804 anonymous_method_parameter
3805 : opt_parameter_modifier type IDENTIFIER {
3806 LocatedToken lt = (LocatedToken) $3;
3807 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3809 | PARAMS type IDENTIFIER {
3810 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3815 default_value_expression
3816 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3818 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3823 : primary_expression
3824 | BANG prefixed_unary_expression
3826 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3828 | TILDE prefixed_unary_expression
3830 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3836 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3838 $$ = new Cast ((Expression) $1, (Expression) $3);
3840 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3842 $$ = new Cast ((Expression) $1, (Expression) $3);
3844 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3846 $$ = new Cast ((Expression) $1, (Expression) $3);
3852 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3854 // TODO: wrong location
3855 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3860 // The idea to split this out is from Rhys' grammar
3861 // to solve the problem with casts.
3863 prefixed_unary_expression
3865 | PLUS prefixed_unary_expression
3867 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3869 | MINUS prefixed_unary_expression
3871 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3873 | OP_INC prefixed_unary_expression
3875 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3876 (Expression) $2, (Location) $1);
3878 | OP_DEC prefixed_unary_expression
3880 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3881 (Expression) $2, (Location) $1);
3883 | STAR prefixed_unary_expression
3885 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3887 | BITWISE_AND prefixed_unary_expression
3889 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3893 pre_increment_expression
3894 : OP_INC prefixed_unary_expression
3896 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3897 (Expression) $2, (Location) $1);
3901 pre_decrement_expression
3902 : OP_DEC prefixed_unary_expression
3904 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3905 (Expression) $2, (Location) $1);
3909 multiplicative_expression
3910 : prefixed_unary_expression
3911 | multiplicative_expression STAR prefixed_unary_expression
3913 $$ = new Binary (Binary.Operator.Multiply,
3914 (Expression) $1, (Expression) $3);
3916 | multiplicative_expression DIV prefixed_unary_expression
3918 $$ = new Binary (Binary.Operator.Division,
3919 (Expression) $1, (Expression) $3);
3921 | multiplicative_expression PERCENT prefixed_unary_expression
3923 $$ = new Binary (Binary.Operator.Modulus,
3924 (Expression) $1, (Expression) $3);
3929 : multiplicative_expression
3930 | additive_expression PLUS multiplicative_expression
3932 $$ = new Binary (Binary.Operator.Addition,
3933 (Expression) $1, (Expression) $3);
3935 | additive_expression MINUS multiplicative_expression
3937 $$ = new Binary (Binary.Operator.Subtraction,
3938 (Expression) $1, (Expression) $3);
3943 : additive_expression
3944 | shift_expression OP_SHIFT_LEFT additive_expression
3946 $$ = new Binary (Binary.Operator.LeftShift,
3947 (Expression) $1, (Expression) $3);
3949 | shift_expression OP_SHIFT_RIGHT additive_expression
3951 $$ = new Binary (Binary.Operator.RightShift,
3952 (Expression) $1, (Expression) $3);
3963 lexer.PutbackNullable ();
3968 nullable_type_or_conditional
3971 if (((bool) $2) && ($1 is ComposedCast))
3972 $$ = ((ComposedCast) $1).RemoveNullable ();
3978 relational_expression
3980 | relational_expression OP_LT shift_expression
3982 $$ = new Binary (Binary.Operator.LessThan,
3983 (Expression) $1, (Expression) $3);
3985 | relational_expression OP_GT shift_expression
3987 $$ = new Binary (Binary.Operator.GreaterThan,
3988 (Expression) $1, (Expression) $3);
3990 | relational_expression OP_LE shift_expression
3992 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3993 (Expression) $1, (Expression) $3);
3995 | relational_expression OP_GE shift_expression
3997 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3998 (Expression) $1, (Expression) $3);
4000 | relational_expression IS
4003 } nullable_type_or_conditional
4005 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
4007 | relational_expression AS
4010 } nullable_type_or_conditional
4012 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
4017 : relational_expression
4018 | equality_expression OP_EQ relational_expression
4020 $$ = new Binary (Binary.Operator.Equality,
4021 (Expression) $1, (Expression) $3);
4023 | equality_expression OP_NE relational_expression
4025 $$ = new Binary (Binary.Operator.Inequality,
4026 (Expression) $1, (Expression) $3);
4031 : equality_expression
4032 | and_expression BITWISE_AND equality_expression
4034 $$ = new Binary (Binary.Operator.BitwiseAnd,
4035 (Expression) $1, (Expression) $3);
4039 exclusive_or_expression
4041 | exclusive_or_expression CARRET and_expression
4043 $$ = new Binary (Binary.Operator.ExclusiveOr,
4044 (Expression) $1, (Expression) $3);
4048 inclusive_or_expression
4049 : exclusive_or_expression
4050 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4052 $$ = new Binary (Binary.Operator.BitwiseOr,
4053 (Expression) $1, (Expression) $3);
4057 conditional_and_expression
4058 : inclusive_or_expression
4059 | conditional_and_expression OP_AND inclusive_or_expression
4061 $$ = new Binary (Binary.Operator.LogicalAnd,
4062 (Expression) $1, (Expression) $3);
4066 conditional_or_expression
4067 : conditional_and_expression
4068 | conditional_or_expression OP_OR conditional_and_expression
4070 $$ = new Binary (Binary.Operator.LogicalOr,
4071 (Expression) $1, (Expression) $3);
4075 conditional_expression
4076 : conditional_or_expression
4077 | conditional_or_expression INTERR expression COLON expression
4079 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
4081 | conditional_or_expression OP_COALESCING expression
4083 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
4085 // We'll be resolved into a `parenthesized_expression_0' later on.
4086 | conditional_or_expression INTERR CLOSE_PARENS
4088 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
4089 lexer.PutbackCloseParens ();
4093 assignment_expression
4094 : prefixed_unary_expression ASSIGN expression
4096 $$ = new Assign ((Expression) $1, (Expression) $3);
4098 | prefixed_unary_expression OP_MULT_ASSIGN expression
4100 $$ = new CompoundAssign (
4101 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4103 | prefixed_unary_expression OP_DIV_ASSIGN expression
4105 $$ = new CompoundAssign (
4106 Binary.Operator.Division, (Expression) $1, (Expression) $3);
4108 | prefixed_unary_expression OP_MOD_ASSIGN expression
4110 $$ = new CompoundAssign (
4111 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4113 | prefixed_unary_expression OP_ADD_ASSIGN expression
4115 $$ = new CompoundAssign (
4116 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4118 | prefixed_unary_expression OP_SUB_ASSIGN expression
4120 $$ = new CompoundAssign (
4121 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4123 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4125 $$ = new CompoundAssign (
4126 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4128 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4130 $$ = new CompoundAssign (
4131 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4133 | prefixed_unary_expression OP_AND_ASSIGN expression
4135 $$ = new CompoundAssign (
4136 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4138 | prefixed_unary_expression OP_OR_ASSIGN expression
4140 $$ = new CompoundAssign (
4141 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4143 | prefixed_unary_expression OP_XOR_ASSIGN expression
4145 $$ = new CompoundAssign (
4146 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4150 lambda_parameter_list
4153 ArrayList pars = new ArrayList (4);
4158 | lambda_parameter_list COMMA lambda_parameter
4160 ArrayList pars = (ArrayList) $1;
4161 Parameter p = (Parameter)$3;
4162 if (pars[0].GetType () != p.GetType ()) {
4163 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4172 : parameter_modifier type IDENTIFIER
4174 LocatedToken lt = (LocatedToken) $3;
4176 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4180 LocatedToken lt = (LocatedToken) $2;
4182 $$ = new Parameter ((Expression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4186 LocatedToken lt = (LocatedToken) $1;
4187 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4191 opt_lambda_parameter_list
4192 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
4193 | lambda_parameter_list {
4194 ArrayList pars_list = (ArrayList) $1;
4195 $$ = new Parameters ((Parameter[])pars_list.ToArray (typeof (Parameter)));
4199 lambda_expression_body
4201 start_block (lexer.Location);
4205 Block b = end_block (lexer.Location);
4206 b.AddStatement (new ContextualReturn ((Expression) $2));
4217 LocatedToken lt = (LocatedToken) $1;
4218 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4219 start_anonymous (true, new Parameters (p), (Location) $2);
4221 lambda_expression_body
4223 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
4225 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4227 start_anonymous (true, (Parameters) $2, (Location) $4);
4229 lambda_expression_body
4231 $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
4236 : assignment_expression
4237 | non_assignment_expression
4240 non_assignment_expression
4241 : conditional_expression
4263 lexer.ConstraintsParsing = true;
4267 MemberName name = MakeName ((MemberName) $6);
4268 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4271 opt_type_parameter_constraints_clauses
4273 lexer.ConstraintsParsing = false;
4275 current_class.SetParameterInfo ((ArrayList) $9);
4277 if (RootContext.Documentation != null) {
4278 current_container.DocComment = Lexer.consume_doc_comment ();
4279 Lexer.doc_state = XmlCommentState.Allowed;
4284 if (RootContext.Documentation != null)
4285 Lexer.doc_state = XmlCommentState.Allowed;
4289 $$ = pop_current_class ();
4297 { $$ = $1; } // location
4301 : /* empty */ { $$ = (int) 0; }
4307 | modifiers modifier
4312 if ((m1 & m2) != 0) {
4313 Location l = lexer.Location;
4314 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4316 $$ = (int) (m1 | m2);
4321 : NEW { $$ = Modifiers.NEW; }
4322 | PUBLIC { $$ = Modifiers.PUBLIC; }
4323 | PROTECTED { $$ = Modifiers.PROTECTED; }
4324 | INTERNAL { $$ = Modifiers.INTERNAL; }
4325 | PRIVATE { $$ = Modifiers.PRIVATE; }
4326 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4327 | SEALED { $$ = Modifiers.SEALED; }
4328 | STATIC { $$ = Modifiers.STATIC; }
4329 | READONLY { $$ = Modifiers.READONLY; }
4330 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4331 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4332 | EXTERN { $$ = Modifiers.EXTERN; }
4333 | VOLATILE { $$ = Modifiers.VOLATILE; }
4334 | UNSAFE { $$ = Modifiers.UNSAFE; }
4343 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4346 opt_type_parameter_constraints_clauses
4347 : /* empty */ { $$ = null; }
4348 | type_parameter_constraints_clauses
4352 type_parameter_constraints_clauses
4353 : type_parameter_constraints_clause {
4354 ArrayList constraints = new ArrayList (1);
4355 constraints.Add ($1);
4358 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4359 ArrayList constraints = (ArrayList) $1;
4360 Constraints new_constraint = (Constraints)$2;
4362 foreach (Constraints c in constraints) {
4363 if (new_constraint.TypeParameter == c.TypeParameter) {
4364 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4365 new_constraint.TypeParameter);
4369 constraints.Add (new_constraint);
4374 type_parameter_constraints_clause
4375 : WHERE IDENTIFIER COLON type_parameter_constraints {
4376 LocatedToken lt = (LocatedToken) $2;
4377 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4381 type_parameter_constraints
4382 : type_parameter_constraint {
4383 ArrayList constraints = new ArrayList (1);
4384 constraints.Add ($1);
4387 | type_parameter_constraints COMMA type_parameter_constraint {
4388 ArrayList constraints = (ArrayList) $1;
4390 constraints.Add ($3);
4395 type_parameter_constraint
4397 | NEW OPEN_PARENS CLOSE_PARENS {
4398 $$ = SpecialConstraint.Constructor;
4401 $$ = SpecialConstraint.ReferenceType;
4404 $$ = SpecialConstraint.ValueType;
4413 // A block is "contained" on the following places:
4415 // property_declaration as part of the accessor body (get/set)
4416 // operator_declaration
4417 // constructor_declaration
4418 // destructor_declaration
4419 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4424 ++lexer.parsing_block;
4425 start_block ((Location) $1);
4427 opt_statement_list CLOSE_BRACE
4429 --lexer.parsing_block;
4430 $$ = end_block ((Location) $4);
4437 ++lexer.parsing_block;
4439 opt_statement_list CLOSE_BRACE
4441 --lexer.parsing_block;
4442 $$ = end_block ((Location) $4);
4453 | statement_list statement
4457 : declaration_statement
4459 if ($1 != null && (Block) $1 != current_block){
4460 current_block.AddStatement ((Statement) $1);
4461 current_block = (Block) $1;
4464 | valid_declaration_statement
4466 current_block.AddStatement ((Statement) $1);
4471 valid_declaration_statement
4474 | expression_statement
4475 | selection_statement
4476 | iteration_statement
4480 | unchecked_statement
4488 : valid_declaration_statement
4489 | declaration_statement
4491 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4496 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4504 $$ = EmptyStatement.Value;
4511 LocatedToken lt = (LocatedToken) $1;
4512 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4514 if (current_block.AddLabel (labeled))
4515 current_block.AddStatement (labeled);
4520 declaration_statement
4521 : local_variable_declaration SEMICOLON
4523 current_array_type = null;
4525 DictionaryEntry de = (DictionaryEntry) $1;
4526 Expression e = (Expression) de.Key;
4528 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4532 | local_constant_declaration SEMICOLON
4534 current_array_type = null;
4536 DictionaryEntry de = (DictionaryEntry) $1;
4538 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4544 * The following is from Rhys' grammar:
4545 * > Types in local variable declarations must be recognized as
4546 * > expressions to prevent reduce/reduce errors in the grammar.
4547 * > The expressions are converted into types during semantic analysis.
4550 : primary_expression opt_rank_specifier_or_nullable
4552 // FIXME: Do something smart here regarding the composition of the type.
4554 // Ok, the above "primary_expression" is there to get rid of
4555 // both reduce/reduce and shift/reduces in the grammar, it should
4556 // really just be "type_name". If you use type_name, a reduce/reduce
4557 // creeps up. If you use namespace_or_type_name (which is all we need
4558 // really) two shift/reduces appear.
4561 // So the super-trick is that primary_expression
4562 // can only be either a SimpleName or a MemberAccess.
4563 // The MemberAccess case arises when you have a fully qualified type-name like :
4565 // SimpleName is when you have
4568 Expression expr = (Expression) $1;
4569 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4570 Error_ExpectingTypeName (expr);
4574 // So we extract the string corresponding to the SimpleName
4578 if ((string) $2 == "")
4581 $$ = new ComposedCast ((Expression) $1, (string) $2);
4584 | builtin_types opt_rank_specifier_or_nullable
4586 if ((string) $2 == "")
4589 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4593 local_variable_pointer_type
4594 : primary_expression STAR
4596 Expression expr = (Expression) $1;
4598 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4599 Error_ExpectingTypeName (expr);
4603 $$ = new ComposedCast ((Expression) $1, "*");
4605 | builtin_types STAR
4607 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4611 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4613 | local_variable_pointer_type STAR
4615 $$ = new ComposedCast ((Expression) $1, "*");
4619 local_variable_declaration
4620 : local_variable_type variable_declarators
4623 VarExpr ve = $1 as VarExpr;
4625 ve.VariableInitializer = (ArrayList)$2;
4627 $$ = new DictionaryEntry ($1, $2);
4631 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4636 if ((string) $2 == "")
4637 t = (Expression) $1;
4639 t = new ComposedCast ((Expression) $1, (string) $2);
4640 $$ = new DictionaryEntry (t, $3);
4646 local_constant_declaration
4647 : CONST local_variable_type constant_declarators
4650 $$ = new DictionaryEntry ($2, $3);
4656 expression_statement
4657 : statement_expression SEMICOLON { $$ = $1; }
4661 // We have to do the wrapping here and not in the case above,
4662 // because statement_expression is used for example in for_statement
4664 statement_expression
4667 Expression expr = (Expression) $1;
4668 ExpressionStatement s = expr as ExpressionStatement;
4670 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
4673 $$ = new StatementExpression (s);
4677 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4682 object_creation_expression
4683 : object_or_delegate_creation_expression
4684 { note ("complain if this is a delegate maybe?"); }
4693 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4696 Location l = (Location) $1;
4698 $$ = new If ((Expression) $3, (Statement) $5, l);
4700 // FIXME: location for warning should be loc property of $5.
4701 if ($5 == EmptyStatement.Value)
4702 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4705 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4706 embedded_statement ELSE embedded_statement
4708 Location l = (Location) $1;
4710 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4712 // FIXME: location for warning should be loc property of $5 and $7.
4713 if ($5 == EmptyStatement.Value)
4714 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4715 if ($7 == EmptyStatement.Value)
4716 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4721 : SWITCH OPEN_PARENS
4723 if (switch_stack == null)
4724 switch_stack = new Stack (2);
4725 switch_stack.Push (current_block);
4727 expression CLOSE_PARENS
4730 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4731 current_block = (Block) switch_stack.Pop ();
4747 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4748 $$ = new ArrayList ();
4756 ArrayList sections = new ArrayList (4);
4761 | switch_sections switch_section
4763 ArrayList sections = (ArrayList) $1;
4773 current_block = current_block.CreateSwitchBlock (lexer.Location);
4777 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4784 ArrayList labels = new ArrayList (4);
4789 | switch_labels switch_label
4791 ArrayList labels = (ArrayList) ($1);
4799 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4800 | DEFAULT_COLON { $$ = new SwitchLabel (null, (Location) $1); }
4803 1523, GetLocation ($1),
4804 "The keyword case or default must precede code in switch block");
4816 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4818 Location l = (Location) $1;
4819 $$ = new While ((Expression) $3, (Statement) $5, l);
4824 : DO embedded_statement
4825 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4827 Location l = (Location) $1;
4829 $$ = new Do ((Statement) $2, (Expression) $5, l);
4835 opt_for_initializer SEMICOLON
4837 Location l = lexer.Location;
4839 Block assign_block = current_block;
4841 if ($3 is DictionaryEntry){
4842 DictionaryEntry de = (DictionaryEntry) $3;
4844 Expression type = (Expression) de.Key;
4845 ArrayList var_declarators = (ArrayList) de.Value;
4847 foreach (VariableDeclaration decl in var_declarators){
4851 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4855 Expression expr = decl.expression_or_array_initializer;
4857 LocalVariableReference var;
4858 var = new LocalVariableReference (assign_block, decl.identifier, l);
4861 Assign a = new Assign (var, expr, decl.Location);
4863 assign_block.AddStatement (new StatementExpression (a));
4867 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4868 // This can be referred to as $5 below.
4874 opt_for_condition SEMICOLON
4875 opt_for_iterator CLOSE_PARENS
4878 Location l = (Location) $1;
4880 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4882 current_block.AddStatement (f);
4884 $$ = end_block (lexer.Location);
4889 : /* empty */ { $$ = EmptyStatement.Value; }
4894 : local_variable_declaration
4895 | statement_expression_list
4899 : /* empty */ { $$ = null; }
4900 | boolean_expression
4904 : /* empty */ { $$ = EmptyStatement.Value; }
4909 : statement_expression_list
4912 statement_expression_list
4913 : statement_expression
4915 // CHANGE: was `null'
4916 Statement s = (Statement) $1;
4917 Block b = new Block (current_block, s.loc, lexer.Location);
4922 | statement_expression_list COMMA statement_expression
4924 Block b = (Block) $1;
4926 b.AddStatement ((Statement) $3);
4932 : FOREACH open_parens type IN expression CLOSE_PARENS
4934 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4937 | FOREACH open_parens type IDENTIFIER IN
4938 expression CLOSE_PARENS
4940 start_block (lexer.Location);
4941 Block foreach_block = current_block;
4943 LocatedToken lt = (LocatedToken) $4;
4944 Location l = lt.Location;
4945 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4947 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4949 // Get a writable reference to this read-only variable.
4951 // Note that the $$ here refers to the value of _this_ code block,
4952 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4953 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4960 LocalVariableReference v = (LocalVariableReference) $8;
4961 Location l = (Location) $1;
4964 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4965 current_block.AddStatement (f);
4968 $$ = end_block (lexer.Location);
4974 | continue_statement
4984 $$ = new Break ((Location) $1);
4989 : CONTINUE SEMICOLON
4991 $$ = new Continue ((Location) $1);
4996 : GOTO IDENTIFIER SEMICOLON
4998 LocatedToken lt = (LocatedToken) $2;
4999 $$ = new Goto (lt.Value, lt.Location);
5001 | GOTO CASE constant_expression SEMICOLON
5003 $$ = new GotoCase ((Expression) $3, (Location) $1);
5005 | GOTO DEFAULT SEMICOLON
5007 $$ = new GotoDefault ((Location) $1);
5012 : RETURN opt_expression SEMICOLON
5014 $$ = new Return ((Expression) $2, (Location) $1);
5019 : THROW opt_expression SEMICOLON
5021 $$ = new Throw ((Expression) $2, (Location) $1);
5026 : IDENTIFIER RETURN expression SEMICOLON
5028 LocatedToken lt = (LocatedToken) $1;
5029 string s = lt.Value;
5031 Report.Error (1003, lt.Location, "; expected");
5034 if (RootContext.Version == LanguageVersion.ISO_1){
5035 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
5038 if (anonymous_host == null){
5039 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
5042 anonymous_host.SetYields ();
5043 $$ = new Yield ((Expression) $3, lt.Location);
5046 | IDENTIFIER RETURN SEMICOLON
5048 Report.Error (1627, (Location) $2, "Expression expected after yield return");
5051 | IDENTIFIER BREAK SEMICOLON
5053 LocatedToken lt = (LocatedToken) $1;
5054 string s = lt.Value;
5056 Report.Error (1003, lt.Location, "; expected");
5059 if (RootContext.Version == LanguageVersion.ISO_1){
5060 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
5063 if (anonymous_host == null){
5064 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
5067 anonymous_host.SetYields ();
5068 $$ = new YieldBreak (lt.Location);
5079 : TRY block catch_clauses
5083 ArrayList c = (ArrayList)$3;
5084 for (int i = 0; i < c.Count; ++i) {
5085 Catch cc = (Catch) c [i];
5087 if (i != c.Count - 1)
5088 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
5095 // Now s contains the list of specific catch clauses
5096 // and g contains the general one.
5098 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
5100 | TRY block opt_catch_clauses FINALLY block
5103 ArrayList s = new ArrayList (4);
5104 ArrayList catch_list = (ArrayList) $3;
5106 if (catch_list != null){
5107 foreach (Catch cc in catch_list) {
5115 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
5119 Report.Error (1524, (Location) $1, "Expected catch or finally");
5125 : /* empty */ { $$ = null; }
5132 ArrayList l = new ArrayList (4);
5137 | catch_clauses catch_clause
5139 ArrayList l = (ArrayList) $1;
5147 : /* empty */ { $$ = null; }
5152 : CATCH opt_catch_args
5154 Expression type = null;
5157 DictionaryEntry cc = (DictionaryEntry) $2;
5158 type = (Expression) cc.Key;
5159 LocatedToken lt = (LocatedToken) cc.Value;
5162 ArrayList one = new ArrayList (4);
5164 one.Add (new VariableDeclaration (lt, null));
5166 start_block (lexer.Location);
5167 current_block = declare_local_variables (type, one, lt.Location);
5171 Expression type = null;
5173 Block var_block = null;
5176 DictionaryEntry cc = (DictionaryEntry) $2;
5177 type = (Expression) cc.Key;
5178 LocatedToken lt = (LocatedToken) cc.Value;
5182 var_block = end_block (lexer.Location);
5186 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5191 : /* empty */ { $$ = null; }
5196 : open_parens type opt_identifier CLOSE_PARENS
5198 $$ = new DictionaryEntry ($2, $3);
5206 $$ = new Checked ((Block) $2);
5213 $$ = new Unchecked ((Block) $2);
5220 RootContext.CheckUnsafeOption ((Location) $1);
5222 $$ = new Unsafe ((Block) $3);
5228 type fixed_pointer_declarators
5231 ArrayList list = (ArrayList) $4;
5232 Expression type = (Expression) $3;
5233 Location l = (Location) $1;
5234 int top = list.Count;
5236 if (type is VarExpr)
5237 Report.Error (821, GetLocation ($3), "A fixed statement cannot use an implicitly typed local variable");
5239 start_block (lexer.Location);
5241 for (int i = 0; i < top; i++){
5242 Pair p = (Pair) list [i];
5245 v = current_block.AddVariable (type, (string) p.First, l);
5249 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5257 Location l = (Location) $1;
5259 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5261 current_block.AddStatement (f);
5263 $$ = end_block (lexer.Location);
5267 fixed_pointer_declarators
5268 : fixed_pointer_declarator {
5269 ArrayList declarators = new ArrayList (4);
5271 declarators.Add ($1);
5274 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5276 ArrayList declarators = (ArrayList) $1;
5278 declarators.Add ($3);
5283 fixed_pointer_declarator
5284 : IDENTIFIER ASSIGN expression
5286 LocatedToken lt = (LocatedToken) $1;
5287 // FIXME: keep location
5288 $$ = new Pair (lt.Value, $3);
5292 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5298 : LOCK OPEN_PARENS expression CLOSE_PARENS
5304 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5309 : USING open_parens resource_acquisition CLOSE_PARENS
5311 start_block (lexer.Location);
5312 Block assign_block = current_block;
5314 if ($3 is DictionaryEntry){
5315 DictionaryEntry de = (DictionaryEntry) $3;
5316 Location l = (Location) $1;
5318 Expression type = (Expression) de.Key;
5319 ArrayList var_declarators = (ArrayList) de.Value;
5321 ArrayList vars = new ArrayList (4);
5323 foreach (VariableDeclaration decl in var_declarators){
5325 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5328 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5330 Expression expr = decl.expression_or_array_initializer;
5332 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5335 LocalVariableReference var;
5337 // Get a writable reference to this read-only variable.
5338 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5340 // This is so that it is not a warning on using variables
5343 vars.Add (new DictionaryEntry (var, expr));
5345 // Assign a = new Assign (var, expr, decl.Location);
5346 // assign_block.AddStatement (new StatementExpression (a));
5349 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5350 // It can be referred to as $5 below.
5351 $$ = new DictionaryEntry (type, vars);
5358 Using u = new Using ($5, (Statement) $6, (Location) $1);
5359 current_block.AddStatement (u);
5360 $$ = end_block (lexer.Location);
5364 resource_acquisition
5365 : local_variable_declaration
5373 : first_from_clause query_body
5375 lexer.QueryParsing = false;
5377 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5379 from.Tail.Next = (Linq.AQueryClause)$2;
5382 current_block.SetEndLocation (lexer.Location);
5383 current_block = current_block.Parent;
5388 : FROM IDENTIFIER IN expression
5390 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5391 LocatedToken lt = (LocatedToken) $2;
5393 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
5394 $$ = new Linq.QueryExpression (lt, new Linq.QueryStartClause ((Expression)$4));
5396 | FROM type IDENTIFIER IN expression
5398 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5399 LocatedToken lt = (LocatedToken) $3;
5401 Expression type = (Expression)$2;
5402 current_block.AddVariable (type, lt.Value, lt.Location);
5403 $$ = new Linq.QueryExpression (lt, new Linq.Cast (type, (Expression)$5));
5408 : FROM IDENTIFIER IN expression
5410 LocatedToken lt = (LocatedToken) $2;
5412 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5413 lt.Value, lt.Location);
5415 $$ = new Linq.SelectMany (lt, (Expression)$4);
5417 | FROM type IDENTIFIER IN expression
5419 LocatedToken lt = (LocatedToken) $3;
5421 Expression type = (Expression)$2;
5422 current_block.AddVariable (type, lt.Value, lt.Location);
5423 $$ = new Linq.SelectMany (lt, new Linq.Cast (type, (Expression)$5));
5428 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5430 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5433 head.Next = (Linq.AQueryClause)$3;
5436 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5437 clause.Tail.Next = head;
5445 select_or_group_clause
5448 $$ = new Linq.Select ((Expression)$2, GetLocation ($1));
5450 | GROUP expression BY expression
5452 $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation ($1));
5456 opt_query_body_clauses
5458 | query_body_clauses
5463 | query_body_clauses query_body_clause
5465 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5479 : LET IDENTIFIER ASSIGN expression
5481 LocatedToken lt = (LocatedToken) $2;
5482 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5483 lt.Value, lt.Location);
5484 $$ = new Linq.Let (lt, (Expression)$4, GetLocation ($1));
5489 : WHERE boolean_expression
5491 $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
5496 : JOIN IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5498 Location loc = GetLocation ($1);
5499 LocatedToken lt = (LocatedToken) $2;
5500 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5501 lt.Value, lt.Location);
5504 $$ = new Linq.Join (lt, (Expression)$4, (Expression)$6,
5505 (Expression)$8, loc);
5507 LocatedToken lt_into = (LocatedToken) $9;
5508 $$ = new Linq.GroupJoin (lt, (Expression)$4, (Expression)$6,
5509 (Expression)$8, lt_into, loc);
5512 | JOIN type IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5514 Location loc = GetLocation ($1);
5515 LocatedToken lt = (LocatedToken) $3;
5516 current_block.AddVariable ((Expression)$2, lt.Value, lt.Location);
5518 Linq.Cast cast = new Linq.Cast ((Expression)$2, (Expression)$5);
5520 $$ = new Linq.Join (lt, cast, (Expression)$7,
5521 (Expression)$9, loc);
5523 LocatedToken lt_into = (LocatedToken) $10;
5524 $$ = new Linq.GroupJoin (lt, cast, (Expression)$7,
5525 (Expression)$9, lt_into, loc);
5547 | order_by COMMA orderings_then_by
5549 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$3;
5559 | orderings_then_by COMMA then_by
5561 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5569 $$ = new Linq.OrderByAscending ((Expression)$1);
5571 | expression ASCENDING
5573 $$ = new Linq.OrderByAscending ((Expression)$1);
5575 | expression DESCENDING
5577 $$ = new Linq.OrderByDescending ((Expression)$1);
5584 $$ = new Linq.ThenByAscending ((Expression)$1);
5586 | expression ASCENDING
5588 $$ = new Linq.ThenByAscending ((Expression)$1);
5590 | expression DESCENDING
5592 $$ = new Linq.ThenByDescending ((Expression)$1);
5597 opt_query_continuation
5601 // query continuation block is not linked with query block but with block
5602 // before. This means each query can use same range variable names for
5603 // different identifiers.
5605 current_block.SetEndLocation (GetLocation ($1));
5606 current_block = current_block.Parent;
5607 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5609 LocatedToken lt = (LocatedToken) $2;
5610 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5611 lt.Value, lt.Location);
5615 $$ = new Linq.QueryExpression ((LocatedToken) $2,
5616 (Linq.AQueryClause)$4);
5623 // A class used to pass around variable declarations and constants
5625 public class VariableDeclaration {
5626 public string identifier;
5627 public Expression expression_or_array_initializer;
5628 public Location Location;
5629 public Attributes OptAttributes;
5630 public string DocComment;
5632 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5634 this.identifier = lt.Value;
5635 if (eoai is ArrayList) {
5636 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5638 this.expression_or_array_initializer = (Expression)eoai;
5640 this.Location = lt.Location;
5641 this.OptAttributes = opt_attrs;
5644 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5650 // A class used to hold info about an indexer declarator
5652 public class IndexerDeclaration {
5653 public Expression type;
5654 public MemberName interface_type;
5655 public Parameters param_list;
5656 public Location location;
5658 public IndexerDeclaration (Expression type, MemberName interface_type,
5659 Parameters param_list, Location loc)
5662 this.interface_type = interface_type;
5663 this.param_list = param_list;
5664 this.location = loc;
5669 // We use this when we do not have an object in advance that is an IAnonymousHost
5671 public class SimpleAnonymousHost : IAnonymousHost {
5672 public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
5675 ArrayList anonymous_methods;
5677 public static SimpleAnonymousHost GetSimple () {
5678 Simple.yields = false;
5679 Simple.anonymous_methods = null;
5683 public void SetYields ()
5688 public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
5690 if (anonymous_methods == null)
5691 anonymous_methods = new ArrayList ();
5692 anonymous_methods.Add (anonymous);
5695 public void Propagate (IAnonymousHost real_host)
5698 real_host.SetYields ();
5699 if (anonymous_methods != null) {
5700 foreach (AnonymousMethodExpression ame in anonymous_methods)
5701 real_host.AddAnonymousMethod (ame);
5707 // A class used to hold info about an operator declarator
5709 public class OperatorDeclaration {
5710 public Operator.OpType optype;
5711 public Expression ret_type, arg1type, arg2type;
5712 public string arg1name, arg2name;
5713 public Location location;
5715 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5716 Expression arg1type, string arg1name,
5717 Expression arg2type, string arg2name, Location location)
5720 this.ret_type = ret_type;
5721 this.arg1type = arg1type;
5722 this.arg1name = arg1name;
5723 this.arg2type = arg2type;
5724 this.arg2name = arg2name;
5725 this.location = location;
5730 void Error_ExpectingTypeName (Expression expr)
5732 if (expr is Invocation){
5733 Report.Error (1002, expr.Location, "Expecting `;'");
5735 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5739 public static void Error_ParameterModifierNotValid (Location loc)
5741 Report.Error (631, loc, "The modifiers `ref' and `out' are not valid in this context");
5744 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5746 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5747 Parameter.GetModifierSignature (mod));
5750 static void Error_TypeExpected (Location loc)
5752 Report.Error (1031, loc, "Type expected");
5755 void push_current_class (TypeContainer tc, object partial_token)
5757 if (partial_token != null)
5758 current_container = current_container.AddPartial (tc);
5760 current_container = current_container.AddTypeContainer (tc);
5764 DeclSpace pop_current_class ()
5766 DeclSpace retval = current_class;
5768 current_class = current_class.Parent;
5769 current_container = current_class.PartialContainer;
5775 // Given the @class_name name, it creates a fully qualified name
5776 // based on the containing declaration space
5779 MakeName (MemberName class_name)
5781 Namespace ns = current_namespace.NS;
5783 if (current_container.Name.Length == 0){
5784 if (ns.Name.Length != 0)
5785 return new MemberName (ns.MemberName, class_name);
5789 return new MemberName (current_container.MemberName, class_name);
5793 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5795 Block implicit_block;
5796 ArrayList inits = null;
5799 // We use the `Used' property to check whether statements
5800 // have been added to the current block. If so, we need
5801 // to create another block to contain the new declaration
5802 // otherwise, as an optimization, we use the same block to
5803 // add the declaration.
5805 // FIXME: A further optimization is to check if the statements
5806 // that were added were added as part of the initialization
5807 // below. In which case, no other statements have been executed
5808 // and we might be able to reduce the number of blocks for
5809 // situations like this:
5811 // int j = 1; int k = j + 1;
5813 if (current_block.Used)
5814 implicit_block = new Block (current_block, loc, Location.Null);
5816 implicit_block = current_block;
5818 foreach (VariableDeclaration decl in variable_declarators){
5820 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5821 if (decl.expression_or_array_initializer != null){
5823 inits = new ArrayList (4);
5830 return implicit_block;
5832 foreach (VariableDeclaration decl in inits){
5834 Expression expr = decl.expression_or_array_initializer;
5836 LocalVariableReference var;
5837 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5839 assign = new Assign (var, expr, decl.Location);
5841 implicit_block.AddStatement (new StatementExpression (assign));
5844 return implicit_block;
5847 Block declare_local_constants (Expression type, ArrayList declarators)
5849 Block implicit_block;
5851 if (current_block.Used)
5852 implicit_block = new Block (current_block);
5854 implicit_block = current_block;
5856 foreach (VariableDeclaration decl in declarators){
5857 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5860 return implicit_block;
5863 string CheckAttributeTarget (string a, Location l)
5866 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5870 Report.Warning (658, 1, l,
5871 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5872 return string.Empty;
5875 void CheckUnaryOperator (Operator.OpType op, Location l)
5879 case Operator.OpType.LogicalNot:
5880 case Operator.OpType.OnesComplement:
5881 case Operator.OpType.Increment:
5882 case Operator.OpType.Decrement:
5883 case Operator.OpType.True:
5884 case Operator.OpType.False:
5885 case Operator.OpType.Addition:
5886 case Operator.OpType.Subtraction:
5891 Report.Error (1019, l, "Overloadable unary operator expected");
5897 void CheckBinaryOperator (Operator.OpType op, Location l)
5901 case Operator.OpType.Addition:
5902 case Operator.OpType.Subtraction:
5903 case Operator.OpType.Multiply:
5904 case Operator.OpType.Division:
5905 case Operator.OpType.Modulus:
5906 case Operator.OpType.BitwiseAnd:
5907 case Operator.OpType.BitwiseOr:
5908 case Operator.OpType.ExclusiveOr:
5909 case Operator.OpType.LeftShift:
5910 case Operator.OpType.RightShift:
5911 case Operator.OpType.Equality:
5912 case Operator.OpType.Inequality:
5913 case Operator.OpType.GreaterThan:
5914 case Operator.OpType.LessThan:
5915 case Operator.OpType.GreaterThanOrEqual:
5916 case Operator.OpType.LessThanOrEqual:
5920 Report.Error (1020, l, "Overloadable binary operator expected");
5926 void syntax_error (Location l, string msg)
5928 Report.Error (1003, l, "Syntax error, " + msg);
5931 void note (string s)
5933 // Used to put annotations
5938 public Tokenizer Lexer {
5944 static CSharpParser ()
5946 oob_stack = new Stack ();
5949 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5951 this.name = file.Name;
5953 current_namespace = new NamespaceEntry (null, file, null);
5954 current_class = current_namespace.SlaveDeclSpace;
5955 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5957 lexer = new Tokenizer (reader, file, defines);
5960 public void parse ()
5962 int errors = Report.Errors;
5964 if (yacc_verbose_flag > 1)
5965 yyparse (lexer, new yydebug.yyDebugSimple ());
5968 Tokenizer tokenizer = lexer as Tokenizer;
5969 tokenizer.cleanup ();
5970 } catch (Exception e){
5972 // Removed for production use, use parser verbose to get the output.
5974 // Console.WriteLine (e);
5975 if (Report.Errors == errors)
5976 Report.Error (-25, lexer.Location, "Parsing error");
5977 if (yacc_verbose_flag > 0)
5978 Console.WriteLine (e);
5981 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5982 throw new InternalErrorException ("who set it?");
5985 static void CheckToken (int error, int yyToken, string msg, Location loc)
5987 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5988 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5990 Report.Error (error, loc, msg);
5993 void CheckIdentifierToken (int yyToken, Location loc)
5995 CheckToken (1041, yyToken, "Identifier expected", loc);
5998 string ConsumeStoredComment ()
6000 string s = tmpComment;
6002 Lexer.doc_state = XmlCommentState.Allowed;
6006 Location GetLocation (object obj)
6008 if (obj is MemberCore)
6009 return ((MemberCore) obj).Location;
6010 if (obj is MemberName)
6011 return ((MemberName) obj).Location;
6012 if (obj is LocatedToken)
6013 return ((LocatedToken) obj).Location;
6014 if (obj is Location)
6015 return (Location) obj;
6016 return lexer.Location;
6019 void start_block (Location loc)
6021 if (current_block == null || parsing_anonymous_method) {
6022 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
6023 parsing_anonymous_method = false;
6025 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6030 end_block (Location loc)
6032 Block retval = current_block.Explicit;
6033 retval.SetEndLocation (loc);
6034 current_block = retval.Parent;
6039 start_anonymous (bool lambda, Parameters parameters, Location loc)
6041 oob_stack.Push (current_anonymous_method);
6042 oob_stack.Push (current_local_parameters);
6044 current_local_parameters = parameters;
6046 ToplevelBlock top_current_block = current_block == null ? null : current_block.Toplevel;
6048 current_anonymous_method = lambda
6049 ? new LambdaExpression (
6050 current_anonymous_method, current_generic_method, current_container,
6051 parameters, top_current_block, loc)
6052 : new AnonymousMethodExpression (
6053 current_anonymous_method, current_generic_method, current_container,
6054 parameters, top_current_block, loc);
6056 // Force the next block to be created as a ToplevelBlock
6057 parsing_anonymous_method = true;
6061 * Completes the anonymous method processing, if lambda_expr is null, this
6062 * means that we have a Statement instead of an Expression embedded
6064 AnonymousMethodExpression
6065 end_anonymous (ToplevelBlock anon_block, Location loc)
6067 AnonymousMethodExpression retval;
6069 if (RootContext.Version == LanguageVersion.ISO_1){
6070 Report.FeatureIsNotISO1 (loc, "anonymous methods");
6073 current_anonymous_method.Block = anon_block;
6074 if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
6075 anonymous_host.AddAnonymousMethod (current_anonymous_method);
6077 retval = current_anonymous_method;
6080 current_local_parameters = (Parameters) oob_stack.Pop ();
6081 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();