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 ParametersCompiled 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 ParametersCompiled 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 complex_parameters_modifiers_not_allowed;
123 bool arglist_allowed;
124 bool default_parameter_used;
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 // Stack<ToplevelBlock>
136 Stack linq_clause_blocks;
138 // A counter to create new class names in interactive mode
139 static int class_count;
143 %token NONE /* This token is never returned by our lexer */
144 %token ERROR // This is used not by the parser, but by the tokenizer.
148 *These are the C# keywords
247 %token INTERR_NULLABLE
250 /* Generics <,> tokens */
251 %token OP_GENERICS_LT
252 %token OP_GENERICS_LT_DECL
253 %token OP_GENERICS_GT
255 /* C# keywords which are not really keywords */
261 /* C# single character operators/punctuation. */
289 /* C# multi-character operators. */
294 %token OP_SHIFT_RIGHT
301 %token OP_MULT_ASSIGN
306 %token OP_SHIFT_LEFT_ASSIGN
307 %token OP_SHIFT_RIGHT_ASSIGN
315 %token LITERAL_INTEGER
317 %token LITERAL_DOUBLE
318 %token LITERAL_DECIMAL
319 %token LITERAL_CHARACTER
320 %token LITERAL_STRING
323 %token OPEN_PARENS_LAMBDA
324 %token OPEN_PARENS_CAST
325 %token GENERIC_DIMENSION
328 // Make the parser go into eval mode parsing (statements and compilation units).
329 %token EVAL_STATEMENT_PARSER
330 %token EVAL_COMPILATION_UNIT_PARSER
331 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
334 // This token is generated to trigger the completion engine at this point
336 %token GENERATE_COMPLETION
339 // This token is return repeatedly after the first GENERATE_COMPLETION
340 // token is produced and before the final EOF
342 %token COMPLETE_COMPLETION
344 /* Add precedence rules to solve dangling else s/r conflict */
348 /* Define the operator tokens and their precedences */
356 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
358 %left STAR DIV PERCENT
359 %right BANG CARRET UMINUS
360 %nonassoc OP_INC OP_DEC
362 %left OPEN_BRACKET OPEN_BRACE
365 %start compilation_unit
369 : outer_declarations opt_EOF
370 | outer_declarations global_attributes opt_EOF
371 | global_attributes opt_EOF
372 | opt_EOF /* allow empty files */
373 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
379 Lexer.check_incorrect_doc_comment ();
383 Lexer.check_incorrect_doc_comment ();
389 | outer_declarations outer_declaration
393 : extern_alias_directive
395 | namespace_member_declaration
398 extern_alias_directives
399 : extern_alias_directive
400 | extern_alias_directives extern_alias_directive
403 extern_alias_directive
404 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
406 LocatedToken lt = (LocatedToken) $2;
409 syntax_error (lt.Location, "`alias' expected");
410 } else if (RootContext.Version == LanguageVersion.ISO_1) {
411 Report.FeatureIsNotAvailable (lt.Location, "external alias");
413 lt = (LocatedToken) $3;
414 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
419 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
425 | using_directives using_directive
429 : using_alias_directive
431 if (RootContext.Documentation != null)
432 Lexer.doc_state = XmlCommentState.Allowed;
434 | using_namespace_directive
436 if (RootContext.Documentation != null)
437 Lexer.doc_state = XmlCommentState.Allowed;
441 using_alias_directive
442 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
444 LocatedToken lt = (LocatedToken) $2;
445 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
448 CheckIdentifierToken (yyToken, GetLocation ($2));
453 using_namespace_directive
454 : USING namespace_name SEMICOLON
456 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
461 // Strictly speaking, namespaces don't have attributes but
462 // we parse global attributes along with namespace declarations and then
465 namespace_declaration
466 : opt_attributes NAMESPACE qualified_identifier
468 MemberName name = (MemberName) $3;
471 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
474 current_namespace = new NamespaceEntry (
475 current_namespace, file, name.GetName ());
476 current_class = current_namespace.SlaveDeclSpace;
477 current_container = current_class.PartialContainer;
479 namespace_body opt_semicolon
481 current_namespace = current_namespace.Parent;
482 current_class = current_namespace.SlaveDeclSpace;
483 current_container = current_class.PartialContainer;
490 LocatedToken lt = (LocatedToken) $1;
491 $$ = new MemberName (lt.Value, lt.Location);
493 | qualified_identifier DOT IDENTIFIER
495 LocatedToken lt = (LocatedToken) $3;
496 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
500 syntax_error (lexer.Location, "`.' expected");
515 : namespace_or_type_name
517 MemberName name = (MemberName) $1;
519 if (name.TypeArguments != null)
520 syntax_error (lexer.Location, "namespace name expected");
529 if (RootContext.Documentation != null)
530 Lexer.doc_state = XmlCommentState.Allowed;
536 : opt_extern_alias_directives
538 opt_namespace_member_declarations
542 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
545 | opt_extern_alias_directives
547 opt_namespace_member_declarations
550 Report.Error (1513, lexer.Location, "Expected `}'");
559 opt_extern_alias_directives
561 | extern_alias_directives
564 opt_namespace_member_declarations
566 | namespace_member_declarations
569 namespace_member_declarations
570 : namespace_member_declaration
571 | namespace_member_declarations namespace_member_declaration
574 namespace_member_declaration
578 DeclSpace ds = (DeclSpace)$1;
580 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
581 Report.Error (1527, ds.Location,
582 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
585 current_namespace.DeclarationFound = true;
587 | namespace_declaration {
588 current_namespace.DeclarationFound = true;
591 | field_declaration {
592 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
594 | method_declaration {
595 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
602 | interface_declaration
604 | delegate_declaration
606 // Enable this when we have handled all errors, because this acts as a generic fallback
609 // Console.WriteLine ("Token=" + yyToken);
610 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
622 Attributes attrs = (Attributes)$1;
623 if (global_attrs_enabled) {
624 CodeGen.Assembly.AddAttributes (attrs.Attrs);
626 foreach (Attribute a in attrs.Attrs) {
627 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
638 global_attrs_enabled = false;
643 global_attrs_enabled = false;
652 if (current_attr_target != String.Empty) {
653 ArrayList sect = (ArrayList) $1;
655 if (global_attrs_enabled) {
656 if (current_attr_target == "module") {
657 current_container.Module.AddAttributes (sect);
659 } else if (current_attr_target != null && current_attr_target.Length > 0) {
660 CodeGen.Assembly.AddAttributes (sect);
663 $$ = new Attributes (sect);
666 if (RootContext.Documentation != null) {
667 Lexer.check_incorrect_doc_comment ();
669 XmlCommentState.Allowed;
673 $$ = new Attributes (sect);
678 current_attr_target = null;
680 | attribute_sections attribute_section
682 if (current_attr_target != String.Empty) {
683 Attributes attrs = $1 as Attributes;
684 ArrayList sect = (ArrayList) $2;
686 if (global_attrs_enabled) {
687 if (current_attr_target == "module") {
688 current_container.Module.AddAttributes (sect);
690 } else if (current_attr_target == "assembly") {
691 CodeGen.Assembly.AddAttributes (sect);
695 attrs = new Attributes (sect);
697 attrs.AddAttributes (sect);
701 attrs = new Attributes (sect);
703 attrs.AddAttributes (sect);
709 current_attr_target = null;
714 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
718 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
724 attribute_target_specifier
725 : attribute_target COLON
727 current_attr_target = (string)$1;
735 LocatedToken lt = (LocatedToken) $1;
736 $$ = CheckAttributeTarget (lt.Value, lt.Location);
738 | EVENT { $$ = "event"; }
739 | RETURN { $$ = "return"; }
742 string name = GetTokenName (yyToken);
743 $$ = CheckAttributeTarget (name, GetLocation ($1));
750 ArrayList attrs = new ArrayList (4);
756 | attribute_list COMMA attribute
758 ArrayList attrs = (ArrayList) $1;
768 ++lexer.parsing_block;
770 opt_attribute_arguments
772 --lexer.parsing_block;
773 MemberName mname = (MemberName) $1;
774 if (mname.IsGeneric) {
775 Report.Error (404, lexer.Location,
776 "'<' unexpected: attributes cannot be generic");
779 object [] arguments = (object []) $3;
780 MemberName left = mname.Left;
781 string identifier = mname.Name;
783 Expression left_expr = left == null ? null : left.GetTypeExpression ();
785 if (current_attr_target == String.Empty)
787 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
788 // FIXME: supply "nameEscaped" parameter here.
789 $$ = new GlobalAttribute (current_namespace, current_attr_target,
790 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
792 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
797 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
800 opt_attribute_arguments
801 : /* empty */ { $$ = null; }
802 | OPEN_PARENS attribute_arguments CLOSE_PARENS
810 : /* empty */ { $$ = null; }
811 | positional_or_named_argument
813 ArrayList a = new ArrayList (4);
815 $$ = new object [] { a, null };
817 | named_attribute_argument
819 ArrayList a = new ArrayList (4);
821 $$ = new object [] { null, a };
823 | attribute_arguments COMMA positional_or_named_argument
825 object[] o = (object[]) $1;
827 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
828 o [0] = new ArrayList (4);
831 ArrayList args = ((ArrayList) o [0]);
832 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
833 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
837 | attribute_arguments COMMA named_attribute_argument
839 object[] o = (object[]) $1;
841 o [1] = new ArrayList (4);
844 ((ArrayList) o [1]).Add ($3);
848 positional_or_named_argument
851 $$ = new Argument ((Expression) $1);
856 named_attribute_argument
857 : IDENTIFIER ASSIGN expression
859 $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);
864 : IDENTIFIER COLON expression
866 if (RootContext.Version <= LanguageVersion.V_3)
867 Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
869 $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);
875 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
878 opt_class_member_declarations
880 | class_member_declarations
883 class_member_declarations
884 : class_member_declaration
885 | class_member_declarations
886 class_member_declaration
889 class_member_declaration
890 : constant_declaration // done
891 | field_declaration // done
892 | method_declaration // done
893 | property_declaration // done
894 | event_declaration // done
895 | indexer_declaration // done
896 | operator_declaration // done
897 | constructor_declaration // done
898 | destructor_declaration // done
902 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
903 GetSymbolName (yyToken));
905 lexer.parsing_generic_declaration = false;
915 lexer.ConstraintsParsing = true;
917 type_declaration_name
919 MemberName name = MakeName ((MemberName) $6);
920 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
923 opt_type_parameter_constraints_clauses
925 lexer.ConstraintsParsing = false;
927 current_class.SetParameterInfo ((ArrayList) $9);
929 if (RootContext.Documentation != null)
930 current_container.DocComment = Lexer.consume_doc_comment ();
934 --lexer.parsing_declaration;
935 if (RootContext.Documentation != null)
936 Lexer.doc_state = XmlCommentState.Allowed;
940 $$ = pop_current_class ();
942 | opt_attributes opt_modifiers opt_partial STRUCT error {
943 CheckIdentifierToken (yyToken, GetLocation ($5));
950 if (RootContext.Documentation != null)
951 Lexer.doc_state = XmlCommentState.Allowed;
953 opt_struct_member_declarations CLOSE_BRACE
956 opt_struct_member_declarations
958 | struct_member_declarations
961 struct_member_declarations
962 : struct_member_declaration
963 | struct_member_declarations struct_member_declaration
966 struct_member_declaration
967 : constant_declaration
970 | property_declaration
972 | indexer_declaration
973 | operator_declaration
974 | constructor_declaration
978 * This is only included so we can flag error 575:
979 * destructors only allowed on class types
981 | destructor_declaration
992 int modflags = (int) $2;
993 foreach (VariableDeclaration constant in (ArrayList) $5){
994 Location l = constant.Location;
995 if ((modflags & Modifiers.STATIC) != 0) {
996 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
1000 Const c = new Const (
1001 current_class, (FullNamedExpression) $4, (string) constant.identifier,
1002 (Expression) constant.expression_or_array_initializer, modflags,
1003 (Attributes) $1, l);
1005 if (RootContext.Documentation != null) {
1006 c.DocComment = Lexer.consume_doc_comment ();
1007 Lexer.doc_state = XmlCommentState.Allowed;
1009 current_container.AddConstant (c);
1014 constant_declarators
1015 : constant_declarator
1017 ArrayList constants = new ArrayList (4);
1022 | constant_declarators COMMA constant_declarator
1025 ArrayList constants = (ArrayList) $1;
1034 ++lexer.parsing_block;
1036 constant_initializer
1038 --lexer.parsing_block;
1039 $$ = new VariableDeclaration ((LocatedToken) $1, $4);
1043 // A const field requires a value to be provided
1044 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1049 constant_initializer
1050 : constant_expression
1058 variable_declarators
1061 FullNamedExpression type = (FullNamedExpression) $3;
1062 if (type == TypeManager.system_void_expr)
1063 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1067 current_array_type = null;
1069 foreach (VariableMemberDeclaration var in (ArrayList) $4){
1070 Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1072 field.Initializer = var.expression_or_array_initializer;
1074 if (RootContext.Documentation != null) {
1075 field.DocComment = Lexer.consume_doc_comment ();
1076 Lexer.doc_state = XmlCommentState.Allowed;
1078 current_container.AddField (field);
1079 $$ = field; // FIXME: might be better if it points to the top item
1086 fixed_variable_declarators
1089 FullNamedExpression type = (FullNamedExpression) $4;
1093 current_array_type = null;
1095 foreach (VariableDeclaration var in (ArrayList) $5) {
1096 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1097 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1099 if (RootContext.Documentation != null) {
1100 field.DocComment = Lexer.consume_doc_comment ();
1101 Lexer.doc_state = XmlCommentState.Allowed;
1103 current_container.AddField (field);
1104 $$ = field; // FIXME: might be better if it points to the top item
1113 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1117 fixed_variable_declarators
1118 : fixed_variable_declarator
1120 ArrayList decl = new ArrayList (2);
1124 | fixed_variable_declarators COMMA fixed_variable_declarator
1126 ArrayList decls = (ArrayList) $1;
1132 fixed_variable_declarator
1133 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1135 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1137 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1139 Report.Error (443, lexer.Location, "Value or constant expected");
1140 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1145 local_variable_declarators
1146 : local_variable_declarator
1148 ArrayList decl = new ArrayList (4);
1153 | local_variable_declarators COMMA local_variable_declarator
1155 ArrayList decls = (ArrayList) $1;
1161 local_variable_declarator
1162 : IDENTIFIER ASSIGN local_variable_initializer
1164 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1168 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1170 | IDENTIFIER variable_bad_array
1176 local_variable_initializer
1179 | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
1181 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1185 $$ = new ArglistAccess ((Location) $1);
1187 | STACKALLOC simple_type
1189 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1190 $$ = new StackAlloc ((Expression) $2, null, (Location) $1);
1194 variable_declarators
1195 : variable_declarator
1197 ArrayList decl = new ArrayList (4);
1202 | variable_declarators COMMA variable_declarator
1204 ArrayList decls = (ArrayList) $1;
1211 : member_declaration_name ASSIGN
1213 ++lexer.parsing_block;
1214 lexer.parsing_generic_declaration = false;
1216 variable_initializer
1218 --lexer.parsing_block;
1219 $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
1221 | member_declaration_name
1223 lexer.parsing_generic_declaration = false;
1224 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1226 | member_declaration_name variable_bad_array
1228 lexer.parsing_generic_declaration = false;
1234 : OPEN_BRACKET opt_expression CLOSE_BRACKET
1236 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1237 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1241 variable_initializer
1248 if (RootContext.Documentation != null)
1249 Lexer.doc_state = XmlCommentState.NotAllowed;
1253 Method method = (Method) $1;
1254 method.Block = (ToplevelBlock) $3;
1255 current_container.AddMethod (method);
1257 if (current_container.Kind == Kind.Interface && method.Block != null) {
1258 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1261 current_generic_method = null;
1262 current_local_parameters = null;
1264 if (RootContext.Documentation != null)
1265 Lexer.doc_state = XmlCommentState.Allowed;
1273 method_declaration_name OPEN_PARENS
1275 arglist_allowed = true;
1277 opt_formal_parameter_list CLOSE_PARENS
1279 lexer.ConstraintsParsing = true;
1281 opt_type_parameter_constraints_clauses
1283 lexer.ConstraintsParsing = false;
1284 arglist_allowed = false;
1285 MemberName name = (MemberName) $4;
1286 current_local_parameters = (ParametersCompiled) $7;
1288 if ($10 != null && name.TypeArguments == null)
1289 Report.Error (80, lexer.Location,
1290 "Constraints are not allowed on non-generic declarations");
1294 GenericMethod generic = null;
1295 if (name.TypeArguments != null) {
1296 generic = new GenericMethod (current_namespace, current_class, name,
1297 (FullNamedExpression) $3, current_local_parameters);
1299 generic.SetParameterInfo ((ArrayList) $10);
1302 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1303 name, current_local_parameters, (Attributes) $1);
1305 current_generic_method = generic;
1307 if (RootContext.Documentation != null)
1308 method.DocComment = Lexer.consume_doc_comment ();
1315 VOID method_declaration_name
1318 arglist_allowed = true;
1320 opt_formal_parameter_list CLOSE_PARENS
1322 lexer.ConstraintsParsing = true;
1324 opt_type_parameter_constraints_clauses
1326 lexer.ConstraintsParsing = false;
1327 arglist_allowed = false;
1329 MemberName name = (MemberName) $5;
1330 current_local_parameters = (ParametersCompiled) $8;
1332 if ($10 != null && name.TypeArguments == null)
1333 Report.Error (80, lexer.Location,
1334 "Constraints are not allowed on non-generic declarations");
1337 GenericMethod generic = null;
1338 if (name.TypeArguments != null) {
1339 generic = new GenericMethod (current_namespace, current_class, name,
1340 TypeManager.system_void_expr, current_local_parameters);
1342 generic.SetParameterInfo ((ArrayList) $11);
1345 int modifiers = (int) $2;
1348 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1349 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1351 if ((modifiers & invalid_partial_mod) != 0) {
1352 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1353 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1354 modifiers &= ~invalid_partial_mod;
1357 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1358 Report.Error (751, name.Location, "A partial method must be declared within a " +
1359 "partial class or partial struct");
1362 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1364 method = new Method (current_class, generic, TypeManager.system_void_expr,
1365 modifiers, name, current_local_parameters, (Attributes) $1);
1367 current_generic_method = generic;
1369 if (RootContext.Documentation != null)
1370 method.DocComment = Lexer.consume_doc_comment ();
1377 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1379 MemberName name = (MemberName) $5;
1380 Report.Error (1585, name.Location,
1381 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1383 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1384 0, name, (ParametersCompiled) $7, (Attributes) $1);
1386 current_local_parameters = (ParametersCompiled) $7;
1388 if (RootContext.Documentation != null)
1389 method.DocComment = Lexer.consume_doc_comment ();
1397 | SEMICOLON { $$ = null; }
1400 opt_formal_parameter_list
1401 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1402 | formal_parameter_list
1405 opt_parameter_list_no_mod
1406 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1409 parameter_modifiers_not_allowed = true;
1411 formal_parameter_list
1413 parameter_modifiers_not_allowed = false;
1418 formal_parameter_list
1421 ArrayList pars_list = (ArrayList) $1;
1423 Parameter [] pars = new Parameter [pars_list.Count];
1424 pars_list.CopyTo (pars);
1426 $$ = new ParametersCompiled (pars);
1428 | fixed_parameters COMMA parameter_array
1430 ArrayList pars_list = (ArrayList) $1;
1433 Parameter [] pars = new Parameter [pars_list.Count];
1434 pars_list.CopyTo (pars);
1436 $$ = new ParametersCompiled (pars);
1438 | fixed_parameters COMMA arglist_modifier
1440 ArrayList pars_list = (ArrayList) $1;
1441 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1443 Parameter [] pars = new Parameter [pars_list.Count];
1444 pars_list.CopyTo (pars);
1446 $$ = new ParametersCompiled (pars, true);
1448 | parameter_array COMMA error
1451 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1454 | fixed_parameters COMMA parameter_array COMMA error
1457 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1460 | arglist_modifier COMMA error
1462 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1465 | fixed_parameters COMMA ARGLIST COMMA error
1467 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1472 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1476 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1483 ArrayList pars = new ArrayList (4);
1484 Parameter p = (Parameter) $1;
1487 default_parameter_used = p.HasDefaultValue;
1490 | fixed_parameters COMMA fixed_parameter
1492 ArrayList pars = (ArrayList) $1;
1493 Parameter p = (Parameter) $3;
1495 if (p.HasExtensionMethodModifier)
1496 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1497 else if (!p.HasDefaultValue && default_parameter_used)
1498 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1500 default_parameter_used |= p.HasDefaultValue;
1509 opt_parameter_modifier
1513 LocatedToken lt = (LocatedToken) $4;
1514 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1517 opt_parameter_modifier
1519 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1521 LocatedToken lt = (LocatedToken) $4;
1522 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1526 opt_parameter_modifier
1530 Location l = GetLocation ($4);
1531 CheckIdentifierToken (yyToken, l);
1532 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1535 opt_parameter_modifier
1541 if (RootContext.Version <= LanguageVersion.V_3) {
1542 Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1545 Parameter.Modifier mod = (Parameter.Modifier) $2;
1546 if (mod != Parameter.Modifier.NONE) {
1548 case Parameter.Modifier.REF:
1549 case Parameter.Modifier.OUT:
1550 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1551 Parameter.GetModifierSignature (mod));
1554 case Parameter.Modifier.This:
1555 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1556 Parameter.GetModifierSignature (mod));
1559 throw new NotImplementedException (mod.ToString ());
1562 mod = Parameter.Modifier.NONE;
1565 if (complex_parameters_modifiers_not_allowed)
1566 Report.Error (1065, GetLocation ($6), "Optional parameter is not valid in this context");
1568 LocatedToken lt = (LocatedToken) $4;
1569 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1571 ((Parameter) $$).DefaultValue = (Expression) $6;
1575 opt_parameter_modifier
1576 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1577 | parameter_modifiers
1581 : parameter_modifier
1585 | parameter_modifiers parameter_modifier
1587 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1588 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1589 if (((Parameter.Modifier)$1 & p2) == p2) {
1590 Error_DuplicateParameterModifier (lexer.Location, p2);
1592 switch (mod & ~Parameter.Modifier.This) {
1593 case Parameter.Modifier.REF:
1594 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1596 case Parameter.Modifier.OUT:
1597 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1600 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1611 if (parameter_modifiers_not_allowed)
1612 Error_ParameterModifierNotValid ("ref", (Location)$1);
1614 $$ = Parameter.Modifier.REF;
1618 if (parameter_modifiers_not_allowed)
1619 Error_ParameterModifierNotValid ("out", (Location)$1);
1621 $$ = Parameter.Modifier.OUT;
1625 if (parameter_modifiers_not_allowed)
1626 Error_ParameterModifierNotValid ("this", (Location)$1);
1628 if (RootContext.Version <= LanguageVersion.ISO_2)
1629 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1631 $$ = Parameter.Modifier.This;
1636 : opt_attributes params_modifier type IDENTIFIER
1638 LocatedToken lt = (LocatedToken) $4;
1639 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1641 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1643 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1645 LocatedToken lt = (LocatedToken) $4;
1646 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1648 | opt_attributes params_modifier type error {
1649 CheckIdentifierToken (yyToken, GetLocation ($4));
1657 if (complex_parameters_modifiers_not_allowed)
1658 Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1660 | PARAMS parameter_modifier
1662 Parameter.Modifier mod = (Parameter.Modifier)$2;
1663 if ((mod & Parameter.Modifier.This) != 0) {
1664 Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1666 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1669 | PARAMS params_modifier
1671 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1678 if (!arglist_allowed)
1679 Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1683 property_declaration
1687 member_declaration_name
1689 if (RootContext.Documentation != null)
1690 tmpComment = Lexer.consume_doc_comment ();
1694 implicit_value_parameter_type = (FullNamedExpression) $3;
1695 lexer.PropertyParsing = true;
1697 accessor_declarations
1699 lexer.PropertyParsing = false;
1700 has_get = has_set = false;
1705 Accessors accessors = (Accessors) $8;
1706 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1707 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1708 bool order = accessors != null ? accessors.declared_in_reverse : false;
1710 MemberName name = (MemberName) $4;
1711 FullNamedExpression ptype = (FullNamedExpression) $3;
1713 prop = new Property (current_class, ptype, (int) $2,
1714 name, (Attributes) $1, get_block, set_block, order, current_block);
1716 if (ptype == TypeManager.system_void_expr)
1717 Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
1719 if (accessors == null)
1720 Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1722 if (current_container.Kind == Kind.Interface) {
1723 if (prop.Get.Block != null)
1724 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1726 if (prop.Set.Block != null)
1727 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1730 current_container.AddProperty (prop);
1731 implicit_value_parameter_type = null;
1733 if (RootContext.Documentation != null)
1734 prop.DocComment = ConsumeStoredComment ();
1739 accessor_declarations
1740 : get_accessor_declaration
1742 $$ = new Accessors ((Accessor) $1, null);
1744 | get_accessor_declaration accessor_declarations
1746 Accessors accessors = (Accessors) $2;
1747 accessors.get_or_add = (Accessor) $1;
1750 | set_accessor_declaration
1752 $$ = new Accessors (null, (Accessor) $1);
1754 | set_accessor_declaration accessor_declarations
1756 Accessors accessors = (Accessors) $2;
1757 accessors.set_or_remove = (Accessor) $1;
1758 accessors.declared_in_reverse = true;
1763 if (yyToken == Token.CLOSE_BRACE) {
1766 if (yyToken == Token.SEMICOLON)
1767 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1769 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1771 $$ = new Accessors (null, null);
1776 get_accessor_declaration
1777 : opt_attributes opt_modifiers GET
1779 // If this is not the case, then current_local_parameters has already
1780 // been set in indexer_declaration
1781 if (parsing_indexer == false)
1782 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1784 current_local_parameters = indexer_parameters;
1785 lexer.PropertyParsing = false;
1790 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1793 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1795 current_local_parameters = null;
1796 lexer.PropertyParsing = true;
1798 if (RootContext.Documentation != null)
1799 if (Lexer.doc_state == XmlCommentState.Error)
1800 Lexer.doc_state = XmlCommentState.NotAllowed;
1806 set_accessor_declaration
1807 : opt_attributes opt_modifiers SET
1809 Parameter implicit_value_parameter = new Parameter (
1810 implicit_value_parameter_type, "value",
1811 Parameter.Modifier.NONE, null, (Location) $3);
1813 if (!parsing_indexer) {
1814 current_local_parameters = new ParametersCompiled (new Parameter [] { implicit_value_parameter });
1816 current_local_parameters = ParametersCompiled.MergeGenerated (
1817 indexer_parameters, true, implicit_value_parameter, null);
1820 lexer.PropertyParsing = false;
1825 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1828 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1830 current_local_parameters = null;
1831 lexer.PropertyParsing = true;
1833 if (RootContext.Documentation != null
1834 && Lexer.doc_state == XmlCommentState.Error)
1835 Lexer.doc_state = XmlCommentState.NotAllowed;
1849 Error_SyntaxError (1043, yyToken);
1854 interface_declaration
1860 lexer.ConstraintsParsing = true;
1862 type_declaration_name
1864 MemberName name = MakeName ((MemberName) $6);
1865 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1868 opt_type_parameter_constraints_clauses
1870 lexer.ConstraintsParsing = false;
1872 current_class.SetParameterInfo ((ArrayList) $9);
1874 if (RootContext.Documentation != null) {
1875 current_container.DocComment = Lexer.consume_doc_comment ();
1876 Lexer.doc_state = XmlCommentState.Allowed;
1881 --lexer.parsing_declaration;
1882 if (RootContext.Documentation != null)
1883 Lexer.doc_state = XmlCommentState.Allowed;
1887 $$ = pop_current_class ();
1889 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1890 CheckIdentifierToken (yyToken, GetLocation ($5));
1896 opt_interface_member_declarations
1900 opt_interface_member_declarations
1902 | interface_member_declarations
1905 interface_member_declarations
1906 : interface_member_declaration
1907 | interface_member_declarations interface_member_declaration
1910 interface_member_declaration
1911 : constant_declaration
1913 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1917 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1919 | method_declaration
1920 | property_declaration
1922 | indexer_declaration
1923 | operator_declaration
1925 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1927 | constructor_declaration
1929 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1933 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1937 operator_declaration
1938 : opt_attributes opt_modifiers operator_declarator
1946 OperatorDeclaration decl = (OperatorDeclaration) $3;
1947 Operator op = new Operator (
1948 current_class, decl.optype, decl.ret_type, (int) $2,
1949 current_local_parameters,
1950 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1952 if (RootContext.Documentation != null) {
1953 op.DocComment = tmpComment;
1954 Lexer.doc_state = XmlCommentState.Allowed;
1957 // Note again, checking is done in semantic analysis
1958 current_container.AddOperator (op);
1960 current_local_parameters = null;
1966 | SEMICOLON { $$ = null; }
1970 : type_expression_or_array
1973 Report.Error (590, lexer.Location, "User-defined operators cannot return void");
1974 $$ = TypeManager.system_void_expr;
1979 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1981 complex_parameters_modifiers_not_allowed = true;
1983 opt_parameter_list_no_mod CLOSE_PARENS
1985 complex_parameters_modifiers_not_allowed = false;
1987 Location loc = (Location) $2;
1988 Operator.OpType op = (Operator.OpType) $3;
1989 current_local_parameters = (ParametersCompiled)$6;
1991 int p_count = current_local_parameters.Count;
1993 if (op == Operator.OpType.Addition)
1994 op = Operator.OpType.UnaryPlus;
1995 else if (op == Operator.OpType.Subtraction)
1996 op = Operator.OpType.UnaryNegation;
1999 if (IsUnaryOperator (op)) {
2001 Report.Error (1020, loc, "Overloadable binary operator expected");
2002 } else if (p_count != 1) {
2003 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2004 Operator.GetName (op));
2008 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2009 Operator.GetName (op));
2010 } else if (p_count != 2) {
2011 Report.Error (1019, loc, "Overloadable unary operator expected");
2015 if (RootContext.Documentation != null) {
2016 tmpComment = Lexer.consume_doc_comment ();
2017 Lexer.doc_state = XmlCommentState.NotAllowed;
2020 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2022 | conversion_operator_declarator
2025 overloadable_operator
2027 : BANG { $$ = Operator.OpType.LogicalNot; }
2028 | TILDE { $$ = Operator.OpType.OnesComplement; }
2029 | OP_INC { $$ = Operator.OpType.Increment; }
2030 | OP_DEC { $$ = Operator.OpType.Decrement; }
2031 | TRUE { $$ = Operator.OpType.True; }
2032 | FALSE { $$ = Operator.OpType.False; }
2033 // Unary and binary:
2034 | PLUS { $$ = Operator.OpType.Addition; }
2035 | MINUS { $$ = Operator.OpType.Subtraction; }
2037 | STAR { $$ = Operator.OpType.Multiply; }
2038 | DIV { $$ = Operator.OpType.Division; }
2039 | PERCENT { $$ = Operator.OpType.Modulus; }
2040 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2041 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2042 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2043 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2044 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2045 | OP_EQ { $$ = Operator.OpType.Equality; }
2046 | OP_NE { $$ = Operator.OpType.Inequality; }
2047 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2048 | OP_LT { $$ = Operator.OpType.LessThan; }
2049 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2050 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2053 conversion_operator_declarator
2054 : IMPLICIT OPERATOR type OPEN_PARENS
2056 complex_parameters_modifiers_not_allowed = true;
2058 opt_parameter_list_no_mod CLOSE_PARENS
2060 complex_parameters_modifiers_not_allowed = false;
2062 Location loc = (Location) $2;
2063 current_local_parameters = (ParametersCompiled)$6;
2065 if (RootContext.Documentation != null) {
2066 tmpComment = Lexer.consume_doc_comment ();
2067 Lexer.doc_state = XmlCommentState.NotAllowed;
2070 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2072 | EXPLICIT OPERATOR type OPEN_PARENS
2074 complex_parameters_modifiers_not_allowed = true;
2076 opt_parameter_list_no_mod CLOSE_PARENS
2078 complex_parameters_modifiers_not_allowed = false;
2080 Location loc = (Location) $2;
2081 current_local_parameters = (ParametersCompiled)$6;
2083 if (RootContext.Documentation != null) {
2084 tmpComment = Lexer.consume_doc_comment ();
2085 Lexer.doc_state = XmlCommentState.NotAllowed;
2088 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2092 Error_SyntaxError (yyToken);
2093 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2097 Error_SyntaxError (yyToken);
2098 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2102 constructor_declaration
2103 : constructor_declarator
2106 Constructor c = (Constructor) $1;
2107 c.Block = (ToplevelBlock) $2;
2109 if (RootContext.Documentation != null)
2110 c.DocComment = ConsumeStoredComment ();
2112 current_container.AddConstructor (c);
2114 current_local_parameters = null;
2115 if (RootContext.Documentation != null)
2116 Lexer.doc_state = XmlCommentState.Allowed;
2120 constructor_declarator
2125 if (RootContext.Documentation != null) {
2126 tmpComment = Lexer.consume_doc_comment ();
2127 Lexer.doc_state = XmlCommentState.Allowed;
2129 arglist_allowed = true;
2131 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2133 arglist_allowed = false;
2134 current_local_parameters = (ParametersCompiled) $6;
2137 // start block here, so possible anonymous methods inside
2138 // constructor initializer can get correct parent block
2140 start_block (lexer.Location);
2142 opt_constructor_initializer
2144 LocatedToken lt = (LocatedToken) $3;
2145 int mods = (int) $2;
2146 ConstructorInitializer ci = (ConstructorInitializer) $9;
2148 Constructor c = new Constructor (current_class, lt.Value, mods,
2149 (Attributes) $1, current_local_parameters, ci, lt.Location);
2151 if (lt.Value != current_container.MemberName.Name) {
2152 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2153 } else if ((mods & Modifiers.STATIC) != 0) {
2154 if ((mods & Modifiers.Accessibility) != 0){
2155 Report.Error (515, c.Location,
2156 "`{0}': static constructor cannot have an access modifier",
2157 c.GetSignatureForError ());
2160 Report.Error (514, c.Location,
2161 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2162 c.GetSignatureForError ());
2173 | SEMICOLON { current_block = null; $$ = null; }
2176 opt_constructor_initializer
2178 | constructor_initializer
2181 constructor_initializer
2182 : COLON BASE OPEN_PARENS
2184 ++lexer.parsing_block;
2186 opt_argument_list CLOSE_PARENS
2188 --lexer.parsing_block;
2189 $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2);
2191 | COLON THIS OPEN_PARENS
2193 ++lexer.parsing_block;
2195 opt_argument_list CLOSE_PARENS
2197 --lexer.parsing_block;
2198 $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2);
2201 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2206 destructor_declaration
2207 : opt_attributes opt_modifiers TILDE
2209 if (RootContext.Documentation != null) {
2210 tmpComment = Lexer.consume_doc_comment ();
2211 Lexer.doc_state = XmlCommentState.NotAllowed;
2214 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2216 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2218 LocatedToken lt = (LocatedToken) $5;
2219 if (lt.Value != current_container.MemberName.Name){
2220 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2221 } else if (current_container.Kind != Kind.Class){
2222 Report.Error (575, lt.Location, "Only class types can contain destructor");
2224 Destructor d = new Destructor (current_class, (int) $2,
2225 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2226 if (RootContext.Documentation != null)
2227 d.DocComment = ConsumeStoredComment ();
2229 d.Block = (ToplevelBlock) $8;
2230 current_container.AddMethod (d);
2233 current_local_parameters = null;
2240 EVENT type variable_declarators SEMICOLON
2242 current_array_type = null;
2243 foreach (VariableMemberDeclaration var in (ArrayList) $5) {
2245 EventField e = new EventField (
2246 current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
2248 if (var.expression_or_array_initializer != null) {
2249 if (current_container.Kind == Kind.Interface) {
2250 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2253 e.Initializer = var.expression_or_array_initializer;
2256 if (var.MemberName.Left != null) {
2257 Report.Error (71, e.Location,
2258 "`{0}': An explicit interface implementation of an event must use property syntax",
2259 e.GetSignatureForError ());
2262 current_container.AddEvent (e);
2264 if (RootContext.Documentation != null) {
2265 e.DocComment = Lexer.consume_doc_comment ();
2266 Lexer.doc_state = XmlCommentState.Allowed;
2272 EVENT type member_declaration_name
2275 implicit_value_parameter_type = (FullNamedExpression) $4;
2276 current_local_parameters = new ParametersCompiled (
2277 new Parameter (implicit_value_parameter_type, "value",
2278 Parameter.Modifier.NONE, null, GetLocation ($3)));
2280 lexer.EventParsing = true;
2282 event_accessor_declarations
2284 lexer.EventParsing = false;
2288 MemberName name = (MemberName) $5;
2290 if (current_container.Kind == Kind.Interface) {
2291 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2295 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2296 current_container.Name, name.GetSignatureForError ());
2299 Accessors accessors = (Accessors) $8;
2301 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2302 // CS0073 is already reported, so no CS0065 here.
2305 Event e = new EventProperty (
2306 current_class, (FullNamedExpression) $4, (int) $2, name,
2307 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2308 if (RootContext.Documentation != null) {
2309 e.DocComment = Lexer.consume_doc_comment ();
2310 Lexer.doc_state = XmlCommentState.Allowed;
2313 current_container.AddEvent (e);
2314 implicit_value_parameter_type = null;
2317 current_local_parameters = null;
2319 | opt_attributes opt_modifiers EVENT type member_declaration_name error
2321 MemberName mn = (MemberName) $5;
2322 if (mn.Left != null)
2323 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2325 if (RootContext.Documentation != null)
2326 Lexer.doc_state = XmlCommentState.Allowed;
2328 Error_SyntaxError (yyToken);
2333 event_accessor_declarations
2334 : add_accessor_declaration remove_accessor_declaration
2336 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2338 | remove_accessor_declaration add_accessor_declaration
2340 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2341 accessors.declared_in_reverse = true;
2344 | add_accessor_declaration { $$ = null; }
2345 | remove_accessor_declaration { $$ = null; }
2348 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2354 add_accessor_declaration
2355 : opt_attributes ADD
2357 lexer.EventParsing = false;
2361 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2362 lexer.EventParsing = true;
2365 | opt_attributes ADD error {
2366 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2369 | opt_attributes modifiers ADD {
2370 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2375 remove_accessor_declaration
2376 : opt_attributes REMOVE
2378 lexer.EventParsing = false;
2382 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2383 lexer.EventParsing = true;
2385 | opt_attributes REMOVE error {
2386 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2389 | opt_attributes modifiers REMOVE {
2390 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2396 : opt_attributes opt_modifiers
2397 member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
2400 implicit_value_parameter_type = (FullNamedExpression) $3;
2401 indexer_parameters = (ParametersCompiled) $6;
2403 if (indexer_parameters.IsEmpty) {
2404 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2405 } else if (indexer_parameters.Count == 1) {
2406 Parameter p = indexer_parameters [0];
2407 if (p.HasDefaultValue)
2408 p.Warning_UselessOptionalParameter ();
2411 if (RootContext.Documentation != null) {
2412 tmpComment = Lexer.consume_doc_comment ();
2413 Lexer.doc_state = XmlCommentState.Allowed;
2416 lexer.PropertyParsing = true;
2417 parsing_indexer = true;
2420 accessor_declarations
2422 lexer.PropertyParsing = false;
2423 has_get = has_set = false;
2424 parsing_indexer = false;
2428 Accessors accessors = (Accessors) $10;
2429 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2430 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2431 bool order = accessors != null ? accessors.declared_in_reverse : false;
2433 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
2434 (MemberName)$4, (int) $2, (ParametersCompiled) $6, (Attributes) $1,
2435 get_block, set_block, order);
2437 if ($3 == TypeManager.system_void_expr)
2438 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2440 if (accessors == null)
2441 Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2443 if (current_container.Kind == Kind.Interface) {
2444 if (indexer.Get.Block != null)
2445 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2447 if (indexer.Set.Block != null)
2448 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2451 if (RootContext.Documentation != null)
2452 indexer.DocComment = ConsumeStoredComment ();
2454 current_container.AddIndexer (indexer);
2456 current_local_parameters = null;
2457 implicit_value_parameter_type = null;
2458 indexer_parameters = null;
2465 ENUM type_declaration_name
2467 if (RootContext.Documentation != null)
2468 enumTypeComment = Lexer.consume_doc_comment ();
2473 MemberName name = (MemberName) $4;
2474 if (name.IsGeneric) {
2475 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2478 name = MakeName (name);
2479 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2480 name, (Attributes) $1);
2482 if (RootContext.Documentation != null)
2483 e.DocComment = enumTypeComment;
2486 EnumMember em = null;
2487 foreach (VariableDeclaration ev in (ArrayList) $7) {
2488 em = new EnumMember (
2489 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2490 ev.OptAttributes, ev.Location);
2492 // if (RootContext.Documentation != null)
2493 em.DocComment = ev.DocComment;
2495 e.AddEnumMember (em);
2497 if (RootContext.EvalMode)
2498 undo.AddTypeContainer (current_container, e);
2500 current_container.AddTypeContainer (e);
2508 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2511 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2512 $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2513 $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2514 $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
2515 Enum.Error_1008 (GetLocation ($2));
2521 Error_TypeExpected (lexer.Location);
2528 if (RootContext.Documentation != null)
2529 Lexer.doc_state = XmlCommentState.Allowed;
2531 opt_enum_member_declarations
2533 // here will be evaluated after CLOSE_BLACE is consumed.
2534 if (RootContext.Documentation != null)
2535 Lexer.doc_state = XmlCommentState.Allowed;
2543 opt_enum_member_declarations
2544 : /* empty */ { $$ = new ArrayList (4); }
2545 | enum_member_declarations opt_comma { $$ = $1; }
2548 enum_member_declarations
2549 : enum_member_declaration
2551 ArrayList l = new ArrayList (4);
2556 | enum_member_declarations COMMA enum_member_declaration
2558 ArrayList l = (ArrayList) $1;
2566 enum_member_declaration
2567 : opt_attributes IDENTIFIER
2569 VariableDeclaration vd = new VariableDeclaration (
2570 (LocatedToken) $2, null, (Attributes) $1);
2572 if (RootContext.Documentation != null) {
2573 vd.DocComment = Lexer.consume_doc_comment ();
2574 Lexer.doc_state = XmlCommentState.Allowed;
2579 | opt_attributes IDENTIFIER
2581 ++lexer.parsing_block;
2582 if (RootContext.Documentation != null) {
2583 tmpComment = Lexer.consume_doc_comment ();
2584 Lexer.doc_state = XmlCommentState.NotAllowed;
2587 ASSIGN constant_expression
2589 --lexer.parsing_block;
2590 VariableDeclaration vd = new VariableDeclaration (
2591 (LocatedToken) $2, $5, (Attributes) $1);
2593 if (RootContext.Documentation != null)
2594 vd.DocComment = ConsumeStoredComment ();
2600 delegate_declaration
2604 member_type type_declaration_name
2605 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2607 MemberName name = MakeName ((MemberName) $5);
2608 ParametersCompiled p = (ParametersCompiled) $7;
2610 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2611 (int) $2, name, p, (Attributes) $1);
2613 if (RootContext.Documentation != null) {
2614 del.DocComment = Lexer.consume_doc_comment ();
2615 Lexer.doc_state = XmlCommentState.Allowed;
2618 current_container.AddDelegate (del);
2619 current_delegate = del;
2620 lexer.ConstraintsParsing = true;
2622 opt_type_parameter_constraints_clauses
2624 lexer.ConstraintsParsing = false;
2628 current_delegate.SetParameterInfo ((ArrayList) $10);
2629 $$ = current_delegate;
2631 current_delegate = null;
2642 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2643 Report.FeatureIsNotSupported (lexer.Location, "nullable types");
2644 else if (RootContext.Version < LanguageVersion.ISO_2)
2645 Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2651 namespace_or_type_name
2653 | qualified_alias_member IDENTIFIER opt_type_argument_list
2655 LocatedToken lt1 = (LocatedToken) $1;
2656 LocatedToken lt2 = (LocatedToken) $2;
2658 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2664 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2666 LocatedToken lt = (LocatedToken) $3;
2667 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2672 : IDENTIFIER opt_type_argument_list
2674 LocatedToken lt = (LocatedToken) $1;
2675 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2680 // Generics arguments (any type, without attributes)
2682 opt_type_argument_list
2683 : /* empty */ { $$ = null; }
2684 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2686 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2687 Report.FeatureIsNotSupported (lexer.Location, "generics");
2688 else if (RootContext.Version < LanguageVersion.ISO_2)
2689 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2693 | OP_GENERICS_LT error
2695 Error_TypeExpected (lexer.Location);
2696 $$ = new TypeArguments ();
2703 TypeArguments type_args = new TypeArguments ();
2704 type_args.Add ((FullNamedExpression) $1);
2707 | type_arguments COMMA type
2709 TypeArguments type_args = (TypeArguments) $1;
2710 type_args.Add ((FullNamedExpression) $3);
2716 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2718 type_declaration_name
2721 lexer.parsing_generic_declaration = true;
2723 opt_type_parameter_list
2725 lexer.parsing_generic_declaration = false;
2726 LocatedToken lt = (LocatedToken) $1;
2727 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2731 member_declaration_name
2732 : method_declaration_name
2734 MemberName mn = (MemberName)$1;
2735 if (mn.TypeArguments != null)
2736 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2737 mn.GetSignatureForError ()));
2741 method_declaration_name
2742 : type_declaration_name
2743 | explicit_interface IDENTIFIER opt_type_parameter_list
2745 lexer.parsing_generic_declaration = false;
2746 LocatedToken lt = (LocatedToken) $2;
2747 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2751 indexer_declaration_name
2754 lexer.parsing_generic_declaration = false;
2755 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2757 | explicit_interface THIS
2759 lexer.parsing_generic_declaration = false;
2760 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2765 : IDENTIFIER opt_type_argument_list DOT
2767 LocatedToken lt = (LocatedToken) $1;
2768 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2770 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2772 LocatedToken lt1 = (LocatedToken) $1;
2773 LocatedToken lt2 = (LocatedToken) $2;
2775 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2777 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2779 LocatedToken lt = (LocatedToken) $2;
2780 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2784 opt_type_parameter_list
2785 : /* empty */ { $$ = null; }
2786 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2788 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2789 Report.FeatureIsNotSupported (lexer.Location, "generics");
2790 else if (RootContext.Version < LanguageVersion.ISO_2)
2791 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2800 TypeArguments type_args = new TypeArguments ();
2801 type_args.Add ((FullNamedExpression)$1);
2804 | type_parameters COMMA type_parameter
2806 TypeArguments type_args = (TypeArguments) $1;
2807 type_args.Add ((FullNamedExpression)$3);
2813 : opt_attributes opt_type_parameter_variance IDENTIFIER
2815 LocatedToken lt = (LocatedToken)$3;
2816 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2820 if (GetTokenName (yyToken) == "type")
2821 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2823 Error_SyntaxError (yyToken);
2825 $$ = new TypeParameterName ("", null, lexer.Location);
2830 // All types where void is allowed
2833 : type_expression_or_array
2836 $$ = TypeManager.system_void_expr;
2843 lexer.parsing_generic_declaration = true;
2848 // A type which does not allow `void' to be used
2851 : type_expression_or_array
2854 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2855 $$ = TypeManager.system_void_expr;
2863 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2864 $$ = TypeManager.system_void_expr;
2868 type_expression_or_array
2870 | type_expression rank_specifiers
2872 string rank_specifiers = (string) $2;
2873 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2878 : namespace_or_type_name opt_nullable
2880 MemberName name = (MemberName) $1;
2883 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2885 if (name.Left == null && name.Name == "var" && RootContext.Version > LanguageVersion.ISO_2)
2886 $$ = current_array_type = new VarExpr (name.Location);
2888 $$ = name.GetTypeExpression ();
2891 | builtin_types opt_nullable
2894 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2896 | type_expression STAR
2899 // Note that here only unmanaged types are allowed but we
2900 // can't perform checks during this phase - we do it during
2901 // semantic analysis.
2903 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2907 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2914 ArrayList types = new ArrayList (2);
2918 | type_list COMMA base_type_name
2920 ArrayList types = (ArrayList) $1;
2929 if ($1 is ComposedCast)
2930 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2935 Error_TypeExpected (lexer.Location);
2940 * replaces all the productions for isolating the various
2941 * simple types, but we need this to reuse it easily in variable_type
2944 : OBJECT { $$ = TypeManager.system_object_expr; }
2945 | STRING { $$ = TypeManager.system_string_expr; }
2946 | BOOL { $$ = TypeManager.system_boolean_expr; }
2947 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2948 | FLOAT { $$ = TypeManager.system_single_expr; }
2949 | DOUBLE { $$ = TypeManager.system_double_expr; }
2954 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2955 | BYTE { $$ = TypeManager.system_byte_expr; }
2956 | SHORT { $$ = TypeManager.system_int16_expr; }
2957 | USHORT { $$ = TypeManager.system_uint16_expr; }
2958 | INT { $$ = TypeManager.system_int32_expr; }
2959 | UINT { $$ = TypeManager.system_uint32_expr; }
2960 | LONG { $$ = TypeManager.system_int64_expr; }
2961 | ULONG { $$ = TypeManager.system_uint64_expr; }
2962 | CHAR { $$ = TypeManager.system_char_expr; }
2969 $$ = TypeManager.system_void_expr;
2974 // Expressions, section 7.5
2979 : primary_expression_no_array_creation
2980 | array_creation_expression
2983 primary_expression_no_array_creation
2985 | IDENTIFIER opt_type_argument_list
2987 LocatedToken lt = (LocatedToken) $1;
2988 $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
2990 | IDENTIFIER GENERATE_COMPLETION {
2991 LocatedToken lt = (LocatedToken) $1;
2992 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
2994 | parenthesized_expression
2995 | default_value_expression
2997 | invocation_expression
3001 | post_increment_expression
3002 | post_decrement_expression
3003 | object_or_delegate_creation_expression
3004 | anonymous_type_expression
3007 | checked_expression
3008 | unchecked_expression
3009 | pointer_member_access
3010 | anonymous_method_expression
3017 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3018 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
3019 | NULL { $$ = new NullLiteral (lexer.Location); }
3023 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3024 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3025 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3030 object v = lexer.Value;
3033 $$ = new IntLiteral ((int) v, lexer.Location);
3034 } else if (v is uint)
3035 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3037 $$ = new LongLiteral ((Int64) v, lexer.Location);
3038 else if (v is ulong)
3039 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3041 Console.WriteLine ("OOPS. Unexpected result from scanner");
3046 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3047 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3052 // Here is the trick, tokenizer may think that parens is a special but
3053 // parser is interested in open parens only, so we merge them.
3054 // Consider: if (a)foo ();
3059 | OPEN_PARENS_LAMBDA
3062 parenthesized_expression
3063 : OPEN_PARENS expression CLOSE_PARENS
3065 $$ = new ParenthesizedExpression ((Expression) $2);
3067 | OPEN_PARENS expression COMPLETE_COMPLETION
3069 $$ = new ParenthesizedExpression ((Expression) $2);
3074 : primary_expression DOT IDENTIFIER opt_type_argument_list
3076 LocatedToken lt = (LocatedToken) $3;
3077 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3079 | predefined_type DOT IDENTIFIER opt_type_argument_list
3081 LocatedToken lt = (LocatedToken) $3;
3082 // TODO: Location is wrong as some predefined types doesn't hold a location
3083 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3085 | qualified_alias_member IDENTIFIER opt_type_argument_list
3087 LocatedToken lt1 = (LocatedToken) $1;
3088 LocatedToken lt2 = (LocatedToken) $2;
3090 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3092 | primary_expression DOT GENERATE_COMPLETION {
3093 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3095 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3096 LocatedToken lt = (LocatedToken) $3;
3097 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3099 | predefined_type DOT GENERATE_COMPLETION
3101 // TODO: Location is wrong as some predefined types doesn't hold a location
3102 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3104 | predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
3105 LocatedToken lt = (LocatedToken) $3;
3106 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3110 invocation_expression
3111 : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
3113 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3117 opt_object_or_collection_initializer
3118 : /* empty */ { $$ = null; }
3119 | object_or_collection_initializer
3122 object_or_collection_initializer
3123 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3126 $$ = CollectionOrObjectInitializers.Empty;
3128 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3130 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3132 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3136 opt_member_initializer_list
3137 : /* empty */ { $$ = null; }
3138 | member_initializer_list
3144 member_initializer_list
3145 : member_initializer
3147 ArrayList a = new ArrayList ();
3151 | member_initializer_list COMMA member_initializer
3153 ArrayList a = (ArrayList)$1;
3160 : IDENTIFIER ASSIGN initializer_value
3162 LocatedToken lt = $1 as LocatedToken;
3163 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3165 | GENERATE_COMPLETION
3167 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3169 | non_assignment_expression opt_COMPLETE_COMPLETION {
3170 CompletionSimpleName csn = $1 as CompletionSimpleName;
3172 $$ = new CollectionElementInitializer ((Expression)$1);
3174 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3176 | OPEN_BRACE expression_list CLOSE_BRACE
3178 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3180 | OPEN_BRACE CLOSE_BRACE
3182 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3188 | object_or_collection_initializer
3192 : /* empty */ { $$ = null; }
3199 ArrayList list = new ArrayList (4);
3203 | argument_list COMMA argument
3205 ArrayList list = (ArrayList) $1;
3206 if (!($3 is NamedArgument) && list [list.Count - 1] is NamedArgument)
3207 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3212 | argument_list COMMA
3214 Report.Error (839, GetLocation ($2), "An argument is missing");
3219 Report.Error (839, GetLocation ($1), "An argument is missing");
3227 $$ = new Argument ((Expression) $1);
3229 | non_simple_argument
3234 : REF variable_reference
3236 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3238 | OUT variable_reference
3240 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3242 | ARGLIST open_parens_any argument_list CLOSE_PARENS
3244 ArrayList list = (ArrayList) $3;
3245 Argument[] args = new Argument [list.Count];
3246 list.CopyTo (args, 0);
3248 $$ = new Argument (new Arglist (args, (Location) $1));
3250 | ARGLIST open_parens_any CLOSE_PARENS
3252 $$ = new Argument (new Arglist ((Location) $1));
3256 $$ = new Argument (new ArglistAccess ((Location) $1));
3265 : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET
3267 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3269 | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3271 // LAMESPEC: Not allowed according to specification
3272 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3274 | primary_expression_no_array_creation rank_specifiers
3276 // So the super-trick is that primary_expression
3277 // can only be either a SimpleName or a MemberAccess.
3278 // The MemberAccess case arises when you have a fully qualified type-name like :
3280 // SimpleName is when you have
3283 Expression expr = (Expression) $1;
3284 if (expr is ComposedCast){
3285 $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3286 } else if (expr is ATypeNameExpression){
3288 // So we extract the string corresponding to the SimpleName
3291 $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3293 Error_ExpectingTypeName (expr);
3294 $$ = TypeManager.system_object_expr;
3297 current_array_type = (FullNamedExpression)$$;
3304 ArrayList list = new ArrayList (4);
3308 | expression_list COMMA expression
3310 ArrayList list = (ArrayList) $1;
3319 $$ = new This (current_block, (Location) $1);
3324 : BASE DOT IDENTIFIER opt_type_argument_list
3326 LocatedToken lt = (LocatedToken) $3;
3327 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3329 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3331 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3334 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3339 post_increment_expression
3340 : primary_expression OP_INC
3342 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
3346 post_decrement_expression
3347 : primary_expression OP_DEC
3349 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
3353 object_or_delegate_creation_expression
3354 : new_expr_start open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3357 if (RootContext.Version <= LanguageVersion.ISO_2)
3358 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3360 $$ = new NewInitialize ((Expression) $1, (ArrayList) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1));
3363 $$ = new New ((Expression) $1, (ArrayList) $3, GetLocation ($1));
3365 | new_expr_start object_or_collection_initializer
3367 if (RootContext.Version <= LanguageVersion.ISO_2)
3368 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3370 $$ = new NewInitialize ((Expression) $1, null, (CollectionOrObjectInitializers) $2, GetLocation ($1));
3374 array_creation_expression
3375 : new_expr_start OPEN_BRACKET expression_list CLOSE_BRACKET
3376 opt_rank_specifier // shift/reduce on OPEN_BRACE
3377 opt_array_initializer
3379 $$ = new ArrayCreation ((FullNamedExpression) $1, (ArrayList) $3, (string) $5, (ArrayList) $6, GetLocation ($1));
3381 | new_expr_start rank_specifiers opt_array_initializer
3384 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3386 $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayList) $3, GetLocation ($1));
3388 | NEW rank_specifiers array_initializer
3390 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1));
3392 | new_expr_start error
3394 Report.Error (1526, GetLocation ($1), "A new expression requires () or [] after type");
3402 ++lexer.parsing_type;
3406 --lexer.parsing_type;
3411 anonymous_type_expression
3412 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3414 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3415 Report.FeatureIsNotSupported (lexer.Location, "anonymous types");
3416 else if (RootContext.Version <= LanguageVersion.ISO_2)
3417 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3419 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3423 anonymous_type_parameters_opt_comma
3424 : anonymous_type_parameters_opt
3425 | anonymous_type_parameters COMMA
3428 anonymous_type_parameters_opt
3430 | anonymous_type_parameters
3433 anonymous_type_parameters
3434 : anonymous_type_parameter
3436 ArrayList a = new ArrayList (4);
3440 | anonymous_type_parameters COMMA anonymous_type_parameter
3442 ArrayList a = (ArrayList) $1;
3448 anonymous_type_parameter
3449 : IDENTIFIER ASSIGN variable_initializer
3451 LocatedToken lt = (LocatedToken)$1;
3452 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3456 LocatedToken lt = (LocatedToken)$1;
3457 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3458 lt.Value, lt.Location);
3460 | BASE DOT IDENTIFIER opt_type_argument_list
3462 LocatedToken lt = (LocatedToken) $3;
3463 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3464 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3468 MemberAccess ma = (MemberAccess) $1;
3469 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3473 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3474 "Anonymous type members must be a member assignment, simple name or member access expression");
3489 opt_rank_specifier_or_nullable
3497 | opt_nullable rank_specifiers
3500 $$ = "?" + (string) $2;
3508 | rank_specifier rank_specifiers
3510 $$ = (string) $2 + (string) $1;
3515 : OPEN_BRACKET CLOSE_BRACKET
3519 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3521 $$ = "[" + (string) $2 + "]";
3523 | OPEN_BRACKET error CLOSE_BRACKET
3525 ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1));
3535 | dim_separators COMMA
3537 $$ = (string) $1 + ",";
3541 opt_array_initializer
3553 : OPEN_BRACE CLOSE_BRACE
3555 ArrayList list = new ArrayList (4);
3558 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3560 $$ = (ArrayList) $2;
3564 variable_initializer_list
3565 : variable_initializer
3567 ArrayList list = new ArrayList (4);
3571 | variable_initializer_list COMMA variable_initializer
3573 ArrayList list = (ArrayList) $1;
3579 Error_SyntaxError (yyToken);
3580 $$ = new ArrayList ();
3587 pushed_current_array_type = current_array_type;
3588 lexer.TypeOfParsing = true;
3590 open_parens_any typeof_type_expression CLOSE_PARENS
3592 lexer.TypeOfParsing = false;
3593 Expression type = (Expression)$4;
3594 if (type == TypeManager.system_void_expr)
3595 $$ = new TypeOfVoid ((Location) $1);
3597 $$ = new TypeOf (type, (Location) $1);
3598 current_array_type = pushed_current_array_type;
3602 typeof_type_expression
3607 Error_TypeExpected (lexer.Location);
3613 : IDENTIFIER generic_dimension
3615 LocatedToken lt = (LocatedToken) $1;
3617 $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
3619 | qualified_alias_member IDENTIFIER generic_dimension
3621 LocatedToken lt1 = (LocatedToken) $1;
3622 LocatedToken lt2 = (LocatedToken) $2;
3624 $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
3626 | unbound_type_name DOT IDENTIFIER
3628 LocatedToken lt = (LocatedToken) $3;
3630 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3632 | unbound_type_name DOT IDENTIFIER generic_dimension
3634 LocatedToken lt = (LocatedToken) $3;
3636 $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3638 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3640 LocatedToken lt = (LocatedToken) $3;
3641 MemberName name = (MemberName) $1;
3643 $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3650 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3651 Report.FeatureIsNotSupported (lexer.Location, "generics");
3652 else if (RootContext.Version < LanguageVersion.ISO_2)
3653 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3659 qualified_alias_member
3660 : IDENTIFIER DOUBLE_COLON
3662 LocatedToken lt = (LocatedToken) $1;
3663 if (RootContext.Version == LanguageVersion.ISO_1)
3664 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3671 : SIZEOF open_parens_any type CLOSE_PARENS {
3672 $$ = new SizeOf ((Expression) $3, (Location) $1);
3677 : CHECKED open_parens_any expression CLOSE_PARENS
3679 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3683 unchecked_expression
3684 : UNCHECKED open_parens_any expression CLOSE_PARENS
3686 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3690 pointer_member_access
3691 : primary_expression OP_PTR IDENTIFIER
3694 LocatedToken lt = (LocatedToken) $3;
3696 deref = new Indirection ((Expression) $1, lt.Location);
3697 $$ = new MemberAccess (deref, lt.Value);
3701 anonymous_method_expression
3702 : DELEGATE opt_anonymous_method_signature
3704 start_anonymous (false, (ParametersCompiled) $2, (Location) $1);
3708 $$ = end_anonymous ((ToplevelBlock) $4);
3712 opt_anonymous_method_signature
3715 $$ = ParametersCompiled.Undefined;
3717 | anonymous_method_signature
3720 anonymous_method_signature
3723 complex_parameters_modifiers_not_allowed = true;
3725 opt_formal_parameter_list CLOSE_PARENS
3727 complex_parameters_modifiers_not_allowed = false;
3732 default_value_expression
3733 : DEFAULT open_parens_any type CLOSE_PARENS
3735 if (RootContext.Version < LanguageVersion.ISO_2)
3736 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3738 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3743 : primary_expression
3744 | BANG prefixed_unary_expression
3746 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
3748 | TILDE prefixed_unary_expression
3750 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
3756 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3758 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3760 | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
3762 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3767 // The idea to split this out is from Rhys' grammar
3768 // to solve the problem with casts.
3770 prefixed_unary_expression
3772 | PLUS prefixed_unary_expression
3774 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
3776 | MINUS prefixed_unary_expression
3778 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
3780 | OP_INC prefixed_unary_expression
3782 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
3784 | OP_DEC prefixed_unary_expression
3786 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
3788 | STAR prefixed_unary_expression
3790 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3792 | BITWISE_AND prefixed_unary_expression
3794 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
3798 multiplicative_expression
3799 : prefixed_unary_expression
3800 | multiplicative_expression STAR prefixed_unary_expression
3802 $$ = new Binary (Binary.Operator.Multiply,
3803 (Expression) $1, (Expression) $3);
3805 | multiplicative_expression DIV prefixed_unary_expression
3807 $$ = new Binary (Binary.Operator.Division,
3808 (Expression) $1, (Expression) $3);
3810 | multiplicative_expression PERCENT prefixed_unary_expression
3812 $$ = new Binary (Binary.Operator.Modulus,
3813 (Expression) $1, (Expression) $3);
3818 : multiplicative_expression
3819 | additive_expression PLUS multiplicative_expression
3821 $$ = new Binary (Binary.Operator.Addition,
3822 (Expression) $1, (Expression) $3);
3824 | additive_expression MINUS multiplicative_expression
3826 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3828 | parenthesized_expression MINUS multiplicative_expression
3830 // Shift/Reduce conflict
3831 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3833 | additive_expression AS type
3835 $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
3837 | additive_expression IS type
3839 $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
3844 : additive_expression
3845 | shift_expression OP_SHIFT_LEFT additive_expression
3847 $$ = new Binary (Binary.Operator.LeftShift,
3848 (Expression) $1, (Expression) $3);
3850 | shift_expression OP_SHIFT_RIGHT additive_expression
3852 $$ = new Binary (Binary.Operator.RightShift,
3853 (Expression) $1, (Expression) $3);
3857 relational_expression
3859 | relational_expression OP_LT shift_expression
3861 $$ = new Binary (Binary.Operator.LessThan,
3862 (Expression) $1, (Expression) $3);
3864 | relational_expression OP_GT shift_expression
3866 $$ = new Binary (Binary.Operator.GreaterThan,
3867 (Expression) $1, (Expression) $3);
3869 | relational_expression OP_LE shift_expression
3871 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3872 (Expression) $1, (Expression) $3);
3874 | relational_expression OP_GE shift_expression
3876 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3877 (Expression) $1, (Expression) $3);
3882 : relational_expression
3883 | equality_expression OP_EQ relational_expression
3885 $$ = new Binary (Binary.Operator.Equality,
3886 (Expression) $1, (Expression) $3);
3888 | equality_expression OP_NE relational_expression
3890 $$ = new Binary (Binary.Operator.Inequality,
3891 (Expression) $1, (Expression) $3);
3896 : equality_expression
3897 | and_expression BITWISE_AND equality_expression
3899 $$ = new Binary (Binary.Operator.BitwiseAnd,
3900 (Expression) $1, (Expression) $3);
3904 exclusive_or_expression
3906 | exclusive_or_expression CARRET and_expression
3908 $$ = new Binary (Binary.Operator.ExclusiveOr,
3909 (Expression) $1, (Expression) $3);
3913 inclusive_or_expression
3914 : exclusive_or_expression
3915 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3917 $$ = new Binary (Binary.Operator.BitwiseOr,
3918 (Expression) $1, (Expression) $3);
3922 conditional_and_expression
3923 : inclusive_or_expression
3924 | conditional_and_expression OP_AND inclusive_or_expression
3926 $$ = new Binary (Binary.Operator.LogicalAnd,
3927 (Expression) $1, (Expression) $3);
3931 conditional_or_expression
3932 : conditional_and_expression
3933 | conditional_or_expression OP_OR conditional_and_expression
3935 $$ = new Binary (Binary.Operator.LogicalOr,
3936 (Expression) $1, (Expression) $3);
3940 null_coalescing_expression
3941 : conditional_or_expression
3942 | conditional_or_expression OP_COALESCING null_coalescing_expression
3944 if (RootContext.Version < LanguageVersion.ISO_2)
3945 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3947 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
3951 conditional_expression
3952 : null_coalescing_expression
3953 | null_coalescing_expression INTERR expression COLON expression
3955 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3959 assignment_expression
3960 : prefixed_unary_expression ASSIGN expression
3962 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
3964 | prefixed_unary_expression OP_MULT_ASSIGN expression
3966 $$ = new CompoundAssign (
3967 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3969 | prefixed_unary_expression OP_DIV_ASSIGN expression
3971 $$ = new CompoundAssign (
3972 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3974 | prefixed_unary_expression OP_MOD_ASSIGN expression
3976 $$ = new CompoundAssign (
3977 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3979 | prefixed_unary_expression OP_ADD_ASSIGN expression
3981 $$ = new CompoundAssign (
3982 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3984 | prefixed_unary_expression OP_SUB_ASSIGN expression
3986 $$ = new CompoundAssign (
3987 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3989 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3991 $$ = new CompoundAssign (
3992 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3994 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3996 $$ = new CompoundAssign (
3997 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3999 | prefixed_unary_expression OP_AND_ASSIGN expression
4001 $$ = new CompoundAssign (
4002 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4004 | prefixed_unary_expression OP_OR_ASSIGN expression
4006 $$ = new CompoundAssign (
4007 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4009 | prefixed_unary_expression OP_XOR_ASSIGN expression
4011 $$ = new CompoundAssign (
4012 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4016 lambda_parameter_list
4019 ArrayList pars = new ArrayList (4);
4024 | lambda_parameter_list COMMA lambda_parameter
4026 ArrayList pars = (ArrayList) $1;
4027 Parameter p = (Parameter)$3;
4028 if (pars[0].GetType () != p.GetType ()) {
4029 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4038 : parameter_modifier type IDENTIFIER
4040 LocatedToken lt = (LocatedToken) $3;
4042 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4046 LocatedToken lt = (LocatedToken) $2;
4048 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4052 LocatedToken lt = (LocatedToken) $1;
4053 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4057 opt_lambda_parameter_list
4058 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4059 | lambda_parameter_list {
4060 ArrayList pars_list = (ArrayList) $1;
4061 $$ = new ParametersCompiled ((Parameter[])pars_list.ToArray (typeof (Parameter)));
4065 lambda_expression_body
4067 start_block (lexer.Location);
4071 Block b = end_block (lexer.Location);
4072 b.AddStatement (new ContextualReturn ((Expression) $2));
4083 LocatedToken lt = (LocatedToken) $1;
4084 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4085 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
4087 lambda_expression_body
4089 $$ = end_anonymous ((ToplevelBlock) $4);
4091 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4093 start_anonymous (true, (ParametersCompiled) $2, GetLocation ($1));
4095 lambda_expression_body
4097 $$ = end_anonymous ((ToplevelBlock) $6);
4102 : assignment_expression
4103 | non_assignment_expression
4106 non_assignment_expression
4107 : conditional_expression
4129 lexer.ConstraintsParsing = true;
4131 type_declaration_name
4133 MemberName name = MakeName ((MemberName) $6);
4134 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4137 opt_type_parameter_constraints_clauses
4139 lexer.ConstraintsParsing = false;
4141 current_class.SetParameterInfo ((ArrayList) $9);
4143 if (RootContext.Documentation != null) {
4144 current_container.DocComment = Lexer.consume_doc_comment ();
4145 Lexer.doc_state = XmlCommentState.Allowed;
4150 --lexer.parsing_declaration;
4151 if (RootContext.Documentation != null)
4152 Lexer.doc_state = XmlCommentState.Allowed;
4156 $$ = pop_current_class ();
4164 { $$ = $1; } // location
4168 : /* empty */ { $$ = (int) 0; }
4174 | modifiers modifier
4179 if ((m1 & m2) != 0) {
4180 Location l = lexer.Location;
4181 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4183 $$ = (int) (m1 | m2);
4191 if (current_container == RootContext.ToplevelTypes)
4192 Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
4194 | PUBLIC { $$ = Modifiers.PUBLIC; }
4195 | PROTECTED { $$ = Modifiers.PROTECTED; }
4196 | INTERNAL { $$ = Modifiers.INTERNAL; }
4197 | PRIVATE { $$ = Modifiers.PRIVATE; }
4198 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4199 | SEALED { $$ = Modifiers.SEALED; }
4200 | STATIC { $$ = Modifiers.STATIC; }
4201 | READONLY { $$ = Modifiers.READONLY; }
4202 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4203 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4204 | EXTERN { $$ = Modifiers.EXTERN; }
4205 | VOLATILE { $$ = Modifiers.VOLATILE; }
4206 | UNSAFE { $$ = Modifiers.UNSAFE; }
4215 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4218 opt_type_parameter_constraints_clauses
4219 : /* empty */ { $$ = null; }
4220 | type_parameter_constraints_clauses
4224 type_parameter_constraints_clauses
4225 : type_parameter_constraints_clause {
4226 ArrayList constraints = new ArrayList (1);
4227 constraints.Add ($1);
4230 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4231 ArrayList constraints = (ArrayList) $1;
4232 Constraints new_constraint = (Constraints)$2;
4234 foreach (Constraints c in constraints) {
4235 if (new_constraint.TypeParameter == c.TypeParameter) {
4236 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4237 new_constraint.TypeParameter);
4241 constraints.Add (new_constraint);
4246 type_parameter_constraints_clause
4247 : WHERE IDENTIFIER COLON type_parameter_constraints {
4248 LocatedToken lt = (LocatedToken) $2;
4249 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4253 type_parameter_constraints
4254 : type_parameter_constraint {
4255 ArrayList constraints = new ArrayList (1);
4256 constraints.Add ($1);
4259 | type_parameter_constraints COMMA type_parameter_constraint {
4260 ArrayList constraints = (ArrayList) $1;
4262 constraints.Add ($3);
4267 type_parameter_constraint
4269 | NEW OPEN_PARENS CLOSE_PARENS {
4270 $$ = SpecialConstraint.Constructor;
4273 $$ = SpecialConstraint.ReferenceType;
4276 $$ = SpecialConstraint.ValueType;
4280 opt_type_parameter_variance
4285 | type_parameter_variance
4287 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
4288 Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
4289 else if (RootContext.Version <= LanguageVersion.V_3)
4290 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4296 type_parameter_variance
4299 $$ = Variance.Covariant;
4303 $$ = Variance.Contravariant;
4312 // A block is "contained" on the following places:
4314 // property_declaration as part of the accessor body (get/set)
4315 // operator_declaration
4316 // constructor_declaration
4317 // destructor_declaration
4318 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4323 ++lexer.parsing_block;
4324 start_block ((Location) $1);
4326 opt_statement_list block_end
4335 --lexer.parsing_block;
4336 $$ = end_block ((Location) $1);
4338 | COMPLETE_COMPLETION
4340 --lexer.parsing_block;
4341 $$ = end_block (lexer.Location);
4349 ++lexer.parsing_block;
4350 current_block.StartLocation = GetLocation ($1);
4352 opt_statement_list CLOSE_BRACE
4354 --lexer.parsing_block;
4355 $$ = end_block ((Location) $4);
4366 | statement_list statement
4370 : declaration_statement
4372 if ($1 != null && (Block) $1 != current_block){
4373 current_block.AddStatement ((Statement) $1);
4374 current_block = (Block) $1;
4377 | valid_declaration_statement
4379 current_block.AddStatement ((Statement) $1);
4385 // The interactive_statement and its derivatives are only
4386 // used to provide a special version of `expression_statement'
4387 // that has a side effect of assigning the expression to
4390 interactive_statement_list
4391 : interactive_statement
4392 | interactive_statement_list interactive_statement
4395 interactive_statement
4396 : declaration_statement
4398 if ($1 != null && (Block) $1 != current_block){
4399 current_block.AddStatement ((Statement) $1);
4400 current_block = (Block) $1;
4403 | interactive_valid_declaration_statement
4405 current_block.AddStatement ((Statement) $1);
4410 valid_declaration_statement
4413 | expression_statement
4414 | selection_statement
4415 | iteration_statement
4419 | unchecked_statement
4426 interactive_valid_declaration_statement
4429 | interactive_expression_statement
4430 | selection_statement
4431 | iteration_statement
4435 | unchecked_statement
4443 : valid_declaration_statement
4444 | declaration_statement
4446 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4451 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4459 $$ = EmptyStatement.Value;
4466 LocatedToken lt = (LocatedToken) $1;
4467 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4469 if (current_block.AddLabel (labeled))
4470 current_block.AddStatement (labeled);
4475 declaration_statement
4476 : local_variable_declaration SEMICOLON
4478 current_array_type = null;
4480 DictionaryEntry de = (DictionaryEntry) $1;
4481 Expression e = (Expression) de.Key;
4483 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4487 | local_constant_declaration SEMICOLON
4489 current_array_type = null;
4491 DictionaryEntry de = (DictionaryEntry) $1;
4493 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4499 * The following is from Rhys' grammar:
4500 * > Types in local variable declarations must be recognized as
4501 * > expressions to prevent reduce/reduce errors in the grammar.
4502 * > The expressions are converted into types during semantic analysis.
4505 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4507 // FIXME: Do something smart here regarding the composition of the type.
4509 // Ok, the above "primary_expression" is there to get rid of
4510 // both reduce/reduce and shift/reduces in the grammar, it should
4511 // really just be "type_name". If you use type_name, a reduce/reduce
4512 // creeps up. If you use namespace_or_type_name (which is all we need
4513 // really) two shift/reduces appear.
4516 // So the super-trick is that primary_expression
4517 // can only be either a SimpleName or a MemberAccess.
4518 // The MemberAccess case arises when you have a fully qualified type-name like :
4520 // SimpleName is when you have
4523 Expression expr = (Expression) $1;
4524 string rank_or_nullable = (string) $2;
4526 if (expr is ComposedCast){
4527 $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4528 } else if (expr is ATypeNameExpression){
4530 // So we extract the string corresponding to the SimpleName
4533 if (rank_or_nullable.Length == 0) {
4534 SimpleName sn = expr as SimpleName;
4535 if (sn != null && sn.Name == "var" && RootContext.Version > LanguageVersion.ISO_2)
4536 $$ = current_array_type = new VarExpr (sn.Location);
4540 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4543 Error_ExpectingTypeName (expr);
4544 $$ = TypeManager.system_object_expr;
4547 | builtin_types opt_rank_specifier_or_nullable
4549 if ((string) $2 == "")
4552 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4554 | VOID opt_rank_specifier
4556 Expression.Error_VoidInvalidInTheContext (lexer.Location);
4557 $$ = TypeManager.system_void_expr;
4561 local_variable_pointer_type
4562 : primary_expression_no_array_creation STAR
4564 ATypeNameExpression expr = $1 as ATypeNameExpression;
4567 $$ = new ComposedCast (expr, "*");
4569 Error_ExpectingTypeName ((Expression)$1);
4573 | builtin_types STAR
4575 $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
4579 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4581 | local_variable_pointer_type STAR
4583 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4589 | local_variable_pointer_type opt_rank_specifier
4592 string rank = (string)$2;
4597 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
4604 local_variable_declaration
4605 : local_variable_type local_variable_declarators
4608 VarExpr ve = $1 as VarExpr;
4610 ve.VariableInitializer = (ArrayList)$2;
4612 $$ = new DictionaryEntry ($1, $2);
4618 local_constant_declaration
4619 : CONST variable_type constant_declarators
4622 $$ = new DictionaryEntry ($2, $3);
4628 expression_statement
4629 : statement_expression SEMICOLON { $$ = $1; }
4630 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4633 interactive_expression_statement
4634 : interactive_statement_expression SEMICOLON { $$ = $1; }
4635 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4639 // We have to do the wrapping here and not in the case above,
4640 // because statement_expression is used for example in for_statement
4642 statement_expression
4645 ExpressionStatement s = $1 as ExpressionStatement;
4647 ((Expression) $1).Error_InvalidExpressionStatement ();
4648 s = EmptyExpressionStatement.Instance;
4651 $$ = new StatementExpression (s);
4655 Error_SyntaxError (yyToken);
4660 interactive_statement_expression
4663 Expression expr = (Expression) $1;
4664 ExpressionStatement s;
4666 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4667 $$ = new StatementExpression (s);
4671 Error_SyntaxError (yyToken);
4682 : IF open_parens_any boolean_expression CLOSE_PARENS
4685 Location l = (Location) $1;
4687 $$ = new If ((Expression) $3, (Statement) $5, l);
4689 // FIXME: location for warning should be loc property of $5.
4690 if ($5 == EmptyStatement.Value)
4691 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4694 | IF open_parens_any boolean_expression CLOSE_PARENS
4695 embedded_statement ELSE embedded_statement
4697 Location l = (Location) $1;
4699 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4701 // FIXME: location for warning should be loc property of $5 and $7.
4702 if ($5 == EmptyStatement.Value)
4703 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4704 if ($7 == EmptyStatement.Value)
4705 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4710 : SWITCH open_parens_any
4712 if (switch_stack == null)
4713 switch_stack = new Stack (2);
4714 switch_stack.Push (current_block);
4716 expression CLOSE_PARENS
4719 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4720 current_block = (Block) switch_stack.Pop ();
4736 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4737 $$ = new ArrayList ();
4745 ArrayList sections = new ArrayList (4);
4750 | switch_sections switch_section
4752 ArrayList sections = (ArrayList) $1;
4762 current_block = current_block.CreateSwitchBlock (lexer.Location);
4766 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4773 ArrayList labels = new ArrayList (4);
4778 | switch_labels switch_label
4780 ArrayList labels = (ArrayList) ($1);
4788 : CASE constant_expression COLON
4790 $$ = new SwitchLabel ((Expression) $2, (Location) $1);
4794 $$ = new SwitchLabel (null, (Location) $1);
4806 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
4808 Location l = (Location) $1;
4809 $$ = new While ((Expression) $3, (Statement) $5, l);
4814 : DO embedded_statement
4815 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
4817 Location l = (Location) $1;
4819 $$ = new Do ((Statement) $2, (Expression) $5, l);
4824 : FOR open_parens_any opt_for_initializer SEMICOLON
4826 Location l = lexer.Location;
4828 Block assign_block = current_block;
4830 if ($3 is DictionaryEntry){
4831 DictionaryEntry de = (DictionaryEntry) $3;
4833 Expression type = (Expression) de.Key;
4834 ArrayList var_declarators = (ArrayList) de.Value;
4836 foreach (VariableDeclaration decl in var_declarators){
4840 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4844 Expression expr = decl.expression_or_array_initializer;
4846 LocalVariableReference var;
4847 var = new LocalVariableReference (assign_block, decl.identifier, l);
4850 Assign a = new SimpleAssign (var, expr, decl.Location);
4852 assign_block.AddStatement (new StatementExpression (a));
4856 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4857 // This can be referred to as $5 below.
4863 opt_for_condition SEMICOLON
4864 opt_for_iterator CLOSE_PARENS
4867 Location l = (Location) $1;
4869 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4871 current_block.AddStatement (f);
4873 $$ = end_block (lexer.Location);
4878 : /* empty */ { $$ = EmptyStatement.Value; }
4883 : local_variable_declaration
4884 | statement_expression_list
4888 : /* empty */ { $$ = null; }
4889 | boolean_expression
4893 : /* empty */ { $$ = EmptyStatement.Value; }
4898 : statement_expression_list
4901 statement_expression_list
4902 : statement_expression
4904 // CHANGE: was `null'
4905 Statement s = (Statement) $1;
4906 Block b = new Block (current_block, s.loc, lexer.Location);
4911 | statement_expression_list COMMA statement_expression
4913 Block b = (Block) $1;
4915 b.AddStatement ((Statement) $3);
4921 : FOREACH open_parens_any type IN expression CLOSE_PARENS
4923 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4926 | FOREACH open_parens_any type IDENTIFIER IN
4927 expression CLOSE_PARENS
4929 start_block (lexer.Location);
4930 Block foreach_block = current_block;
4932 LocatedToken lt = (LocatedToken) $4;
4933 Location l = lt.Location;
4934 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4936 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4938 // Get a writable reference to this read-only variable.
4940 // Note that the $$ here refers to the value of _this_ code block,
4941 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4942 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4949 LocalVariableReference v = (LocalVariableReference) $8;
4950 Location l = (Location) $1;
4953 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4954 current_block.AddStatement (f);
4957 $$ = end_block (lexer.Location);
4963 | continue_statement
4973 $$ = new Break ((Location) $1);
4978 : CONTINUE SEMICOLON
4980 $$ = new Continue ((Location) $1);
4985 : GOTO IDENTIFIER SEMICOLON
4987 LocatedToken lt = (LocatedToken) $2;
4988 $$ = new Goto (lt.Value, lt.Location);
4990 | GOTO CASE constant_expression SEMICOLON
4992 $$ = new GotoCase ((Expression) $3, (Location) $1);
4994 | GOTO DEFAULT SEMICOLON
4996 $$ = new GotoDefault ((Location) $1);
5001 : RETURN opt_expression SEMICOLON
5003 $$ = new Return ((Expression) $2, (Location) $1);
5008 : THROW opt_expression SEMICOLON
5010 $$ = new Throw ((Expression) $2, (Location) $1);
5015 : IDENTIFIER RETURN expression SEMICOLON
5017 LocatedToken lt = (LocatedToken) $1;
5018 string s = lt.Value;
5020 Report.Error (1003, lt.Location, "; expected");
5023 if (RootContext.Version == LanguageVersion.ISO_1){
5024 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5027 current_block.Toplevel.IsIterator = true;
5028 $$ = new Yield ((Expression) $3, lt.Location);
5030 | IDENTIFIER RETURN SEMICOLON
5032 Report.Error (1627, (Location) $2, "Expression expected after yield return");
5035 | IDENTIFIER BREAK SEMICOLON
5037 LocatedToken lt = (LocatedToken) $1;
5038 string s = lt.Value;
5040 Report.Error (1003, lt.Location, "; expected");
5043 if (RootContext.Version == LanguageVersion.ISO_1){
5044 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5048 current_block.Toplevel.IsIterator = true;
5049 $$ = new YieldBreak (lt.Location);
5059 : TRY block catch_clauses
5061 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
5063 | TRY block FINALLY block
5065 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
5067 | TRY block catch_clauses FINALLY block
5069 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
5073 Report.Error (1524, (Location) $1, "Expected catch or finally");
5081 ArrayList l = new ArrayList (4);
5086 | catch_clauses catch_clause
5088 ArrayList l = (ArrayList) $1;
5096 : /* empty */ { $$ = null; }
5101 : CATCH opt_catch_args
5103 Expression type = null;
5106 DictionaryEntry cc = (DictionaryEntry) $2;
5107 type = (Expression) cc.Key;
5108 LocatedToken lt = (LocatedToken) cc.Value;
5111 ArrayList one = new ArrayList (4);
5113 one.Add (new VariableDeclaration (lt, null));
5115 start_block (lexer.Location);
5116 current_block = declare_local_variables (type, one, lt.Location);
5120 Expression type = null;
5122 Block var_block = null;
5125 DictionaryEntry cc = (DictionaryEntry) $2;
5126 type = (Expression) cc.Key;
5127 LocatedToken lt = (LocatedToken) cc.Value;
5131 var_block = end_block (lexer.Location);
5135 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5140 : /* empty */ { $$ = null; }
5145 : open_parens_any type opt_identifier CLOSE_PARENS
5147 $$ = new DictionaryEntry ($2, $3);
5149 | open_parens_any CLOSE_PARENS
5151 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5158 $$ = new Checked ((Block) $2);
5165 $$ = new Unchecked ((Block) $2);
5172 RootContext.CheckUnsafeOption ((Location) $1);
5174 $$ = new Unsafe ((Block) $3);
5179 : FIXED open_parens_any
5180 type_and_void fixed_pointer_declarators
5183 ArrayList list = (ArrayList) $4;
5184 Expression type = (Expression) $3;
5185 Location l = (Location) $1;
5186 int top = list.Count;
5188 start_block (lexer.Location);
5190 for (int i = 0; i < top; i++){
5191 Pair p = (Pair) list [i];
5194 v = current_block.AddVariable (type, (string) p.First, l);
5198 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5206 Location l = (Location) $1;
5208 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5210 current_block.AddStatement (f);
5212 $$ = end_block (lexer.Location);
5216 fixed_pointer_declarators
5217 : fixed_pointer_declarator {
5218 ArrayList declarators = new ArrayList (4);
5220 declarators.Add ($1);
5223 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5225 ArrayList declarators = (ArrayList) $1;
5227 declarators.Add ($3);
5232 fixed_pointer_declarator
5233 : IDENTIFIER ASSIGN expression
5235 LocatedToken lt = (LocatedToken) $1;
5236 // FIXME: keep location
5237 $$ = new Pair (lt.Value, $3);
5241 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5247 : LOCK open_parens_any expression CLOSE_PARENS
5253 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5258 : USING open_parens_any local_variable_declaration CLOSE_PARENS
5260 start_block (lexer.Location);
5261 Block assign_block = current_block;
5263 DictionaryEntry de = (DictionaryEntry) $3;
5264 Location l = (Location) $1;
5266 Expression type = (Expression) de.Key;
5267 ArrayList var_declarators = (ArrayList) de.Value;
5269 Stack vars = new Stack ();
5271 foreach (VariableDeclaration decl in var_declarators) {
5272 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5275 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5277 Expression expr = decl.expression_or_array_initializer;
5279 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5282 LocalVariableReference var;
5284 // Get a writable reference to this read-only variable.
5285 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5287 // This is so that it is not a warning on using variables
5290 vars.Push (new DictionaryEntry (var, expr));
5292 // Assign a = new SimpleAssign (var, expr, decl.Location);
5293 // assign_block.AddStatement (new StatementExpression (a));
5296 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5297 // It can be referred to as $5 below.
5302 Statement stmt = (Statement) $6;
5303 Stack vars = (Stack) $5;
5304 Location l = (Location) $1;
5306 while (vars.Count > 0) {
5307 DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5308 stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5310 current_block.AddStatement (stmt);
5311 $$ = end_block (lexer.Location);
5313 | USING open_parens_any expression CLOSE_PARENS
5315 start_block (lexer.Location);
5319 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5320 $$ = end_block (lexer.Location);
5328 : first_from_clause query_body
5330 lexer.query_parsing = false;
5332 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5334 from.Tail.Next = (Linq.AQueryClause)$2;
5337 current_block.SetEndLocation (lexer.Location);
5338 current_block = current_block.Parent;
5340 | nested_from_clause query_body
5342 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5344 from.Tail.Next = (Linq.AQueryClause)$2;
5347 current_block.SetEndLocation (lexer.Location);
5348 current_block = current_block.Parent;
5353 : FROM_FIRST IDENTIFIER IN expression
5355 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5356 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5358 | FROM_FIRST type IDENTIFIER IN expression
5360 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5361 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5366 : FROM IDENTIFIER IN expression
5368 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5369 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5371 | FROM type IDENTIFIER IN expression
5373 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5374 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5379 : FROM IDENTIFIER IN
5381 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5385 LocatedToken lt = (LocatedToken) $2;
5386 $$ = new Linq.SelectMany (current_block.Toplevel, lt, (Expression)$5);
5388 current_block.SetEndLocation (lexer.Location);
5389 current_block = current_block.Parent;
5391 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5393 | FROM type IDENTIFIER IN
5395 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5399 LocatedToken lt = (LocatedToken) $3;
5400 FullNamedExpression type = (FullNamedExpression)$2;
5402 $$ = new Linq.SelectMany (current_block.Toplevel, lt, new Linq.Cast (type, (FullNamedExpression)$6));
5404 current_block.SetEndLocation (lexer.Location);
5405 current_block = current_block.Parent;
5407 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5412 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5414 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5417 head.Next = (Linq.AQueryClause)$3;
5420 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5421 clause.Tail.Next = head;
5429 select_or_group_clause
5432 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5436 $$ = new Linq.Select (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5438 current_block.SetEndLocation (lexer.Location);
5439 current_block = current_block.Parent;
5443 if (linq_clause_blocks == null)
5444 linq_clause_blocks = new Stack ();
5446 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5447 linq_clause_blocks.Push (current_block);
5451 current_block.SetEndLocation (lexer.Location);
5452 current_block = current_block.Parent;
5454 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5458 $$ = new Linq.GroupBy (current_block.Toplevel, (Expression)$3, (ToplevelBlock) linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5460 current_block.SetEndLocation (lexer.Location);
5461 current_block = current_block.Parent;
5465 opt_query_body_clauses
5467 | query_body_clauses
5472 | query_body_clauses query_body_clause
5474 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5488 : LET IDENTIFIER ASSIGN
5490 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5494 LocatedToken lt = (LocatedToken) $2;
5495 $$ = new Linq.Let (current_block.Toplevel, current_container, lt, (Expression)$5);
5497 current_block.SetEndLocation (lexer.Location);
5498 current_block = current_block.Parent;
5500 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5507 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5511 $$ = new Linq.Where (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5513 current_block.SetEndLocation (lexer.Location);
5514 current_block = current_block.Parent;
5519 : JOIN IDENTIFIER IN
5521 if (linq_clause_blocks == null)
5522 linq_clause_blocks = new Stack ();
5524 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5525 linq_clause_blocks.Push (current_block);
5529 current_block.SetEndLocation (lexer.Location);
5530 current_block = current_block.Parent;
5532 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5533 linq_clause_blocks.Push (current_block);
5537 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5538 current_block.SetEndLocation (lexer.Location);
5539 current_block = current_block.Parent;
5541 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, lexer.Location);
5543 expression opt_join_into
5545 LocatedToken lt = (LocatedToken) $2;
5547 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5548 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5551 $$ = new Linq.Join (block, lt, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
5553 $$ = new Linq.GroupJoin (block, lt, (Expression)$5, outer_selector, current_block.Toplevel,
5554 (LocatedToken) $12, GetLocation ($1));
5557 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5558 current_block.SetEndLocation (lexer.Location);
5559 current_block = current_block.Parent;
5562 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5564 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $12);
5566 | JOIN type IDENTIFIER IN
5568 if (linq_clause_blocks == null)
5569 linq_clause_blocks = new Stack ();
5571 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5572 linq_clause_blocks.Push (current_block);
5576 current_block.SetEndLocation (lexer.Location);
5577 current_block = current_block.Parent;
5579 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5580 linq_clause_blocks.Push (current_block);
5584 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5585 current_block.SetEndLocation (lexer.Location);
5586 current_block = current_block.Parent;
5588 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, lexer.Location);
5590 expression opt_join_into
5592 LocatedToken lt = (LocatedToken) $3;
5593 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5594 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5596 Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
5598 $$ = new Linq.Join (block, lt, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
5600 $$ = new Linq.GroupJoin (block, lt, cast, outer_selector, current_block.Toplevel,
5601 (LocatedToken) $13, GetLocation ($1));
5604 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5605 current_block.SetEndLocation (lexer.Location);
5606 current_block = current_block.Parent;
5609 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5611 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $13);
5626 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5630 current_block.SetEndLocation (lexer.Location);
5631 current_block = current_block.Parent;
5641 current_block.SetEndLocation (lexer.Location);
5642 current_block = current_block.Parent;
5644 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5648 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5655 | orderings_then_by COMMA
5657 current_block.SetEndLocation (lexer.Location);
5658 current_block = current_block.Parent;
5660 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5664 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5672 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5674 | expression ASCENDING
5676 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5678 | expression DESCENDING
5680 $$ = new Linq.OrderByDescending (current_block.Toplevel, (Expression)$1);
5687 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5689 | expression ASCENDING
5691 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5693 | expression DESCENDING
5695 $$ = new Linq.ThenByDescending (current_block.Toplevel, (Expression)$1);
5700 opt_query_continuation
5704 // query continuation block is not linked with query block but with block
5705 // before. This means each query can use same range variable names for
5706 // different identifiers.
5708 current_block.SetEndLocation (GetLocation ($1));
5709 current_block = current_block.Parent;
5711 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5715 $$ = new Linq.QueryExpression (current_block, (Linq.AQueryClause)$4);
5720 // Support for using the compiler as an interactive parser
5722 // The INTERACTIVE_PARSER token is first sent to parse our
5723 // productions; If the result is a Statement, the parsing
5724 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5725 // to setup the blocks in advance.
5727 // This setup is here so that in the future we can add
5728 // support for other constructs (type parsing, namespaces, etc)
5729 // that do not require a block to be setup in advance
5733 : EVAL_STATEMENT_PARSER EOF
5734 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5735 | EVAL_STATEMENT_PARSER {
5736 Evaluator.LoadAliases (current_namespace);
5738 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5739 Modifiers.PUBLIC, null), null);
5741 ArrayList baseclass_list = new ArrayList ();
5742 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5743 current_container.AddBasesForPart (current_class, baseclass_list);
5745 // (ref object retval)
5746 Parameter [] mpar = new Parameter [1];
5747 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5749 ParametersCompiled pars = new ParametersCompiled (mpar);
5750 current_local_parameters = pars;
5751 Method method = new Method (
5754 TypeManager.system_void_expr,
5755 Modifiers.PUBLIC | Modifiers.STATIC,
5756 new MemberName ("Host"),
5758 null /* attributes */);
5760 oob_stack.Push (method);
5761 ++lexer.parsing_block;
5762 start_block (lexer.Location);
5764 interactive_statement_list opt_COMPLETE_COMPLETION
5766 --lexer.parsing_block;
5767 Method method = (Method) oob_stack.Pop ();
5769 method.Block = (ToplevelBlock) end_block(lexer.Location);
5770 current_container.AddMethod (method);
5772 --lexer.parsing_declaration;
5773 InteractiveResult = pop_current_class ();
5774 current_local_parameters = null;
5776 | EVAL_COMPILATION_UNIT_PARSER {
5777 Evaluator.LoadAliases (current_namespace);
5779 interactive_compilation_unit
5782 interactive_compilation_unit
5783 : outer_declarations
5784 | outer_declarations global_attributes
5789 opt_COMPLETE_COMPLETION
5791 | COMPLETE_COMPLETION
5794 close_brace_or_complete_completion
5796 | COMPLETE_COMPLETION
5801 // A class used to pass around variable declarations and constants
5803 public class VariableDeclaration {
5804 public string identifier;
5805 public Expression expression_or_array_initializer;
5806 public Location Location;
5807 public Attributes OptAttributes;
5808 public string DocComment;
5810 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5812 this.identifier = lt.Value;
5813 if (eoai is ArrayList) {
5814 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5816 this.expression_or_array_initializer = (Expression)eoai;
5818 this.Location = lt.Location;
5819 this.OptAttributes = opt_attrs;
5822 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5827 class VariableMemberDeclaration
5829 public readonly MemberName MemberName;
5830 public Expression expression_or_array_initializer;
5832 public VariableMemberDeclaration (MemberName mn, object initializer)
5836 if (initializer is ArrayList) {
5837 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
5839 this.expression_or_array_initializer = (Expression)initializer;
5846 // A class used to hold info about an operator declarator
5848 struct OperatorDeclaration {
5849 public readonly Operator.OpType optype;
5850 public readonly FullNamedExpression ret_type;
5851 public readonly Location location;
5853 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5856 this.ret_type = ret_type;
5857 this.location = location;
5861 static void Error_ExpectingTypeName (Expression expr)
5863 if (expr is Invocation){
5864 Report.Error (1002, expr.Location, "Expecting `;'");
5866 expr.Error_InvalidExpressionStatement ();
5870 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5872 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5876 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5878 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5879 Parameter.GetModifierSignature (mod));
5882 static void Error_TypeExpected (Location loc)
5884 Report.Error (1031, loc, "Type expected");
5887 static void Error_NamedArgumentExpected (NamedArgument a)
5889 Report.Error (1738, a.Name.Location, "Named arguments must appear after the positional arguments");
5892 void push_current_class (TypeContainer tc, object partial_token)
5894 if (RootContext.EvalMode){
5895 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5896 undo.AddTypeContainer (current_container, tc);
5899 if (partial_token != null)
5900 current_container = current_container.AddPartial (tc);
5902 current_container = current_container.AddTypeContainer (tc);
5904 ++lexer.parsing_declaration;
5908 DeclSpace pop_current_class ()
5910 DeclSpace retval = current_class;
5912 current_class = current_class.Parent;
5913 current_container = current_class.PartialContainer;
5919 // Given the @class_name name, it creates a fully qualified name
5920 // based on the containing declaration space
5923 MakeName (MemberName class_name)
5925 Namespace ns = current_namespace.NS;
5927 if (current_container == RootContext.ToplevelTypes) {
5928 if (ns.Name.Length != 0)
5929 return new MemberName (ns.MemberName, class_name);
5933 return new MemberName (current_container.MemberName, class_name);
5937 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5939 Block implicit_block;
5940 ArrayList inits = null;
5943 // If we are doing interactive editing, we want variable declarations
5944 // that are in the top block to be added instead to the class as
5947 if (RootContext.StatementMode){
5950 for (Block b = current_block; b != null; b = b.Parent){
5951 if (b is ExplicitBlock && !(b is ToplevelBlock)){
5952 // There has been an explicit block, we cant add to the class
5959 // We can use "current_block" since we know there are no explicit blocks
5961 foreach (VariableDeclaration decl in variable_declarators){
5962 // We can not use the super-handy f.Initializer, because
5963 // multiple lines would force code to be executed out of sync
5964 if (decl.expression_or_array_initializer != null){
5965 string id = "$" + decl.identifier;
5966 current_block.AddVariable (type, id, decl.Location);
5968 LocalVariableReference var;
5969 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
5970 Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
5971 current_block.AddStatement (new StatementExpression (assign));
5972 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
5973 current_block.AddStatement (new StatementExpression (assign));
5975 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
5976 new MemberName (decl.identifier, loc), null);
5977 current_container.AddField (f);
5979 // Register the field to be visible later as a global variable
5980 Evaluator.QueueField (f);
5984 return current_block;
5989 // We use the `Used' property to check whether statements
5990 // have been added to the current block. If so, we need
5991 // to create another block to contain the new declaration
5992 // otherwise, as an optimization, we use the same block to
5993 // add the declaration.
5995 // FIXME: A further optimization is to check if the statements
5996 // that were added were added as part of the initialization
5997 // below. In which case, no other statements have been executed
5998 // and we might be able to reduce the number of blocks for
5999 // situations like this:
6001 // int j = 1; int k = j + 1;
6003 if (current_block.Used)
6004 implicit_block = new Block (current_block, loc, lexer.Location);
6006 implicit_block = current_block;
6008 foreach (VariableDeclaration decl in variable_declarators){
6010 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
6011 if (decl.expression_or_array_initializer != null){
6013 inits = new ArrayList (4);
6020 return implicit_block;
6022 foreach (VariableDeclaration decl in inits){
6024 Expression expr = decl.expression_or_array_initializer;
6026 LocalVariableReference var;
6027 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
6029 assign = new SimpleAssign (var, expr, decl.Location);
6031 implicit_block.AddStatement (new StatementExpression (assign));
6034 return implicit_block;
6037 Block declare_local_constants (Expression type, ArrayList declarators)
6039 Block implicit_block;
6041 if (current_block.Used)
6042 implicit_block = new Block (current_block);
6044 implicit_block = current_block;
6046 foreach (VariableDeclaration decl in declarators){
6047 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
6050 return implicit_block;
6053 string CheckAttributeTarget (string a, Location l)
6056 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6060 Report.Warning (658, 1, l,
6061 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6062 return string.Empty;
6065 static bool IsUnaryOperator (Operator.OpType op)
6069 case Operator.OpType.LogicalNot:
6070 case Operator.OpType.OnesComplement:
6071 case Operator.OpType.Increment:
6072 case Operator.OpType.Decrement:
6073 case Operator.OpType.True:
6074 case Operator.OpType.False:
6075 case Operator.OpType.UnaryPlus:
6076 case Operator.OpType.UnaryNegation:
6082 void syntax_error (Location l, string msg)
6084 Report.Error (1003, l, "Syntax error, " + msg);
6089 public Tokenizer Lexer {
6095 static CSharpParser ()
6097 oob_stack = new Stack ();
6100 public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
6102 if (RootContext.EvalMode)
6106 current_namespace = new NamespaceEntry (null, file, null);
6107 current_class = current_namespace.SlaveDeclSpace;
6108 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6110 lexer = new Tokenizer (reader, file);
6113 public void parse ()
6115 eof_token = Token.EOF;
6118 if (yacc_verbose_flag > 1)
6119 yyparse (lexer, new yydebug.yyDebugSimple ());
6122 } catch (Exception e){
6123 if (e is yyParser.yyUnexpectedEof)
6124 UnexpectedEOF = true;
6125 else if (yacc_verbose_flag > 0)
6126 Console.WriteLine (e);
6127 if (e is yyParser.yyException)
6128 Report.Error (-25, lexer.Location, "Parsing error");
6130 Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
6132 Tokenizer tokenizer = lexer as Tokenizer;
6133 tokenizer.cleanup ();
6135 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6136 throw new InternalErrorException ("who set it?");
6139 static void CheckToken (int error, int yyToken, string msg, Location loc)
6141 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6142 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6144 Report.Error (error, loc, msg);
6147 void CheckIdentifierToken (int yyToken, Location loc)
6149 CheckToken (1041, yyToken, "Identifier expected", loc);
6152 string ConsumeStoredComment ()
6154 string s = tmpComment;
6156 Lexer.doc_state = XmlCommentState.Allowed;
6160 Location GetLocation (object obj)
6162 if (obj is MemberCore)
6163 return ((MemberCore) obj).Location;
6164 if (obj is MemberName)
6165 return ((MemberName) obj).Location;
6166 if (obj is LocatedToken)
6167 return ((LocatedToken) obj).Location;
6168 if (obj is Location)
6169 return (Location) obj;
6170 return lexer.Location;
6173 void start_block (Location loc)
6175 if (current_block == null || parsing_anonymous_method) {
6176 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
6177 parsing_anonymous_method = false;
6179 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6184 end_block (Location loc)
6186 Block retval = current_block.Explicit;
6187 retval.SetEndLocation (loc);
6188 current_block = retval.Parent;
6193 start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6195 if (RootContext.Version == LanguageVersion.ISO_1){
6196 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6199 oob_stack.Push (current_anonymous_method);
6200 oob_stack.Push (current_local_parameters);
6202 current_local_parameters = parameters;
6204 current_anonymous_method = lambda
6205 ? new LambdaExpression (loc)
6206 : new AnonymousMethodExpression (loc);
6208 // Force the next block to be created as a ToplevelBlock
6209 parsing_anonymous_method = true;
6213 * Completes the anonymous method processing, if lambda_expr is null, this
6214 * means that we have a Statement instead of an Expression embedded
6216 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
6218 AnonymousMethodExpression retval;
6220 current_anonymous_method.Block = anon_block;
6221 retval = current_anonymous_method;
6223 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6224 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6229 public NamespaceEntry CurrentNamespace {
6231 return current_namespace;
6236 void Error_SyntaxError (int token)
6238 Error_SyntaxError (0, token);
6241 void Error_SyntaxError (int error_code, int token)
6243 string symbol = GetSymbolName (token);
6244 string expecting = GetExpecting ();
6246 if (error_code == 0) {
6247 if (expecting == "`)'")
6253 if (expecting != null)
6254 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
6257 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
6260 string GetExpecting ()
6262 int [] tokens = yyExpectingTokens (yyExpectingState);
6263 ArrayList names = new ArrayList (tokens.Length);
6264 bool has_type = false;
6265 bool has_identifier = false;
6266 for (int i = 0; i < tokens.Length; i++){
6267 int token = tokens [i];
6268 has_identifier |= token == Token.IDENTIFIER;
6270 string name = GetTokenName (token);
6271 if (name == "<internal>")
6274 has_type |= name == "type";
6275 if (names.Contains (name))
6282 // Too many tokens to enumerate
6284 if (names.Count > 8)
6287 if (has_type && has_identifier)
6288 names.Remove ("identifier");
6290 if (names.Count == 1)
6291 return "`" + GetTokenName (tokens [0]) + "'";
6293 StringBuilder sb = new StringBuilder ();
6295 int count = names.Count;
6296 for (int i = 0; i < count; i++){
6297 bool last = i + 1 == count;
6301 sb.Append (names [i]);
6302 sb.Append (last ? "'" : "', ");
6304 return sb.ToString ();
6308 string GetSymbolName (int token)
6311 case Token.LITERAL_FLOAT:
6312 case Token.LITERAL_INTEGER:
6313 case Token.LITERAL_DOUBLE:
6314 case Token.LITERAL_DECIMAL:
6315 case Token.LITERAL_CHARACTER:
6316 case Token.LITERAL_STRING:
6317 return lexer.Value.ToString ();
6318 case Token.IDENTIFIER:
6319 return ((LocatedToken)lexer.Value).Value;
6361 case Token.BITWISE_AND:
6363 case Token.BITWISE_OR:
6377 case Token.OP_SHIFT_LEFT:
6379 case Token.OP_SHIFT_RIGHT:
6399 case Token.OP_COALESCING:
6401 case Token.OP_MULT_ASSIGN:
6403 case Token.OP_DIV_ASSIGN:
6405 case Token.OP_MOD_ASSIGN:
6407 case Token.OP_ADD_ASSIGN:
6409 case Token.OP_SUB_ASSIGN:
6411 case Token.OP_SHIFT_LEFT_ASSIGN:
6413 case Token.OP_SHIFT_RIGHT_ASSIGN:
6415 case Token.OP_AND_ASSIGN:
6417 case Token.OP_XOR_ASSIGN:
6419 case Token.OP_OR_ASSIGN:
6423 return GetTokenName (token);
6426 static string GetTokenName (int token)
6429 case Token.ABSTRACT:
6449 case Token.CONTINUE:
6453 case Token.DELEGATE:
6463 case Token.EXPLICIT:
6481 case Token.IMPLICIT:
6485 case Token.INTERFACE:
6487 case Token.INTERNAL:
6493 case Token.NAMESPACE:
6499 case Token.OPERATOR:
6503 case Token.OVERRIDE:
6509 case Token.PROTECTED:
6513 case Token.READONLY:
6525 case Token.STACKALLOC:
6526 return "stackalloc";
6543 case Token.UNCHECKED:
6551 case Token.VOLATILE:
6564 case Token.FROM_FIRST:
6582 case Token.ASCENDING:
6584 case Token.DESCENDING:
6585 return "descending";
6592 case Token.OPEN_BRACE:
6594 case Token.CLOSE_BRACE:
6596 case Token.OPEN_BRACKET:
6598 case Token.CLOSE_BRACKET:
6600 case Token.OPEN_PARENS_CAST:
6601 case Token.OPEN_PARENS_LAMBDA:
6602 case Token.OPEN_PARENS:
6604 case Token.CLOSE_PARENS:
6610 case Token.DEFAULT_COLON:
6614 case Token.SEMICOLON:
6625 case Token.BITWISE_AND:
6626 case Token.BITWISE_OR:
6633 case Token.OP_SHIFT_LEFT:
6634 case Token.OP_SHIFT_RIGHT:
6642 case Token.OP_COALESCING:
6643 case Token.OP_MULT_ASSIGN:
6644 case Token.OP_DIV_ASSIGN:
6645 case Token.OP_MOD_ASSIGN:
6646 case Token.OP_ADD_ASSIGN:
6647 case Token.OP_SUB_ASSIGN:
6648 case Token.OP_SHIFT_LEFT_ASSIGN:
6649 case Token.OP_SHIFT_RIGHT_ASSIGN:
6650 case Token.OP_AND_ASSIGN:
6651 case Token.OP_XOR_ASSIGN:
6652 case Token.OP_OR_ASSIGN:
6653 return "<operator>";
6675 case Token.OP_GENERICS_LT:
6676 case Token.GENERIC_DIMENSION:
6678 case Token.OP_GENERICS_GT:
6681 case Token.INTERR_NULLABLE:
6683 case Token.DOUBLE_COLON:
6685 case Token.LITERAL_FLOAT:
6686 case Token.LITERAL_INTEGER:
6687 case Token.LITERAL_DOUBLE:
6688 case Token.LITERAL_DECIMAL:
6689 case Token.LITERAL_CHARACTER:
6690 case Token.LITERAL_STRING:
6692 case Token.IDENTIFIER:
6693 return "identifier";
6695 // All of these are internal.
6698 case Token.FIRST_KEYWORD:
6700 case Token.EVAL_COMPILATION_UNIT_PARSER:
6701 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6702 case Token.EVAL_STATEMENT_PARSER:
6703 case Token.LAST_KEYWORD:
6704 case Token.GENERATE_COMPLETION:
6705 case Token.COMPLETE_COMPLETION:
6706 return "<internal>";
6708 // A bit more robust.
6710 return yyNames [token];