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; }
1452 | THIS { $$ = Parameter.Modifier.This; }
1456 : opt_attributes PARAMS type IDENTIFIER
1458 LocatedToken lt = (LocatedToken) $4;
1459 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1461 | opt_attributes PARAMS PARAMS type IDENTIFIER
1463 Error_DuplicateParameterModifier (lexer.Location, Parameter.Modifier.PARAMS);
1466 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1468 Parameter.Modifier mod = (Parameter.Modifier)$3;
1469 if ((mod & Parameter.Modifier.This) != 0) {
1470 Report.Error (1104, lexer.Location, "The parameter modifiers `this' and `params' cannot be used altogether");
1472 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1476 | opt_attributes PARAMS type error {
1477 CheckIdentifierToken (yyToken, GetLocation ($4));
1482 property_declaration
1486 namespace_or_type_name
1488 if (RootContext.Documentation != null)
1489 tmpComment = Lexer.consume_doc_comment ();
1493 implicit_value_parameter_type = (Expression) $3;
1495 lexer.PropertyParsing = true;
1497 accessor_declarations
1499 lexer.PropertyParsing = false;
1500 has_get = has_set = false;
1508 Accessors accessors = (Accessors) $8;
1509 Accessor get_block = accessors.get_or_add;
1510 Accessor set_block = accessors.set_or_remove;
1512 MemberName name = (MemberName) $4;
1514 if (name.TypeArguments != null)
1515 syntax_error (lexer.Location, "a property can't have type arguments");
1517 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1518 name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse, current_block);
1520 current_container.AddProperty (prop);
1521 implicit_value_parameter_type = null;
1523 if (RootContext.Documentation != null)
1524 prop.DocComment = ConsumeStoredComment ();
1529 accessor_declarations
1530 : get_accessor_declaration
1532 $$ = new Accessors ((Accessor) $1, null);
1534 | get_accessor_declaration accessor_declarations
1536 Accessors accessors = (Accessors) $2;
1537 accessors.get_or_add = (Accessor) $1;
1540 | set_accessor_declaration
1542 $$ = new Accessors (null, (Accessor) $1);
1544 | set_accessor_declaration accessor_declarations
1546 Accessors accessors = (Accessors) $2;
1547 accessors.set_or_remove = (Accessor) $1;
1548 accessors.declared_in_reverse = true;
1553 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1558 get_accessor_declaration
1559 : opt_attributes opt_modifiers GET
1561 // If this is not the case, then current_local_parameters has already
1562 // been set in indexer_declaration
1563 if (parsing_indexer == false)
1564 current_local_parameters = null;
1566 current_local_parameters = indexer_parameters;
1567 lexer.PropertyParsing = false;
1569 anonymous_host = SimpleAnonymousHost.GetSimple ();
1574 Report.Error (1007, (Location) $3, "Property accessor already defined");
1577 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1579 current_local_parameters = null;
1580 lexer.PropertyParsing = true;
1582 SimpleAnonymousHost.Simple.Propagate (accessor);
1583 anonymous_host = null;
1585 if (RootContext.Documentation != null)
1586 if (Lexer.doc_state == XmlCommentState.Error)
1587 Lexer.doc_state = XmlCommentState.NotAllowed;
1593 set_accessor_declaration
1594 : opt_attributes opt_modifiers SET
1597 Parameter implicit_value_parameter = new Parameter (
1598 implicit_value_parameter_type, "value",
1599 Parameter.Modifier.NONE, null, (Location) $3);
1601 if (parsing_indexer == false) {
1602 args = new Parameter [1];
1603 args [0] = implicit_value_parameter;
1604 current_local_parameters = new Parameters (args);
1606 Parameter [] fpars = indexer_parameters.FixedParameters;
1609 int count = fpars.Length;
1611 args = new Parameter [count + 1];
1612 fpars.CopyTo (args, 0);
1613 args [count] = implicit_value_parameter;
1616 current_local_parameters = new Parameters (
1620 lexer.PropertyParsing = false;
1622 anonymous_host = SimpleAnonymousHost.GetSimple ();
1627 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1630 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1632 current_local_parameters = null;
1633 lexer.PropertyParsing = true;
1635 SimpleAnonymousHost.Simple.Propagate (accessor);
1636 anonymous_host = null;
1638 if (RootContext.Documentation != null
1639 && Lexer.doc_state == XmlCommentState.Error)
1640 Lexer.doc_state = XmlCommentState.NotAllowed;
1648 | SEMICOLON { $$ = null; }
1651 interface_declaration
1657 lexer.ConstraintsParsing = true;
1661 MemberName name = MakeName ((MemberName) $6);
1662 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1665 opt_type_parameter_constraints_clauses
1667 lexer.ConstraintsParsing = false;
1669 current_class.SetParameterInfo ((ArrayList) $9);
1671 if (RootContext.Documentation != null) {
1672 current_container.DocComment = Lexer.consume_doc_comment ();
1673 Lexer.doc_state = XmlCommentState.Allowed;
1678 if (RootContext.Documentation != null)
1679 Lexer.doc_state = XmlCommentState.Allowed;
1683 $$ = pop_current_class ();
1685 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1686 CheckIdentifierToken (yyToken, GetLocation ($5));
1692 opt_interface_member_declarations
1696 opt_interface_member_declarations
1698 | interface_member_declarations
1701 interface_member_declarations
1702 : interface_member_declaration
1703 | interface_member_declarations interface_member_declaration
1706 interface_member_declaration
1707 : interface_method_declaration
1712 Method m = (Method) $1;
1714 if (m.IsExplicitImpl)
1715 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1716 m.GetSignatureForError ());
1718 current_container.AddMethod (m);
1720 if (RootContext.Documentation != null)
1721 Lexer.doc_state = XmlCommentState.Allowed;
1723 | interface_property_declaration
1728 Property p = (Property) $1;
1730 if (p.IsExplicitImpl)
1731 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1732 p.GetSignatureForError ());
1734 current_container.AddProperty (p);
1736 if (RootContext.Documentation != null)
1737 Lexer.doc_state = XmlCommentState.Allowed;
1739 | interface_event_declaration
1742 Event e = (Event) $1;
1744 if (e.IsExplicitImpl)
1745 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1746 e.GetSignatureForError ());
1748 current_container.AddEvent (e);
1751 if (RootContext.Documentation != null)
1752 Lexer.doc_state = XmlCommentState.Allowed;
1754 | interface_indexer_declaration
1759 Indexer i = (Indexer) $1;
1761 if (i.IsExplicitImpl)
1762 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1763 i.GetSignatureForError ());
1765 current_container.AddIndexer (i);
1767 if (RootContext.Documentation != null)
1768 Lexer.doc_state = XmlCommentState.Allowed;
1770 | delegate_declaration
1773 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1774 ((MemberCore)$1).GetSignatureForError ());
1780 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1781 ((MemberCore)$1).GetSignatureForError ());
1784 | struct_declaration
1787 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1788 ((MemberCore)$1).GetSignatureForError ());
1794 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1795 ((MemberCore)$1).GetSignatureForError ());
1798 | interface_declaration
1801 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1802 ((MemberCore)$1).GetSignatureForError ());
1805 | constant_declaration
1807 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1815 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1820 interface_method_declaration_body
1823 lexer.ConstraintsParsing = false;
1825 opt_statement_list CLOSE_BRACE
1827 Report.Error (531, lexer.Location,
1828 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1834 interface_method_declaration
1835 : opt_attributes opt_new type namespace_or_type_name
1836 open_parens opt_formal_parameter_list CLOSE_PARENS
1838 lexer.ConstraintsParsing = true;
1840 opt_type_parameter_constraints_clauses
1842 // Refer to the name as $-1 in interface_method_declaration_body
1845 interface_method_declaration_body
1847 lexer.ConstraintsParsing = false;
1849 MemberName name = (MemberName) $4;
1851 if ($9 != null && name.TypeArguments == null)
1852 Report.Error (80, lexer.Location,
1853 "Constraints are not allowed on non-generic declarations");
1855 GenericMethod generic = null;
1856 if (name.TypeArguments != null) {
1857 generic = new GenericMethod (current_namespace, current_class, name,
1858 (Expression) $3, (Parameters) $6);
1860 generic.SetParameterInfo ((ArrayList) $9);
1863 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1864 (Parameters) $6, (Attributes) $1);
1865 if (RootContext.Documentation != null)
1866 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1868 | opt_attributes opt_new VOID namespace_or_type_name
1869 open_parens opt_formal_parameter_list CLOSE_PARENS
1871 lexer.ConstraintsParsing = true;
1873 opt_type_parameter_constraints_clauses
1877 interface_method_declaration_body
1879 lexer.ConstraintsParsing = false;
1881 MemberName name = (MemberName) $4;
1883 if ($9 != null && name.TypeArguments == null)
1884 Report.Error (80, lexer.Location,
1885 "Constraints are not allowed on non-generic declarations");
1887 GenericMethod generic = null;
1888 if (name.TypeArguments != null) {
1889 generic = new GenericMethod (current_namespace, current_class, name,
1890 TypeManager.system_void_expr, (Parameters) $6);
1892 generic.SetParameterInfo ((ArrayList) $9);
1895 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1896 true, name, (Parameters) $6, (Attributes) $1);
1897 if (RootContext.Documentation != null)
1898 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1902 interface_property_declaration
1908 lexer.PropertyParsing = true;
1909 implicit_value_parameter_type = (Expression)$3;
1911 accessor_declarations
1913 has_get = has_set = false;
1914 lexer.PropertyParsing = false;
1915 implicit_value_parameter_type = null;
1919 LocatedToken lt = (LocatedToken) $4;
1920 MemberName name = new MemberName (lt.Value, lt.Location);
1922 if ($3 == TypeManager.system_void_expr) {
1923 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1929 p = new Property (current_class, (Expression) $3, (int) $2, true,
1930 name, (Attributes) $1,
1933 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1937 Accessors accessor = (Accessors) $7;
1938 p = new Property (current_class, (Expression) $3, (int) $2, true,
1939 name, (Attributes) $1,
1940 accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
1942 if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
1943 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1948 if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
1949 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1954 if (RootContext.Documentation != null)
1955 p.DocComment = Lexer.consume_doc_comment ();
1962 CheckIdentifierToken (yyToken, GetLocation ($4));
1968 interface_event_declaration
1969 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1971 LocatedToken lt = (LocatedToken) $5;
1972 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1973 new MemberName (lt.Value, lt.Location),
1975 if (RootContext.Documentation != null)
1976 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1978 | opt_attributes opt_new EVENT type error {
1979 CheckIdentifierToken (yyToken, GetLocation ($5));
1982 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1983 LocatedToken lt = (LocatedToken) $5;
1984 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1987 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1989 implicit_value_parameter_type = (Expression) $4;
1990 lexer.EventParsing = true;
1992 event_accessor_declarations
1994 lexer.EventParsing = false;
1995 implicit_value_parameter_type = null;
1998 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2003 interface_indexer_declaration
2004 : opt_attributes opt_new type THIS
2005 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
2008 lexer.PropertyParsing = true;
2009 implicit_value_parameter_type = (Expression)$3;
2011 accessor_declarations
2013 has_get = has_set = false;
2014 lexer.PropertyParsing = false;
2015 implicit_value_parameter_type = null;
2021 i = new Indexer (current_class, (Expression) $3,
2022 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2023 (int) $2, true, (Parameters) $6, (Attributes) $1,
2026 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
2030 Accessors accessors = (Accessors) $10;
2031 i = new Indexer (current_class, (Expression) $3,
2032 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2033 (int) $2, true, (Parameters) $6, (Attributes) $1,
2034 accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
2036 if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
2037 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
2042 if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
2043 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
2048 if (RootContext.Documentation != null)
2049 i.DocComment = ConsumeStoredComment ();
2055 operator_declaration
2056 : opt_attributes opt_modifiers operator_declarator
2058 anonymous_host = SimpleAnonymousHost.GetSimple ();
2065 OperatorDeclaration decl = (OperatorDeclaration) $3;
2067 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
2069 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
2070 if (decl.arg2type != null)
2071 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
2073 Operator op = new Operator (
2074 current_class, decl.optype, decl.ret_type, (int) $2,
2075 new Parameters (param_list),
2076 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2078 if (RootContext.Documentation != null) {
2079 op.DocComment = tmpComment;
2080 Lexer.doc_state = XmlCommentState.Allowed;
2083 SimpleAnonymousHost.Simple.Propagate (op);
2084 anonymous_host = null;
2086 // Note again, checking is done in semantic analysis
2087 current_container.AddOperator (op);
2089 current_local_parameters = null;
2095 | SEMICOLON { $$ = null; }
2098 : type OPERATOR overloadable_operator
2099 open_parens opt_attributes opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2101 // TODO: wrong location
2102 if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE)
2103 Error_ParameterModifierNotValid ((Location) $2);
2105 LocatedToken lt = (LocatedToken) $8;
2106 Operator.OpType op = (Operator.OpType) $3;
2107 CheckUnaryOperator (op, lt.Location);
2109 if (op == Operator.OpType.Addition)
2110 op = Operator.OpType.UnaryPlus;
2112 if (op == Operator.OpType.Subtraction)
2113 op = Operator.OpType.UnaryNegation;
2115 Parameter [] pars = new Parameter [1];
2116 Expression type = (Expression) $7;
2118 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, (Attributes) $5, lt.Location);
2120 current_local_parameters = new Parameters (pars);
2122 if (RootContext.Documentation != null) {
2123 tmpComment = Lexer.consume_doc_comment ();
2124 Lexer.doc_state = XmlCommentState.NotAllowed;
2127 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2128 null, null, (Location) $2);
2130 | type OPERATOR overloadable_operator
2132 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
2133 opt_attributes opt_parameter_modifier type IDENTIFIER
2136 // TODO: wrong location
2137 if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE || (Parameter.Modifier)$11 != Parameter.Modifier.NONE)
2138 Error_ParameterModifierNotValid ((Location) $2);
2140 LocatedToken ltParam1 = (LocatedToken) $8;
2141 LocatedToken ltParam2 = (LocatedToken) $13;
2142 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2144 Parameter [] pars = new Parameter [2];
2146 Expression typeL = (Expression) $7;
2147 Expression typeR = (Expression) $12;
2149 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, (Attributes) $5, ltParam1.Location);
2150 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, (Attributes) $10, ltParam2.Location);
2152 current_local_parameters = new Parameters (pars);
2154 if (RootContext.Documentation != null) {
2155 tmpComment = Lexer.consume_doc_comment ();
2156 Lexer.doc_state = XmlCommentState.NotAllowed;
2159 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2160 typeL, ltParam1.Value,
2161 typeR, ltParam2.Value, (Location) $2);
2163 | conversion_operator_declarator
2164 | type OPERATOR overloadable_operator
2166 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
2167 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA error
2169 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2170 Operator.GetName ((Operator.OpType) $3));
2173 | type OPERATOR overloadable_operator
2174 open_parens CLOSE_PARENS
2176 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2177 Operator.GetName ((Operator.OpType) $3));
2182 overloadable_operator
2184 : BANG { $$ = Operator.OpType.LogicalNot; }
2185 | TILDE { $$ = Operator.OpType.OnesComplement; }
2186 | OP_INC { $$ = Operator.OpType.Increment; }
2187 | OP_DEC { $$ = Operator.OpType.Decrement; }
2188 | TRUE { $$ = Operator.OpType.True; }
2189 | FALSE { $$ = Operator.OpType.False; }
2190 // Unary and binary:
2191 | PLUS { $$ = Operator.OpType.Addition; }
2192 | MINUS { $$ = Operator.OpType.Subtraction; }
2194 | STAR { $$ = Operator.OpType.Multiply; }
2195 | DIV { $$ = Operator.OpType.Division; }
2196 | PERCENT { $$ = Operator.OpType.Modulus; }
2197 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2198 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2199 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2200 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2201 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2202 | OP_EQ { $$ = Operator.OpType.Equality; }
2203 | OP_NE { $$ = Operator.OpType.Inequality; }
2204 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2205 | OP_LT { $$ = Operator.OpType.LessThan; }
2206 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2207 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2210 conversion_operator_declarator
2211 : IMPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2213 // TODO: wrong location
2214 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2215 Error_ParameterModifierNotValid (GetLocation ($4));
2217 LocatedToken lt = (LocatedToken) $7;
2218 Parameter [] pars = new Parameter [1];
2220 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2222 current_local_parameters = new Parameters (pars);
2224 if (RootContext.Documentation != null) {
2225 tmpComment = Lexer.consume_doc_comment ();
2226 Lexer.doc_state = XmlCommentState.NotAllowed;
2229 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $6, lt.Value,
2230 null, null, (Location) $2);
2232 | EXPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2234 // TODO: wrong location
2235 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2236 Error_ParameterModifierNotValid (GetLocation ($4));
2238 LocatedToken lt = (LocatedToken) $7;
2239 Parameter [] pars = new Parameter [1];
2241 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2243 current_local_parameters = new Parameters (pars);
2245 if (RootContext.Documentation != null) {
2246 tmpComment = Lexer.consume_doc_comment ();
2247 Lexer.doc_state = XmlCommentState.NotAllowed;
2250 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $6, lt.Value,
2251 null, null, (Location) $2);
2255 syntax_error ((Location) $1, "'operator' expected");
2259 syntax_error ((Location) $1, "'operator' expected");
2263 constructor_declaration
2266 constructor_declarator
2269 Constructor c = (Constructor) $3;
2270 c.Block = (ToplevelBlock) $4;
2271 c.OptAttributes = (Attributes) $1;
2272 c.ModFlags = (int) $2;
2274 if (RootContext.Documentation != null)
2275 c.DocComment = ConsumeStoredComment ();
2277 if (c.Name == current_container.Basename){
2278 if ((c.ModFlags & Modifiers.STATIC) != 0){
2279 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2280 Report.Error (515, c.Location,
2281 "`{0}': access modifiers are not allowed on static constructors",
2282 c.GetSignatureForError ());
2285 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2287 if (c.Initializer != null){
2288 Report.Error (514, c.Location,
2289 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2290 c.GetSignatureForError ());
2293 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2296 // We let another layer check the validity of the constructor.
2297 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2300 current_container.AddConstructor (c);
2302 current_local_parameters = null;
2303 if (RootContext.Documentation != null)
2304 Lexer.doc_state = XmlCommentState.Allowed;
2308 constructor_declarator
2309 : constructor_header
2313 | constructor_header constructor_initializer
2315 ((Constructor)$1).Initializer = (ConstructorInitializer) $2;
2323 if (RootContext.Documentation != null) {
2324 tmpComment = Lexer.consume_doc_comment ();
2325 Lexer.doc_state = XmlCommentState.Allowed;
2328 open_parens opt_formal_parameter_list CLOSE_PARENS
2330 LocatedToken lt = (LocatedToken) $1;
2331 current_local_parameters = (Parameters) $4;
2332 current_block = new ToplevelBlock (null, current_local_parameters, null, lt.Location);
2334 $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
2337 anonymous_host = (IAnonymousHost) $$;
2343 | SEMICOLON { current_block = null; $$ = null; }
2346 constructor_initializer
2347 : COLON BASE open_parens opt_argument_list CLOSE_PARENS
2349 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2351 | COLON THIS open_parens opt_argument_list CLOSE_PARENS
2353 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2356 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2362 : /* EMPTY */ { $$ = 0; }
2363 | UNSAFE { $$ = Modifiers.UNSAFE; }
2364 | EXTERN { $$ = Modifiers.EXTERN; }
2367 destructor_declaration
2368 : opt_attributes opt_finalizer TILDE
2370 if (RootContext.Documentation != null) {
2371 tmpComment = Lexer.consume_doc_comment ();
2372 Lexer.doc_state = XmlCommentState.NotAllowed;
2375 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2377 LocatedToken lt = (LocatedToken) $5;
2378 if (lt.Value != current_container.MemberName.Name){
2379 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2380 } else if (current_container.Kind != Kind.Class){
2381 Report.Error (575, lt.Location, "Only class types can contain destructor");
2383 Location l = lt.Location;
2386 if (!RootContext.StdLib && current_container.Name == "System.Object")
2387 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2389 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2391 Method d = new Destructor (
2392 current_class, TypeManager.system_void_expr, m, "Finalize",
2393 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2394 if (RootContext.Documentation != null)
2395 d.DocComment = ConsumeStoredComment ();
2397 d.Block = (ToplevelBlock) $8;
2398 current_container.AddMethod (d);
2406 EVENT type variable_declarators SEMICOLON
2408 current_array_type = null;
2409 foreach (VariableDeclaration var in (ArrayList) $5) {
2411 MemberName name = new MemberName (var.identifier,
2414 EventField e = new EventField (
2415 current_class, (Expression) $4, (int) $2, false, name,
2418 e.Initializer = var.expression_or_array_initializer;
2420 current_container.AddEvent (e);
2422 if (RootContext.Documentation != null) {
2423 e.DocComment = Lexer.consume_doc_comment ();
2424 Lexer.doc_state = XmlCommentState.Allowed;
2430 EVENT type namespace_or_type_name
2433 implicit_value_parameter_type = (Expression) $4;
2434 lexer.EventParsing = true;
2436 event_accessor_declarations
2438 lexer.EventParsing = false;
2442 MemberName name = (MemberName) $5;
2445 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2446 current_container.Name, name.ToString ());
2449 Accessors accessors = (Accessors) $8;
2451 if (name.TypeArguments != null)
2452 syntax_error (lexer.Location, "an event can't have type arguments");
2454 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2455 // CS0073 is already reported, so no CS0065 here.
2458 Event e = new EventProperty (
2459 current_class, (Expression) $4, (int) $2, false, name,
2460 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2461 if (RootContext.Documentation != null) {
2462 e.DocComment = Lexer.consume_doc_comment ();
2463 Lexer.doc_state = XmlCommentState.Allowed;
2466 current_container.AddEvent (e);
2467 implicit_value_parameter_type = null;
2471 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2472 MemberName mn = (MemberName) $5;
2474 if (mn.Left != null)
2475 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2477 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2479 if (RootContext.Documentation != null)
2480 Lexer.doc_state = XmlCommentState.Allowed;
2484 event_accessor_declarations
2485 : add_accessor_declaration remove_accessor_declaration
2487 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2489 | remove_accessor_declaration add_accessor_declaration
2491 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2492 accessors.declared_in_reverse = true;
2495 | add_accessor_declaration { $$ = null; }
2496 | remove_accessor_declaration { $$ = null; }
2499 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2505 add_accessor_declaration
2506 : opt_attributes ADD
2508 Parameter [] args = new Parameter [1];
2509 Parameter implicit_value_parameter = new Parameter (
2510 implicit_value_parameter_type, "value",
2511 Parameter.Modifier.NONE, null, (Location) $2);
2513 args [0] = implicit_value_parameter;
2515 current_local_parameters = new Parameters (args);
2516 lexer.EventParsing = false;
2518 anonymous_host = SimpleAnonymousHost.GetSimple ();
2522 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2523 lexer.EventParsing = true;
2525 current_local_parameters = null;
2526 SimpleAnonymousHost.Simple.Propagate (accessor);
2527 anonymous_host = null;
2531 | opt_attributes ADD error {
2532 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2535 | opt_attributes modifiers ADD {
2536 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2541 remove_accessor_declaration
2542 : opt_attributes REMOVE
2544 Parameter [] args = new Parameter [1];
2545 Parameter implicit_value_parameter = new Parameter (
2546 implicit_value_parameter_type, "value",
2547 Parameter.Modifier.NONE, null, (Location) $2);
2549 args [0] = implicit_value_parameter;
2551 current_local_parameters = new Parameters (args);
2552 lexer.EventParsing = false;
2556 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2557 lexer.EventParsing = true;
2559 | opt_attributes REMOVE error {
2560 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2563 | opt_attributes modifiers REMOVE {
2564 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2570 : opt_attributes opt_modifiers indexer_declarator
2573 IndexerDeclaration decl = (IndexerDeclaration) $3;
2575 implicit_value_parameter_type = decl.type;
2577 lexer.PropertyParsing = true;
2578 parsing_indexer = true;
2580 indexer_parameters = decl.param_list;
2581 anonymous_host = SimpleAnonymousHost.GetSimple ();
2583 accessor_declarations
2585 lexer.PropertyParsing = false;
2586 has_get = has_set = false;
2587 parsing_indexer = false;
2594 // The signature is computed from the signature of the indexer. Look
2595 // at section 3.6 on the spec
2597 IndexerDeclaration decl = (IndexerDeclaration) $3;
2598 Location loc = decl.location;
2599 Accessors accessors = (Accessors) $6;
2600 Accessor get_block = accessors.get_or_add;
2601 Accessor set_block = accessors.set_or_remove;
2604 if (decl.interface_type != null)
2605 name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);
2607 name = new MemberName (TypeContainer.DefaultIndexerName, loc);
2609 indexer = new Indexer (current_class, decl.type, name,
2610 (int) $2, false, decl.param_list, (Attributes) $1,
2611 get_block, set_block, accessors.declared_in_reverse);
2613 if (RootContext.Documentation != null)
2614 indexer.DocComment = ConsumeStoredComment ();
2616 current_container.AddIndexer (indexer);
2618 current_local_parameters = null;
2619 implicit_value_parameter_type = null;
2620 indexer_parameters = null;
2625 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2627 Parameters pars = (Parameters) $4;
2628 if (pars.HasArglist) {
2629 // "__arglist is not valid in this context"
2630 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2631 } else if (pars.Empty){
2632 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2634 if (RootContext.Documentation != null) {
2635 tmpComment = Lexer.consume_doc_comment ();
2636 Lexer.doc_state = XmlCommentState.Allowed;
2639 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2641 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2643 Parameters pars = (Parameters) $6;
2645 if (pars.HasArglist) {
2646 // "__arglist is not valid in this context"
2647 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2648 } else if (pars.Empty){
2649 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2652 MemberName name = (MemberName) $2;
2653 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2655 if (RootContext.Documentation != null) {
2656 tmpComment = Lexer.consume_doc_comment ();
2657 Lexer.doc_state = XmlCommentState.Allowed;
2667 if (RootContext.Documentation != null)
2668 enumTypeComment = Lexer.consume_doc_comment ();
2673 LocatedToken lt = (LocatedToken) $4;
2674 Location enum_location = lt.Location;
2676 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2677 Enum e = new Enum (current_namespace, current_class, (Expression) $5, (int) $2,
2678 name, (Attributes) $1);
2680 if (RootContext.Documentation != null)
2681 e.DocComment = enumTypeComment;
2684 EnumMember em = null;
2685 foreach (VariableDeclaration ev in (ArrayList) $7) {
2686 em = new EnumMember (
2687 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2688 ev.OptAttributes, ev.Location);
2690 // if (RootContext.Documentation != null)
2691 em.DocComment = ev.DocComment;
2693 e.AddEnumMember (em);
2696 current_container.AddTypeContainer (e);
2703 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2704 | COLON type { $$ = $2; }
2710 if (RootContext.Documentation != null)
2711 Lexer.doc_state = XmlCommentState.Allowed;
2713 opt_enum_member_declarations
2715 // here will be evaluated after CLOSE_BLACE is consumed.
2716 if (RootContext.Documentation != null)
2717 Lexer.doc_state = XmlCommentState.Allowed;
2725 opt_enum_member_declarations
2726 : /* empty */ { $$ = new ArrayList (4); }
2727 | enum_member_declarations opt_comma { $$ = $1; }
2730 enum_member_declarations
2731 : enum_member_declaration
2733 ArrayList l = new ArrayList (4);
2738 | enum_member_declarations COMMA enum_member_declaration
2740 ArrayList l = (ArrayList) $1;
2748 enum_member_declaration
2749 : opt_attributes IDENTIFIER
2751 VariableDeclaration vd = new VariableDeclaration (
2752 (LocatedToken) $2, null, (Attributes) $1);
2754 if (RootContext.Documentation != null) {
2755 vd.DocComment = Lexer.consume_doc_comment ();
2756 Lexer.doc_state = XmlCommentState.Allowed;
2761 | opt_attributes IDENTIFIER
2763 if (RootContext.Documentation != null) {
2764 tmpComment = Lexer.consume_doc_comment ();
2765 Lexer.doc_state = XmlCommentState.NotAllowed;
2770 VariableDeclaration vd = new VariableDeclaration (
2771 (LocatedToken) $2, $5, (Attributes) $1);
2773 if (RootContext.Documentation != null)
2774 vd.DocComment = ConsumeStoredComment ();
2780 delegate_declaration
2785 lexer.ConstraintsParsing = true;
2788 open_parens opt_formal_parameter_list CLOSE_PARENS
2790 MemberName name = MakeName ((MemberName) $6);
2791 Parameters p = (Parameters) $8;
2793 // TODO: wrong location
2794 Report.Error (1669, name.Location, "__arglist is not valid in this context");
2797 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2798 (int) $2, name, p, (Attributes) $1);
2800 if (RootContext.Documentation != null) {
2801 del.DocComment = Lexer.consume_doc_comment ();
2802 Lexer.doc_state = XmlCommentState.Allowed;
2805 current_container.AddDelegate (del);
2806 current_delegate = del;
2808 opt_type_parameter_constraints_clauses
2810 lexer.ConstraintsParsing = false;
2814 current_delegate.SetParameterInfo ((ArrayList) $11);
2815 $$ = current_delegate;
2817 current_delegate = null;
2824 lexer.CheckNullable (false);
2829 lexer.CheckNullable (true);
2834 namespace_or_type_name
2835 : IDENTIFIER opt_type_argument_list
2837 LocatedToken lt = (LocatedToken) $1;
2838 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2840 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2841 LocatedToken lt1 = (LocatedToken) $1;
2842 LocatedToken lt2 = (LocatedToken) $3;
2843 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2845 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2846 LocatedToken lt = (LocatedToken) $3;
2847 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2852 : IDENTIFIER opt_type_parameter_list
2854 LocatedToken lt = (LocatedToken) $1;
2855 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2857 | namespace_or_type_name DOT IDENTIFIER opt_type_parameter_list
2859 LocatedToken lt = (LocatedToken) $3;
2860 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2865 : IDENTIFIER opt_type_parameter_list
2867 LocatedToken lt = (LocatedToken) $1;
2868 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2873 // Generics arguments (any type, without attributes)
2876 opt_type_argument_list
2877 : /* empty */ { $$ = null; }
2878 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2880 if (RootContext.Version == LanguageVersion.ISO_1)
2881 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2888 // Generics parameters (identifiers only, with attributes), used in type, method declarations
2891 opt_type_parameter_list
2892 : /* empty */ { $$ = null; }
2893 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2895 if (RootContext.Version == LanguageVersion.ISO_1)
2896 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2905 TypeArguments type_args = new TypeArguments (lexer.Location);
2906 type_args.Add ((Expression) $1);
2909 | type_arguments COMMA type_argument
2911 TypeArguments type_args = (TypeArguments) $1;
2912 type_args.Add ((Expression) $3);
2922 | attribute_sections type
2924 SimpleName sn = $2 as SimpleName;
2926 Error_TypeExpected (GetLocation ($2));
2928 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2934 * Before you think of adding a return_type, notice that we have been
2935 * using two rules in the places where it matters (one rule using type
2936 * and another identical one that uses VOID as the return type). This
2937 * gets rid of a shift/reduce couple
2940 : namespace_or_type_name opt_nullable
2942 MemberName name = (MemberName) $1;
2943 $$ = name.GetTypeExpression ();
2946 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2948 | builtin_types opt_nullable
2951 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2961 // Note that here only unmanaged types are allowed but we
2962 // can't perform checks during this phase - we do it during
2963 // semantic analysis.
2965 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2969 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2974 : builtin_types opt_nullable
2977 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2979 | non_expression_type rank_specifier
2981 Location loc = GetLocation ($1);
2983 loc = lexer.Location;
2984 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2986 | non_expression_type STAR
2988 Location loc = GetLocation ($1);
2990 loc = lexer.Location;
2991 $$ = new ComposedCast ((Expression) $1, "*", loc);
2993 | expression rank_specifiers
2995 $$ = new ComposedCast ((Expression) $1, (string) $2);
2999 $$ = new ComposedCast ((Expression) $1, "*");
3003 // We need this because the parser will happily go and reduce IDENTIFIER STAR
3004 // through this different path
3006 | multiplicative_expression STAR
3008 $$ = new ComposedCast ((Expression) $1, "*");
3015 ArrayList types = new ArrayList (4);
3020 | type_list COMMA type
3022 ArrayList types = (ArrayList) $1;
3030 * replaces all the productions for isolating the various
3031 * simple types, but we need this to reuse it easily in local_variable_type
3034 : OBJECT { $$ = TypeManager.system_object_expr; }
3035 | STRING { $$ = TypeManager.system_string_expr; }
3036 | BOOL { $$ = TypeManager.system_boolean_expr; }
3037 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
3038 | FLOAT { $$ = TypeManager.system_single_expr; }
3039 | DOUBLE { $$ = TypeManager.system_double_expr; }
3044 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
3045 | BYTE { $$ = TypeManager.system_byte_expr; }
3046 | SHORT { $$ = TypeManager.system_int16_expr; }
3047 | USHORT { $$ = TypeManager.system_uint16_expr; }
3048 | INT { $$ = TypeManager.system_int32_expr; }
3049 | UINT { $$ = TypeManager.system_uint32_expr; }
3050 | LONG { $$ = TypeManager.system_int64_expr; }
3051 | ULONG { $$ = TypeManager.system_uint64_expr; }
3052 | CHAR { $$ = TypeManager.system_char_expr; }
3053 | VOID { $$ = TypeManager.system_void_expr; }
3057 : type rank_specifiers opt_nullable
3059 string rank_specifiers = (string) $2;
3061 rank_specifiers += "?";
3063 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
3068 // Expressions, section 7.5
3077 MemberName mn = (MemberName) $1;
3078 $$ = mn.GetTypeExpression ();
3080 | IDENTIFIER DOUBLE_COLON IDENTIFIER
3082 LocatedToken lt1 = (LocatedToken) $1;
3083 LocatedToken lt2 = (LocatedToken) $3;
3084 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
3086 | parenthesized_expression
3087 | default_value_expression
3089 | invocation_expression
3093 | post_increment_expression
3094 | post_decrement_expression
3098 | checked_expression
3099 | unchecked_expression
3100 | pointer_member_access
3101 | anonymous_method_expression
3108 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3109 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
3110 | NULL { $$ = new NullLiteral (lexer.Location); }
3114 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3115 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3116 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3121 object v = lexer.Value;
3124 $$ = new IntLiteral ((int) v, lexer.Location);
3125 } else if (v is uint)
3126 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3128 $$ = new LongLiteral ((Int64) v, lexer.Location);
3129 else if (v is ulong)
3130 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3132 Console.WriteLine ("OOPS. Unexpected result from scanner");
3137 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3138 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3141 parenthesized_expression_0
3142 : OPEN_PARENS expression CLOSE_PARENS
3145 lexer.Deambiguate_CloseParens ($$);
3146 // After this, the next token returned is one of
3147 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
3148 // or CLOSE_PARENS_MINUS.
3150 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
3153 parenthesized_expression
3154 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
3158 | parenthesized_expression_0 CLOSE_PARENS
3162 | parenthesized_expression_0 CLOSE_PARENS_MINUS
3164 // If a parenthesized expression is followed by a minus, we need to wrap
3165 // the expression inside a ParenthesizedExpression for the CS0075 check
3166 // in Binary.DoResolve().
3167 $$ = new ParenthesizedExpression ((Expression) $1);
3172 : primary_expression DOT IDENTIFIER opt_type_argument_list
3174 LocatedToken lt = (LocatedToken) $3;
3175 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3177 | predefined_type DOT IDENTIFIER opt_type_argument_list
3179 LocatedToken lt = (LocatedToken) $3;
3180 // TODO: Location is wrong as some predefined types doesn't hold a location
3181 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3189 invocation_expression
3190 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3193 Report.Error (1, (Location) $2, "Parse error");
3195 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3197 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3199 $$ = new Invocation ((Expression) $1, new ArrayList ());
3201 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3203 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3205 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3207 ArrayList args = new ArrayList (1);
3209 $$ = new Invocation ((Expression) $1, args);
3211 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3213 ArrayList args = ((ArrayList) $4);
3215 $$ = new Invocation ((Expression) $1, args);
3219 opt_object_or_collection_initializer
3220 : /* empty */ { $$ = null; }
3221 | object_or_collection_initializer
3224 object_or_collection_initializer
3225 : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
3228 $$ = CollectionOrObjectInitializers.Empty;
3230 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3232 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3234 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3238 opt_member_initializer_list
3239 : /* empty */ { $$ = null; }
3240 | member_initializer_list
3246 member_initializer_list
3247 : member_initializer
3249 ArrayList a = new ArrayList ();
3253 | member_initializer_list COMMA member_initializer
3255 ArrayList a = (ArrayList)$1;
3262 : IDENTIFIER ASSIGN initializer_value
3264 LocatedToken lt = $1 as LocatedToken;
3265 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3267 | non_assignment_expression
3269 $$ = new CollectionElementInitializer ((Expression)$1);
3271 | OPEN_BRACE expression_list CLOSE_BRACE
3273 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3275 | OPEN_BRACE CLOSE_BRACE
3277 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3283 | object_or_collection_initializer
3287 : /* empty */ { $$ = null; }
3294 ArrayList list = new ArrayList (4);
3298 | argument_list COMMA argument
3300 ArrayList list = (ArrayList) $1;
3304 | argument_list error {
3305 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3313 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3315 | non_simple_argument
3322 : REF variable_reference
3324 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3326 | OUT variable_reference
3328 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3330 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3332 ArrayList list = (ArrayList) $3;
3333 Argument[] args = new Argument [list.Count];
3334 list.CopyTo (args, 0);
3336 Expression expr = new Arglist (args, (Location) $1);
3337 $$ = new Argument (expr, Argument.AType.Expression);
3339 | ARGLIST OPEN_PARENS CLOSE_PARENS
3341 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3345 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3350 : expression { note ("section 5.4"); $$ = $1; }
3354 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3356 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3358 | primary_expression rank_specifiers
3360 // So the super-trick is that primary_expression
3361 // can only be either a SimpleName or a MemberAccess.
3362 // The MemberAccess case arises when you have a fully qualified type-name like :
3364 // SimpleName is when you have
3367 Expression expr = (Expression) $1;
3368 if (expr is ComposedCast){
3369 $$ = new ComposedCast (expr, (string) $2);
3370 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3371 Error_ExpectingTypeName (expr);
3372 $$ = TypeManager.system_object_expr;
3375 // So we extract the string corresponding to the SimpleName
3378 $$ = new ComposedCast (expr, (string) $2);
3380 current_array_type = (Expression)$$;
3387 ArrayList list = new ArrayList (4);
3391 | expression_list COMMA expression
3393 ArrayList list = (ArrayList) $1;
3402 $$ = new This (current_block, (Location) $1);
3407 : BASE DOT IDENTIFIER opt_type_argument_list
3409 LocatedToken lt = (LocatedToken) $3;
3410 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3412 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3414 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3417 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3422 post_increment_expression
3423 : primary_expression OP_INC
3425 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3426 (Expression) $1, (Location) $2);
3430 post_decrement_expression
3431 : primary_expression OP_DEC
3433 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3434 (Expression) $1, (Location) $2);
3439 : object_or_delegate_creation_expression
3440 | array_creation_expression
3441 | anonymous_type_expression
3444 object_or_delegate_creation_expression
3445 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3448 if (RootContext.Version < LanguageVersion.LINQ) {
3449 Error_ExpectingTypeName ((Expression) $2);
3453 $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (CollectionOrObjectInitializers) $6, (Location) $1);
3456 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3458 | NEW type object_or_collection_initializer
3460 if (RootContext.Version < LanguageVersion.LINQ) {
3461 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3465 $$ = new NewInitialize ((Expression) $2, null, (CollectionOrObjectInitializers) $3, (Location) $1);
3469 array_creation_expression
3470 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3472 opt_array_initializer
3474 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3476 | NEW type rank_specifiers array_initializer
3478 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3480 | NEW rank_specifiers array_initializer
3482 if (RootContext.Version < LanguageVersion.LINQ) {
3483 Report.Error (1031, (Location) $1, "Type expected");
3487 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
3491 Report.Error (1031, (Location) $1, "Type expected");
3496 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3501 anonymous_type_expression
3502 : NEW OPEN_BRACE anonymous_type_parameters CLOSE_BRACE
3504 if (RootContext.Version < LanguageVersion.LINQ) {
3505 Report.Error (1031, (Location) $1, "Type expected");
3509 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, lexer.Location);
3513 anonymous_type_parameters
3515 | anonymous_type_parameter
3517 ArrayList a = new ArrayList (4);
3521 | anonymous_type_parameters COMMA anonymous_type_parameter
3523 ArrayList a = (ArrayList) $1;
3529 anonymous_type_parameter
3530 : IDENTIFIER ASSIGN variable_initializer
3532 LocatedToken lt = (LocatedToken)$1;
3533 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3537 LocatedToken lt = (LocatedToken)$1;
3538 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3539 lt.Value, lt.Location);
3543 MemberAccess ma = (MemberAccess) $1;
3544 $$ = new AnonymousTypeParameter (ma, ma.Identifier, ma.Location);
3548 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3549 "Anonymous type members must be a member assignment, simple name or member access expression");
3564 opt_rank_specifier_or_nullable
3573 | opt_nullable rank_specifiers
3580 | opt_nullable rank_specifiers INTERR
3583 $$ = "?" + $2 + "?";
3590 : rank_specifier opt_rank_specifier
3592 $$ = (string) $2 + (string) $1;
3597 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3599 $$ = "[" + (string) $2 + "]";
3619 | dim_separators COMMA
3621 $$ = (string) $1 + ",";
3625 opt_array_initializer
3637 : OPEN_BRACE CLOSE_BRACE
3639 ArrayList list = new ArrayList (4);
3642 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3644 $$ = (ArrayList) $2;
3648 variable_initializer_list
3649 : variable_initializer
3651 ArrayList list = new ArrayList (4);
3655 | variable_initializer_list COMMA variable_initializer
3657 ArrayList list = (ArrayList) $1;
3666 pushed_current_array_type = current_array_type;
3667 lexer.TypeOfParsing = true;
3669 OPEN_PARENS typeof_type_expression CLOSE_PARENS
3671 lexer.TypeOfParsing = false;
3672 Expression type = (Expression)$4;
3673 if (type == TypeManager.system_void_expr)
3674 $$ = new TypeOfVoid ((Location) $1);
3676 $$ = new TypeOf (type, (Location) $1);
3677 current_array_type = pushed_current_array_type;
3681 typeof_type_expression
3688 $$ = new UnboundTypeExpression ((MemberName)$1, lexer.Location);
3693 : IDENTIFIER GENERIC_DIMENSION
3695 if (RootContext.Version == LanguageVersion.ISO_1)
3696 Report.FeatureIsNotISO1 (lexer.Location, "generics");
3698 LocatedToken lt = (LocatedToken) $1;
3699 TypeArguments ta = new TypeArguments ((int)$2, lt.Location);
3701 $$ = new MemberName (lt.Value, ta, lt.Location);
3703 | IDENTIFIER DOUBLE_COLON IDENTIFIER GENERIC_DIMENSION
3705 LocatedToken lt = (LocatedToken) $1;
3706 MemberName left = new MemberName (lt.Value, lt.Location);
3707 lt = (LocatedToken) $3;
3708 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3710 $$ = new MemberName (left, lt.Value, ta, lt.Location);
3712 | unbound_type_name DOT IDENTIFIER GENERIC_DIMENSION
3714 LocatedToken lt = (LocatedToken) $3;
3715 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3717 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3719 | namespace_or_type_name DOT IDENTIFIER GENERIC_DIMENSION
3721 LocatedToken lt = (LocatedToken) $3;
3722 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3724 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3730 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3731 $$ = new SizeOf ((Expression) $3, (Location) $1);
3736 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3738 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3742 unchecked_expression
3743 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3745 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3749 pointer_member_access
3750 : primary_expression OP_PTR IDENTIFIER
3753 LocatedToken lt = (LocatedToken) $3;
3755 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3756 $$ = new MemberAccess (deref, lt.Value);
3760 anonymous_method_expression
3761 : DELEGATE opt_anonymous_method_signature
3763 start_anonymous (false, (Parameters) $2, (Location) $1);
3767 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
3771 opt_anonymous_method_signature
3772 : /* empty */ { $$ = null; }
3773 | anonymous_method_signature
3776 anonymous_method_signature
3777 : open_parens opt_anonymous_method_parameter_list CLOSE_PARENS
3780 $$ = Parameters.EmptyReadOnlyParameters;
3782 ArrayList par_list = (ArrayList) $2;
3783 Parameter [] pars = new Parameter [par_list.Count];
3784 par_list.CopyTo (pars);
3785 $$ = new Parameters (pars);
3790 opt_anonymous_method_parameter_list
3791 : /* empty */ { $$ = null; }
3792 | anonymous_method_parameter_list { $$ = $1; }
3795 anonymous_method_parameter_list
3796 : anonymous_method_parameter
3798 ArrayList a = new ArrayList (4);
3802 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3804 ArrayList a = (ArrayList) $1;
3810 anonymous_method_parameter
3811 : opt_parameter_modifier type IDENTIFIER {
3812 LocatedToken lt = (LocatedToken) $3;
3813 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3815 | PARAMS type IDENTIFIER {
3816 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3821 default_value_expression
3822 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3824 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3829 : primary_expression
3830 | BANG prefixed_unary_expression
3832 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3834 | TILDE prefixed_unary_expression
3836 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3842 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3844 $$ = new Cast ((Expression) $1, (Expression) $3);
3846 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3848 $$ = new Cast ((Expression) $1, (Expression) $3);
3850 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3852 $$ = new Cast ((Expression) $1, (Expression) $3);
3858 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3860 // TODO: wrong location
3861 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3866 // The idea to split this out is from Rhys' grammar
3867 // to solve the problem with casts.
3869 prefixed_unary_expression
3871 | PLUS prefixed_unary_expression
3873 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3875 | MINUS prefixed_unary_expression
3877 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3879 | OP_INC prefixed_unary_expression
3881 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3882 (Expression) $2, (Location) $1);
3884 | OP_DEC prefixed_unary_expression
3886 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3887 (Expression) $2, (Location) $1);
3889 | STAR prefixed_unary_expression
3891 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3893 | BITWISE_AND prefixed_unary_expression
3895 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3899 pre_increment_expression
3900 : OP_INC prefixed_unary_expression
3902 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3903 (Expression) $2, (Location) $1);
3907 pre_decrement_expression
3908 : OP_DEC prefixed_unary_expression
3910 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3911 (Expression) $2, (Location) $1);
3915 multiplicative_expression
3916 : prefixed_unary_expression
3917 | multiplicative_expression STAR prefixed_unary_expression
3919 $$ = new Binary (Binary.Operator.Multiply,
3920 (Expression) $1, (Expression) $3);
3922 | multiplicative_expression DIV prefixed_unary_expression
3924 $$ = new Binary (Binary.Operator.Division,
3925 (Expression) $1, (Expression) $3);
3927 | multiplicative_expression PERCENT prefixed_unary_expression
3929 $$ = new Binary (Binary.Operator.Modulus,
3930 (Expression) $1, (Expression) $3);
3935 : multiplicative_expression
3936 | additive_expression PLUS multiplicative_expression
3938 $$ = new Binary (Binary.Operator.Addition,
3939 (Expression) $1, (Expression) $3);
3941 | additive_expression MINUS multiplicative_expression
3943 $$ = new Binary (Binary.Operator.Subtraction,
3944 (Expression) $1, (Expression) $3);
3949 : additive_expression
3950 | shift_expression OP_SHIFT_LEFT additive_expression
3952 $$ = new Binary (Binary.Operator.LeftShift,
3953 (Expression) $1, (Expression) $3);
3955 | shift_expression OP_SHIFT_RIGHT additive_expression
3957 $$ = new Binary (Binary.Operator.RightShift,
3958 (Expression) $1, (Expression) $3);
3969 lexer.PutbackNullable ();
3974 nullable_type_or_conditional
3977 if (((bool) $2) && ($1 is ComposedCast))
3978 $$ = ((ComposedCast) $1).RemoveNullable ();
3984 relational_expression
3986 | relational_expression OP_LT shift_expression
3988 $$ = new Binary (Binary.Operator.LessThan,
3989 (Expression) $1, (Expression) $3);
3991 | relational_expression OP_GT shift_expression
3993 $$ = new Binary (Binary.Operator.GreaterThan,
3994 (Expression) $1, (Expression) $3);
3996 | relational_expression OP_LE shift_expression
3998 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3999 (Expression) $1, (Expression) $3);
4001 | relational_expression OP_GE shift_expression
4003 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
4004 (Expression) $1, (Expression) $3);
4006 | relational_expression IS
4009 } nullable_type_or_conditional
4011 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
4013 | relational_expression AS
4016 } nullable_type_or_conditional
4018 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
4023 : relational_expression
4024 | equality_expression OP_EQ relational_expression
4026 $$ = new Binary (Binary.Operator.Equality,
4027 (Expression) $1, (Expression) $3);
4029 | equality_expression OP_NE relational_expression
4031 $$ = new Binary (Binary.Operator.Inequality,
4032 (Expression) $1, (Expression) $3);
4037 : equality_expression
4038 | and_expression BITWISE_AND equality_expression
4040 $$ = new Binary (Binary.Operator.BitwiseAnd,
4041 (Expression) $1, (Expression) $3);
4045 exclusive_or_expression
4047 | exclusive_or_expression CARRET and_expression
4049 $$ = new Binary (Binary.Operator.ExclusiveOr,
4050 (Expression) $1, (Expression) $3);
4054 inclusive_or_expression
4055 : exclusive_or_expression
4056 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4058 $$ = new Binary (Binary.Operator.BitwiseOr,
4059 (Expression) $1, (Expression) $3);
4063 conditional_and_expression
4064 : inclusive_or_expression
4065 | conditional_and_expression OP_AND inclusive_or_expression
4067 $$ = new Binary (Binary.Operator.LogicalAnd,
4068 (Expression) $1, (Expression) $3);
4072 conditional_or_expression
4073 : conditional_and_expression
4074 | conditional_or_expression OP_OR conditional_and_expression
4076 $$ = new Binary (Binary.Operator.LogicalOr,
4077 (Expression) $1, (Expression) $3);
4081 conditional_expression
4082 : conditional_or_expression
4083 | conditional_or_expression INTERR expression COLON expression
4085 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
4087 | conditional_or_expression OP_COALESCING expression
4089 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
4091 // We'll be resolved into a `parenthesized_expression_0' later on.
4092 | conditional_or_expression INTERR CLOSE_PARENS
4094 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
4095 lexer.PutbackCloseParens ();
4099 assignment_expression
4100 : prefixed_unary_expression ASSIGN expression
4102 $$ = new Assign ((Expression) $1, (Expression) $3);
4104 | prefixed_unary_expression OP_MULT_ASSIGN expression
4106 $$ = new CompoundAssign (
4107 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4109 | prefixed_unary_expression OP_DIV_ASSIGN expression
4111 $$ = new CompoundAssign (
4112 Binary.Operator.Division, (Expression) $1, (Expression) $3);
4114 | prefixed_unary_expression OP_MOD_ASSIGN expression
4116 $$ = new CompoundAssign (
4117 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4119 | prefixed_unary_expression OP_ADD_ASSIGN expression
4121 $$ = new CompoundAssign (
4122 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4124 | prefixed_unary_expression OP_SUB_ASSIGN expression
4126 $$ = new CompoundAssign (
4127 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4129 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4131 $$ = new CompoundAssign (
4132 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4134 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4136 $$ = new CompoundAssign (
4137 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4139 | prefixed_unary_expression OP_AND_ASSIGN expression
4141 $$ = new CompoundAssign (
4142 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4144 | prefixed_unary_expression OP_OR_ASSIGN expression
4146 $$ = new CompoundAssign (
4147 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4149 | prefixed_unary_expression OP_XOR_ASSIGN expression
4151 $$ = new CompoundAssign (
4152 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4156 lambda_parameter_list
4159 ArrayList pars = new ArrayList (4);
4164 | lambda_parameter_list COMMA lambda_parameter
4166 ArrayList pars = (ArrayList) $1;
4167 Parameter p = (Parameter)$3;
4168 if (pars[0].GetType () != p.GetType ()) {
4169 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4178 : parameter_modifier type IDENTIFIER
4180 LocatedToken lt = (LocatedToken) $3;
4182 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4186 LocatedToken lt = (LocatedToken) $2;
4188 $$ = new Parameter ((Expression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4192 LocatedToken lt = (LocatedToken) $1;
4193 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4197 opt_lambda_parameter_list
4198 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
4199 | lambda_parameter_list {
4200 ArrayList pars_list = (ArrayList) $1;
4201 $$ = new Parameters ((Parameter[])pars_list.ToArray (typeof (Parameter)));
4205 lambda_expression_body
4207 start_block (lexer.Location);
4211 Block b = end_block (lexer.Location);
4212 b.AddStatement (new ContextualReturn ((Expression) $2));
4223 LocatedToken lt = (LocatedToken) $1;
4224 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4225 start_anonymous (true, new Parameters (p), (Location) $2);
4227 lambda_expression_body
4229 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
4231 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4233 start_anonymous (true, (Parameters) $2, (Location) $4);
4235 lambda_expression_body
4237 $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
4242 : assignment_expression
4243 | non_assignment_expression
4246 non_assignment_expression
4247 : conditional_expression
4269 lexer.ConstraintsParsing = true;
4273 MemberName name = MakeName ((MemberName) $6);
4274 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4277 opt_type_parameter_constraints_clauses
4279 lexer.ConstraintsParsing = false;
4281 current_class.SetParameterInfo ((ArrayList) $9);
4283 if (RootContext.Documentation != null) {
4284 current_container.DocComment = Lexer.consume_doc_comment ();
4285 Lexer.doc_state = XmlCommentState.Allowed;
4290 if (RootContext.Documentation != null)
4291 Lexer.doc_state = XmlCommentState.Allowed;
4295 $$ = pop_current_class ();
4303 { $$ = $1; } // location
4307 : /* empty */ { $$ = (int) 0; }
4313 | modifiers modifier
4318 if ((m1 & m2) != 0) {
4319 Location l = lexer.Location;
4320 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4322 $$ = (int) (m1 | m2);
4327 : NEW { $$ = Modifiers.NEW; }
4328 | PUBLIC { $$ = Modifiers.PUBLIC; }
4329 | PROTECTED { $$ = Modifiers.PROTECTED; }
4330 | INTERNAL { $$ = Modifiers.INTERNAL; }
4331 | PRIVATE { $$ = Modifiers.PRIVATE; }
4332 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4333 | SEALED { $$ = Modifiers.SEALED; }
4334 | STATIC { $$ = Modifiers.STATIC; }
4335 | READONLY { $$ = Modifiers.READONLY; }
4336 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4337 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4338 | EXTERN { $$ = Modifiers.EXTERN; }
4339 | VOLATILE { $$ = Modifiers.VOLATILE; }
4340 | UNSAFE { $$ = Modifiers.UNSAFE; }
4349 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4352 opt_type_parameter_constraints_clauses
4353 : /* empty */ { $$ = null; }
4354 | type_parameter_constraints_clauses
4358 type_parameter_constraints_clauses
4359 : type_parameter_constraints_clause {
4360 ArrayList constraints = new ArrayList (1);
4361 constraints.Add ($1);
4364 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4365 ArrayList constraints = (ArrayList) $1;
4366 Constraints new_constraint = (Constraints)$2;
4368 foreach (Constraints c in constraints) {
4369 if (new_constraint.TypeParameter == c.TypeParameter) {
4370 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4371 new_constraint.TypeParameter);
4375 constraints.Add (new_constraint);
4380 type_parameter_constraints_clause
4381 : WHERE IDENTIFIER COLON type_parameter_constraints {
4382 LocatedToken lt = (LocatedToken) $2;
4383 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4387 type_parameter_constraints
4388 : type_parameter_constraint {
4389 ArrayList constraints = new ArrayList (1);
4390 constraints.Add ($1);
4393 | type_parameter_constraints COMMA type_parameter_constraint {
4394 ArrayList constraints = (ArrayList) $1;
4396 constraints.Add ($3);
4401 type_parameter_constraint
4403 | NEW OPEN_PARENS CLOSE_PARENS {
4404 $$ = SpecialConstraint.Constructor;
4407 $$ = SpecialConstraint.ReferenceType;
4410 $$ = SpecialConstraint.ValueType;
4419 // A block is "contained" on the following places:
4421 // property_declaration as part of the accessor body (get/set)
4422 // operator_declaration
4423 // constructor_declaration
4424 // destructor_declaration
4425 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4430 ++lexer.parsing_block;
4431 start_block ((Location) $1);
4433 opt_statement_list CLOSE_BRACE
4435 --lexer.parsing_block;
4436 $$ = end_block ((Location) $4);
4443 ++lexer.parsing_block;
4445 opt_statement_list CLOSE_BRACE
4447 --lexer.parsing_block;
4448 $$ = end_block ((Location) $4);
4459 | statement_list statement
4463 : declaration_statement
4465 if ($1 != null && (Block) $1 != current_block){
4466 current_block.AddStatement ((Statement) $1);
4467 current_block = (Block) $1;
4470 | valid_declaration_statement
4472 current_block.AddStatement ((Statement) $1);
4477 valid_declaration_statement
4480 | expression_statement
4481 | selection_statement
4482 | iteration_statement
4486 | unchecked_statement
4494 : valid_declaration_statement
4495 | declaration_statement
4497 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4502 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4510 $$ = EmptyStatement.Value;
4517 LocatedToken lt = (LocatedToken) $1;
4518 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4520 if (current_block.AddLabel (labeled))
4521 current_block.AddStatement (labeled);
4526 declaration_statement
4527 : local_variable_declaration SEMICOLON
4529 current_array_type = null;
4531 DictionaryEntry de = (DictionaryEntry) $1;
4532 Expression e = (Expression) de.Key;
4534 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4538 | local_constant_declaration SEMICOLON
4540 current_array_type = null;
4542 DictionaryEntry de = (DictionaryEntry) $1;
4544 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4550 * The following is from Rhys' grammar:
4551 * > Types in local variable declarations must be recognized as
4552 * > expressions to prevent reduce/reduce errors in the grammar.
4553 * > The expressions are converted into types during semantic analysis.
4556 : primary_expression opt_rank_specifier_or_nullable
4558 // FIXME: Do something smart here regarding the composition of the type.
4560 // Ok, the above "primary_expression" is there to get rid of
4561 // both reduce/reduce and shift/reduces in the grammar, it should
4562 // really just be "type_name". If you use type_name, a reduce/reduce
4563 // creeps up. If you use namespace_or_type_name (which is all we need
4564 // really) two shift/reduces appear.
4567 // So the super-trick is that primary_expression
4568 // can only be either a SimpleName or a MemberAccess.
4569 // The MemberAccess case arises when you have a fully qualified type-name like :
4571 // SimpleName is when you have
4574 Expression expr = (Expression) $1;
4575 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4576 Error_ExpectingTypeName (expr);
4580 // So we extract the string corresponding to the SimpleName
4584 if ((string) $2 == "")
4587 $$ = new ComposedCast ((Expression) $1, (string) $2);
4590 | builtin_types opt_rank_specifier_or_nullable
4592 if ((string) $2 == "")
4595 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4599 local_variable_pointer_type
4600 : primary_expression STAR
4602 Expression expr = (Expression) $1;
4604 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4605 Error_ExpectingTypeName (expr);
4609 $$ = new ComposedCast ((Expression) $1, "*");
4611 | builtin_types STAR
4613 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4617 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4619 | local_variable_pointer_type STAR
4621 $$ = new ComposedCast ((Expression) $1, "*");
4625 local_variable_declaration
4626 : local_variable_type variable_declarators
4629 VarExpr ve = $1 as VarExpr;
4631 ve.VariableInitializer = (ArrayList)$2;
4633 $$ = new DictionaryEntry ($1, $2);
4637 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4642 if ((string) $2 == "")
4643 t = (Expression) $1;
4645 t = new ComposedCast ((Expression) $1, (string) $2);
4646 $$ = new DictionaryEntry (t, $3);
4652 local_constant_declaration
4653 : CONST local_variable_type constant_declarators
4656 $$ = new DictionaryEntry ($2, $3);
4662 expression_statement
4663 : statement_expression SEMICOLON { $$ = $1; }
4667 // We have to do the wrapping here and not in the case above,
4668 // because statement_expression is used for example in for_statement
4670 statement_expression
4673 Expression expr = (Expression) $1;
4674 ExpressionStatement s = expr as ExpressionStatement;
4676 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
4679 $$ = new StatementExpression (s);
4683 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4688 object_creation_expression
4689 : object_or_delegate_creation_expression
4690 { note ("complain if this is a delegate maybe?"); }
4699 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4702 Location l = (Location) $1;
4704 $$ = new If ((Expression) $3, (Statement) $5, l);
4706 // FIXME: location for warning should be loc property of $5.
4707 if ($5 == EmptyStatement.Value)
4708 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4711 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4712 embedded_statement ELSE embedded_statement
4714 Location l = (Location) $1;
4716 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4718 // FIXME: location for warning should be loc property of $5 and $7.
4719 if ($5 == EmptyStatement.Value)
4720 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4721 if ($7 == EmptyStatement.Value)
4722 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4727 : SWITCH OPEN_PARENS
4729 if (switch_stack == null)
4730 switch_stack = new Stack (2);
4731 switch_stack.Push (current_block);
4733 expression CLOSE_PARENS
4736 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4737 current_block = (Block) switch_stack.Pop ();
4753 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4754 $$ = new ArrayList ();
4762 ArrayList sections = new ArrayList (4);
4767 | switch_sections switch_section
4769 ArrayList sections = (ArrayList) $1;
4779 current_block = current_block.CreateSwitchBlock (lexer.Location);
4783 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4790 ArrayList labels = new ArrayList (4);
4795 | switch_labels switch_label
4797 ArrayList labels = (ArrayList) ($1);
4805 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4806 | DEFAULT_COLON { $$ = new SwitchLabel (null, (Location) $1); }
4809 1523, GetLocation ($1),
4810 "The keyword case or default must precede code in switch block");
4822 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4824 Location l = (Location) $1;
4825 $$ = new While ((Expression) $3, (Statement) $5, l);
4830 : DO embedded_statement
4831 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4833 Location l = (Location) $1;
4835 $$ = new Do ((Statement) $2, (Expression) $5, l);
4841 opt_for_initializer SEMICOLON
4843 Location l = lexer.Location;
4845 Block assign_block = current_block;
4847 if ($3 is DictionaryEntry){
4848 DictionaryEntry de = (DictionaryEntry) $3;
4850 Expression type = (Expression) de.Key;
4851 ArrayList var_declarators = (ArrayList) de.Value;
4853 foreach (VariableDeclaration decl in var_declarators){
4857 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4861 Expression expr = decl.expression_or_array_initializer;
4863 LocalVariableReference var;
4864 var = new LocalVariableReference (assign_block, decl.identifier, l);
4867 Assign a = new Assign (var, expr, decl.Location);
4869 assign_block.AddStatement (new StatementExpression (a));
4873 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4874 // This can be referred to as $5 below.
4880 opt_for_condition SEMICOLON
4881 opt_for_iterator CLOSE_PARENS
4884 Location l = (Location) $1;
4886 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4888 current_block.AddStatement (f);
4890 $$ = end_block (lexer.Location);
4895 : /* empty */ { $$ = EmptyStatement.Value; }
4900 : local_variable_declaration
4901 | statement_expression_list
4905 : /* empty */ { $$ = null; }
4906 | boolean_expression
4910 : /* empty */ { $$ = EmptyStatement.Value; }
4915 : statement_expression_list
4918 statement_expression_list
4919 : statement_expression
4921 // CHANGE: was `null'
4922 Statement s = (Statement) $1;
4923 Block b = new Block (current_block, s.loc, lexer.Location);
4928 | statement_expression_list COMMA statement_expression
4930 Block b = (Block) $1;
4932 b.AddStatement ((Statement) $3);
4938 : FOREACH open_parens type IN expression CLOSE_PARENS
4940 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4943 | FOREACH open_parens type IDENTIFIER IN
4944 expression CLOSE_PARENS
4946 start_block (lexer.Location);
4947 Block foreach_block = current_block;
4949 LocatedToken lt = (LocatedToken) $4;
4950 Location l = lt.Location;
4951 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4953 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4955 // Get a writable reference to this read-only variable.
4957 // Note that the $$ here refers to the value of _this_ code block,
4958 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4959 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4966 LocalVariableReference v = (LocalVariableReference) $8;
4967 Location l = (Location) $1;
4970 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4971 current_block.AddStatement (f);
4974 $$ = end_block (lexer.Location);
4980 | continue_statement
4990 $$ = new Break ((Location) $1);
4995 : CONTINUE SEMICOLON
4997 $$ = new Continue ((Location) $1);
5002 : GOTO IDENTIFIER SEMICOLON
5004 LocatedToken lt = (LocatedToken) $2;
5005 $$ = new Goto (lt.Value, lt.Location);
5007 | GOTO CASE constant_expression SEMICOLON
5009 $$ = new GotoCase ((Expression) $3, (Location) $1);
5011 | GOTO DEFAULT SEMICOLON
5013 $$ = new GotoDefault ((Location) $1);
5018 : RETURN opt_expression SEMICOLON
5020 $$ = new Return ((Expression) $2, (Location) $1);
5025 : THROW opt_expression SEMICOLON
5027 $$ = new Throw ((Expression) $2, (Location) $1);
5032 : IDENTIFIER RETURN expression SEMICOLON
5034 LocatedToken lt = (LocatedToken) $1;
5035 string s = lt.Value;
5037 Report.Error (1003, lt.Location, "; expected");
5040 if (RootContext.Version == LanguageVersion.ISO_1){
5041 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
5044 if (anonymous_host == null){
5045 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
5048 anonymous_host.SetYields ();
5049 $$ = new Yield ((Expression) $3, lt.Location);
5052 | IDENTIFIER RETURN SEMICOLON
5054 Report.Error (1627, (Location) $2, "Expression expected after yield return");
5057 | IDENTIFIER BREAK SEMICOLON
5059 LocatedToken lt = (LocatedToken) $1;
5060 string s = lt.Value;
5062 Report.Error (1003, lt.Location, "; expected");
5065 if (RootContext.Version == LanguageVersion.ISO_1){
5066 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
5069 if (anonymous_host == null){
5070 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
5073 anonymous_host.SetYields ();
5074 $$ = new YieldBreak (lt.Location);
5085 : TRY block catch_clauses
5089 ArrayList c = (ArrayList)$3;
5090 for (int i = 0; i < c.Count; ++i) {
5091 Catch cc = (Catch) c [i];
5093 if (i != c.Count - 1)
5094 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
5101 // Now s contains the list of specific catch clauses
5102 // and g contains the general one.
5104 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
5106 | TRY block opt_catch_clauses FINALLY block
5109 ArrayList s = new ArrayList (4);
5110 ArrayList catch_list = (ArrayList) $3;
5112 if (catch_list != null){
5113 foreach (Catch cc in catch_list) {
5121 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
5125 Report.Error (1524, (Location) $1, "Expected catch or finally");
5131 : /* empty */ { $$ = null; }
5138 ArrayList l = new ArrayList (4);
5143 | catch_clauses catch_clause
5145 ArrayList l = (ArrayList) $1;
5153 : /* empty */ { $$ = null; }
5158 : CATCH opt_catch_args
5160 Expression type = null;
5163 DictionaryEntry cc = (DictionaryEntry) $2;
5164 type = (Expression) cc.Key;
5165 LocatedToken lt = (LocatedToken) cc.Value;
5168 ArrayList one = new ArrayList (4);
5170 one.Add (new VariableDeclaration (lt, null));
5172 start_block (lexer.Location);
5173 current_block = declare_local_variables (type, one, lt.Location);
5177 Expression type = null;
5179 Block var_block = null;
5182 DictionaryEntry cc = (DictionaryEntry) $2;
5183 type = (Expression) cc.Key;
5184 LocatedToken lt = (LocatedToken) cc.Value;
5188 var_block = end_block (lexer.Location);
5192 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5197 : /* empty */ { $$ = null; }
5202 : open_parens type opt_identifier CLOSE_PARENS
5204 $$ = new DictionaryEntry ($2, $3);
5212 $$ = new Checked ((Block) $2);
5219 $$ = new Unchecked ((Block) $2);
5226 RootContext.CheckUnsafeOption ((Location) $1);
5228 $$ = new Unsafe ((Block) $3);
5234 type fixed_pointer_declarators
5237 ArrayList list = (ArrayList) $4;
5238 Expression type = (Expression) $3;
5239 Location l = (Location) $1;
5240 int top = list.Count;
5242 if (type is VarExpr)
5243 Report.Error (821, GetLocation ($3), "A fixed statement cannot use an implicitly typed local variable");
5245 start_block (lexer.Location);
5247 for (int i = 0; i < top; i++){
5248 Pair p = (Pair) list [i];
5251 v = current_block.AddVariable (type, (string) p.First, l);
5255 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5263 Location l = (Location) $1;
5265 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5267 current_block.AddStatement (f);
5269 $$ = end_block (lexer.Location);
5273 fixed_pointer_declarators
5274 : fixed_pointer_declarator {
5275 ArrayList declarators = new ArrayList (4);
5277 declarators.Add ($1);
5280 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5282 ArrayList declarators = (ArrayList) $1;
5284 declarators.Add ($3);
5289 fixed_pointer_declarator
5290 : IDENTIFIER ASSIGN expression
5292 LocatedToken lt = (LocatedToken) $1;
5293 // FIXME: keep location
5294 $$ = new Pair (lt.Value, $3);
5298 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5304 : LOCK OPEN_PARENS expression CLOSE_PARENS
5310 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5315 : USING open_parens resource_acquisition CLOSE_PARENS
5317 start_block (lexer.Location);
5318 Block assign_block = current_block;
5320 if ($3 is DictionaryEntry){
5321 DictionaryEntry de = (DictionaryEntry) $3;
5322 Location l = (Location) $1;
5324 Expression type = (Expression) de.Key;
5325 ArrayList var_declarators = (ArrayList) de.Value;
5327 ArrayList vars = new ArrayList (4);
5329 foreach (VariableDeclaration decl in var_declarators){
5331 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5334 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5336 Expression expr = decl.expression_or_array_initializer;
5338 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5341 LocalVariableReference var;
5343 // Get a writable reference to this read-only variable.
5344 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5346 // This is so that it is not a warning on using variables
5349 vars.Add (new DictionaryEntry (var, expr));
5351 // Assign a = new Assign (var, expr, decl.Location);
5352 // assign_block.AddStatement (new StatementExpression (a));
5355 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5356 // It can be referred to as $5 below.
5357 $$ = new DictionaryEntry (type, vars);
5364 Using u = new Using ($5, (Statement) $6, (Location) $1);
5365 current_block.AddStatement (u);
5366 $$ = end_block (lexer.Location);
5370 resource_acquisition
5371 : local_variable_declaration
5379 : from_clause query_body
5381 lexer.QueryParsing = false;
5382 $$ = new Linq.QueryExpression (current_container, current_block, (Expression)$1, (Linq.AQueryClause)$2);
5383 end_block (lexer.Location);
5388 : FROM IDENTIFIER IN expression opt_join_clauses
5390 start_block (lexer.Location);
5391 LocatedToken lt = (LocatedToken) $2;
5393 current_block.AddVariable (Linq.ImplicitArgument.Instance, lt.Value, lt.Location);
5396 | FROM type IDENTIFIER IN expression opt_join_clauses
5398 start_block (lexer.Location);
5399 LocatedToken lt = (LocatedToken) $3;
5401 Expression type = (Expression)$2;
5402 current_block.AddVariable (type, lt.Value, lt.Location);
5403 $$ = new Linq.Cast (type, (Expression)$5, lt.Location);
5414 | join_clauses join_clause
5418 : JOIN join_clause_body
5419 | JOIN join_clause_body INTO IDENTIFIER
5420 | JOIN type join_clause_body
5421 | JOIN type join_clause_body INTO IDENTIFIER
5425 : IDENTIFIER IN expression ON expression EQUALS expression
5429 : opt_from_let_where_clauses opt_orderby_clause SELECT expression opt_query_continuation
5431 Linq.AQueryClause head = new Linq.Select ((Expression)$4, GetLocation ($3));
5434 Linq.AQueryClause clause = (Linq.AQueryClause)$2;
5435 clause.Tail.Next = head;
5440 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5441 clause.Tail.Next = head;
5447 | opt_from_let_where_clauses opt_orderby_clause group_clause opt_query_continuation
5449 Linq.AQueryClause head = (Linq.AQueryClause)$3;
5452 Linq.AQueryClause clause = (Linq.AQueryClause)$2;
5453 clause.Tail.Next = head;
5458 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5459 clause.Tail.Next = head;
5467 opt_from_let_where_clauses
5469 | from_let_where_clauses
5472 from_let_where_clauses
5473 : from_let_where_clause
5474 | from_let_where_clauses from_let_where_clause
5477 from_let_where_clause
5484 : LET IDENTIFIER ASSIGN expression
5488 : WHERE boolean_expression
5490 $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
5507 | order_by COMMA then_by
5509 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$3;
5517 $$ = new Linq.OrderByAscending ((Expression)$1);
5519 | expression ASCENDING
5521 $$ = new Linq.OrderByAscending ((Expression)$1);
5523 | expression DESCENDING
5525 $$ = new Linq.OrderByDescending ((Expression)$1);
5532 $$ = new Linq.ThenByAscending ((Expression)$1);
5534 | expression ASCENDING
5536 $$ = new Linq.ThenByAscending ((Expression)$1);
5538 | expression DESCENDING
5540 $$ = new Linq.ThenByDescending ((Expression)$1);
5546 : GROUP expression BY expression
5548 $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation ($1));
5552 opt_query_continuation
5554 | query_continuation
5558 : INTO IDENTIFIER opt_join_clauses query_body
5564 // A class used to pass around variable declarations and constants
5566 public class VariableDeclaration {
5567 public string identifier;
5568 public Expression expression_or_array_initializer;
5569 public Location Location;
5570 public Attributes OptAttributes;
5571 public string DocComment;
5573 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5575 this.identifier = lt.Value;
5576 if (eoai is ArrayList) {
5577 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5579 this.expression_or_array_initializer = (Expression)eoai;
5581 this.Location = lt.Location;
5582 this.OptAttributes = opt_attrs;
5585 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5591 // A class used to hold info about an indexer declarator
5593 public class IndexerDeclaration {
5594 public Expression type;
5595 public MemberName interface_type;
5596 public Parameters param_list;
5597 public Location location;
5599 public IndexerDeclaration (Expression type, MemberName interface_type,
5600 Parameters param_list, Location loc)
5603 this.interface_type = interface_type;
5604 this.param_list = param_list;
5605 this.location = loc;
5610 // We use this when we do not have an object in advance that is an IAnonymousHost
5612 public class SimpleAnonymousHost : IAnonymousHost {
5613 public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
5616 ArrayList anonymous_methods;
5618 public static SimpleAnonymousHost GetSimple () {
5619 Simple.yields = false;
5620 Simple.anonymous_methods = null;
5624 public void SetYields ()
5629 public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
5631 if (anonymous_methods == null)
5632 anonymous_methods = new ArrayList ();
5633 anonymous_methods.Add (anonymous);
5636 public void Propagate (IAnonymousHost real_host)
5639 real_host.SetYields ();
5640 if (anonymous_methods != null) {
5641 foreach (AnonymousMethodExpression ame in anonymous_methods)
5642 real_host.AddAnonymousMethod (ame);
5648 // A class used to hold info about an operator declarator
5650 public class OperatorDeclaration {
5651 public Operator.OpType optype;
5652 public Expression ret_type, arg1type, arg2type;
5653 public string arg1name, arg2name;
5654 public Location location;
5656 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5657 Expression arg1type, string arg1name,
5658 Expression arg2type, string arg2name, Location location)
5661 this.ret_type = ret_type;
5662 this.arg1type = arg1type;
5663 this.arg1name = arg1name;
5664 this.arg2type = arg2type;
5665 this.arg2name = arg2name;
5666 this.location = location;
5671 void Error_ExpectingTypeName (Expression expr)
5673 if (expr is Invocation){
5674 Report.Error (1002, expr.Location, "Expecting `;'");
5676 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5680 public static void Error_ParameterModifierNotValid (Location loc)
5682 Report.Error (631, loc, "The modifiers `ref' and `out' are not valid in this context");
5685 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5687 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5688 Parameter.GetModifierSignature (mod));
5691 static void Error_TypeExpected (Location loc)
5693 Report.Error (1031, loc, "Type expected");
5696 void push_current_class (TypeContainer tc, object partial_token)
5698 if (partial_token != null)
5699 current_container = current_container.AddPartial (tc);
5701 current_container = current_container.AddTypeContainer (tc);
5705 DeclSpace pop_current_class ()
5707 DeclSpace retval = current_class;
5709 current_class = current_class.Parent;
5710 current_container = current_class.PartialContainer;
5716 // Given the @class_name name, it creates a fully qualified name
5717 // based on the containing declaration space
5720 MakeName (MemberName class_name)
5722 Namespace ns = current_namespace.NS;
5724 if (current_container.Name.Length == 0){
5725 if (ns.Name.Length != 0)
5726 return new MemberName (ns.MemberName, class_name);
5730 return new MemberName (current_container.MemberName, class_name);
5734 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5736 Block implicit_block;
5737 ArrayList inits = null;
5740 // We use the `Used' property to check whether statements
5741 // have been added to the current block. If so, we need
5742 // to create another block to contain the new declaration
5743 // otherwise, as an optimization, we use the same block to
5744 // add the declaration.
5746 // FIXME: A further optimization is to check if the statements
5747 // that were added were added as part of the initialization
5748 // below. In which case, no other statements have been executed
5749 // and we might be able to reduce the number of blocks for
5750 // situations like this:
5752 // int j = 1; int k = j + 1;
5754 if (current_block.Used)
5755 implicit_block = new Block (current_block, loc, Location.Null);
5757 implicit_block = current_block;
5759 foreach (VariableDeclaration decl in variable_declarators){
5761 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5762 if (decl.expression_or_array_initializer != null){
5764 inits = new ArrayList (4);
5771 return implicit_block;
5773 foreach (VariableDeclaration decl in inits){
5775 Expression expr = decl.expression_or_array_initializer;
5777 LocalVariableReference var;
5778 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5780 assign = new Assign (var, expr, decl.Location);
5782 implicit_block.AddStatement (new StatementExpression (assign));
5785 return implicit_block;
5788 Block declare_local_constants (Expression type, ArrayList declarators)
5790 Block implicit_block;
5792 if (current_block.Used)
5793 implicit_block = new Block (current_block);
5795 implicit_block = current_block;
5797 foreach (VariableDeclaration decl in declarators){
5798 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5801 return implicit_block;
5804 string CheckAttributeTarget (string a, Location l)
5807 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5811 Report.Warning (658, 1, l,
5812 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5813 return string.Empty;
5816 void CheckUnaryOperator (Operator.OpType op, Location l)
5820 case Operator.OpType.LogicalNot:
5821 case Operator.OpType.OnesComplement:
5822 case Operator.OpType.Increment:
5823 case Operator.OpType.Decrement:
5824 case Operator.OpType.True:
5825 case Operator.OpType.False:
5826 case Operator.OpType.Addition:
5827 case Operator.OpType.Subtraction:
5832 Report.Error (1019, l, "Overloadable unary operator expected");
5838 void CheckBinaryOperator (Operator.OpType op, Location l)
5842 case Operator.OpType.Addition:
5843 case Operator.OpType.Subtraction:
5844 case Operator.OpType.Multiply:
5845 case Operator.OpType.Division:
5846 case Operator.OpType.Modulus:
5847 case Operator.OpType.BitwiseAnd:
5848 case Operator.OpType.BitwiseOr:
5849 case Operator.OpType.ExclusiveOr:
5850 case Operator.OpType.LeftShift:
5851 case Operator.OpType.RightShift:
5852 case Operator.OpType.Equality:
5853 case Operator.OpType.Inequality:
5854 case Operator.OpType.GreaterThan:
5855 case Operator.OpType.LessThan:
5856 case Operator.OpType.GreaterThanOrEqual:
5857 case Operator.OpType.LessThanOrEqual:
5861 Report.Error (1020, l, "Overloadable binary operator expected");
5867 void syntax_error (Location l, string msg)
5869 Report.Error (1003, l, "Syntax error, " + msg);
5872 void note (string s)
5874 // Used to put annotations
5879 public Tokenizer Lexer {
5885 static CSharpParser ()
5887 oob_stack = new Stack ();
5890 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5892 this.name = file.Name;
5894 current_namespace = new NamespaceEntry (null, file, null);
5895 current_class = current_namespace.SlaveDeclSpace;
5896 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5898 lexer = new Tokenizer (reader, file, defines);
5901 public void parse ()
5903 int errors = Report.Errors;
5905 if (yacc_verbose_flag > 1)
5906 yyparse (lexer, new yydebug.yyDebugSimple ());
5909 Tokenizer tokenizer = lexer as Tokenizer;
5910 tokenizer.cleanup ();
5911 } catch (Exception e){
5913 // Removed for production use, use parser verbose to get the output.
5915 // Console.WriteLine (e);
5916 if (Report.Errors == errors)
5917 Report.Error (-25, lexer.Location, "Parsing error");
5918 if (yacc_verbose_flag > 0)
5919 Console.WriteLine (e);
5922 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5923 throw new InternalErrorException ("who set it?");
5926 static void CheckToken (int error, int yyToken, string msg, Location loc)
5928 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5929 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5931 Report.Error (error, loc, msg);
5934 void CheckIdentifierToken (int yyToken, Location loc)
5936 CheckToken (1041, yyToken, "Identifier expected", loc);
5939 string ConsumeStoredComment ()
5941 string s = tmpComment;
5943 Lexer.doc_state = XmlCommentState.Allowed;
5947 Location GetLocation (object obj)
5949 if (obj is MemberCore)
5950 return ((MemberCore) obj).Location;
5951 if (obj is MemberName)
5952 return ((MemberName) obj).Location;
5953 if (obj is LocatedToken)
5954 return ((LocatedToken) obj).Location;
5955 if (obj is Location)
5956 return (Location) obj;
5957 return lexer.Location;
5960 void start_block (Location loc)
5962 if (current_block == null || parsing_anonymous_method) {
5963 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
5964 parsing_anonymous_method = false;
5966 current_block = new ExplicitBlock (current_block, loc, Location.Null);
5971 end_block (Location loc)
5973 Block retval = current_block.Explicit;
5974 retval.SetEndLocation (loc);
5975 current_block = retval.Parent;
5980 start_anonymous (bool lambda, Parameters parameters, Location loc)
5982 oob_stack.Push (current_anonymous_method);
5983 oob_stack.Push (current_local_parameters);
5985 current_local_parameters = parameters;
5987 ToplevelBlock top_current_block = current_block == null ? null : current_block.Toplevel;
5989 current_anonymous_method = lambda
5990 ? new LambdaExpression (
5991 current_anonymous_method, current_generic_method, current_container,
5992 parameters, top_current_block, loc)
5993 : new AnonymousMethodExpression (
5994 current_anonymous_method, current_generic_method, current_container,
5995 parameters, top_current_block, loc);
5997 // Force the next block to be created as a ToplevelBlock
5998 parsing_anonymous_method = true;
6002 * Completes the anonymous method processing, if lambda_expr is null, this
6003 * means that we have a Statement instead of an Expression embedded
6005 AnonymousMethodExpression
6006 end_anonymous (ToplevelBlock anon_block, Location loc)
6008 AnonymousMethodExpression retval;
6010 if (RootContext.Version == LanguageVersion.ISO_1){
6011 Report.FeatureIsNotISO1 (loc, "anonymous methods");
6014 current_anonymous_method.Block = anon_block;
6015 if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
6016 anonymous_host.AddAnonymousMethod (current_anonymous_method);
6018 retval = current_anonymous_method;
6021 current_local_parameters = (Parameters) oob_stack.Pop ();
6022 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();