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.
30 using System.Collections;
35 public class CSharpParser {
36 NamespaceEntry current_namespace;
37 TypeContainer current_container;
38 DeclSpace current_class;
41 /// Current block is used to add statements as we find
46 Delegate current_delegate;
48 GenericMethod current_generic_method;
49 AnonymousMethodExpression current_anonymous_method;
52 /// This is used by the unary_expression code to resolve
53 /// a name against a parameter.
56 // FIXME: This is very ugly and it's very hard to reset it correctly
57 // on all places, especially when some parameters are autogenerated.
58 Parameters current_local_parameters;
61 /// Using during property parsing to describe the implicit
62 /// value parameter that is passed to the "set" and "get"accesor
63 /// methods (properties and indexers).
65 FullNamedExpression implicit_value_parameter_type;
66 Parameters indexer_parameters;
69 /// Hack to help create non-typed array initializer
71 public static FullNamedExpression current_array_type;
72 FullNamedExpression pushed_current_array_type;
75 /// Used to determine if we are parsing the get/set pair
76 /// of an indexer or a property
80 bool parsing_anonymous_method;
83 /// An out-of-band stack.
85 static Stack oob_stack;
93 /// Controls the verbosity of the errors produced by the parser
95 static public int yacc_verbose_flag;
98 /// Used by the interactive shell, flags whether EOF was reached
99 /// and an error was produced
101 public bool UnexpectedEOF;
104 /// The current file.
106 CompilationUnit file;
109 /// Temporary Xml documentation cache.
110 /// For enum types, we need one more temporary store.
113 string enumTypeComment;
115 /// Current attribute target
116 string current_attr_target;
118 /// assembly and module attribute definitions are enabled
119 bool global_attrs_enabled = true;
120 bool has_get, has_set;
121 bool parameter_modifiers_not_allowed;
122 bool params_modifiers_not_allowed;
123 bool arglist_allowed;
126 /// When using the interactive parser, this holds the
127 /// resulting expression
128 public object InteractiveResult;
131 // Keeps track of global data changes to undo on parser error
135 // A counter to create new class names in interactive mode
136 static int class_count;
140 %token NONE /* This token is never returned by our lexer */
141 %token ERROR // This is used not by the parser, but by the tokenizer.
145 *These are the C# keywords
232 %token QUERY_FIRST_TOKEN
245 %token QUERY_LAST_TOKEN
247 /* C# keywords which are not really keywords */
253 /* C# single character operators/punctuation. */
254 %token OPEN_BRACE "{"
255 %token CLOSE_BRACE "}"
256 %token OPEN_BRACKET "["
257 %token CLOSE_BRACKET "]"
258 %token OPEN_PARENS "("
259 %token CLOSE_PARENS ")"
271 %token OP_GENERICS_LT "<"
273 %token OP_GENERICS_GT ">"
274 %token BITWISE_AND "&"
275 %token BITWISE_OR "|"
282 /* C# multi-character operators. */
283 %token DOUBLE_COLON "::"
286 %token OP_SHIFT_LEFT "<<"
287 %token OP_SHIFT_RIGHT ">>"
294 %token OP_MULT_ASSIGN "*="
295 %token OP_DIV_ASSIGN "/="
296 %token OP_MOD_ASSIGN "%="
297 %token OP_ADD_ASSIGN "+="
298 %token OP_SUB_ASSIGN "-="
299 %token OP_SHIFT_LEFT_ASSIGN "<<="
300 %token OP_SHIFT_RIGHT_ASSIGN ">>="
301 %token OP_AND_ASSIGN "&="
302 %token OP_XOR_ASSIGN "^="
303 %token OP_OR_ASSIGN "|="
305 %token OP_COALESCING "??"
308 %token LITERAL_INTEGER "int literal"
309 %token LITERAL_FLOAT "float literal"
310 %token LITERAL_DOUBLE "double literal"
311 %token LITERAL_DECIMAL "decimal literal"
312 %token LITERAL_CHARACTER "character literal"
313 %token LITERAL_STRING "string literal"
316 %token OPEN_PARENS_LAMBDA
317 %token CLOSE_PARENS_CAST
318 %token CLOSE_PARENS_NO_CAST
319 %token CLOSE_PARENS_OPEN_PARENS
320 %token CLOSE_PARENS_MINUS
321 %token DEFAULT_OPEN_PARENS
322 %token GENERIC_DIMENSION
325 // Make the parser go into eval mode parsing (statements and compilation units).
326 %token EVAL_STATEMENT_PARSER
327 %token EVAL_COMPILATION_UNIT_PARSER
328 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
330 /* Add precedence rules to solve dangling else s/r conflict */
339 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
341 %left STAR DIV PERCENT
342 %right BANG CARRET UMINUS
343 %nonassoc OP_INC OP_DEC
345 %left OPEN_BRACKET OPEN_BRACE
349 %start compilation_unit
353 : outer_declarations opt_EOF
354 | outer_declarations global_attributes opt_EOF
355 | global_attributes opt_EOF
356 | opt_EOF /* allow empty files */
357 | interactive_parsing opt_EOF
363 Lexer.check_incorrect_doc_comment ();
367 Lexer.check_incorrect_doc_comment ();
373 | outer_declarations outer_declaration
377 : extern_alias_directive
379 | namespace_member_declaration
382 extern_alias_directives
383 : extern_alias_directive
384 | extern_alias_directives extern_alias_directive;
386 extern_alias_directive
387 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
389 LocatedToken lt = (LocatedToken) $2;
392 Report.Error (1003, lt.Location, "'alias' expected");
393 } else if (RootContext.Version == LanguageVersion.ISO_1) {
394 Report.FeatureIsNotAvailable (lt.Location, "external alias");
396 lt = (LocatedToken) $3;
397 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
404 | using_directives using_directive
408 : using_alias_directive
410 if (RootContext.Documentation != null)
411 Lexer.doc_state = XmlCommentState.Allowed;
413 | using_namespace_directive
415 if (RootContext.Documentation != null)
416 Lexer.doc_state = XmlCommentState.Allowed;
420 using_alias_directive
421 : USING IDENTIFIER ASSIGN
422 namespace_or_type_name SEMICOLON
424 LocatedToken lt = (LocatedToken) $2;
425 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
428 CheckIdentifierToken (yyToken, GetLocation ($2));
433 using_namespace_directive
434 : USING namespace_name SEMICOLON
436 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
441 // Strictly speaking, namespaces don't have attributes but
442 // we parse global attributes along with namespace declarations and then
445 namespace_declaration
446 : opt_attributes NAMESPACE qualified_identifier
448 MemberName name = (MemberName) $3;
451 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
454 current_namespace = new NamespaceEntry (
455 current_namespace, file, name.GetName ());
456 current_class = current_namespace.SlaveDeclSpace;
457 current_container = current_class.PartialContainer;
459 namespace_body opt_semicolon
461 current_namespace = current_namespace.Parent;
462 current_class = current_namespace.SlaveDeclSpace;
463 current_container = current_class.PartialContainer;
470 LocatedToken lt = (LocatedToken) $1;
471 $$ = new MemberName (lt.Value, lt.Location);
473 | qualified_identifier DOT IDENTIFIER
475 LocatedToken lt = (LocatedToken) $3;
476 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
480 syntax_error (lexer.Location, "`.' expected");
495 : namespace_or_type_name {
496 MemberName name = (MemberName) $1;
498 if (name.TypeArguments != null)
499 syntax_error (lexer.Location, "namespace name expected");
508 if (RootContext.Documentation != null)
509 Lexer.doc_state = XmlCommentState.Allowed;
515 : opt_extern_alias_directives
517 opt_namespace_member_declarations
521 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
524 | opt_extern_alias_directives
526 opt_namespace_member_declarations
529 Report.Error (1513, lexer.Location, "} expected");
538 opt_extern_alias_directives
540 | extern_alias_directives
543 opt_namespace_member_declarations
545 | namespace_member_declarations
548 namespace_member_declarations
549 : namespace_member_declaration
550 | namespace_member_declarations namespace_member_declaration
553 namespace_member_declaration
557 DeclSpace ds = (DeclSpace)$1;
559 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
560 Report.Error (1527, ds.Location,
561 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
564 current_namespace.DeclarationFound = true;
566 | namespace_declaration {
567 current_namespace.DeclarationFound = true;
570 | field_declaration {
571 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
573 | method_declaration {
574 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
581 | interface_declaration
583 | delegate_declaration
585 // Enable this when we have handled all errors, because this acts as a generic fallback
588 // Console.WriteLine ("Token=" + yyToken);
589 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
601 Attributes attrs = (Attributes)$1;
602 if (global_attrs_enabled) {
603 CodeGen.Assembly.AddAttributes (attrs.Attrs);
605 foreach (Attribute a in attrs.Attrs) {
606 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
617 global_attrs_enabled = false;
622 global_attrs_enabled = false;
631 if (current_attr_target != String.Empty) {
632 ArrayList sect = (ArrayList) $1;
634 if (global_attrs_enabled) {
635 if (current_attr_target == "module") {
636 CodeGen.Module.AddAttributes (sect);
638 } else if (current_attr_target != null && current_attr_target.Length > 0) {
639 CodeGen.Assembly.AddAttributes (sect);
642 $$ = new Attributes (sect);
645 if (RootContext.Documentation != null) {
646 Lexer.check_incorrect_doc_comment ();
648 XmlCommentState.Allowed;
652 $$ = new Attributes (sect);
657 current_attr_target = null;
659 | attribute_sections attribute_section
661 if (current_attr_target != String.Empty) {
662 Attributes attrs = $1 as Attributes;
663 ArrayList sect = (ArrayList) $2;
665 if (global_attrs_enabled) {
666 if (current_attr_target == "module") {
667 CodeGen.Module.AddAttributes (sect);
669 } else if (current_attr_target == "assembly") {
670 CodeGen.Assembly.AddAttributes (sect);
674 attrs = new Attributes (sect);
676 attrs.AddAttributes (sect);
680 attrs = new Attributes (sect);
682 attrs.AddAttributes (sect);
688 current_attr_target = null;
693 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
697 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
703 attribute_target_specifier
704 : attribute_target COLON
706 current_attr_target = (string)$1;
714 LocatedToken lt = (LocatedToken) $1;
715 $$ = CheckAttributeTarget (lt.Value, lt.Location);
717 | EVENT { $$ = "event"; }
718 | RETURN { $$ = "return"; }
721 string name = yyNames [yyToken].ToLower ();
722 $$ = CheckAttributeTarget (name, GetLocation ($1));
729 ArrayList attrs = new ArrayList (4);
735 | attribute_list COMMA attribute
737 ArrayList attrs = (ArrayList) $1;
745 : attribute_name opt_attribute_arguments
747 MemberName mname = (MemberName) $1;
748 if (mname.IsGeneric) {
749 Report.Error (404, lexer.Location,
750 "'<' unexpected: attributes cannot be generic");
753 object [] arguments = (object []) $2;
754 MemberName left = mname.Left;
755 string identifier = mname.Name;
757 Expression left_expr = left == null ? null : left.GetTypeExpression ();
759 if (current_attr_target == String.Empty)
761 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
762 // FIXME: supply "nameEscaped" parameter here.
763 $$ = new GlobalAttribute (current_namespace, current_attr_target,
764 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
766 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
771 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
774 opt_attribute_arguments
775 : /* empty */ { $$ = null; }
776 | OPEN_PARENS attribute_arguments CLOSE_PARENS
784 : opt_positional_argument_list
789 $$ = new object [] { $1, null };
792 | positional_argument_list COMMA named_argument_list
794 $$ = new object[] { $1, $3 };
796 | named_argument_list
798 $$ = new object [] { null, $1 };
803 opt_positional_argument_list
804 : /* empty */ { $$ = null; }
805 | positional_argument_list
808 positional_argument_list
811 ArrayList args = new ArrayList (4);
812 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
816 | positional_argument_list COMMA expression
818 ArrayList args = (ArrayList) $1;
819 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
828 ArrayList args = new ArrayList (4);
833 | named_argument_list COMMA named_argument
835 ArrayList args = (ArrayList) $1;
840 | named_argument_list COMMA expression
842 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
848 : IDENTIFIER ASSIGN expression
850 // FIXME: keep location
851 $$ = new DictionaryEntry (
852 ((LocatedToken) $1).Value,
853 new Argument ((Expression) $3, Argument.AType.Expression));
859 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
862 opt_class_member_declarations
864 | class_member_declarations
867 class_member_declarations
868 : class_member_declaration
869 | class_member_declarations
870 class_member_declaration
873 class_member_declaration
874 : constant_declaration // done
875 | field_declaration // done
876 | method_declaration // done
877 | property_declaration // done
878 | event_declaration // done
879 | indexer_declaration // done
880 | operator_declaration // done
881 | constructor_declaration // done
882 | destructor_declaration // done
892 lexer.ConstraintsParsing = true;
896 MemberName name = MakeName ((MemberName) $6);
897 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
900 opt_type_parameter_constraints_clauses
902 lexer.ConstraintsParsing = false;
904 current_class.SetParameterInfo ((ArrayList) $9);
906 if (RootContext.Documentation != null)
907 current_container.DocComment = Lexer.consume_doc_comment ();
911 if (RootContext.Documentation != null)
912 Lexer.doc_state = XmlCommentState.Allowed;
916 $$ = pop_current_class ();
918 | opt_attributes opt_modifiers opt_partial STRUCT error {
919 CheckIdentifierToken (yyToken, GetLocation ($5));
926 if (RootContext.Documentation != null)
927 Lexer.doc_state = XmlCommentState.Allowed;
929 opt_struct_member_declarations CLOSE_BRACE
932 opt_struct_member_declarations
934 | struct_member_declarations
937 struct_member_declarations
938 : struct_member_declaration
939 | struct_member_declarations struct_member_declaration
942 struct_member_declaration
943 : constant_declaration
946 | property_declaration
948 | indexer_declaration
949 | operator_declaration
950 | constructor_declaration
954 * This is only included so we can flag error 575:
955 * destructors only allowed on class types
957 | destructor_declaration
968 int modflags = (int) $2;
969 foreach (VariableDeclaration constant in (ArrayList) $5){
970 Location l = constant.Location;
971 if ((modflags & Modifiers.STATIC) != 0) {
972 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
976 Const c = new Const (
977 current_class, (FullNamedExpression) $4, (string) constant.identifier,
978 (Expression) constant.expression_or_array_initializer, modflags,
981 if (RootContext.Documentation != null) {
982 c.DocComment = Lexer.consume_doc_comment ();
983 Lexer.doc_state = XmlCommentState.Allowed;
985 current_container.AddConstant (c);
991 : constant_declarator
993 ArrayList constants = new ArrayList (4);
998 | constant_declarators COMMA constant_declarator
1001 ArrayList constants = (ArrayList) $1;
1008 : IDENTIFIER ASSIGN constant_expression
1010 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1014 // A const field requires a value to be provided
1015 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1024 variable_declarators
1027 FullNamedExpression type = (FullNamedExpression) $3;
1030 current_array_type = null;
1032 foreach (VariableDeclaration var in (ArrayList) $4){
1033 Field field = new Field (current_class, type, mod, var.identifier,
1034 (Attributes) $1, var.Location);
1036 field.Initializer = var.expression_or_array_initializer;
1038 if (RootContext.Documentation != null) {
1039 field.DocComment = Lexer.consume_doc_comment ();
1040 Lexer.doc_state = XmlCommentState.Allowed;
1042 current_container.AddField (field);
1043 $$ = field; // FIXME: might be better if it points to the top item
1050 fixed_variable_declarators
1053 FullNamedExpression type = (FullNamedExpression) $4;
1056 current_array_type = null;
1058 foreach (VariableDeclaration var in (ArrayList) $5) {
1059 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1060 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1062 if (RootContext.Documentation != null) {
1063 field.DocComment = Lexer.consume_doc_comment ();
1064 Lexer.doc_state = XmlCommentState.Allowed;
1066 current_container.AddField (field);
1067 $$ = field; // FIXME: might be better if it points to the top item
1076 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1081 variable_declarators
1083 current_array_type = null;
1084 Report.Error (670, (Location) $3, "Fields cannot have void type");
1088 fixed_variable_declarators
1089 : fixed_variable_declarator
1091 ArrayList decl = new ArrayList (2);
1095 | fixed_variable_declarators COMMA fixed_variable_declarator
1097 ArrayList decls = (ArrayList) $1;
1103 fixed_variable_declarator
1104 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1106 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1108 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1110 Report.Error (443, lexer.Location, "Value or constant expected");
1111 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1115 variable_declarators
1116 : variable_declarator
1118 ArrayList decl = new ArrayList (4);
1123 | variable_declarators COMMA variable_declarator
1125 ArrayList decls = (ArrayList) $1;
1132 : IDENTIFIER ASSIGN variable_initializer
1134 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1138 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1140 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1142 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1143 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1148 variable_initializer
1157 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1159 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1163 $$ = new ArglistAccess ((Location) $1);
1167 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1174 if (RootContext.Documentation != null)
1175 Lexer.doc_state = XmlCommentState.NotAllowed;
1179 Method method = (Method) $1;
1180 method.Block = (ToplevelBlock) $3;
1181 current_container.AddMethod (method);
1183 if (current_container.Kind == Kind.Interface && method.Block != null) {
1184 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1187 current_generic_method = null;
1188 current_local_parameters = null;
1190 if (RootContext.Documentation != null)
1191 Lexer.doc_state = XmlCommentState.Allowed;
1204 Report.Error (1585, lexer.Location,
1205 "Member modifier `{0}' must precede the member type and name",
1206 Modifiers.Name (i));
1220 arglist_allowed = true;
1222 opt_formal_parameter_list CLOSE_PARENS
1224 lexer.ConstraintsParsing = true;
1226 opt_type_parameter_constraints_clauses
1228 lexer.ConstraintsParsing = false;
1229 arglist_allowed = false;
1230 MemberName name = (MemberName) $4;
1231 current_local_parameters = (Parameters) $7;
1233 if ($10 != null && name.TypeArguments == null)
1234 Report.Error (80, lexer.Location,
1235 "Constraints are not allowed on non-generic declarations");
1239 GenericMethod generic = null;
1240 if (name.TypeArguments != null) {
1241 generic = new GenericMethod (current_namespace, current_class, name,
1242 (FullNamedExpression) $3, current_local_parameters);
1244 generic.SetParameterInfo ((ArrayList) $10);
1247 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1248 name, current_local_parameters, (Attributes) $1);
1250 current_generic_method = generic;
1252 if (RootContext.Documentation != null)
1253 method.DocComment = Lexer.consume_doc_comment ();
1262 arglist_allowed = true;
1264 opt_formal_parameter_list CLOSE_PARENS
1266 lexer.ConstraintsParsing = true;
1268 opt_type_parameter_constraints_clauses
1270 lexer.ConstraintsParsing = false;
1271 arglist_allowed = false;
1273 MemberName name = (MemberName) $4;
1274 current_local_parameters = (Parameters) $7;
1276 if ($10 != null && name.TypeArguments == null)
1277 Report.Error (80, lexer.Location,
1278 "Constraints are not allowed on non-generic declarations");
1281 GenericMethod generic = null;
1282 if (name.TypeArguments != null) {
1283 generic = new GenericMethod (current_namespace, current_class, name,
1284 TypeManager.system_void_expr, current_local_parameters);
1286 generic.SetParameterInfo ((ArrayList) $10);
1289 method = new Method (current_class, generic, TypeManager.system_void_expr,
1290 (int) $2, name, current_local_parameters, (Attributes) $1);
1292 current_generic_method = generic;
1294 if (RootContext.Documentation != null)
1295 method.DocComment = Lexer.consume_doc_comment ();
1303 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1305 lexer.ConstraintsParsing = true;
1307 opt_type_parameter_constraints_clauses
1309 lexer.ConstraintsParsing = false;
1311 MemberName name = (MemberName) $5;
1312 current_local_parameters = (Parameters) $7;
1314 if ($9 != null && name.TypeArguments == null)
1315 Report.Error (80, lexer.Location,
1316 "Constraints are not allowed on non-generic declarations");
1319 GenericMethod generic = null;
1320 if (name.TypeArguments != null) {
1321 generic = new GenericMethod (current_namespace, current_class, name,
1322 TypeManager.system_void_expr, current_local_parameters);
1324 generic.SetParameterInfo ((ArrayList) $10);
1327 int modifiers = (int) $2;
1330 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1331 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1333 if ((modifiers & invalid_partial_mod) != 0) {
1334 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1335 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1336 modifiers &= ~invalid_partial_mod;
1339 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1340 Report.Error (751, name.Location, "A partial method must be declared within a " +
1341 "partial class or partial struct");
1344 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1346 method = new Method (current_class, generic, TypeManager.system_void_expr,
1347 modifiers, name, current_local_parameters, (Attributes) $1);
1349 current_generic_method = generic;
1351 if (RootContext.Documentation != null)
1352 method.DocComment = Lexer.consume_doc_comment ();
1359 modifiers member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1361 MemberName name = (MemberName) $5;
1362 Report.Error (1585, name.Location,
1363 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1365 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1366 0, name, (Parameters) $7, (Attributes) $1);
1368 current_local_parameters = (Parameters) $7;
1370 if (RootContext.Documentation != null)
1371 method.DocComment = Lexer.consume_doc_comment ();
1379 | SEMICOLON { $$ = null; }
1382 opt_formal_parameter_list
1383 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1384 | formal_parameter_list
1387 opt_parameter_list_no_mod
1388 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1391 parameter_modifiers_not_allowed = true;
1393 formal_parameter_list
1395 parameter_modifiers_not_allowed = false;
1400 formal_parameter_list
1403 ArrayList pars_list = (ArrayList) $1;
1405 Parameter [] pars = new Parameter [pars_list.Count];
1406 pars_list.CopyTo (pars);
1408 $$ = new Parameters (pars);
1410 | fixed_parameters COMMA parameter_array
1412 ArrayList pars_list = (ArrayList) $1;
1415 Parameter [] pars = new Parameter [pars_list.Count];
1416 pars_list.CopyTo (pars);
1418 $$ = new Parameters (pars);
1420 | fixed_parameters COMMA arglist_modifier
1422 ArrayList pars_list = (ArrayList) $1;
1423 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1425 Parameter [] pars = new Parameter [pars_list.Count];
1426 pars_list.CopyTo (pars);
1428 $$ = new Parameters (pars, true);
1430 | parameter_array COMMA error
1433 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1436 | fixed_parameters COMMA parameter_array COMMA error
1439 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1442 | arglist_modifier COMMA error
1444 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1447 | fixed_parameters COMMA ARGLIST COMMA error
1449 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1454 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1458 $$ = new Parameters (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1465 ArrayList pars = new ArrayList (4);
1470 | fixed_parameters COMMA fixed_parameter
1472 ArrayList pars = (ArrayList) $1;
1473 Parameter p = (Parameter)$3;
1475 if (p.HasExtensionMethodModifier)
1476 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1485 opt_parameter_modifier
1489 LocatedToken lt = (LocatedToken) $4;
1490 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1493 opt_parameter_modifier
1495 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1497 LocatedToken lt = (LocatedToken) $4;
1498 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1502 opt_parameter_modifier
1505 Report.Error (1001, GetLocation ($3), "Identifier expected");
1509 opt_parameter_modifier
1512 CheckIdentifierToken (yyToken, GetLocation ($4));
1516 opt_parameter_modifier
1522 LocatedToken lt = (LocatedToken) $4;
1523 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1528 opt_parameter_modifier
1529 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1530 | parameter_modifiers
1534 : parameter_modifier
1538 | parameter_modifiers parameter_modifier
1540 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1541 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1542 if (((Parameter.Modifier)$1 & p2) == p2) {
1543 Error_DuplicateParameterModifier (lexer.Location, p2);
1545 switch (mod & ~Parameter.Modifier.This) {
1546 case Parameter.Modifier.REF:
1547 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1549 case Parameter.Modifier.OUT:
1550 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1553 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1564 if (parameter_modifiers_not_allowed)
1565 Error_ParameterModifierNotValid ("ref", (Location)$1);
1567 $$ = Parameter.Modifier.REF;
1571 if (parameter_modifiers_not_allowed)
1572 Error_ParameterModifierNotValid ("out", (Location)$1);
1574 $$ = Parameter.Modifier.OUT;
1578 if (parameter_modifiers_not_allowed)
1579 Error_ParameterModifierNotValid ("this", (Location)$1);
1581 if (RootContext.Version <= LanguageVersion.ISO_2)
1582 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1584 $$ = Parameter.Modifier.This;
1589 : opt_attributes params_modifier type IDENTIFIER
1591 LocatedToken lt = (LocatedToken) $4;
1592 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1594 | opt_attributes params_modifier type error {
1595 CheckIdentifierToken (yyToken, GetLocation ($4));
1603 if (params_modifiers_not_allowed)
1604 Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1606 | PARAMS parameter_modifier
1608 Parameter.Modifier mod = (Parameter.Modifier)$2;
1609 if ((mod & Parameter.Modifier.This) != 0) {
1610 Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1612 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1615 | PARAMS params_modifier
1617 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1624 if (!arglist_allowed)
1625 Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1629 property_declaration
1633 namespace_or_type_name
1635 if (RootContext.Documentation != null)
1636 tmpComment = Lexer.consume_doc_comment ();
1640 implicit_value_parameter_type = (FullNamedExpression) $3;
1642 lexer.PropertyParsing = true;
1644 accessor_declarations
1646 lexer.PropertyParsing = false;
1647 has_get = has_set = false;
1652 Accessors accessors = (Accessors) $8;
1653 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1654 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1655 bool order = accessors != null ? accessors.declared_in_reverse : false;
1657 MemberName name = (MemberName) $4;
1658 FullNamedExpression ptype = (FullNamedExpression) $3;
1660 if (name.TypeArguments != null)
1661 syntax_error (lexer.Location, "a property can't have type arguments");
1663 prop = new Property (current_class, ptype, (int) $2,
1664 name, (Attributes) $1, get_block, set_block, order, current_block);
1666 if (ptype == TypeManager.system_void_expr)
1667 Report.Error (547, ptype.Location, "`{0}': property return type cannot be `void'", prop.GetSignatureForError ());
1669 if (accessors == null)
1670 Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1672 if (current_container.Kind == Kind.Interface) {
1673 if (prop.Get.Block != null)
1674 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1676 if (prop.Set.Block != null)
1677 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1680 current_container.AddProperty (prop);
1681 implicit_value_parameter_type = null;
1683 if (RootContext.Documentation != null)
1684 prop.DocComment = ConsumeStoredComment ();
1689 accessor_declarations
1690 : get_accessor_declaration
1692 $$ = new Accessors ((Accessor) $1, null);
1694 | get_accessor_declaration accessor_declarations
1696 Accessors accessors = (Accessors) $2;
1697 accessors.get_or_add = (Accessor) $1;
1700 | set_accessor_declaration
1702 $$ = new Accessors (null, (Accessor) $1);
1704 | set_accessor_declaration accessor_declarations
1706 Accessors accessors = (Accessors) $2;
1707 accessors.set_or_remove = (Accessor) $1;
1708 accessors.declared_in_reverse = true;
1713 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1718 get_accessor_declaration
1719 : opt_attributes opt_modifiers GET
1721 // If this is not the case, then current_local_parameters has already
1722 // been set in indexer_declaration
1723 if (parsing_indexer == false)
1724 current_local_parameters = null;
1726 current_local_parameters = indexer_parameters;
1727 lexer.PropertyParsing = false;
1732 Report.Error (1007, (Location) $3, "Property accessor already defined");
1735 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1737 current_local_parameters = null;
1738 lexer.PropertyParsing = true;
1740 if (RootContext.Documentation != null)
1741 if (Lexer.doc_state == XmlCommentState.Error)
1742 Lexer.doc_state = XmlCommentState.NotAllowed;
1748 set_accessor_declaration
1749 : opt_attributes opt_modifiers SET
1751 Parameter implicit_value_parameter = new Parameter (
1752 implicit_value_parameter_type, "value",
1753 Parameter.Modifier.NONE, null, (Location) $3);
1755 if (!parsing_indexer) {
1756 current_local_parameters = new Parameters (new Parameter [] { implicit_value_parameter });
1758 current_local_parameters = Parameters.MergeGenerated (
1759 indexer_parameters, true, implicit_value_parameter, null);
1762 lexer.PropertyParsing = false;
1767 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1770 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1772 current_local_parameters = null;
1773 lexer.PropertyParsing = true;
1775 if (RootContext.Documentation != null
1776 && Lexer.doc_state == XmlCommentState.Error)
1777 Lexer.doc_state = XmlCommentState.NotAllowed;
1785 | SEMICOLON { $$ = null; }
1788 interface_declaration
1794 lexer.ConstraintsParsing = true;
1798 MemberName name = MakeName ((MemberName) $6);
1799 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1802 opt_type_parameter_constraints_clauses
1804 lexer.ConstraintsParsing = false;
1806 current_class.SetParameterInfo ((ArrayList) $9);
1808 if (RootContext.Documentation != null) {
1809 current_container.DocComment = Lexer.consume_doc_comment ();
1810 Lexer.doc_state = XmlCommentState.Allowed;
1815 if (RootContext.Documentation != null)
1816 Lexer.doc_state = XmlCommentState.Allowed;
1820 $$ = pop_current_class ();
1822 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1823 CheckIdentifierToken (yyToken, GetLocation ($5));
1829 opt_interface_member_declarations
1833 opt_interface_member_declarations
1835 | interface_member_declarations
1838 interface_member_declarations
1839 : interface_member_declaration
1840 | interface_member_declarations interface_member_declaration
1843 interface_member_declaration
1844 : constant_declaration
1846 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1850 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1852 | method_declaration
1853 | property_declaration
1855 | indexer_declaration
1856 | operator_declaration
1858 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1860 | constructor_declaration
1862 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1866 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1870 operator_declaration
1871 : opt_attributes opt_modifiers operator_declarator
1879 OperatorDeclaration decl = (OperatorDeclaration) $3;
1880 Operator op = new Operator (
1881 current_class, decl.optype, decl.ret_type, (int) $2,
1882 current_local_parameters,
1883 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1885 if (RootContext.Documentation != null) {
1886 op.DocComment = tmpComment;
1887 Lexer.doc_state = XmlCommentState.Allowed;
1890 // Note again, checking is done in semantic analysis
1891 current_container.AddOperator (op);
1893 current_local_parameters = null;
1899 | SEMICOLON { $$ = null; }
1903 : type OPERATOR overloadable_operator OPEN_PARENS
1905 params_modifiers_not_allowed = true;
1907 opt_parameter_list_no_mod CLOSE_PARENS
1909 params_modifiers_not_allowed = false;
1911 Location loc = (Location) $2;
1912 Operator.OpType op = (Operator.OpType) $3;
1913 current_local_parameters = (Parameters)$6;
1915 int p_count = current_local_parameters.Count;
1917 if (op == Operator.OpType.Addition)
1918 op = Operator.OpType.UnaryPlus;
1919 else if (op == Operator.OpType.Subtraction)
1920 op = Operator.OpType.UnaryNegation;
1923 if (IsUnaryOperator (op)) {
1925 Report.Error (1020, loc, "Overloadable binary operator expected");
1926 } else if (p_count != 1) {
1927 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1928 Operator.GetName (op));
1932 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1933 Operator.GetName (op));
1934 } else if (p_count != 2) {
1935 Report.Error (1019, loc, "Overloadable unary operator expected");
1939 if (RootContext.Documentation != null) {
1940 tmpComment = Lexer.consume_doc_comment ();
1941 Lexer.doc_state = XmlCommentState.NotAllowed;
1944 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
1946 | conversion_operator_declarator
1949 overloadable_operator
1951 : BANG { $$ = Operator.OpType.LogicalNot; }
1952 | TILDE { $$ = Operator.OpType.OnesComplement; }
1953 | OP_INC { $$ = Operator.OpType.Increment; }
1954 | OP_DEC { $$ = Operator.OpType.Decrement; }
1955 | TRUE { $$ = Operator.OpType.True; }
1956 | FALSE { $$ = Operator.OpType.False; }
1957 // Unary and binary:
1958 | PLUS { $$ = Operator.OpType.Addition; }
1959 | MINUS { $$ = Operator.OpType.Subtraction; }
1961 | STAR { $$ = Operator.OpType.Multiply; }
1962 | DIV { $$ = Operator.OpType.Division; }
1963 | PERCENT { $$ = Operator.OpType.Modulus; }
1964 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1965 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1966 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1967 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1968 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1969 | OP_EQ { $$ = Operator.OpType.Equality; }
1970 | OP_NE { $$ = Operator.OpType.Inequality; }
1971 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1972 | OP_LT { $$ = Operator.OpType.LessThan; }
1973 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1974 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1977 conversion_operator_declarator
1978 : IMPLICIT OPERATOR type OPEN_PARENS
1980 params_modifiers_not_allowed = true;
1982 opt_parameter_list_no_mod CLOSE_PARENS
1984 params_modifiers_not_allowed = false;
1986 Location loc = (Location) $2;
1987 current_local_parameters = (Parameters)$6;
1989 if (RootContext.Documentation != null) {
1990 tmpComment = Lexer.consume_doc_comment ();
1991 Lexer.doc_state = XmlCommentState.NotAllowed;
1994 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
1996 | EXPLICIT OPERATOR type OPEN_PARENS
1998 params_modifiers_not_allowed = true;
2000 opt_parameter_list_no_mod CLOSE_PARENS
2002 params_modifiers_not_allowed = false;
2004 Location loc = (Location) $2;
2005 current_local_parameters = (Parameters)$6;
2007 if (RootContext.Documentation != null) {
2008 tmpComment = Lexer.consume_doc_comment ();
2009 Lexer.doc_state = XmlCommentState.NotAllowed;
2012 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2016 syntax_error ((Location) $1, "'operator' expected");
2020 syntax_error ((Location) $1, "'operator' expected");
2024 constructor_declaration
2027 constructor_declarator
2030 Constructor c = (Constructor) $3;
2031 c.Block = (ToplevelBlock) $4;
2032 c.OptAttributes = (Attributes) $1;
2033 int mods = (int) $2;
2035 if (RootContext.Documentation != null)
2036 c.DocComment = ConsumeStoredComment ();
2038 if ((mods & Modifiers.STATIC) != 0 && c.Name == current_container.MemberName.Name) {
2039 if ((mods & Modifiers.Accessibility) != 0){
2040 Report.Error (515, c.Location,
2041 "`{0}': static constructor cannot have an access modifier",
2042 c.GetSignatureForError ());
2045 if (c.Initializer != null){
2046 Report.Error (514, c.Location,
2047 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2048 c.GetSignatureForError ());
2052 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, mods, Modifiers.PRIVATE, c.Location);
2053 current_container.AddConstructor (c);
2055 current_local_parameters = null;
2056 if (RootContext.Documentation != null)
2057 Lexer.doc_state = XmlCommentState.Allowed;
2061 constructor_declarator
2062 : constructor_header
2066 | constructor_header constructor_initializer
2068 ((Constructor)$1).Initializer = (ConstructorInitializer) $2;
2076 if (RootContext.Documentation != null) {
2077 tmpComment = Lexer.consume_doc_comment ();
2078 Lexer.doc_state = XmlCommentState.Allowed;
2081 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2083 LocatedToken lt = (LocatedToken) $1;
2084 current_local_parameters = (Parameters) $4;
2085 current_block = new ToplevelBlock (null, current_local_parameters, null, lt.Location);
2087 $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
2094 | SEMICOLON { current_block = null; $$ = null; }
2097 constructor_initializer
2098 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
2100 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2102 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
2104 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2107 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2112 destructor_declaration
2113 : opt_attributes opt_modifiers TILDE
2115 if (RootContext.Documentation != null) {
2116 tmpComment = Lexer.consume_doc_comment ();
2117 Lexer.doc_state = XmlCommentState.NotAllowed;
2120 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2122 LocatedToken lt = (LocatedToken) $5;
2123 if (lt.Value != current_container.MemberName.Name){
2124 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2125 } else if (current_container.Kind != Kind.Class){
2126 Report.Error (575, lt.Location, "Only class types can contain destructor");
2128 Method d = new Destructor (
2129 current_class, TypeManager.system_void_expr, (int) $2, "Finalize",
2130 Parameters.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2131 if (RootContext.Documentation != null)
2132 d.DocComment = ConsumeStoredComment ();
2134 d.Block = (ToplevelBlock) $8;
2135 current_container.AddMethod (d);
2143 EVENT type variable_declarators SEMICOLON
2145 current_array_type = null;
2146 foreach (VariableDeclaration var in (ArrayList) $5) {
2148 MemberName name = new MemberName (var.identifier,
2151 EventField e = new EventField (
2152 current_class, (FullNamedExpression) $4, (int) $2, name,
2155 if (var.expression_or_array_initializer != null) {
2156 if (current_container.Kind == Kind.Interface) {
2157 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2160 e.Initializer = var.expression_or_array_initializer;
2163 current_container.AddEvent (e);
2165 if (RootContext.Documentation != null) {
2166 e.DocComment = Lexer.consume_doc_comment ();
2167 Lexer.doc_state = XmlCommentState.Allowed;
2173 EVENT type namespace_or_type_name
2176 implicit_value_parameter_type = (FullNamedExpression) $4;
2177 current_local_parameters = new Parameters (
2178 new Parameter (implicit_value_parameter_type, "value",
2179 Parameter.Modifier.NONE, null, GetLocation ($3)));
2181 lexer.EventParsing = true;
2183 event_accessor_declarations
2185 lexer.EventParsing = false;
2189 MemberName name = (MemberName) $5;
2191 if (current_container.Kind == Kind.Interface) {
2192 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2196 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2197 current_container.Name, name.GetSignatureForError ());
2200 Accessors accessors = (Accessors) $8;
2202 if (name.TypeArguments != null)
2203 syntax_error (lexer.Location, "an event can't have type arguments");
2205 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2206 // CS0073 is already reported, so no CS0065 here.
2209 Event e = new EventProperty (
2210 current_class, (FullNamedExpression) $4, (int) $2, name,
2211 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2212 if (RootContext.Documentation != null) {
2213 e.DocComment = Lexer.consume_doc_comment ();
2214 Lexer.doc_state = XmlCommentState.Allowed;
2217 current_container.AddEvent (e);
2218 implicit_value_parameter_type = null;
2221 current_local_parameters = null;
2223 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2224 MemberName mn = (MemberName) $5;
2226 if (mn.Left != null)
2227 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2229 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2231 if (RootContext.Documentation != null)
2232 Lexer.doc_state = XmlCommentState.Allowed;
2236 event_accessor_declarations
2237 : add_accessor_declaration remove_accessor_declaration
2239 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2241 | remove_accessor_declaration add_accessor_declaration
2243 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2244 accessors.declared_in_reverse = true;
2247 | add_accessor_declaration { $$ = null; }
2248 | remove_accessor_declaration { $$ = null; }
2251 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2257 add_accessor_declaration
2258 : opt_attributes ADD
2260 lexer.EventParsing = false;
2264 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2265 lexer.EventParsing = true;
2268 | opt_attributes ADD error {
2269 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2272 | opt_attributes modifiers ADD {
2273 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2278 remove_accessor_declaration
2279 : opt_attributes REMOVE
2281 lexer.EventParsing = false;
2285 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2286 lexer.EventParsing = true;
2288 | opt_attributes REMOVE error {
2289 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2292 | opt_attributes modifiers REMOVE {
2293 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2299 : opt_attributes opt_modifiers indexer_declarator
2302 IndexerDeclaration decl = (IndexerDeclaration) $3;
2304 implicit_value_parameter_type = decl.type;
2306 lexer.PropertyParsing = true;
2307 parsing_indexer = true;
2309 indexer_parameters = decl.param_list;
2311 accessor_declarations
2313 lexer.PropertyParsing = false;
2314 has_get = has_set = false;
2315 parsing_indexer = false;
2319 // The signature is computed from the signature of the indexer. Look
2320 // at section 3.6 on the spec
2322 IndexerDeclaration decl = (IndexerDeclaration) $3;
2323 Location loc = decl.location;
2324 Accessors accessors = (Accessors) $6;
2325 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2326 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2327 bool order = accessors != null ? accessors.declared_in_reverse : false;
2330 if (decl.interface_type != null)
2331 name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);
2333 name = new MemberName (TypeContainer.DefaultIndexerName, loc);
2335 indexer = new Indexer (current_class, decl.type, name,
2336 (int) $2, decl.param_list, (Attributes) $1,
2337 get_block, set_block, order);
2339 if (decl.type == TypeManager.system_void_expr)
2340 Report.Error (620, loc, "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2342 if (accessors == null)
2343 Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2345 if (current_container.Kind == Kind.Interface) {
2346 if (indexer.Get.Block != null)
2347 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2349 if (indexer.Set.Block != null)
2350 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2353 if (RootContext.Documentation != null)
2354 indexer.DocComment = ConsumeStoredComment ();
2356 current_container.AddIndexer (indexer);
2358 current_local_parameters = null;
2359 implicit_value_parameter_type = null;
2360 indexer_parameters = null;
2365 : type THIS OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
2367 Parameters pars = (Parameters) $4;
2369 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2371 if (RootContext.Documentation != null) {
2372 tmpComment = Lexer.consume_doc_comment ();
2373 Lexer.doc_state = XmlCommentState.Allowed;
2376 $$ = new IndexerDeclaration ((FullNamedExpression) $1, null, pars, (Location) $2);
2378 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2380 Parameters pars = (Parameters) $6;
2382 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2385 MemberName name = (MemberName) $2;
2386 $$ = new IndexerDeclaration ((FullNamedExpression) $1, name, pars, (Location) $4);
2388 if (RootContext.Documentation != null) {
2389 tmpComment = Lexer.consume_doc_comment ();
2390 Lexer.doc_state = XmlCommentState.Allowed;
2400 if (RootContext.Documentation != null)
2401 enumTypeComment = Lexer.consume_doc_comment ();
2406 MemberName name = (MemberName) $4;
2407 if (name.IsGeneric) {
2408 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2411 name = MakeName (name);
2412 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2413 name, (Attributes) $1);
2415 if (RootContext.Documentation != null)
2416 e.DocComment = enumTypeComment;
2419 EnumMember em = null;
2420 foreach (VariableDeclaration ev in (ArrayList) $7) {
2421 em = new EnumMember (
2422 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2423 ev.OptAttributes, ev.Location);
2425 // if (RootContext.Documentation != null)
2426 em.DocComment = ev.DocComment;
2428 e.AddEnumMember (em);
2430 if (RootContext.EvalMode)
2431 undo.AddTypeContainer (current_container, e);
2433 current_container.AddTypeContainer (e);
2441 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2444 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2445 $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2446 $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2447 $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
2448 Enum.Error_1008 (GetLocation ($2));
2454 Error_TypeExpected (lexer.Location);
2461 if (RootContext.Documentation != null)
2462 Lexer.doc_state = XmlCommentState.Allowed;
2464 opt_enum_member_declarations
2466 // here will be evaluated after CLOSE_BLACE is consumed.
2467 if (RootContext.Documentation != null)
2468 Lexer.doc_state = XmlCommentState.Allowed;
2476 opt_enum_member_declarations
2477 : /* empty */ { $$ = new ArrayList (4); }
2478 | enum_member_declarations opt_comma { $$ = $1; }
2481 enum_member_declarations
2482 : enum_member_declaration
2484 ArrayList l = new ArrayList (4);
2489 | enum_member_declarations COMMA enum_member_declaration
2491 ArrayList l = (ArrayList) $1;
2499 enum_member_declaration
2500 : opt_attributes IDENTIFIER
2502 VariableDeclaration vd = new VariableDeclaration (
2503 (LocatedToken) $2, null, (Attributes) $1);
2505 if (RootContext.Documentation != null) {
2506 vd.DocComment = Lexer.consume_doc_comment ();
2507 Lexer.doc_state = XmlCommentState.Allowed;
2512 | opt_attributes IDENTIFIER
2514 if (RootContext.Documentation != null) {
2515 tmpComment = Lexer.consume_doc_comment ();
2516 Lexer.doc_state = XmlCommentState.NotAllowed;
2519 ASSIGN constant_expression
2521 VariableDeclaration vd = new VariableDeclaration (
2522 (LocatedToken) $2, $5, (Attributes) $1);
2524 if (RootContext.Documentation != null)
2525 vd.DocComment = ConsumeStoredComment ();
2531 delegate_declaration
2536 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2538 MemberName name = MakeName ((MemberName) $5);
2539 Parameters p = (Parameters) $7;
2541 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2542 (int) $2, name, p, (Attributes) $1);
2544 if (RootContext.Documentation != null) {
2545 del.DocComment = Lexer.consume_doc_comment ();
2546 Lexer.doc_state = XmlCommentState.Allowed;
2549 current_container.AddDelegate (del);
2550 current_delegate = del;
2551 lexer.ConstraintsParsing = true;
2553 opt_type_parameter_constraints_clauses
2555 lexer.ConstraintsParsing = false;
2559 current_delegate.SetParameterInfo ((ArrayList) $10);
2560 $$ = current_delegate;
2562 current_delegate = null;
2569 lexer.CheckNullable (false);
2574 // FIXME: A hack with parsing conditional operator as nullable type
2575 //if (RootContext.Version < LanguageVersion.ISO_2)
2576 // Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2578 lexer.CheckNullable (true);
2583 namespace_or_type_name
2584 : IDENTIFIER opt_type_argument_list
2586 LocatedToken lt = (LocatedToken) $1;
2587 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2589 | IDENTIFIER DOUBLE_COLON IDENTIFIER opt_type_argument_list {
2590 LocatedToken lt1 = (LocatedToken) $1;
2591 LocatedToken lt2 = (LocatedToken) $3;
2592 if (RootContext.Version == LanguageVersion.ISO_1)
2593 Report.FeatureIsNotAvailable (lt1.Location, "namespace alias qualifier");
2595 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $4, lt1.Location);
2597 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2598 LocatedToken lt = (LocatedToken) $3;
2599 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2604 : IDENTIFIER opt_type_parameter_list
2606 LocatedToken lt = (LocatedToken) $1;
2607 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2609 | namespace_or_type_name DOT IDENTIFIER opt_type_parameter_list
2611 LocatedToken lt = (LocatedToken) $3;
2612 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2617 : IDENTIFIER opt_type_parameter_list
2619 LocatedToken lt = (LocatedToken) $1;
2620 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2625 // Generics arguments (any type, without attributes)
2628 opt_type_argument_list
2629 : /* empty */ { $$ = null; }
2630 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2632 if (RootContext.Version < LanguageVersion.ISO_2)
2633 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2637 | OP_GENERICS_LT error
2639 Error_TypeExpected (lexer.Location);
2644 // Generics parameters (identifiers only, with attributes), used in type, method declarations
2647 opt_type_parameter_list
2648 : /* empty */ { $$ = null; }
2649 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2651 if (RootContext.Version < LanguageVersion.ISO_2)
2652 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2656 | OP_GENERICS_LT error
2658 Error_TypeExpected (lexer.Location);
2665 TypeArguments type_args = new TypeArguments (lexer.Location);
2666 type_args.Add ((Expression) $1);
2669 | type_arguments COMMA type_argument
2671 TypeArguments type_args = (TypeArguments) $1;
2672 type_args.Add ((Expression) $3);
2682 | attribute_sections type
2684 SimpleName sn = $2 as SimpleName;
2686 Error_TypeExpected (GetLocation ($2));
2688 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2694 * Before you think of adding a return_type, notice that we have been
2695 * using two rules in the places where it matters (one rule using type
2696 * and another identical one that uses VOID as the return type). This
2697 * gets rid of a shift/reduce couple
2700 : namespace_or_type_name opt_nullable
2702 MemberName name = (MemberName) $1;
2705 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2707 if (name.Left == null && name.Name == "var" &&
2708 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
2709 $$ = new VarExpr (name.Location);
2711 $$ = name.GetTypeExpression ();
2714 | builtin_types opt_nullable
2717 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2727 // Note that here only unmanaged types are allowed but we
2728 // can't perform checks during this phase - we do it during
2729 // semantic analysis.
2731 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2735 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2740 : builtin_types opt_nullable
2743 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2745 | non_expression_type rank_specifier
2747 Location loc = GetLocation ($1);
2749 loc = lexer.Location;
2750 $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, loc);
2752 | non_expression_type STAR
2754 Location loc = GetLocation ($1);
2756 loc = lexer.Location;
2757 $$ = new ComposedCast ((FullNamedExpression) $1, "*", loc);
2761 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2762 // through this different path
2764 | multiplicative_expression STAR
2766 FullNamedExpression e = $1 as FullNamedExpression;
2768 $$ = new ComposedCast (e, "*");
2770 Error_TypeExpected (GetLocation ($1));
2777 ArrayList types = new ArrayList (2);
2781 | type_list COMMA base_type_name
2783 ArrayList types = (ArrayList) $1;
2792 if ($1 is ComposedCast)
2793 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2798 Error_TypeExpected (lexer.Location);
2803 * replaces all the productions for isolating the various
2804 * simple types, but we need this to reuse it easily in local_variable_type
2807 : OBJECT { $$ = TypeManager.system_object_expr; }
2808 | STRING { $$ = TypeManager.system_string_expr; }
2809 | BOOL { $$ = TypeManager.system_boolean_expr; }
2810 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2811 | FLOAT { $$ = TypeManager.system_single_expr; }
2812 | DOUBLE { $$ = TypeManager.system_double_expr; }
2813 | VOID { $$ = TypeManager.system_void_expr; }
2818 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2819 | BYTE { $$ = TypeManager.system_byte_expr; }
2820 | SHORT { $$ = TypeManager.system_int16_expr; }
2821 | USHORT { $$ = TypeManager.system_uint16_expr; }
2822 | INT { $$ = TypeManager.system_int32_expr; }
2823 | UINT { $$ = TypeManager.system_uint32_expr; }
2824 | LONG { $$ = TypeManager.system_int64_expr; }
2825 | ULONG { $$ = TypeManager.system_uint64_expr; }
2826 | CHAR { $$ = TypeManager.system_char_expr; }
2830 : type rank_specifiers
2832 string rank_specifiers = (string) $2;
2833 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2838 // Expressions, section 7.5
2847 MemberName mn = (MemberName) $1;
2848 $$ = mn.GetTypeExpression ();
2850 | IDENTIFIER DOUBLE_COLON IDENTIFIER opt_type_argument_list
2852 LocatedToken lt1 = (LocatedToken) $1;
2853 LocatedToken lt2 = (LocatedToken) $3;
2854 if (RootContext.Version == LanguageVersion.ISO_1)
2855 Report.FeatureIsNotAvailable (lt1.Location, "namespace alias qualifier");
2857 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $4, lt1.Location);
2859 | parenthesized_expression
2860 | default_value_expression
2862 | invocation_expression
2866 | post_increment_expression
2867 | post_decrement_expression
2871 | checked_expression
2872 | unchecked_expression
2873 | pointer_member_access
2874 | anonymous_method_expression
2881 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2882 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2883 | NULL { $$ = new NullLiteral (lexer.Location); }
2887 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2888 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2889 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2894 object v = lexer.Value;
2897 $$ = new IntLiteral ((int) v, lexer.Location);
2898 } else if (v is uint)
2899 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2901 $$ = new LongLiteral ((Int64) v, lexer.Location);
2902 else if (v is ulong)
2903 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2905 Console.WriteLine ("OOPS. Unexpected result from scanner");
2910 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
2911 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
2914 parenthesized_expression_0
2915 : OPEN_PARENS expression CLOSE_PARENS
2918 lexer.Deambiguate_CloseParens ($$);
2919 // After this, the next token returned is one of
2920 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
2921 // or CLOSE_PARENS_MINUS.
2923 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
2926 parenthesized_expression
2927 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2931 | parenthesized_expression_0 CLOSE_PARENS
2935 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2937 // If a parenthesized expression is followed by a minus, we need to wrap
2938 // the expression inside a ParenthesizedExpression for the CS0075 check
2939 // in Binary.DoResolve().
2940 $$ = new ParenthesizedExpression ((Expression) $1);
2945 : primary_expression DOT IDENTIFIER opt_type_argument_list
2947 LocatedToken lt = (LocatedToken) $3;
2948 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2950 | predefined_type DOT IDENTIFIER opt_type_argument_list
2952 LocatedToken lt = (LocatedToken) $3;
2953 // TODO: Location is wrong as some predefined types doesn't hold a location
2954 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2962 invocation_expression
2963 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
2966 Report.Error (1, (Location) $2, "Parse error");
2968 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
2970 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
2972 $$ = new Invocation ((Expression) $1, new ArrayList ());
2974 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
2976 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
2978 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
2980 ArrayList args = new ArrayList (1);
2982 $$ = new Invocation ((Expression) $1, args);
2984 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
2986 ArrayList args = ((ArrayList) $4);
2988 $$ = new Invocation ((Expression) $1, args);
2992 opt_object_or_collection_initializer
2993 : /* empty */ { $$ = null; }
2994 | object_or_collection_initializer
2997 object_or_collection_initializer
2998 : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
3001 $$ = CollectionOrObjectInitializers.Empty;
3003 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3005 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3007 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3011 opt_member_initializer_list
3012 : /* empty */ { $$ = null; }
3013 | member_initializer_list
3019 member_initializer_list
3020 : member_initializer
3022 ArrayList a = new ArrayList ();
3026 | member_initializer_list COMMA member_initializer
3028 ArrayList a = (ArrayList)$1;
3035 : IDENTIFIER ASSIGN initializer_value
3037 LocatedToken lt = $1 as LocatedToken;
3038 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3040 | non_assignment_expression
3042 $$ = new CollectionElementInitializer ((Expression)$1);
3044 | OPEN_BRACE expression_list CLOSE_BRACE
3046 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3048 | OPEN_BRACE CLOSE_BRACE
3050 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3056 | object_or_collection_initializer
3060 : /* empty */ { $$ = null; }
3067 ArrayList list = new ArrayList (4);
3071 | argument_list COMMA argument
3073 ArrayList list = (ArrayList) $1;
3077 | argument_list COMMA
3079 Report.Error (839, GetLocation ($2), "An argument is missing");
3084 Report.Error (839, GetLocation ($1), "An argument is missing");
3087 | argument_list error {
3088 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3096 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3098 | non_simple_argument
3105 : REF variable_reference
3107 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3109 | OUT variable_reference
3111 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3113 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3115 ArrayList list = (ArrayList) $3;
3116 Argument[] args = new Argument [list.Count];
3117 list.CopyTo (args, 0);
3119 Expression expr = new Arglist (args, (Location) $1);
3120 $$ = new Argument (expr, Argument.AType.Expression);
3122 | ARGLIST OPEN_PARENS CLOSE_PARENS
3124 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3128 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3133 : expression { note ("section 5.4"); $$ = $1; }
3137 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3139 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3141 | primary_expression rank_specifiers
3143 // So the super-trick is that primary_expression
3144 // can only be either a SimpleName or a MemberAccess.
3145 // The MemberAccess case arises when you have a fully qualified type-name like :
3147 // SimpleName is when you have
3150 Expression expr = (Expression) $1;
3151 if (expr is ComposedCast){
3152 $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3153 } else if (expr is ATypeNameExpression){
3155 // So we extract the string corresponding to the SimpleName
3158 $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3160 Error_ExpectingTypeName (expr);
3161 $$ = TypeManager.system_object_expr;
3164 current_array_type = (FullNamedExpression)$$;
3171 ArrayList list = new ArrayList (4);
3175 | expression_list COMMA expression
3177 ArrayList list = (ArrayList) $1;
3186 $$ = new This (current_block, (Location) $1);
3191 : BASE DOT IDENTIFIER opt_type_argument_list
3193 LocatedToken lt = (LocatedToken) $3;
3194 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3196 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3198 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3201 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3206 post_increment_expression
3207 : primary_expression OP_INC
3209 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3210 (Expression) $1, (Location) $2);
3214 post_decrement_expression
3215 : primary_expression OP_DEC
3217 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3218 (Expression) $1, (Location) $2);
3223 : object_or_delegate_creation_expression
3224 | array_creation_expression
3225 | anonymous_type_expression
3228 object_or_delegate_creation_expression
3229 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3232 if (RootContext.Version <= LanguageVersion.ISO_2)
3233 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3235 $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (CollectionOrObjectInitializers) $6, (Location) $1);
3238 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3240 | NEW type object_or_collection_initializer
3242 if (RootContext.Version <= LanguageVersion.ISO_2)
3243 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3245 $$ = new NewInitialize ((Expression) $2, null, (CollectionOrObjectInitializers) $3, (Location) $1);
3249 array_creation_expression
3250 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3252 opt_array_initializer
3254 $$ = new ArrayCreation ((FullNamedExpression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3256 | NEW type rank_specifiers array_initializer
3258 $$ = new ArrayCreation ((FullNamedExpression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3260 | NEW rank_specifiers array_initializer
3262 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
3266 Report.Error (1031, (Location) $1, "Type expected");
3271 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3276 anonymous_type_expression
3277 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3279 if (RootContext.Version <= LanguageVersion.ISO_2)
3280 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3282 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3286 anonymous_type_parameters_opt_comma
3287 : anonymous_type_parameters_opt
3288 | anonymous_type_parameters COMMA
3291 anonymous_type_parameters_opt
3293 | anonymous_type_parameters
3296 anonymous_type_parameters
3297 : anonymous_type_parameter
3299 ArrayList a = new ArrayList (4);
3303 | anonymous_type_parameters COMMA anonymous_type_parameter
3305 ArrayList a = (ArrayList) $1;
3311 anonymous_type_parameter
3312 : IDENTIFIER ASSIGN variable_initializer
3314 LocatedToken lt = (LocatedToken)$1;
3315 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3319 LocatedToken lt = (LocatedToken)$1;
3320 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3321 lt.Value, lt.Location);
3323 | BASE DOT IDENTIFIER opt_type_argument_list
3325 LocatedToken lt = (LocatedToken) $3;
3326 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3327 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3331 MemberAccess ma = (MemberAccess) $1;
3332 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3336 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3337 "Anonymous type members must be a member assignment, simple name or member access expression");
3352 opt_rank_specifier_or_nullable
3359 if (RootContext.Version < LanguageVersion.ISO_2)
3360 Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
3364 | opt_nullable rank_specifiers
3374 : rank_specifier opt_rank_specifier
3376 $$ = (string) $2 + (string) $1;
3381 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3383 $$ = "[" + (string) $2 + "]";
3403 | dim_separators COMMA
3405 $$ = (string) $1 + ",";
3409 opt_array_initializer
3421 : OPEN_BRACE CLOSE_BRACE
3423 ArrayList list = new ArrayList (4);
3426 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3428 $$ = (ArrayList) $2;
3432 variable_initializer_list
3433 : variable_initializer
3435 ArrayList list = new ArrayList (4);
3439 | variable_initializer_list COMMA variable_initializer
3441 ArrayList list = (ArrayList) $1;
3450 pushed_current_array_type = current_array_type;
3451 lexer.TypeOfParsing = true;
3453 OPEN_PARENS typeof_type_expression CLOSE_PARENS
3455 lexer.TypeOfParsing = false;
3456 Expression type = (Expression)$4;
3457 if (type == TypeManager.system_void_expr)
3458 $$ = new TypeOfVoid ((Location) $1);
3460 $$ = new TypeOf (type, (Location) $1);
3461 current_array_type = pushed_current_array_type;
3465 typeof_type_expression
3472 $$ = new UnboundTypeExpression ((MemberName)$1, lexer.Location);
3476 Error_TypeExpected (lexer.Location);
3481 : IDENTIFIER GENERIC_DIMENSION
3483 if (RootContext.Version < LanguageVersion.ISO_2)
3484 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3486 LocatedToken lt = (LocatedToken) $1;
3487 TypeArguments ta = new TypeArguments ((int)$2, lt.Location);
3489 $$ = new MemberName (lt.Value, ta, lt.Location);
3491 | IDENTIFIER DOUBLE_COLON IDENTIFIER GENERIC_DIMENSION
3493 LocatedToken lt = (LocatedToken) $1;
3494 MemberName left = new MemberName (lt.Value, lt.Location);
3495 lt = (LocatedToken) $3;
3496 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3498 if (RootContext.Version == LanguageVersion.ISO_1)
3499 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3501 $$ = new MemberName (left, lt.Value, ta, lt.Location);
3503 | unbound_type_name DOT IDENTIFIER GENERIC_DIMENSION
3505 LocatedToken lt = (LocatedToken) $3;
3506 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3508 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3510 | namespace_or_type_name DOT IDENTIFIER GENERIC_DIMENSION
3512 LocatedToken lt = (LocatedToken) $3;
3513 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3515 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3521 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3522 $$ = new SizeOf ((Expression) $3, (Location) $1);
3527 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3529 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3533 unchecked_expression
3534 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3536 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3540 pointer_member_access
3541 : primary_expression OP_PTR IDENTIFIER
3544 LocatedToken lt = (LocatedToken) $3;
3546 deref = new Indirection ((Expression) $1, lt.Location);
3547 $$ = new MemberAccess (deref, lt.Value);
3551 anonymous_method_expression
3552 : DELEGATE opt_anonymous_method_signature
3554 start_anonymous (false, (Parameters) $2, (Location) $1);
3558 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
3562 opt_anonymous_method_signature
3563 : /* empty */ { $$ = null; }
3564 | anonymous_method_signature
3567 anonymous_method_signature
3570 params_modifiers_not_allowed = true;
3572 opt_formal_parameter_list CLOSE_PARENS
3574 params_modifiers_not_allowed = false;
3579 default_value_expression
3580 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3582 if (RootContext.Version < LanguageVersion.ISO_2)
3583 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3585 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3590 : primary_expression
3591 | BANG prefixed_unary_expression
3593 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3595 | TILDE prefixed_unary_expression
3597 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3603 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3605 $$ = new Cast ((Expression) $1, (Expression) $3);
3607 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3609 $$ = new Cast ((Expression) $1, (Expression) $3);
3611 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3613 $$ = new Cast ((Expression) $1, (Expression) $3);
3619 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3621 // TODO: wrong location
3622 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3627 // The idea to split this out is from Rhys' grammar
3628 // to solve the problem with casts.
3630 prefixed_unary_expression
3632 | PLUS prefixed_unary_expression
3634 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3636 | MINUS prefixed_unary_expression
3638 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3640 | OP_INC prefixed_unary_expression
3642 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3643 (Expression) $2, (Location) $1);
3645 | OP_DEC prefixed_unary_expression
3647 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3648 (Expression) $2, (Location) $1);
3650 | STAR prefixed_unary_expression
3652 $$ = new Indirection ((Expression) $2, (Location) $1);
3654 | BITWISE_AND prefixed_unary_expression
3656 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3660 multiplicative_expression
3661 : prefixed_unary_expression
3662 | multiplicative_expression STAR prefixed_unary_expression
3664 $$ = new Binary (Binary.Operator.Multiply,
3665 (Expression) $1, (Expression) $3);
3667 | multiplicative_expression DIV prefixed_unary_expression
3669 $$ = new Binary (Binary.Operator.Division,
3670 (Expression) $1, (Expression) $3);
3672 | multiplicative_expression PERCENT prefixed_unary_expression
3674 $$ = new Binary (Binary.Operator.Modulus,
3675 (Expression) $1, (Expression) $3);
3680 : multiplicative_expression
3681 | additive_expression PLUS multiplicative_expression
3683 $$ = new Binary (Binary.Operator.Addition,
3684 (Expression) $1, (Expression) $3);
3686 | additive_expression MINUS multiplicative_expression
3688 $$ = new Binary (Binary.Operator.Subtraction,
3689 (Expression) $1, (Expression) $3);
3694 : additive_expression
3695 | shift_expression OP_SHIFT_LEFT additive_expression
3697 $$ = new Binary (Binary.Operator.LeftShift,
3698 (Expression) $1, (Expression) $3);
3700 | shift_expression OP_SHIFT_RIGHT additive_expression
3702 $$ = new Binary (Binary.Operator.RightShift,
3703 (Expression) $1, (Expression) $3);
3714 lexer.PutbackNullable ();
3719 nullable_type_or_conditional
3722 if (((bool) $2) && ($1 is ComposedCast))
3723 $$ = ((ComposedCast) $1).RemoveNullable ();
3729 relational_expression
3731 | relational_expression OP_LT shift_expression
3733 $$ = new Binary (Binary.Operator.LessThan,
3734 (Expression) $1, (Expression) $3);
3736 | relational_expression OP_GT shift_expression
3738 $$ = new Binary (Binary.Operator.GreaterThan,
3739 (Expression) $1, (Expression) $3);
3741 | relational_expression OP_LE shift_expression
3743 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3744 (Expression) $1, (Expression) $3);
3746 | relational_expression OP_GE shift_expression
3748 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3749 (Expression) $1, (Expression) $3);
3751 | relational_expression IS
3754 } nullable_type_or_conditional
3756 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
3758 | relational_expression AS
3761 } nullable_type_or_conditional
3763 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
3768 : relational_expression
3769 | equality_expression OP_EQ relational_expression
3771 $$ = new Binary (Binary.Operator.Equality,
3772 (Expression) $1, (Expression) $3);
3774 | equality_expression OP_NE relational_expression
3776 $$ = new Binary (Binary.Operator.Inequality,
3777 (Expression) $1, (Expression) $3);
3782 : equality_expression
3783 | and_expression BITWISE_AND equality_expression
3785 $$ = new Binary (Binary.Operator.BitwiseAnd,
3786 (Expression) $1, (Expression) $3);
3790 exclusive_or_expression
3792 | exclusive_or_expression CARRET and_expression
3794 $$ = new Binary (Binary.Operator.ExclusiveOr,
3795 (Expression) $1, (Expression) $3);
3799 inclusive_or_expression
3800 : exclusive_or_expression
3801 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3803 $$ = new Binary (Binary.Operator.BitwiseOr,
3804 (Expression) $1, (Expression) $3);
3808 conditional_and_expression
3809 : inclusive_or_expression
3810 | conditional_and_expression OP_AND inclusive_or_expression
3812 $$ = new Binary (Binary.Operator.LogicalAnd,
3813 (Expression) $1, (Expression) $3);
3817 conditional_or_expression
3818 : conditional_and_expression
3819 | conditional_or_expression OP_OR conditional_and_expression
3821 $$ = new Binary (Binary.Operator.LogicalOr,
3822 (Expression) $1, (Expression) $3);
3826 conditional_expression
3827 : conditional_or_expression
3828 | conditional_or_expression INTERR expression COLON expression
3830 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3832 | conditional_or_expression OP_COALESCING expression
3834 if (RootContext.Version < LanguageVersion.ISO_2)
3835 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3837 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
3839 // We'll be resolved into a `parenthesized_expression_0' later on.
3840 | conditional_or_expression INTERR CLOSE_PARENS
3842 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
3843 lexer.PutbackCloseParens ();
3847 assignment_expression
3848 : prefixed_unary_expression ASSIGN expression
3850 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
3852 | prefixed_unary_expression OP_MULT_ASSIGN expression
3854 $$ = new CompoundAssign (
3855 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3857 | prefixed_unary_expression OP_DIV_ASSIGN expression
3859 $$ = new CompoundAssign (
3860 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3862 | prefixed_unary_expression OP_MOD_ASSIGN expression
3864 $$ = new CompoundAssign (
3865 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3867 | prefixed_unary_expression OP_ADD_ASSIGN expression
3869 $$ = new CompoundAssign (
3870 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3872 | prefixed_unary_expression OP_SUB_ASSIGN expression
3874 $$ = new CompoundAssign (
3875 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3877 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3879 $$ = new CompoundAssign (
3880 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3882 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3884 $$ = new CompoundAssign (
3885 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3887 | prefixed_unary_expression OP_AND_ASSIGN expression
3889 $$ = new CompoundAssign (
3890 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3892 | prefixed_unary_expression OP_OR_ASSIGN expression
3894 $$ = new CompoundAssign (
3895 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3897 | prefixed_unary_expression OP_XOR_ASSIGN expression
3899 $$ = new CompoundAssign (
3900 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3904 lambda_parameter_list
3907 ArrayList pars = new ArrayList (4);
3912 | lambda_parameter_list COMMA lambda_parameter
3914 ArrayList pars = (ArrayList) $1;
3915 Parameter p = (Parameter)$3;
3916 if (pars[0].GetType () != p.GetType ()) {
3917 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
3926 : parameter_modifier type IDENTIFIER
3928 LocatedToken lt = (LocatedToken) $3;
3930 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3934 LocatedToken lt = (LocatedToken) $2;
3936 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
3940 LocatedToken lt = (LocatedToken) $1;
3941 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
3945 opt_lambda_parameter_list
3946 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
3947 | lambda_parameter_list {
3948 ArrayList pars_list = (ArrayList) $1;
3949 $$ = new Parameters ((Parameter[])pars_list.ToArray (typeof (Parameter)));
3953 lambda_expression_body
3955 start_block (lexer.Location);
3959 Block b = end_block (lexer.Location);
3960 b.AddStatement (new ContextualReturn ((Expression) $2));
3971 LocatedToken lt = (LocatedToken) $1;
3972 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
3973 start_anonymous (true, new Parameters (p), (Location) $2);
3975 lambda_expression_body
3977 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
3979 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
3981 start_anonymous (true, (Parameters) $2, (Location) $4);
3983 lambda_expression_body
3985 $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
3990 : assignment_expression
3991 | non_assignment_expression
3994 non_assignment_expression
3995 : conditional_expression
4017 lexer.ConstraintsParsing = true;
4021 MemberName name = MakeName ((MemberName) $6);
4022 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4025 opt_type_parameter_constraints_clauses
4027 lexer.ConstraintsParsing = false;
4029 current_class.SetParameterInfo ((ArrayList) $9);
4031 if (RootContext.Documentation != null) {
4032 current_container.DocComment = Lexer.consume_doc_comment ();
4033 Lexer.doc_state = XmlCommentState.Allowed;
4038 if (RootContext.Documentation != null)
4039 Lexer.doc_state = XmlCommentState.Allowed;
4043 $$ = pop_current_class ();
4051 { $$ = $1; } // location
4055 : /* empty */ { $$ = (int) 0; }
4061 | modifiers modifier
4066 if ((m1 & m2) != 0) {
4067 Location l = lexer.Location;
4068 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4070 $$ = (int) (m1 | m2);
4075 : NEW { $$ = Modifiers.NEW; }
4076 | PUBLIC { $$ = Modifiers.PUBLIC; }
4077 | PROTECTED { $$ = Modifiers.PROTECTED; }
4078 | INTERNAL { $$ = Modifiers.INTERNAL; }
4079 | PRIVATE { $$ = Modifiers.PRIVATE; }
4080 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4081 | SEALED { $$ = Modifiers.SEALED; }
4082 | STATIC { $$ = Modifiers.STATIC; }
4083 | READONLY { $$ = Modifiers.READONLY; }
4084 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4085 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4086 | EXTERN { $$ = Modifiers.EXTERN; }
4087 | VOLATILE { $$ = Modifiers.VOLATILE; }
4088 | UNSAFE { $$ = Modifiers.UNSAFE; }
4097 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4100 opt_type_parameter_constraints_clauses
4101 : /* empty */ { $$ = null; }
4102 | type_parameter_constraints_clauses
4106 type_parameter_constraints_clauses
4107 : type_parameter_constraints_clause {
4108 ArrayList constraints = new ArrayList (1);
4109 constraints.Add ($1);
4112 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4113 ArrayList constraints = (ArrayList) $1;
4114 Constraints new_constraint = (Constraints)$2;
4116 foreach (Constraints c in constraints) {
4117 if (new_constraint.TypeParameter == c.TypeParameter) {
4118 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4119 new_constraint.TypeParameter);
4123 constraints.Add (new_constraint);
4128 type_parameter_constraints_clause
4129 : WHERE IDENTIFIER COLON type_parameter_constraints {
4130 LocatedToken lt = (LocatedToken) $2;
4131 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4135 type_parameter_constraints
4136 : type_parameter_constraint {
4137 ArrayList constraints = new ArrayList (1);
4138 constraints.Add ($1);
4141 | type_parameter_constraints COMMA type_parameter_constraint {
4142 ArrayList constraints = (ArrayList) $1;
4144 constraints.Add ($3);
4149 type_parameter_constraint
4151 | NEW OPEN_PARENS CLOSE_PARENS {
4152 $$ = SpecialConstraint.Constructor;
4155 $$ = SpecialConstraint.ReferenceType;
4158 $$ = SpecialConstraint.ValueType;
4167 // A block is "contained" on the following places:
4169 // property_declaration as part of the accessor body (get/set)
4170 // operator_declaration
4171 // constructor_declaration
4172 // destructor_declaration
4173 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4178 ++lexer.parsing_block;
4179 start_block ((Location) $1);
4181 opt_statement_list CLOSE_BRACE
4183 --lexer.parsing_block;
4184 $$ = end_block ((Location) $4);
4191 ++lexer.parsing_block;
4193 opt_statement_list CLOSE_BRACE
4195 --lexer.parsing_block;
4196 $$ = end_block ((Location) $4);
4207 | statement_list statement
4211 : declaration_statement
4213 if ($1 != null && (Block) $1 != current_block){
4214 current_block.AddStatement ((Statement) $1);
4215 current_block = (Block) $1;
4218 | valid_declaration_statement
4220 current_block.AddStatement ((Statement) $1);
4226 // The interactive_statement and its derivatives are only
4227 // used to provide a special version of `expression_statement'
4228 // that has a side effect of assigning the expression to
4231 interactive_statement_list
4232 : interactive_statement
4233 | interactive_statement_list interactive_statement
4236 interactive_statement
4237 : declaration_statement
4239 if ($1 != null && (Block) $1 != current_block){
4240 current_block.AddStatement ((Statement) $1);
4241 current_block = (Block) $1;
4244 | interactive_valid_declaration_statement
4246 current_block.AddStatement ((Statement) $1);
4251 valid_declaration_statement
4254 | expression_statement
4255 | selection_statement
4256 | iteration_statement
4260 | unchecked_statement
4267 interactive_valid_declaration_statement
4270 | interactive_expression_statement
4271 | selection_statement
4272 | iteration_statement
4276 | unchecked_statement
4284 : valid_declaration_statement
4285 | declaration_statement
4287 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4292 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4300 $$ = EmptyStatement.Value;
4307 LocatedToken lt = (LocatedToken) $1;
4308 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4310 if (current_block.AddLabel (labeled))
4311 current_block.AddStatement (labeled);
4316 declaration_statement
4317 : local_variable_declaration SEMICOLON
4319 current_array_type = null;
4321 DictionaryEntry de = (DictionaryEntry) $1;
4322 Expression e = (Expression) de.Key;
4324 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4328 | local_constant_declaration SEMICOLON
4330 current_array_type = null;
4332 DictionaryEntry de = (DictionaryEntry) $1;
4334 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4340 * The following is from Rhys' grammar:
4341 * > Types in local variable declarations must be recognized as
4342 * > expressions to prevent reduce/reduce errors in the grammar.
4343 * > The expressions are converted into types during semantic analysis.
4346 : primary_expression opt_rank_specifier_or_nullable
4348 // FIXME: Do something smart here regarding the composition of the type.
4350 // Ok, the above "primary_expression" is there to get rid of
4351 // both reduce/reduce and shift/reduces in the grammar, it should
4352 // really just be "type_name". If you use type_name, a reduce/reduce
4353 // creeps up. If you use namespace_or_type_name (which is all we need
4354 // really) two shift/reduces appear.
4357 // So the super-trick is that primary_expression
4358 // can only be either a SimpleName or a MemberAccess.
4359 // The MemberAccess case arises when you have a fully qualified type-name like :
4361 // SimpleName is when you have
4364 Expression expr = (Expression) $1;
4365 string rank_or_nullable = (string) $2;
4367 if (expr is ComposedCast){
4368 $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4369 } else if (expr is ATypeNameExpression){
4371 // So we extract the string corresponding to the SimpleName
4374 if (rank_or_nullable.Length == 0) {
4375 SimpleName sn = expr as SimpleName;
4376 if (sn != null && sn.Name == "var" &&
4377 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
4378 $$ = new VarExpr (sn.Location);
4382 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4385 Error_ExpectingTypeName (expr);
4386 $$ = TypeManager.system_object_expr;
4389 | builtin_types opt_rank_specifier_or_nullable
4391 if ((string) $2 == "")
4394 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4398 local_variable_pointer_type
4399 : primary_expression STAR
4401 ATypeNameExpression expr = $1 as ATypeNameExpression;
4404 $$ = new ComposedCast (expr, "*");
4406 Error_ExpectingTypeName ((Expression)$1);
4410 | builtin_types STAR
4412 $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
4416 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4418 | local_variable_pointer_type STAR
4420 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4424 local_variable_declaration
4425 : local_variable_type variable_declarators
4428 VarExpr ve = $1 as VarExpr;
4430 ve.VariableInitializer = (ArrayList)$2;
4432 $$ = new DictionaryEntry ($1, $2);
4436 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4441 if ((string) $2 == "")
4442 t = (Expression) $1;
4444 t = new ComposedCast ((FullNamedExpression) $1, (string) $2);
4445 $$ = new DictionaryEntry (t, $3);
4451 local_constant_declaration
4452 : CONST local_variable_type constant_declarators
4455 $$ = new DictionaryEntry ($2, $3);
4461 expression_statement
4462 : statement_expression SEMICOLON { $$ = $1; }
4465 interactive_expression_statement
4466 : interactive_statement_expression SEMICOLON { $$ = $1; }
4470 // We have to do the wrapping here and not in the case above,
4471 // because statement_expression is used for example in for_statement
4473 statement_expression
4476 Expression expr = (Expression) $1;
4477 ExpressionStatement s;
4479 s = expr as ExpressionStatement;
4482 expr.Error_InvalidExpressionStatement ();
4485 $$ = new StatementExpression (s);
4489 Report.ExtraInformation (GetLocation ($1), "(token is: " + yyToken + " in previous ");
4490 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4495 interactive_statement_expression
4498 Expression expr = (Expression) $1;
4499 ExpressionStatement s;
4501 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4502 $$ = new StatementExpression (s);
4506 Report.Error (1002, GetLocation ($1), "Expecting `;' (token is: {0})", yyToken);
4517 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4520 Location l = (Location) $1;
4522 $$ = new If ((Expression) $3, (Statement) $5, l);
4524 // FIXME: location for warning should be loc property of $5.
4525 if ($5 == EmptyStatement.Value)
4526 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4529 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4530 embedded_statement ELSE embedded_statement
4532 Location l = (Location) $1;
4534 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4536 // FIXME: location for warning should be loc property of $5 and $7.
4537 if ($5 == EmptyStatement.Value)
4538 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4539 if ($7 == EmptyStatement.Value)
4540 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4545 : SWITCH OPEN_PARENS
4547 if (switch_stack == null)
4548 switch_stack = new Stack (2);
4549 switch_stack.Push (current_block);
4551 expression CLOSE_PARENS
4554 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4555 current_block = (Block) switch_stack.Pop ();
4571 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4572 $$ = new ArrayList ();
4580 ArrayList sections = new ArrayList (4);
4585 | switch_sections switch_section
4587 ArrayList sections = (ArrayList) $1;
4597 current_block = current_block.CreateSwitchBlock (lexer.Location);
4601 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4608 ArrayList labels = new ArrayList (4);
4613 | switch_labels switch_label
4615 ArrayList labels = (ArrayList) ($1);
4623 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4624 | DEFAULT_COLON { $$ = new SwitchLabel (null, (Location) $1); }
4627 1523, GetLocation ($1),
4628 "The keyword case or default must precede code in switch block");
4640 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4642 Location l = (Location) $1;
4643 $$ = new While ((Expression) $3, (Statement) $5, l);
4648 : DO embedded_statement
4649 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4651 Location l = (Location) $1;
4653 $$ = new Do ((Statement) $2, (Expression) $5, l);
4659 opt_for_initializer SEMICOLON
4661 Location l = lexer.Location;
4663 Block assign_block = current_block;
4665 if ($3 is DictionaryEntry){
4666 DictionaryEntry de = (DictionaryEntry) $3;
4668 Expression type = (Expression) de.Key;
4669 ArrayList var_declarators = (ArrayList) de.Value;
4671 foreach (VariableDeclaration decl in var_declarators){
4675 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4679 Expression expr = decl.expression_or_array_initializer;
4681 LocalVariableReference var;
4682 var = new LocalVariableReference (assign_block, decl.identifier, l);
4685 Assign a = new SimpleAssign (var, expr, decl.Location);
4687 assign_block.AddStatement (new StatementExpression (a));
4691 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4692 // This can be referred to as $5 below.
4698 opt_for_condition SEMICOLON
4699 opt_for_iterator CLOSE_PARENS
4702 Location l = (Location) $1;
4704 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4706 current_block.AddStatement (f);
4708 $$ = end_block (lexer.Location);
4713 : /* empty */ { $$ = EmptyStatement.Value; }
4718 : local_variable_declaration
4719 | statement_expression_list
4723 : /* empty */ { $$ = null; }
4724 | boolean_expression
4728 : /* empty */ { $$ = EmptyStatement.Value; }
4733 : statement_expression_list
4736 statement_expression_list
4737 : statement_expression
4739 // CHANGE: was `null'
4740 Statement s = (Statement) $1;
4741 Block b = new Block (current_block, s.loc, lexer.Location);
4746 | statement_expression_list COMMA statement_expression
4748 Block b = (Block) $1;
4750 b.AddStatement ((Statement) $3);
4756 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4758 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4761 | FOREACH OPEN_PARENS type IDENTIFIER IN
4762 expression CLOSE_PARENS
4764 start_block (lexer.Location);
4765 Block foreach_block = current_block;
4767 LocatedToken lt = (LocatedToken) $4;
4768 Location l = lt.Location;
4769 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4771 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4773 // Get a writable reference to this read-only variable.
4775 // Note that the $$ here refers to the value of _this_ code block,
4776 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4777 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4784 LocalVariableReference v = (LocalVariableReference) $8;
4785 Location l = (Location) $1;
4788 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4789 current_block.AddStatement (f);
4792 $$ = end_block (lexer.Location);
4798 | continue_statement
4808 $$ = new Break ((Location) $1);
4813 : CONTINUE SEMICOLON
4815 $$ = new Continue ((Location) $1);
4820 : GOTO IDENTIFIER SEMICOLON
4822 LocatedToken lt = (LocatedToken) $2;
4823 $$ = new Goto (lt.Value, lt.Location);
4825 | GOTO CASE constant_expression SEMICOLON
4827 $$ = new GotoCase ((Expression) $3, (Location) $1);
4829 | GOTO DEFAULT SEMICOLON
4831 $$ = new GotoDefault ((Location) $1);
4836 : RETURN opt_expression SEMICOLON
4838 $$ = new Return ((Expression) $2, (Location) $1);
4843 : THROW opt_expression SEMICOLON
4845 $$ = new Throw ((Expression) $2, (Location) $1);
4850 : IDENTIFIER RETURN expression SEMICOLON
4852 LocatedToken lt = (LocatedToken) $1;
4853 string s = lt.Value;
4855 Report.Error (1003, lt.Location, "; expected");
4858 if (RootContext.Version == LanguageVersion.ISO_1){
4859 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4862 current_block.Toplevel.IsIterator = true;
4863 $$ = new Yield ((Expression) $3, lt.Location);
4865 | IDENTIFIER RETURN SEMICOLON
4867 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4870 | IDENTIFIER BREAK SEMICOLON
4872 LocatedToken lt = (LocatedToken) $1;
4873 string s = lt.Value;
4875 Report.Error (1003, lt.Location, "; expected");
4878 if (RootContext.Version == LanguageVersion.ISO_1){
4879 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4883 current_block.Toplevel.IsIterator = true;
4884 $$ = new YieldBreak (lt.Location);
4894 : TRY block catch_clauses
4896 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
4898 | TRY block FINALLY block
4900 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
4902 | TRY block catch_clauses FINALLY block
4904 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
4908 Report.Error (1524, (Location) $1, "Expected catch or finally");
4916 ArrayList l = new ArrayList (4);
4921 | catch_clauses catch_clause
4923 ArrayList l = (ArrayList) $1;
4931 : /* empty */ { $$ = null; }
4936 : CATCH opt_catch_args
4938 Expression type = null;
4941 DictionaryEntry cc = (DictionaryEntry) $2;
4942 type = (Expression) cc.Key;
4943 LocatedToken lt = (LocatedToken) cc.Value;
4946 ArrayList one = new ArrayList (4);
4948 one.Add (new VariableDeclaration (lt, null));
4950 start_block (lexer.Location);
4951 current_block = declare_local_variables (type, one, lt.Location);
4955 Expression type = null;
4957 Block var_block = null;
4960 DictionaryEntry cc = (DictionaryEntry) $2;
4961 type = (Expression) cc.Key;
4962 LocatedToken lt = (LocatedToken) cc.Value;
4966 var_block = end_block (lexer.Location);
4970 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
4975 : /* empty */ { $$ = null; }
4980 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4982 $$ = new DictionaryEntry ($2, $3);
4984 | OPEN_PARENS CLOSE_PARENS
4986 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
4993 $$ = new Checked ((Block) $2);
5000 $$ = new Unchecked ((Block) $2);
5007 RootContext.CheckUnsafeOption ((Location) $1);
5009 $$ = new Unsafe ((Block) $3);
5015 type fixed_pointer_declarators
5018 ArrayList list = (ArrayList) $4;
5019 Expression type = (Expression) $3;
5020 Location l = (Location) $1;
5021 int top = list.Count;
5023 start_block (lexer.Location);
5025 for (int i = 0; i < top; i++){
5026 Pair p = (Pair) list [i];
5029 v = current_block.AddVariable (type, (string) p.First, l);
5033 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5041 Location l = (Location) $1;
5043 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5045 current_block.AddStatement (f);
5047 $$ = end_block (lexer.Location);
5051 fixed_pointer_declarators
5052 : fixed_pointer_declarator {
5053 ArrayList declarators = new ArrayList (4);
5055 declarators.Add ($1);
5058 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5060 ArrayList declarators = (ArrayList) $1;
5062 declarators.Add ($3);
5067 fixed_pointer_declarator
5068 : IDENTIFIER ASSIGN expression
5070 LocatedToken lt = (LocatedToken) $1;
5071 // FIXME: keep location
5072 $$ = new Pair (lt.Value, $3);
5076 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5082 : LOCK OPEN_PARENS expression CLOSE_PARENS
5088 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5093 : USING OPEN_PARENS local_variable_declaration CLOSE_PARENS
5095 start_block (lexer.Location);
5096 Block assign_block = current_block;
5098 DictionaryEntry de = (DictionaryEntry) $3;
5099 Location l = (Location) $1;
5101 Expression type = (Expression) de.Key;
5102 ArrayList var_declarators = (ArrayList) de.Value;
5104 Stack vars = new Stack ();
5106 foreach (VariableDeclaration decl in var_declarators) {
5107 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5110 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5112 Expression expr = decl.expression_or_array_initializer;
5114 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5117 LocalVariableReference var;
5119 // Get a writable reference to this read-only variable.
5120 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5122 // This is so that it is not a warning on using variables
5125 vars.Push (new DictionaryEntry (var, expr));
5127 // Assign a = new SimpleAssign (var, expr, decl.Location);
5128 // assign_block.AddStatement (new StatementExpression (a));
5131 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5132 // It can be referred to as $5 below.
5137 Statement stmt = (Statement) $6;
5138 Stack vars = (Stack) $5;
5139 Location l = (Location) $1;
5141 while (vars.Count > 0) {
5142 DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5143 stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5145 current_block.AddStatement (stmt);
5146 $$ = end_block (lexer.Location);
5148 | USING OPEN_PARENS expression CLOSE_PARENS
5150 start_block (lexer.Location);
5154 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5155 $$ = end_block (lexer.Location);
5165 ++lexer.query_parsing;
5169 if (--lexer.query_parsing == 1)
5170 lexer.query_parsing = 0;
5172 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5174 from.Tail.Next = (Linq.AQueryClause)$3;
5177 current_block.SetEndLocation (lexer.Location);
5178 current_block = current_block.Parent;
5183 : FROM IDENTIFIER IN expression
5185 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5186 LocatedToken lt = (LocatedToken) $2;
5188 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
5189 $$ = new Linq.QueryExpression (lt, new Linq.QueryStartClause ((Expression)$4));
5191 | FROM type IDENTIFIER IN expression
5193 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5194 LocatedToken lt = (LocatedToken) $3;
5196 Expression type = (Expression)$2;
5197 current_block.AddVariable (type, lt.Value, lt.Location);
5198 $$ = new Linq.QueryExpression (lt, new Linq.Cast (type, (Expression)$5));
5203 : FROM IDENTIFIER IN expression
5205 LocatedToken lt = (LocatedToken) $2;
5207 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5208 lt.Value, lt.Location);
5210 $$ = new Linq.SelectMany (lt, (Expression)$4);
5212 | FROM type IDENTIFIER IN expression
5214 LocatedToken lt = (LocatedToken) $3;
5216 Expression type = (Expression)$2;
5217 current_block.AddVariable (type, lt.Value, lt.Location);
5218 $$ = new Linq.SelectMany (lt, new Linq.Cast (type, (Expression)$5));
5223 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5225 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5228 head.Next = (Linq.AQueryClause)$3;
5231 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5232 clause.Tail.Next = head;
5240 select_or_group_clause
5243 $$ = new Linq.Select ((Expression)$2, GetLocation ($1));
5245 | GROUP expression BY expression
5247 $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation ($1));
5251 opt_query_body_clauses
5253 | query_body_clauses
5258 | query_body_clauses query_body_clause
5260 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5274 : LET IDENTIFIER ASSIGN expression
5276 LocatedToken lt = (LocatedToken) $2;
5277 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5278 lt.Value, lt.Location);
5279 $$ = new Linq.Let (lt, (Expression)$4, GetLocation ($1));
5284 : WHERE boolean_expression
5286 $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
5291 : JOIN IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5293 Location loc = GetLocation ($1);
5294 LocatedToken lt = (LocatedToken) $2;
5295 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5296 lt.Value, lt.Location);
5299 $$ = new Linq.Join (lt, (Expression)$4, (Expression)$6,
5300 (Expression)$8, loc);
5302 LocatedToken lt_into = (LocatedToken) $9;
5303 $$ = new Linq.GroupJoin (lt, (Expression)$4, (Expression)$6,
5304 (Expression)$8, lt_into, loc);
5307 | JOIN type IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5309 Location loc = GetLocation ($1);
5310 LocatedToken lt = (LocatedToken) $3;
5311 current_block.AddVariable ((Expression)$2, lt.Value, lt.Location);
5313 Linq.Cast cast = new Linq.Cast ((Expression)$2, (Expression)$5);
5315 $$ = new Linq.Join (lt, cast, (Expression)$7,
5316 (Expression)$9, loc);
5318 LocatedToken lt_into = (LocatedToken) $10;
5319 $$ = new Linq.GroupJoin (lt, cast, (Expression)$7,
5320 (Expression)$9, lt_into, loc);
5342 | order_by COMMA orderings_then_by
5344 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$3;
5354 | orderings_then_by COMMA then_by
5356 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5364 $$ = new Linq.OrderByAscending ((Expression)$1);
5366 | expression ASCENDING
5368 $$ = new Linq.OrderByAscending ((Expression)$1);
5370 | expression DESCENDING
5372 $$ = new Linq.OrderByDescending ((Expression)$1);
5379 $$ = new Linq.ThenByAscending ((Expression)$1);
5381 | expression ASCENDING
5383 $$ = new Linq.ThenByAscending ((Expression)$1);
5385 | expression DESCENDING
5387 $$ = new Linq.ThenByDescending ((Expression)$1);
5392 opt_query_continuation
5396 // query continuation block is not linked with query block but with block
5397 // before. This means each query can use same range variable names for
5398 // different identifiers.
5400 current_block.SetEndLocation (GetLocation ($1));
5401 current_block = current_block.Parent;
5402 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5404 LocatedToken lt = (LocatedToken) $2;
5405 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5406 lt.Value, lt.Location);
5410 $$ = new Linq.QueryExpression ((LocatedToken) $2,
5411 (Linq.AQueryClause)$4);
5416 // Support for using the compiler as an interactive parser
5418 // The INTERACTIVE_PARSER token is first sent to parse our
5419 // productions; If the result is a Statement, the parsing
5420 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5421 // to setup the blocks in advance.
5423 // This setup is here so that in the future we can add
5424 // support for other constructs (type parsing, namespaces, etc)
5425 // that do not require a block to be setup in advance
5429 : EVAL_STATEMENT_PARSER EOF
5430 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5431 | EVAL_STATEMENT_PARSER {
5432 InteractiveShell.LoadAliases (current_namespace);
5434 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5435 Modifiers.PUBLIC, null), null);
5437 ArrayList baseclass_list = new ArrayList ();
5438 baseclass_list.Add (new TypeExpression (typeof (InteractiveBase), lexer.Location));
5439 current_container.AddBasesForPart (current_class, baseclass_list);
5441 // (ref object retval)
5442 Parameter [] mpar = new Parameter [1];
5443 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5445 Parameters pars = new Parameters (mpar);
5446 current_local_parameters = pars;
5447 Method method = new Method (
5450 TypeManager.system_void_expr,
5451 Modifiers.PUBLIC | Modifiers.STATIC,
5452 new MemberName ("Host"),
5454 null /* attributes */);
5456 oob_stack.Push (method);
5457 ++lexer.parsing_block;
5458 start_block (lexer.Location);
5460 interactive_statement_list
5462 --lexer.parsing_block;
5463 Method method = (Method) oob_stack.Pop ();
5465 method.Block = (ToplevelBlock) end_block(lexer.Location);
5466 current_container.AddMethod (method);
5468 InteractiveResult = pop_current_class ();
5469 current_local_parameters = null;
5471 // | EVAL_COMPILATION_UNIT_PARSER {
5472 // InteractiveShell.LoadAliases (current_namespace);
5479 // A class used to pass around variable declarations and constants
5481 public class VariableDeclaration {
5482 public string identifier;
5483 public Expression expression_or_array_initializer;
5484 public Location Location;
5485 public Attributes OptAttributes;
5486 public string DocComment;
5488 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5490 this.identifier = lt.Value;
5491 if (eoai is ArrayList) {
5492 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5494 this.expression_or_array_initializer = (Expression)eoai;
5496 this.Location = lt.Location;
5497 this.OptAttributes = opt_attrs;
5500 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5506 // A class used to hold info about an indexer declarator
5508 public class IndexerDeclaration {
5509 public FullNamedExpression type;
5510 public MemberName interface_type;
5511 public Parameters param_list;
5512 public Location location;
5514 public IndexerDeclaration (FullNamedExpression type, MemberName interface_type,
5515 Parameters param_list, Location loc)
5518 this.interface_type = interface_type;
5519 this.param_list = param_list;
5520 this.location = loc;
5525 // A class used to hold info about an operator declarator
5527 struct OperatorDeclaration {
5528 public readonly Operator.OpType optype;
5529 public readonly FullNamedExpression ret_type;
5530 public readonly Location location;
5532 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5535 this.ret_type = ret_type;
5536 this.location = location;
5540 void Error_ExpectingTypeName (Expression expr)
5542 if (expr is Invocation){
5543 Report.Error (1002, expr.Location, "Expecting `;'");
5545 expr.Error_InvalidExpressionStatement ();
5549 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5551 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5555 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5557 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5558 Parameter.GetModifierSignature (mod));
5561 static void Error_TypeExpected (Location loc)
5563 Report.Error (1031, loc, "Type expected");
5566 void push_current_class (TypeContainer tc, object partial_token)
5568 if (RootContext.EvalMode){
5569 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5570 undo.AddTypeContainer (current_container, tc);
5573 if (partial_token != null)
5574 current_container = current_container.AddPartial (tc);
5576 current_container = current_container.AddTypeContainer (tc);
5582 DeclSpace pop_current_class ()
5584 DeclSpace retval = current_class;
5586 current_class = current_class.Parent;
5587 current_container = current_class.PartialContainer;
5593 // Given the @class_name name, it creates a fully qualified name
5594 // based on the containing declaration space
5597 MakeName (MemberName class_name)
5599 Namespace ns = current_namespace.NS;
5601 if (current_container.Name.Length == 0){
5602 if (ns.Name.Length != 0)
5603 return new MemberName (ns.MemberName, class_name);
5607 return new MemberName (current_container.MemberName, class_name);
5611 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5613 Block implicit_block;
5614 ArrayList inits = null;
5617 // If we are doing interactive editing, we want variable declarations
5618 // that are in the top block to be added instead to the class as
5621 if (RootContext.StatementMode){
5624 for (Block b = current_block; b != null; b = b.Parent){
5625 if (b is ExplicitBlock && !(b is ToplevelBlock)){
5626 // There has been an explicit block, we cant add to the class
5633 // We can use "current_block" since we know there are no explicit blocks
5635 foreach (VariableDeclaration decl in variable_declarators){
5636 // We can not use the super-handy f.Initializer, because
5637 // multiple lines would force code to be executed out of sync
5638 if (decl.expression_or_array_initializer != null){
5639 string id = "$" + decl.identifier;
5640 current_block.AddVariable (type, id, decl.Location);
5642 LocalVariableReference var;
5643 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
5644 Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
5645 current_block.AddStatement (new StatementExpression (assign));
5646 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
5647 current_block.AddStatement (new StatementExpression (assign));
5649 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC, decl.identifier, null, loc);
5650 current_container.AddField (f);
5652 // Register the field to be visible later as a global variable
5653 InteractiveShell.QueueField (f);
5657 return current_block;
5662 // We use the `Used' property to check whether statements
5663 // have been added to the current block. If so, we need
5664 // to create another block to contain the new declaration
5665 // otherwise, as an optimization, we use the same block to
5666 // add the declaration.
5668 // FIXME: A further optimization is to check if the statements
5669 // that were added were added as part of the initialization
5670 // below. In which case, no other statements have been executed
5671 // and we might be able to reduce the number of blocks for
5672 // situations like this:
5674 // int j = 1; int k = j + 1;
5676 if (current_block.Used)
5677 implicit_block = new Block (current_block, loc, lexer.Location);
5679 implicit_block = current_block;
5681 foreach (VariableDeclaration decl in variable_declarators){
5683 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5684 if (decl.expression_or_array_initializer != null){
5686 inits = new ArrayList (4);
5693 return implicit_block;
5695 foreach (VariableDeclaration decl in inits){
5697 Expression expr = decl.expression_or_array_initializer;
5699 LocalVariableReference var;
5700 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5702 assign = new SimpleAssign (var, expr, decl.Location);
5704 implicit_block.AddStatement (new StatementExpression (assign));
5707 return implicit_block;
5710 Block declare_local_constants (Expression type, ArrayList declarators)
5712 Block implicit_block;
5714 if (current_block.Used)
5715 implicit_block = new Block (current_block);
5717 implicit_block = current_block;
5719 foreach (VariableDeclaration decl in declarators){
5720 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5723 return implicit_block;
5726 string CheckAttributeTarget (string a, Location l)
5729 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5733 Report.Warning (658, 1, l,
5734 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5735 return string.Empty;
5738 static bool IsUnaryOperator (Operator.OpType op)
5742 case Operator.OpType.LogicalNot:
5743 case Operator.OpType.OnesComplement:
5744 case Operator.OpType.Increment:
5745 case Operator.OpType.Decrement:
5746 case Operator.OpType.True:
5747 case Operator.OpType.False:
5748 case Operator.OpType.UnaryPlus:
5749 case Operator.OpType.UnaryNegation:
5755 void syntax_error (Location l, string msg)
5757 Report.Error (1003, l, "Syntax error, " + msg);
5760 void note (string s)
5762 // Used to put annotations
5767 public Tokenizer Lexer {
5773 static CSharpParser ()
5775 oob_stack = new Stack ();
5778 public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
5780 if (RootContext.EvalMode)
5784 current_namespace = new NamespaceEntry (null, file, null);
5785 current_class = current_namespace.SlaveDeclSpace;
5786 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5788 lexer = new Tokenizer (reader, file);
5791 public void parse ()
5793 eof_token = Token.EOF;
5796 if (yacc_verbose_flag > 1)
5797 yyparse (lexer, new yydebug.yyDebugSimple ());
5800 } catch (Exception e){
5801 if (e is yyParser.yyUnexpectedEof)
5802 UnexpectedEOF = true;
5803 else if (yacc_verbose_flag > 0)
5804 Console.WriteLine (e);
5805 if (e is yyParser.yyException)
5806 Report.Error (-25, lexer.Location, "Parsing error");
5808 Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
5810 Tokenizer tokenizer = lexer as Tokenizer;
5811 tokenizer.cleanup ();
5813 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5814 throw new InternalErrorException ("who set it?");
5817 static void CheckToken (int error, int yyToken, string msg, Location loc)
5819 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5820 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5822 Report.Error (error, loc, msg);
5825 void CheckIdentifierToken (int yyToken, Location loc)
5827 CheckToken (1041, yyToken, "Identifier expected", loc);
5830 string ConsumeStoredComment ()
5832 string s = tmpComment;
5834 Lexer.doc_state = XmlCommentState.Allowed;
5838 Location GetLocation (object obj)
5840 if (obj is MemberCore)
5841 return ((MemberCore) obj).Location;
5842 if (obj is MemberName)
5843 return ((MemberName) obj).Location;
5844 if (obj is LocatedToken)
5845 return ((LocatedToken) obj).Location;
5846 if (obj is Location)
5847 return (Location) obj;
5848 return lexer.Location;
5851 void start_block (Location loc)
5853 if (current_block == null || parsing_anonymous_method) {
5854 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
5855 parsing_anonymous_method = false;
5857 current_block = new ExplicitBlock (current_block, loc, Location.Null);
5862 end_block (Location loc)
5864 Block retval = current_block.Explicit;
5865 retval.SetEndLocation (loc);
5866 current_block = retval.Parent;
5871 start_anonymous (bool lambda, Parameters parameters, Location loc)
5873 oob_stack.Push (current_anonymous_method);
5874 oob_stack.Push (current_local_parameters);
5876 current_local_parameters = parameters;
5878 current_anonymous_method = lambda
5879 ? new LambdaExpression (parameters, loc)
5880 : new AnonymousMethodExpression (parameters, loc);
5882 // Force the next block to be created as a ToplevelBlock
5883 parsing_anonymous_method = true;
5887 * Completes the anonymous method processing, if lambda_expr is null, this
5888 * means that we have a Statement instead of an Expression embedded
5890 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
5892 AnonymousMethodExpression retval;
5894 if (RootContext.Version == LanguageVersion.ISO_1){
5895 Report.FeatureIsNotAvailable (loc, "anonymous methods");
5898 current_anonymous_method.Block = anon_block;
5899 retval = current_anonymous_method;
5902 current_local_parameters = (Parameters) oob_stack.Pop ();
5903 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
5908 public NamespaceEntry CurrentNamespace {
5910 return current_namespace;