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
38 enum ParameterModifierType
45 DefaultValue = 1 << 6,
47 All = Ref | Out | This | Params | Arglist | DefaultValue
50 NamespaceEntry current_namespace;
51 TypeContainer current_container;
52 DeclSpace current_class;
55 /// Current block is used to add statements as we find
60 Delegate current_delegate;
62 GenericMethod current_generic_method;
63 AnonymousMethodExpression current_anonymous_method;
66 /// This is used by the unary_expression code to resolve
67 /// a name against a parameter.
70 // FIXME: This is very ugly and it's very hard to reset it correctly
71 // on all places, especially when some parameters are autogenerated.
72 ParametersCompiled current_local_parameters;
75 /// Using during property parsing to describe the implicit
76 /// value parameter that is passed to the "set" and "get"accesor
77 /// methods (properties and indexers).
79 FullNamedExpression implicit_value_parameter_type;
80 ParametersCompiled indexer_parameters;
83 /// Hack to help create non-typed array initializer
85 public static FullNamedExpression current_array_type;
86 FullNamedExpression pushed_current_array_type;
89 /// Used to determine if we are parsing the get/set pair
90 /// of an indexer or a property
94 bool parsing_anonymous_method;
97 /// An out-of-band stack.
99 static Stack oob_stack;
107 /// Controls the verbosity of the errors produced by the parser
109 static public int yacc_verbose_flag;
112 /// Used by the interactive shell, flags whether EOF was reached
113 /// and an error was produced
115 public bool UnexpectedEOF;
118 /// The current file.
120 CompilationUnit file;
123 /// Temporary Xml documentation cache.
124 /// For enum types, we need one more temporary store.
127 string enumTypeComment;
129 /// Current attribute target
130 string current_attr_target;
132 /// assembly and module attribute definitions are enabled
133 bool global_attrs_enabled = true;
134 bool has_get, has_set;
136 ParameterModifierType valid_param_mod;
138 bool default_parameter_used;
140 /// When using the interactive parser, this holds the
141 /// resulting expression
142 public object InteractiveResult;
145 // Keeps track of global data changes to undo on parser error
149 // Stack<ToplevelBlock>
150 Stack linq_clause_blocks;
152 // A counter to create new class names in interactive mode
153 static int class_count;
157 %token NONE /* This token is never returned by our lexer */
158 %token ERROR // This is used not by the parser, but by the tokenizer.
162 *These are the C# keywords
261 %token INTERR_NULLABLE
264 /* Generics <,> tokens */
265 %token OP_GENERICS_LT
266 %token OP_GENERICS_LT_DECL
267 %token OP_GENERICS_GT
269 /* C# keywords which are not really keywords */
275 /* C# single character operators/punctuation. */
303 /* C# multi-character operators. */
308 %token OP_SHIFT_RIGHT
315 %token OP_MULT_ASSIGN
320 %token OP_SHIFT_LEFT_ASSIGN
321 %token OP_SHIFT_RIGHT_ASSIGN
329 %token LITERAL_INTEGER
331 %token LITERAL_DOUBLE
332 %token LITERAL_DECIMAL
333 %token LITERAL_CHARACTER
334 %token LITERAL_STRING
337 %token OPEN_PARENS_LAMBDA
338 %token OPEN_PARENS_CAST
339 %token GENERIC_DIMENSION
342 // Make the parser go into eval mode parsing (statements and compilation units).
343 %token EVAL_STATEMENT_PARSER
344 %token EVAL_COMPILATION_UNIT_PARSER
345 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
348 // This token is generated to trigger the completion engine at this point
350 %token GENERATE_COMPLETION
353 // This token is return repeatedly after the first GENERATE_COMPLETION
354 // token is produced and before the final EOF
356 %token COMPLETE_COMPLETION
358 /* Add precedence rules to solve dangling else s/r conflict */
362 /* Define the operator tokens and their precedences */
370 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
372 %left STAR DIV PERCENT
373 %right BANG CARRET UMINUS
374 %nonassoc OP_INC OP_DEC
376 %left OPEN_BRACKET OPEN_BRACE
379 %start compilation_unit
383 : outer_declarations opt_EOF
384 | outer_declarations global_attributes opt_EOF
385 | global_attributes opt_EOF
386 | opt_EOF /* allow empty files */
387 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
393 Lexer.check_incorrect_doc_comment ();
397 Lexer.check_incorrect_doc_comment ();
403 | outer_declarations outer_declaration
407 : extern_alias_directive
409 | namespace_member_declaration
412 extern_alias_directives
413 : extern_alias_directive
414 | extern_alias_directives extern_alias_directive
417 extern_alias_directive
418 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
420 LocatedToken lt = (LocatedToken) $2;
423 syntax_error (lt.Location, "`alias' expected");
424 } else if (RootContext.Version == LanguageVersion.ISO_1) {
425 Report.FeatureIsNotAvailable (lt.Location, "external alias");
427 lt = (LocatedToken) $3;
428 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
433 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
439 | using_directives using_directive
443 : using_alias_directive
445 if (RootContext.Documentation != null)
446 Lexer.doc_state = XmlCommentState.Allowed;
448 | using_namespace_directive
450 if (RootContext.Documentation != null)
451 Lexer.doc_state = XmlCommentState.Allowed;
455 using_alias_directive
456 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
458 LocatedToken lt = (LocatedToken) $2;
459 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
462 CheckIdentifierToken (yyToken, GetLocation ($2));
467 using_namespace_directive
468 : USING namespace_name SEMICOLON
470 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
475 // Strictly speaking, namespaces don't have attributes but
476 // we parse global attributes along with namespace declarations and then
479 namespace_declaration
480 : opt_attributes NAMESPACE qualified_identifier
482 MemberName name = (MemberName) $3;
485 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
488 current_namespace = new NamespaceEntry (
489 current_namespace, file, name.GetName ());
490 current_class = current_namespace.SlaveDeclSpace;
491 current_container = current_class.PartialContainer;
493 namespace_body opt_semicolon
495 current_namespace = current_namespace.Parent;
496 current_class = current_namespace.SlaveDeclSpace;
497 current_container = current_class.PartialContainer;
504 LocatedToken lt = (LocatedToken) $1;
505 $$ = new MemberName (lt.Value, lt.Location);
507 | qualified_identifier DOT IDENTIFIER
509 LocatedToken lt = (LocatedToken) $3;
510 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
514 syntax_error (lexer.Location, "`.' expected");
529 : namespace_or_type_name
531 MemberName name = (MemberName) $1;
533 if (name.TypeArguments != null)
534 syntax_error (lexer.Location, "namespace name expected");
543 if (RootContext.Documentation != null)
544 Lexer.doc_state = XmlCommentState.Allowed;
550 : opt_extern_alias_directives
552 opt_namespace_member_declarations
556 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
559 | opt_extern_alias_directives
561 opt_namespace_member_declarations
564 Report.Error (1513, lexer.Location, "Expected `}'");
573 opt_extern_alias_directives
575 | extern_alias_directives
578 opt_namespace_member_declarations
580 | namespace_member_declarations
583 namespace_member_declarations
584 : namespace_member_declaration
585 | namespace_member_declarations namespace_member_declaration
588 namespace_member_declaration
592 DeclSpace ds = (DeclSpace)$1;
594 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
595 Report.Error (1527, ds.Location,
596 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
599 current_namespace.DeclarationFound = true;
601 | namespace_declaration {
602 current_namespace.DeclarationFound = true;
605 | field_declaration {
606 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
608 | method_declaration {
609 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
616 | interface_declaration
618 | delegate_declaration
620 // Enable this when we have handled all errors, because this acts as a generic fallback
623 // Console.WriteLine ("Token=" + yyToken);
624 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
636 Attributes attrs = (Attributes)$1;
637 if (global_attrs_enabled) {
638 CodeGen.Assembly.AddAttributes (attrs.Attrs);
640 foreach (Attribute a in attrs.Attrs) {
641 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
652 global_attrs_enabled = false;
657 global_attrs_enabled = false;
666 if (current_attr_target != String.Empty) {
667 ArrayList sect = (ArrayList) $1;
669 if (global_attrs_enabled) {
670 if (current_attr_target == "module") {
671 current_container.Module.AddAttributes (sect);
673 } else if (current_attr_target != null && current_attr_target.Length > 0) {
674 CodeGen.Assembly.AddAttributes (sect);
677 $$ = new Attributes (sect);
680 if (RootContext.Documentation != null) {
681 Lexer.check_incorrect_doc_comment ();
683 XmlCommentState.Allowed;
687 $$ = new Attributes (sect);
692 current_attr_target = null;
694 | attribute_sections attribute_section
696 if (current_attr_target != String.Empty) {
697 Attributes attrs = $1 as Attributes;
698 ArrayList sect = (ArrayList) $2;
700 if (global_attrs_enabled) {
701 if (current_attr_target == "module") {
702 current_container.Module.AddAttributes (sect);
704 } else if (current_attr_target == "assembly") {
705 CodeGen.Assembly.AddAttributes (sect);
709 attrs = new Attributes (sect);
711 attrs.AddAttributes (sect);
715 attrs = new Attributes (sect);
717 attrs.AddAttributes (sect);
723 current_attr_target = null;
728 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
732 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
738 attribute_target_specifier
739 : attribute_target COLON
741 current_attr_target = (string)$1;
749 LocatedToken lt = (LocatedToken) $1;
750 $$ = CheckAttributeTarget (lt.Value, lt.Location);
752 | EVENT { $$ = "event"; }
753 | RETURN { $$ = "return"; }
756 string name = GetTokenName (yyToken);
757 $$ = CheckAttributeTarget (name, GetLocation ($1));
764 ArrayList attrs = new ArrayList (4);
770 | attribute_list COMMA attribute
772 ArrayList attrs = (ArrayList) $1;
782 ++lexer.parsing_block;
784 opt_attribute_arguments
786 --lexer.parsing_block;
787 MemberName mname = (MemberName) $1;
788 if (mname.IsGeneric) {
789 Report.Error (404, lexer.Location,
790 "'<' unexpected: attributes cannot be generic");
793 Arguments [] arguments = (Arguments []) $3;
794 MemberName left = mname.Left;
795 string identifier = mname.Name;
797 Expression left_expr = left == null ? null : left.GetTypeExpression ();
799 if (current_attr_target == String.Empty)
801 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
802 // FIXME: supply "nameEscaped" parameter here.
803 $$ = new GlobalAttribute (current_namespace, current_attr_target,
804 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
806 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
811 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
814 opt_attribute_arguments
815 : /* empty */ { $$ = null; }
816 | OPEN_PARENS attribute_arguments CLOSE_PARENS
824 : /* empty */ { $$ = null; }
825 | positional_or_named_argument
827 Arguments a = new Arguments (4);
828 a.Add ((Argument) $1);
829 $$ = new Arguments [] { a, null };
831 | named_attribute_argument
833 Arguments a = new Arguments (4);
834 a.Add ((Argument) $1);
835 $$ = new Arguments [] { null, a };
837 | attribute_arguments COMMA positional_or_named_argument
839 Arguments[] o = (Arguments[]) $1;
841 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
842 o [0] = new Arguments (4);
845 Arguments args = ((Arguments) o [0]);
846 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
847 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
849 args.Add ((Argument) $3);
851 | attribute_arguments COMMA named_attribute_argument
853 Arguments[] o = (Arguments[]) $1;
855 o [1] = new Arguments (4);
858 ((Arguments) o [1]).Add ((Argument) $3);
862 positional_or_named_argument
865 $$ = new Argument ((Expression) $1);
870 named_attribute_argument
871 : IDENTIFIER ASSIGN expression
873 $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);
878 : IDENTIFIER COLON expression
880 if (RootContext.Version <= LanguageVersion.V_3)
881 Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
883 $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);
889 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
892 opt_class_member_declarations
894 | class_member_declarations
897 class_member_declarations
898 : class_member_declaration
899 | class_member_declarations
900 class_member_declaration
903 class_member_declaration
904 : constant_declaration // done
905 | field_declaration // done
906 | method_declaration // done
907 | property_declaration // done
908 | event_declaration // done
909 | indexer_declaration // done
910 | operator_declaration // done
911 | constructor_declaration // done
912 | destructor_declaration // done
916 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
917 GetSymbolName (yyToken));
919 lexer.parsing_generic_declaration = false;
929 lexer.ConstraintsParsing = true;
931 type_declaration_name
933 MemberName name = MakeName ((MemberName) $6);
934 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
937 opt_type_parameter_constraints_clauses
939 lexer.ConstraintsParsing = false;
941 current_class.SetParameterInfo ((ArrayList) $9);
943 if (RootContext.Documentation != null)
944 current_container.DocComment = Lexer.consume_doc_comment ();
948 --lexer.parsing_declaration;
949 if (RootContext.Documentation != null)
950 Lexer.doc_state = XmlCommentState.Allowed;
954 $$ = pop_current_class ();
956 | opt_attributes opt_modifiers opt_partial STRUCT error {
957 CheckIdentifierToken (yyToken, GetLocation ($5));
964 if (RootContext.Documentation != null)
965 Lexer.doc_state = XmlCommentState.Allowed;
967 opt_struct_member_declarations CLOSE_BRACE
970 opt_struct_member_declarations
972 | struct_member_declarations
975 struct_member_declarations
976 : struct_member_declaration
977 | struct_member_declarations struct_member_declaration
980 struct_member_declaration
981 : constant_declaration
984 | property_declaration
986 | indexer_declaration
987 | operator_declaration
988 | constructor_declaration
992 * This is only included so we can flag error 575:
993 * destructors only allowed on class types
995 | destructor_declaration
1003 constant_declarators
1006 int modflags = (int) $2;
1007 foreach (VariableDeclaration constant in (ArrayList) $5){
1008 Location l = constant.Location;
1009 if ((modflags & Modifiers.STATIC) != 0) {
1010 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
1014 Const c = new Const (
1015 current_class, (FullNamedExpression) $4, (string) constant.identifier,
1016 (Expression) constant.expression_or_array_initializer, modflags,
1017 (Attributes) $1, l);
1019 if (RootContext.Documentation != null) {
1020 c.DocComment = Lexer.consume_doc_comment ();
1021 Lexer.doc_state = XmlCommentState.Allowed;
1023 current_container.AddConstant (c);
1028 constant_declarators
1029 : constant_declarator
1031 ArrayList constants = new ArrayList (4);
1036 | constant_declarators COMMA constant_declarator
1039 ArrayList constants = (ArrayList) $1;
1048 ++lexer.parsing_block;
1050 constant_initializer
1052 --lexer.parsing_block;
1053 $$ = new VariableDeclaration ((LocatedToken) $1, $4);
1057 // A const field requires a value to be provided
1058 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1063 constant_initializer
1064 : constant_expression
1072 variable_declarators
1075 FullNamedExpression type = (FullNamedExpression) $3;
1076 if (type == TypeManager.system_void_expr)
1077 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1081 current_array_type = null;
1083 foreach (VariableMemberDeclaration var in (ArrayList) $4){
1084 Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1086 field.Initializer = var.expression_or_array_initializer;
1088 if (RootContext.Documentation != null) {
1089 field.DocComment = Lexer.consume_doc_comment ();
1090 Lexer.doc_state = XmlCommentState.Allowed;
1092 current_container.AddField (field);
1093 $$ = field; // FIXME: might be better if it points to the top item
1100 fixed_variable_declarators
1103 FullNamedExpression type = (FullNamedExpression) $4;
1107 current_array_type = null;
1109 foreach (VariableDeclaration var in (ArrayList) $5) {
1110 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1111 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1113 if (RootContext.Documentation != null) {
1114 field.DocComment = Lexer.consume_doc_comment ();
1115 Lexer.doc_state = XmlCommentState.Allowed;
1117 current_container.AddField (field);
1118 $$ = field; // FIXME: might be better if it points to the top item
1127 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1131 fixed_variable_declarators
1132 : fixed_variable_declarator
1134 ArrayList decl = new ArrayList (2);
1138 | fixed_variable_declarators COMMA fixed_variable_declarator
1140 ArrayList decls = (ArrayList) $1;
1146 fixed_variable_declarator
1147 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1149 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1151 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1153 Report.Error (443, lexer.Location, "Value or constant expected");
1154 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1159 local_variable_declarators
1160 : local_variable_declarator
1162 ArrayList decl = new ArrayList (4);
1167 | local_variable_declarators COMMA local_variable_declarator
1169 ArrayList decls = (ArrayList) $1;
1175 local_variable_declarator
1176 : IDENTIFIER ASSIGN local_variable_initializer
1178 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1182 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1184 | IDENTIFIER variable_bad_array
1190 local_variable_initializer
1193 | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
1195 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1199 $$ = new ArglistAccess ((Location) $1);
1201 | STACKALLOC simple_type
1203 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1204 $$ = new StackAlloc ((Expression) $2, null, (Location) $1);
1208 variable_declarators
1209 : variable_declarator
1211 ArrayList decl = new ArrayList (4);
1216 | variable_declarators COMMA variable_declarator
1218 ArrayList decls = (ArrayList) $1;
1225 : member_declaration_name ASSIGN
1227 ++lexer.parsing_block;
1228 lexer.parsing_generic_declaration = false;
1230 variable_initializer
1232 --lexer.parsing_block;
1233 $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
1235 | member_declaration_name
1237 lexer.parsing_generic_declaration = false;
1238 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1240 | member_declaration_name variable_bad_array
1242 lexer.parsing_generic_declaration = false;
1248 : OPEN_BRACKET opt_expression CLOSE_BRACKET
1250 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1251 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1255 variable_initializer
1262 if (RootContext.Documentation != null)
1263 Lexer.doc_state = XmlCommentState.NotAllowed;
1267 Method method = (Method) $1;
1268 method.Block = (ToplevelBlock) $3;
1269 current_container.AddMethod (method);
1271 if (current_container.Kind == Kind.Interface && method.Block != null) {
1272 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1275 current_generic_method = null;
1276 current_local_parameters = null;
1278 if (RootContext.Documentation != null)
1279 Lexer.doc_state = XmlCommentState.Allowed;
1287 method_declaration_name OPEN_PARENS
1289 valid_param_mod = ParameterModifierType.All;
1291 opt_formal_parameter_list CLOSE_PARENS
1293 lexer.ConstraintsParsing = true;
1295 opt_type_parameter_constraints_clauses
1297 lexer.ConstraintsParsing = false;
1298 valid_param_mod = 0;
1299 MemberName name = (MemberName) $4;
1300 current_local_parameters = (ParametersCompiled) $7;
1302 if ($10 != null && name.TypeArguments == null)
1303 Report.Error (80, lexer.Location,
1304 "Constraints are not allowed on non-generic declarations");
1308 GenericMethod generic = null;
1309 if (name.TypeArguments != null) {
1310 generic = new GenericMethod (current_namespace, current_class, name,
1311 (FullNamedExpression) $3, current_local_parameters);
1313 generic.SetParameterInfo ((ArrayList) $10);
1316 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1317 name, current_local_parameters, (Attributes) $1);
1319 current_generic_method = generic;
1321 if (RootContext.Documentation != null)
1322 method.DocComment = Lexer.consume_doc_comment ();
1329 VOID method_declaration_name
1332 valid_param_mod = ParameterModifierType.All;
1334 opt_formal_parameter_list CLOSE_PARENS
1336 lexer.ConstraintsParsing = true;
1338 opt_type_parameter_constraints_clauses
1340 lexer.ConstraintsParsing = false;
1341 valid_param_mod = 0;
1343 MemberName name = (MemberName) $5;
1344 current_local_parameters = (ParametersCompiled) $8;
1346 if ($10 != null && name.TypeArguments == null)
1347 Report.Error (80, lexer.Location,
1348 "Constraints are not allowed on non-generic declarations");
1351 GenericMethod generic = null;
1352 if (name.TypeArguments != null) {
1353 generic = new GenericMethod (current_namespace, current_class, name,
1354 TypeManager.system_void_expr, current_local_parameters);
1356 generic.SetParameterInfo ((ArrayList) $11);
1359 int modifiers = (int) $2;
1362 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1363 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1365 if ((modifiers & invalid_partial_mod) != 0) {
1366 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1367 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1368 modifiers &= ~invalid_partial_mod;
1371 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1372 Report.Error (751, name.Location, "A partial method must be declared within a " +
1373 "partial class or partial struct");
1376 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1378 method = new Method (current_class, generic, TypeManager.system_void_expr,
1379 modifiers, name, current_local_parameters, (Attributes) $1);
1381 current_generic_method = generic;
1383 if (RootContext.Documentation != null)
1384 method.DocComment = Lexer.consume_doc_comment ();
1391 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1393 MemberName name = (MemberName) $5;
1394 Report.Error (1585, name.Location,
1395 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1397 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1398 0, name, (ParametersCompiled) $7, (Attributes) $1);
1400 current_local_parameters = (ParametersCompiled) $7;
1402 if (RootContext.Documentation != null)
1403 method.DocComment = Lexer.consume_doc_comment ();
1411 | SEMICOLON { $$ = null; }
1414 opt_formal_parameter_list
1415 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1416 | formal_parameter_list
1419 formal_parameter_list
1422 ArrayList pars_list = (ArrayList) $1;
1424 Parameter [] pars = new Parameter [pars_list.Count];
1425 pars_list.CopyTo (pars);
1427 $$ = new ParametersCompiled (pars);
1429 | fixed_parameters COMMA parameter_array
1431 ArrayList pars_list = (ArrayList) $1;
1434 Parameter [] pars = new Parameter [pars_list.Count];
1435 pars_list.CopyTo (pars);
1437 $$ = new ParametersCompiled (pars);
1439 | fixed_parameters COMMA arglist_modifier
1441 ArrayList pars_list = (ArrayList) $1;
1442 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1444 Parameter [] pars = new Parameter [pars_list.Count];
1445 pars_list.CopyTo (pars);
1447 $$ = new ParametersCompiled (pars, true);
1449 | parameter_array COMMA error
1452 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1455 | fixed_parameters COMMA parameter_array COMMA error
1458 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1461 | arglist_modifier COMMA error
1463 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1466 | fixed_parameters COMMA ARGLIST COMMA error
1468 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1473 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1477 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1484 ArrayList pars = new ArrayList (4);
1485 Parameter p = (Parameter) $1;
1488 default_parameter_used = p.HasDefaultValue;
1491 | fixed_parameters COMMA fixed_parameter
1493 ArrayList pars = (ArrayList) $1;
1494 Parameter p = (Parameter) $3;
1496 if (p.HasExtensionMethodModifier)
1497 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1498 else if (!p.HasDefaultValue && default_parameter_used)
1499 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1501 default_parameter_used |= p.HasDefaultValue;
1510 opt_parameter_modifier
1514 LocatedToken lt = (LocatedToken) $4;
1515 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1518 opt_parameter_modifier
1520 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1522 LocatedToken lt = (LocatedToken) $4;
1523 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1527 opt_parameter_modifier
1531 Location l = GetLocation ($4);
1532 CheckIdentifierToken (yyToken, l);
1533 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1536 opt_parameter_modifier
1542 if (RootContext.Version <= LanguageVersion.V_3) {
1543 Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1546 Parameter.Modifier mod = (Parameter.Modifier) $2;
1547 if (mod != Parameter.Modifier.NONE) {
1549 case Parameter.Modifier.REF:
1550 case Parameter.Modifier.OUT:
1551 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1552 Parameter.GetModifierSignature (mod));
1555 case Parameter.Modifier.This:
1556 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1557 Parameter.GetModifierSignature (mod));
1560 throw new NotImplementedException (mod.ToString ());
1563 mod = Parameter.Modifier.NONE;
1566 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1567 Report.Error (1065, GetLocation ($6), "Optional parameter is not valid in this context");
1569 LocatedToken lt = (LocatedToken) $4;
1570 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1572 ((Parameter) $$).DefaultValue = (Expression) $6;
1576 opt_parameter_modifier
1577 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1578 | parameter_modifiers
1582 : parameter_modifier
1586 | parameter_modifiers parameter_modifier
1588 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1589 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1590 if (((Parameter.Modifier)$1 & p2) == p2) {
1591 Error_DuplicateParameterModifier (lexer.Location, p2);
1593 switch (mod & ~Parameter.Modifier.This) {
1594 case Parameter.Modifier.REF:
1595 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1597 case Parameter.Modifier.OUT:
1598 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1601 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1612 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1613 Error_ParameterModifierNotValid ("ref", (Location)$1);
1615 $$ = Parameter.Modifier.REF;
1619 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1620 Error_ParameterModifierNotValid ("out", (Location)$1);
1622 $$ = Parameter.Modifier.OUT;
1626 if ((valid_param_mod & ParameterModifierType.This) == 0)
1627 Error_ParameterModifierNotValid ("this", (Location)$1);
1629 if (RootContext.Version <= LanguageVersion.ISO_2)
1630 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1632 $$ = Parameter.Modifier.This;
1637 : opt_attributes params_modifier type IDENTIFIER
1639 LocatedToken lt = (LocatedToken) $4;
1640 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1642 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1644 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1646 LocatedToken lt = (LocatedToken) $4;
1647 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1649 | opt_attributes params_modifier type error {
1650 CheckIdentifierToken (yyToken, GetLocation ($4));
1658 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1659 Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1661 | PARAMS parameter_modifier
1663 Parameter.Modifier mod = (Parameter.Modifier)$2;
1664 if ((mod & Parameter.Modifier.This) != 0) {
1665 Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1667 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1670 | PARAMS params_modifier
1672 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1679 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1680 Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1684 property_declaration
1688 member_declaration_name
1690 if (RootContext.Documentation != null)
1691 tmpComment = Lexer.consume_doc_comment ();
1695 implicit_value_parameter_type = (FullNamedExpression) $3;
1696 lexer.PropertyParsing = true;
1698 accessor_declarations
1700 lexer.PropertyParsing = false;
1701 has_get = has_set = false;
1706 Accessors accessors = (Accessors) $8;
1707 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1708 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1709 bool order = accessors != null ? accessors.declared_in_reverse : false;
1711 MemberName name = (MemberName) $4;
1712 FullNamedExpression ptype = (FullNamedExpression) $3;
1714 prop = new Property (current_class, ptype, (int) $2,
1715 name, (Attributes) $1, get_block, set_block, order, current_block);
1717 if (ptype == TypeManager.system_void_expr)
1718 Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
1720 if (accessors == null)
1721 Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1723 if (current_container.Kind == Kind.Interface) {
1724 if (prop.Get.Block != null)
1725 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1727 if (prop.Set.Block != null)
1728 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1731 current_container.AddProperty (prop);
1732 implicit_value_parameter_type = null;
1734 if (RootContext.Documentation != null)
1735 prop.DocComment = ConsumeStoredComment ();
1740 accessor_declarations
1741 : get_accessor_declaration
1743 $$ = new Accessors ((Accessor) $1, null);
1745 | get_accessor_declaration accessor_declarations
1747 Accessors accessors = (Accessors) $2;
1748 accessors.get_or_add = (Accessor) $1;
1751 | set_accessor_declaration
1753 $$ = new Accessors (null, (Accessor) $1);
1755 | set_accessor_declaration accessor_declarations
1757 Accessors accessors = (Accessors) $2;
1758 accessors.set_or_remove = (Accessor) $1;
1759 accessors.declared_in_reverse = true;
1764 if (yyToken == Token.CLOSE_BRACE) {
1767 if (yyToken == Token.SEMICOLON)
1768 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1770 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1772 $$ = new Accessors (null, null);
1777 get_accessor_declaration
1778 : opt_attributes opt_modifiers GET
1780 // If this is not the case, then current_local_parameters has already
1781 // been set in indexer_declaration
1782 if (parsing_indexer == false)
1783 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1785 current_local_parameters = indexer_parameters;
1786 lexer.PropertyParsing = false;
1791 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1794 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1796 current_local_parameters = null;
1797 lexer.PropertyParsing = true;
1799 if (RootContext.Documentation != null)
1800 if (Lexer.doc_state == XmlCommentState.Error)
1801 Lexer.doc_state = XmlCommentState.NotAllowed;
1807 set_accessor_declaration
1808 : opt_attributes opt_modifiers SET
1810 Parameter implicit_value_parameter = new Parameter (
1811 implicit_value_parameter_type, "value",
1812 Parameter.Modifier.NONE, null, (Location) $3);
1814 if (!parsing_indexer) {
1815 current_local_parameters = new ParametersCompiled (new Parameter [] { implicit_value_parameter });
1817 current_local_parameters = ParametersCompiled.MergeGenerated (
1818 indexer_parameters, true, implicit_value_parameter, null);
1821 lexer.PropertyParsing = false;
1826 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1829 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1831 current_local_parameters = null;
1832 lexer.PropertyParsing = true;
1834 if (RootContext.Documentation != null
1835 && Lexer.doc_state == XmlCommentState.Error)
1836 Lexer.doc_state = XmlCommentState.NotAllowed;
1850 Error_SyntaxError (1043, yyToken);
1855 interface_declaration
1861 lexer.ConstraintsParsing = true;
1863 type_declaration_name
1865 MemberName name = MakeName ((MemberName) $6);
1866 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1869 opt_type_parameter_constraints_clauses
1871 lexer.ConstraintsParsing = false;
1873 current_class.SetParameterInfo ((ArrayList) $9);
1875 if (RootContext.Documentation != null) {
1876 current_container.DocComment = Lexer.consume_doc_comment ();
1877 Lexer.doc_state = XmlCommentState.Allowed;
1882 --lexer.parsing_declaration;
1883 if (RootContext.Documentation != null)
1884 Lexer.doc_state = XmlCommentState.Allowed;
1888 $$ = pop_current_class ();
1890 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1891 CheckIdentifierToken (yyToken, GetLocation ($5));
1897 opt_interface_member_declarations
1901 opt_interface_member_declarations
1903 | interface_member_declarations
1906 interface_member_declarations
1907 : interface_member_declaration
1908 | interface_member_declarations interface_member_declaration
1911 interface_member_declaration
1912 : constant_declaration
1914 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1918 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1920 | method_declaration
1921 | property_declaration
1923 | indexer_declaration
1924 | operator_declaration
1926 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1928 | constructor_declaration
1930 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1934 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1938 operator_declaration
1939 : opt_attributes opt_modifiers operator_declarator
1947 OperatorDeclaration decl = (OperatorDeclaration) $3;
1948 Operator op = new Operator (
1949 current_class, decl.optype, decl.ret_type, (int) $2,
1950 current_local_parameters,
1951 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1953 if (RootContext.Documentation != null) {
1954 op.DocComment = tmpComment;
1955 Lexer.doc_state = XmlCommentState.Allowed;
1958 // Note again, checking is done in semantic analysis
1959 current_container.AddOperator (op);
1961 current_local_parameters = null;
1967 | SEMICOLON { $$ = null; }
1971 : type_expression_or_array
1974 Report.Error (590, lexer.Location, "User-defined operators cannot return void");
1975 $$ = TypeManager.system_void_expr;
1980 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1982 valid_param_mod = ParameterModifierType.DefaultValue;
1984 opt_formal_parameter_list CLOSE_PARENS
1986 valid_param_mod = 0;
1988 Location loc = (Location) $2;
1989 Operator.OpType op = (Operator.OpType) $3;
1990 current_local_parameters = (ParametersCompiled)$6;
1992 int p_count = current_local_parameters.Count;
1994 if (op == Operator.OpType.Addition)
1995 op = Operator.OpType.UnaryPlus;
1996 else if (op == Operator.OpType.Subtraction)
1997 op = Operator.OpType.UnaryNegation;
2000 if (IsUnaryOperator (op)) {
2002 Report.Error (1020, loc, "Overloadable binary operator expected");
2003 } else if (p_count != 1) {
2004 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2005 Operator.GetName (op));
2009 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2010 Operator.GetName (op));
2011 } else if (p_count != 2) {
2012 Report.Error (1019, loc, "Overloadable unary operator expected");
2016 if (RootContext.Documentation != null) {
2017 tmpComment = Lexer.consume_doc_comment ();
2018 Lexer.doc_state = XmlCommentState.NotAllowed;
2021 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2023 | conversion_operator_declarator
2026 overloadable_operator
2028 : BANG { $$ = Operator.OpType.LogicalNot; }
2029 | TILDE { $$ = Operator.OpType.OnesComplement; }
2030 | OP_INC { $$ = Operator.OpType.Increment; }
2031 | OP_DEC { $$ = Operator.OpType.Decrement; }
2032 | TRUE { $$ = Operator.OpType.True; }
2033 | FALSE { $$ = Operator.OpType.False; }
2034 // Unary and binary:
2035 | PLUS { $$ = Operator.OpType.Addition; }
2036 | MINUS { $$ = Operator.OpType.Subtraction; }
2038 | STAR { $$ = Operator.OpType.Multiply; }
2039 | DIV { $$ = Operator.OpType.Division; }
2040 | PERCENT { $$ = Operator.OpType.Modulus; }
2041 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2042 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2043 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2044 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2045 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2046 | OP_EQ { $$ = Operator.OpType.Equality; }
2047 | OP_NE { $$ = Operator.OpType.Inequality; }
2048 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2049 | OP_LT { $$ = Operator.OpType.LessThan; }
2050 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2051 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2054 conversion_operator_declarator
2055 : IMPLICIT OPERATOR type OPEN_PARENS
2057 valid_param_mod = ParameterModifierType.DefaultValue;
2059 opt_formal_parameter_list CLOSE_PARENS
2061 valid_param_mod = 0;
2063 Location loc = (Location) $2;
2064 current_local_parameters = (ParametersCompiled)$6;
2066 if (RootContext.Documentation != null) {
2067 tmpComment = Lexer.consume_doc_comment ();
2068 Lexer.doc_state = XmlCommentState.NotAllowed;
2071 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2073 | EXPLICIT OPERATOR type OPEN_PARENS
2075 valid_param_mod = ParameterModifierType.DefaultValue;
2077 opt_formal_parameter_list CLOSE_PARENS
2079 valid_param_mod = 0;
2081 Location loc = (Location) $2;
2082 current_local_parameters = (ParametersCompiled)$6;
2084 if (RootContext.Documentation != null) {
2085 tmpComment = Lexer.consume_doc_comment ();
2086 Lexer.doc_state = XmlCommentState.NotAllowed;
2089 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2093 Error_SyntaxError (yyToken);
2094 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2098 Error_SyntaxError (yyToken);
2099 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2103 constructor_declaration
2104 : constructor_declarator
2107 Constructor c = (Constructor) $1;
2108 c.Block = (ToplevelBlock) $2;
2110 if (RootContext.Documentation != null)
2111 c.DocComment = ConsumeStoredComment ();
2113 current_container.AddConstructor (c);
2115 current_local_parameters = null;
2116 if (RootContext.Documentation != null)
2117 Lexer.doc_state = XmlCommentState.Allowed;
2121 constructor_declarator
2126 if (RootContext.Documentation != null) {
2127 tmpComment = Lexer.consume_doc_comment ();
2128 Lexer.doc_state = XmlCommentState.Allowed;
2131 valid_param_mod = ParameterModifierType.All;
2133 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2135 valid_param_mod = 0;
2136 current_local_parameters = (ParametersCompiled) $6;
2139 // start block here, so possible anonymous methods inside
2140 // constructor initializer can get correct parent block
2142 start_block (lexer.Location);
2144 opt_constructor_initializer
2146 LocatedToken lt = (LocatedToken) $3;
2147 int mods = (int) $2;
2148 ConstructorInitializer ci = (ConstructorInitializer) $9;
2150 Constructor c = new Constructor (current_class, lt.Value, mods,
2151 (Attributes) $1, current_local_parameters, ci, lt.Location);
2153 if (lt.Value != current_container.MemberName.Name) {
2154 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2155 } else if ((mods & Modifiers.STATIC) != 0) {
2156 if ((mods & Modifiers.Accessibility) != 0){
2157 Report.Error (515, c.Location,
2158 "`{0}': static constructor cannot have an access modifier",
2159 c.GetSignatureForError ());
2162 Report.Error (514, c.Location,
2163 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2164 c.GetSignatureForError ());
2175 | SEMICOLON { current_block = null; $$ = null; }
2178 opt_constructor_initializer
2180 | constructor_initializer
2183 constructor_initializer
2184 : COLON BASE OPEN_PARENS
2186 ++lexer.parsing_block;
2188 opt_argument_list CLOSE_PARENS
2190 --lexer.parsing_block;
2191 $$ = new ConstructorBaseInitializer ((Arguments) $5, (Location) $2);
2193 | COLON THIS OPEN_PARENS
2195 ++lexer.parsing_block;
2197 opt_argument_list CLOSE_PARENS
2199 --lexer.parsing_block;
2200 $$ = new ConstructorThisInitializer ((Arguments) $5, (Location) $2);
2203 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2208 destructor_declaration
2209 : opt_attributes opt_modifiers TILDE
2211 if (RootContext.Documentation != null) {
2212 tmpComment = Lexer.consume_doc_comment ();
2213 Lexer.doc_state = XmlCommentState.NotAllowed;
2216 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2218 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2220 LocatedToken lt = (LocatedToken) $5;
2221 if (lt.Value != current_container.MemberName.Name){
2222 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2223 } else if (current_container.Kind != Kind.Class){
2224 Report.Error (575, lt.Location, "Only class types can contain destructor");
2226 Destructor d = new Destructor (current_class, (int) $2,
2227 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2228 if (RootContext.Documentation != null)
2229 d.DocComment = ConsumeStoredComment ();
2231 d.Block = (ToplevelBlock) $8;
2232 current_container.AddMethod (d);
2235 current_local_parameters = null;
2242 EVENT type variable_declarators SEMICOLON
2244 current_array_type = null;
2245 foreach (VariableMemberDeclaration var in (ArrayList) $5) {
2247 EventField e = new EventField (
2248 current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
2250 if (var.expression_or_array_initializer != null) {
2251 if (current_container.Kind == Kind.Interface) {
2252 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2255 e.Initializer = var.expression_or_array_initializer;
2258 if (var.MemberName.Left != null) {
2259 Report.Error (71, e.Location,
2260 "`{0}': An explicit interface implementation of an event must use property syntax",
2261 e.GetSignatureForError ());
2264 current_container.AddEvent (e);
2266 if (RootContext.Documentation != null) {
2267 e.DocComment = Lexer.consume_doc_comment ();
2268 Lexer.doc_state = XmlCommentState.Allowed;
2274 EVENT type member_declaration_name
2277 implicit_value_parameter_type = (FullNamedExpression) $4;
2278 current_local_parameters = new ParametersCompiled (
2279 new Parameter (implicit_value_parameter_type, "value",
2280 Parameter.Modifier.NONE, null, GetLocation ($3)));
2282 lexer.EventParsing = true;
2284 event_accessor_declarations
2286 lexer.EventParsing = false;
2290 MemberName name = (MemberName) $5;
2292 if (current_container.Kind == Kind.Interface) {
2293 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2294 $8 = new Accessors (null, null);
2295 } else if ($8 == null) {
2296 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2297 current_container.GetSignatureForError (), name.GetSignatureForError ());
2298 $8 = new Accessors (null, null);
2301 Accessors accessors = (Accessors) $8;
2303 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2304 // CS0073 is already reported, so no CS0065 here.
2307 Event e = new EventProperty (
2308 current_class, (FullNamedExpression) $4, (int) $2, name,
2309 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2310 if (RootContext.Documentation != null) {
2311 e.DocComment = Lexer.consume_doc_comment ();
2312 Lexer.doc_state = XmlCommentState.Allowed;
2315 current_container.AddEvent (e);
2316 implicit_value_parameter_type = null;
2318 current_local_parameters = null;
2320 | opt_attributes opt_modifiers EVENT type member_declaration_name error
2322 MemberName mn = (MemberName) $5;
2323 if (mn.Left != null)
2324 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2326 if (RootContext.Documentation != null)
2327 Lexer.doc_state = XmlCommentState.Allowed;
2329 Error_SyntaxError (yyToken);
2334 event_accessor_declarations
2335 : add_accessor_declaration remove_accessor_declaration
2337 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2339 | remove_accessor_declaration add_accessor_declaration
2341 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2342 accessors.declared_in_reverse = true;
2345 | add_accessor_declaration { $$ = null; }
2346 | remove_accessor_declaration { $$ = null; }
2349 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2355 add_accessor_declaration
2356 : opt_attributes ADD
2358 lexer.EventParsing = false;
2362 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2363 lexer.EventParsing = true;
2366 | opt_attributes ADD error {
2367 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2370 | opt_attributes modifiers ADD {
2371 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2376 remove_accessor_declaration
2377 : opt_attributes REMOVE
2379 lexer.EventParsing = false;
2383 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2384 lexer.EventParsing = true;
2386 | opt_attributes REMOVE error {
2387 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2390 | opt_attributes modifiers REMOVE {
2391 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2397 : opt_attributes opt_modifiers
2398 member_type indexer_declaration_name OPEN_BRACKET
2400 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2402 opt_formal_parameter_list CLOSE_BRACKET
2405 valid_param_mod = 0;
2406 implicit_value_parameter_type = (FullNamedExpression) $3;
2407 indexer_parameters = (ParametersCompiled) $7;
2409 if (indexer_parameters.IsEmpty) {
2410 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2413 if (RootContext.Documentation != null) {
2414 tmpComment = Lexer.consume_doc_comment ();
2415 Lexer.doc_state = XmlCommentState.Allowed;
2418 lexer.PropertyParsing = true;
2419 parsing_indexer = true;
2422 accessor_declarations
2424 lexer.PropertyParsing = false;
2425 has_get = has_set = false;
2426 parsing_indexer = false;
2430 Accessors accessors = (Accessors) $11;
2431 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2432 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2433 bool order = accessors != null ? accessors.declared_in_reverse : false;
2435 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
2436 (MemberName)$4, (int) $2, (ParametersCompiled) $7, (Attributes) $1,
2437 get_block, set_block, order);
2439 if ($3 == TypeManager.system_void_expr)
2440 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2442 if (accessors == null)
2443 Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2445 if (current_container.Kind == Kind.Interface) {
2446 if (indexer.Get.Block != null)
2447 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2449 if (indexer.Set.Block != null)
2450 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2453 if (RootContext.Documentation != null)
2454 indexer.DocComment = ConsumeStoredComment ();
2456 current_container.AddIndexer (indexer);
2458 current_local_parameters = null;
2459 implicit_value_parameter_type = null;
2460 indexer_parameters = null;
2467 ENUM type_declaration_name
2469 if (RootContext.Documentation != null)
2470 enumTypeComment = Lexer.consume_doc_comment ();
2475 MemberName name = (MemberName) $4;
2476 if (name.IsGeneric) {
2477 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2480 name = MakeName (name);
2481 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2482 name, (Attributes) $1);
2484 if (RootContext.Documentation != null)
2485 e.DocComment = enumTypeComment;
2488 EnumMember em = null;
2489 foreach (VariableDeclaration ev in (ArrayList) $7) {
2490 em = new EnumMember (
2491 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2492 ev.OptAttributes, ev.Location);
2494 // if (RootContext.Documentation != null)
2495 em.DocComment = ev.DocComment;
2497 e.AddEnumMember (em);
2499 if (RootContext.EvalMode)
2500 undo.AddTypeContainer (current_container, e);
2502 current_container.AddTypeContainer (e);
2510 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2513 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2514 $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2515 $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2516 $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
2517 Enum.Error_1008 (GetLocation ($2));
2523 Error_TypeExpected (lexer.Location);
2530 if (RootContext.Documentation != null)
2531 Lexer.doc_state = XmlCommentState.Allowed;
2533 opt_enum_member_declarations
2535 // here will be evaluated after CLOSE_BLACE is consumed.
2536 if (RootContext.Documentation != null)
2537 Lexer.doc_state = XmlCommentState.Allowed;
2545 opt_enum_member_declarations
2546 : /* empty */ { $$ = new ArrayList (0); }
2547 | enum_member_declarations opt_comma { $$ = $1; }
2550 enum_member_declarations
2551 : enum_member_declaration
2553 ArrayList l = new ArrayList (4);
2558 | enum_member_declarations COMMA enum_member_declaration
2560 ArrayList l = (ArrayList) $1;
2568 enum_member_declaration
2569 : opt_attributes IDENTIFIER
2571 VariableDeclaration vd = new VariableDeclaration (
2572 (LocatedToken) $2, null, (Attributes) $1);
2574 if (RootContext.Documentation != null) {
2575 vd.DocComment = Lexer.consume_doc_comment ();
2576 Lexer.doc_state = XmlCommentState.Allowed;
2581 | opt_attributes IDENTIFIER
2583 ++lexer.parsing_block;
2584 if (RootContext.Documentation != null) {
2585 tmpComment = Lexer.consume_doc_comment ();
2586 Lexer.doc_state = XmlCommentState.NotAllowed;
2589 ASSIGN constant_expression
2591 --lexer.parsing_block;
2592 VariableDeclaration vd = new VariableDeclaration (
2593 (LocatedToken) $2, $5, (Attributes) $1);
2595 if (RootContext.Documentation != null)
2596 vd.DocComment = ConsumeStoredComment ();
2602 delegate_declaration
2606 member_type type_declaration_name
2609 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2611 opt_formal_parameter_list CLOSE_PARENS
2613 valid_param_mod = 0;
2615 MemberName name = MakeName ((MemberName) $5);
2616 ParametersCompiled p = (ParametersCompiled) $8;
2618 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2619 (int) $2, name, p, (Attributes) $1);
2621 if (RootContext.Documentation != null) {
2622 del.DocComment = Lexer.consume_doc_comment ();
2623 Lexer.doc_state = XmlCommentState.Allowed;
2626 current_container.AddDelegate (del);
2627 current_delegate = del;
2628 lexer.ConstraintsParsing = true;
2630 opt_type_parameter_constraints_clauses
2632 lexer.ConstraintsParsing = false;
2636 current_delegate.SetParameterInfo ((ArrayList) $11);
2637 $$ = current_delegate;
2639 current_delegate = null;
2650 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2651 Report.FeatureIsNotSupported (lexer.Location, "nullable types");
2652 else if (RootContext.Version < LanguageVersion.ISO_2)
2653 Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2659 namespace_or_type_name
2661 | qualified_alias_member IDENTIFIER opt_type_argument_list
2663 LocatedToken lt1 = (LocatedToken) $1;
2664 LocatedToken lt2 = (LocatedToken) $2;
2666 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2672 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2674 LocatedToken lt = (LocatedToken) $3;
2675 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2680 : IDENTIFIER opt_type_argument_list
2682 LocatedToken lt = (LocatedToken) $1;
2683 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2688 // Generics arguments (any type, without attributes)
2690 opt_type_argument_list
2691 : /* empty */ { $$ = null; }
2692 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2694 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2695 Report.FeatureIsNotSupported (lexer.Location, "generics");
2696 else if (RootContext.Version < LanguageVersion.ISO_2)
2697 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2701 | OP_GENERICS_LT error
2703 Error_TypeExpected (lexer.Location);
2704 $$ = new TypeArguments ();
2711 TypeArguments type_args = new TypeArguments ();
2712 type_args.Add ((FullNamedExpression) $1);
2715 | type_arguments COMMA type
2717 TypeArguments type_args = (TypeArguments) $1;
2718 type_args.Add ((FullNamedExpression) $3);
2724 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2726 type_declaration_name
2729 lexer.parsing_generic_declaration = true;
2731 opt_type_parameter_list
2733 lexer.parsing_generic_declaration = false;
2734 LocatedToken lt = (LocatedToken) $1;
2735 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2739 member_declaration_name
2740 : method_declaration_name
2742 MemberName mn = (MemberName)$1;
2743 if (mn.TypeArguments != null)
2744 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2745 mn.GetSignatureForError ()));
2749 method_declaration_name
2750 : type_declaration_name
2751 | explicit_interface IDENTIFIER opt_type_parameter_list
2753 lexer.parsing_generic_declaration = false;
2754 LocatedToken lt = (LocatedToken) $2;
2755 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2759 indexer_declaration_name
2762 lexer.parsing_generic_declaration = false;
2763 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2765 | explicit_interface THIS
2767 lexer.parsing_generic_declaration = false;
2768 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2773 : IDENTIFIER opt_type_argument_list DOT
2775 LocatedToken lt = (LocatedToken) $1;
2776 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2778 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2780 LocatedToken lt1 = (LocatedToken) $1;
2781 LocatedToken lt2 = (LocatedToken) $2;
2783 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2785 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2787 LocatedToken lt = (LocatedToken) $2;
2788 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2792 opt_type_parameter_list
2793 : /* empty */ { $$ = null; }
2794 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2796 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2797 Report.FeatureIsNotSupported (lexer.Location, "generics");
2798 else if (RootContext.Version < LanguageVersion.ISO_2)
2799 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2808 TypeArguments type_args = new TypeArguments ();
2809 type_args.Add ((FullNamedExpression)$1);
2812 | type_parameters COMMA type_parameter
2814 TypeArguments type_args = (TypeArguments) $1;
2815 type_args.Add ((FullNamedExpression)$3);
2821 : opt_attributes opt_type_parameter_variance IDENTIFIER
2823 LocatedToken lt = (LocatedToken)$3;
2824 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2828 if (GetTokenName (yyToken) == "type")
2829 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2831 Error_SyntaxError (yyToken);
2833 $$ = new TypeParameterName ("", null, lexer.Location);
2838 // All types where void is allowed
2841 : type_expression_or_array
2844 $$ = TypeManager.system_void_expr;
2851 lexer.parsing_generic_declaration = true;
2856 // A type which does not allow `void' to be used
2859 : type_expression_or_array
2862 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2863 $$ = TypeManager.system_void_expr;
2871 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2872 $$ = TypeManager.system_void_expr;
2876 type_expression_or_array
2878 | type_expression rank_specifiers
2880 string rank_specifiers = (string) $2;
2881 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2886 : namespace_or_type_name opt_nullable
2888 MemberName name = (MemberName) $1;
2891 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2893 if (name.Left == null && name.Name == "var")
2894 $$ = current_array_type = new VarExpr (name.Location);
2896 $$ = name.GetTypeExpression ();
2899 | builtin_types opt_nullable
2902 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2904 | type_expression STAR
2907 // Note that here only unmanaged types are allowed but we
2908 // can't perform checks during this phase - we do it during
2909 // semantic analysis.
2911 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2915 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2922 ArrayList types = new ArrayList (2);
2926 | type_list COMMA base_type_name
2928 ArrayList types = (ArrayList) $1;
2937 if ($1 is ComposedCast)
2938 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2943 Error_TypeExpected (lexer.Location);
2948 * replaces all the productions for isolating the various
2949 * simple types, but we need this to reuse it easily in variable_type
2952 : OBJECT { $$ = TypeManager.system_object_expr; }
2953 | STRING { $$ = TypeManager.system_string_expr; }
2954 | BOOL { $$ = TypeManager.system_boolean_expr; }
2955 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2956 | FLOAT { $$ = TypeManager.system_single_expr; }
2957 | DOUBLE { $$ = TypeManager.system_double_expr; }
2962 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2963 | BYTE { $$ = TypeManager.system_byte_expr; }
2964 | SHORT { $$ = TypeManager.system_int16_expr; }
2965 | USHORT { $$ = TypeManager.system_uint16_expr; }
2966 | INT { $$ = TypeManager.system_int32_expr; }
2967 | UINT { $$ = TypeManager.system_uint32_expr; }
2968 | LONG { $$ = TypeManager.system_int64_expr; }
2969 | ULONG { $$ = TypeManager.system_uint64_expr; }
2970 | CHAR { $$ = TypeManager.system_char_expr; }
2977 $$ = TypeManager.system_void_expr;
2982 // Expressions, section 7.5
2987 : primary_expression_no_array_creation
2988 | array_creation_expression
2991 primary_expression_no_array_creation
2993 | IDENTIFIER opt_type_argument_list
2995 LocatedToken lt = (LocatedToken) $1;
2996 $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
2998 | IDENTIFIER GENERATE_COMPLETION {
2999 LocatedToken lt = (LocatedToken) $1;
3000 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3002 | parenthesized_expression
3003 | default_value_expression
3005 | invocation_expression
3009 | post_increment_expression
3010 | post_decrement_expression
3011 | object_or_delegate_creation_expression
3012 | anonymous_type_expression
3015 | checked_expression
3016 | unchecked_expression
3017 | pointer_member_access
3018 | anonymous_method_expression
3025 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3026 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
3027 | NULL { $$ = new NullLiteral (lexer.Location); }
3031 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3032 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3033 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3038 object v = lexer.Value;
3041 $$ = new IntLiteral ((int) v, lexer.Location);
3042 } else if (v is uint)
3043 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3045 $$ = new LongLiteral ((Int64) v, lexer.Location);
3046 else if (v is ulong)
3047 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3049 Console.WriteLine ("OOPS. Unexpected result from scanner");
3054 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3055 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3060 // Here is the trick, tokenizer may think that parens is a special but
3061 // parser is interested in open parens only, so we merge them.
3062 // Consider: if (a)foo ();
3067 | OPEN_PARENS_LAMBDA
3070 parenthesized_expression
3071 : OPEN_PARENS expression CLOSE_PARENS
3073 $$ = new ParenthesizedExpression ((Expression) $2);
3075 | OPEN_PARENS expression COMPLETE_COMPLETION
3077 $$ = new ParenthesizedExpression ((Expression) $2);
3082 : primary_expression DOT IDENTIFIER opt_type_argument_list
3084 LocatedToken lt = (LocatedToken) $3;
3085 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3087 | predefined_type DOT IDENTIFIER opt_type_argument_list
3089 LocatedToken lt = (LocatedToken) $3;
3090 // TODO: Location is wrong as some predefined types doesn't hold a location
3091 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3093 | qualified_alias_member IDENTIFIER opt_type_argument_list
3095 LocatedToken lt1 = (LocatedToken) $1;
3096 LocatedToken lt2 = (LocatedToken) $2;
3098 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3100 | primary_expression DOT GENERATE_COMPLETION {
3101 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3103 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3104 LocatedToken lt = (LocatedToken) $3;
3105 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3107 | predefined_type DOT GENERATE_COMPLETION
3109 // TODO: Location is wrong as some predefined types doesn't hold a location
3110 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3112 | predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
3113 LocatedToken lt = (LocatedToken) $3;
3114 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3118 invocation_expression
3119 : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
3121 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3125 opt_object_or_collection_initializer
3126 : /* empty */ { $$ = null; }
3127 | object_or_collection_initializer
3130 object_or_collection_initializer
3131 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3134 $$ = CollectionOrObjectInitializers.Empty;
3136 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3138 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3140 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3144 opt_member_initializer_list
3145 : /* empty */ { $$ = null; }
3146 | member_initializer_list
3152 member_initializer_list
3153 : member_initializer
3155 ArrayList a = new ArrayList ();
3159 | member_initializer_list COMMA member_initializer
3161 ArrayList a = (ArrayList)$1;
3168 : IDENTIFIER ASSIGN initializer_value
3170 LocatedToken lt = $1 as LocatedToken;
3171 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3173 | GENERATE_COMPLETION
3175 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3177 | non_assignment_expression opt_COMPLETE_COMPLETION {
3178 CompletionSimpleName csn = $1 as CompletionSimpleName;
3180 $$ = new CollectionElementInitializer ((Expression)$1);
3182 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3184 | OPEN_BRACE expression_list CLOSE_BRACE
3186 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3188 | OPEN_BRACE CLOSE_BRACE
3190 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3196 | object_or_collection_initializer
3200 : /* empty */ { $$ = null; }
3205 : argument_or_named_argument
3207 Arguments list = new Arguments (4);
3208 list.Add ((Argument) $1);
3211 | argument_list COMMA argument
3213 Arguments list = (Arguments) $1;
3214 if (list [list.Count - 1] is NamedArgument)
3215 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3217 list.Add ((Argument) $3);
3220 | argument_list COMMA named_argument
3222 Arguments list = (Arguments) $1;
3223 NamedArgument a = (NamedArgument) $3;
3224 for (int i = 0; i < list.Count; ++i) {
3225 NamedArgument na = list [i] as NamedArgument;
3226 if (na != null && na.Name.Value == a.Name.Value)
3227 Report.Error (1740, na.Name.Location, "Named argument `{0}' specified multiple times",
3234 | argument_list COMMA
3236 Report.Error (839, GetLocation ($2), "An argument is missing");
3239 | COMMA argument_or_named_argument
3241 Report.Error (839, GetLocation ($1), "An argument is missing");
3249 $$ = new Argument ((Expression) $1);
3251 | non_simple_argument
3254 argument_or_named_argument
3260 : REF variable_reference
3262 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3264 | OUT variable_reference
3266 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3268 | ARGLIST open_parens_any argument_list CLOSE_PARENS
3270 $$ = new Argument (new Arglist ((Arguments) $3, (Location) $1));
3272 | ARGLIST open_parens_any CLOSE_PARENS
3274 $$ = new Argument (new Arglist ((Location) $1));
3278 $$ = new Argument (new ArglistAccess ((Location) $1));
3287 : primary_expression_no_array_creation OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
3289 $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
3291 | array_creation_expression OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
3293 // LAMESPEC: Not allowed according to specification
3294 $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
3296 | primary_expression_no_array_creation rank_specifiers
3298 // So the super-trick is that primary_expression
3299 // can only be either a SimpleName or a MemberAccess.
3300 // The MemberAccess case arises when you have a fully qualified type-name like :
3302 // SimpleName is when you have
3305 Expression expr = (Expression) $1;
3306 if (expr is ComposedCast){
3307 $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3308 } else if (expr is ATypeNameExpression){
3310 // So we extract the string corresponding to the SimpleName
3313 $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3315 Error_ExpectingTypeName (expr);
3316 $$ = TypeManager.system_object_expr;
3319 current_array_type = (FullNamedExpression)$$;
3326 ArrayList list = new ArrayList (4);
3330 | expression_list COMMA expression
3332 ArrayList list = (ArrayList) $1;
3338 expression_list_arguments
3339 : expression_list_argument
3341 Arguments args = new Arguments (4);
3342 args.Add ((Argument) $1);
3345 | expression_list_arguments COMMA expression_list_argument
3347 Arguments args = (Arguments) $1;
3348 args.Add ((Argument) $3);
3353 expression_list_argument
3356 $$ = new Argument ((Expression) $1);
3364 $$ = new This (current_block, (Location) $1);
3369 : BASE DOT IDENTIFIER opt_type_argument_list
3371 LocatedToken lt = (LocatedToken) $3;
3372 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3374 | BASE OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
3376 $$ = new BaseIndexerAccess ((Arguments) $3, (Location) $1);
3380 Error_SyntaxError (yyToken);
3381 $$ = new BaseAccess (null, GetLocation ($2));
3385 post_increment_expression
3386 : primary_expression OP_INC
3388 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
3392 post_decrement_expression
3393 : primary_expression OP_DEC
3395 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
3399 object_or_delegate_creation_expression
3400 : new_expr_start open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3403 if (RootContext.Version <= LanguageVersion.ISO_2)
3404 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3406 $$ = new NewInitialize ((Expression) $1, (Arguments) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1));
3409 $$ = new New ((Expression) $1, (Arguments) $3, GetLocation ($1));
3411 | new_expr_start object_or_collection_initializer
3413 if (RootContext.Version <= LanguageVersion.ISO_2)
3414 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3416 $$ = new NewInitialize ((Expression) $1, null, (CollectionOrObjectInitializers) $2, GetLocation ($1));
3420 array_creation_expression
3421 : new_expr_start OPEN_BRACKET expression_list CLOSE_BRACKET
3422 opt_rank_specifier // shift/reduce on OPEN_BRACE
3423 opt_array_initializer
3425 $$ = new ArrayCreation ((FullNamedExpression) $1, (ArrayList) $3, (string) $5, (ArrayList) $6, GetLocation ($1));
3427 | new_expr_start rank_specifiers opt_array_initializer
3430 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3432 $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayList) $3, GetLocation ($1));
3434 | NEW rank_specifiers array_initializer
3436 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1));
3438 | new_expr_start error
3440 Report.Error (1526, GetLocation ($1), "A new expression requires () or [] after type");
3448 ++lexer.parsing_type;
3452 --lexer.parsing_type;
3457 anonymous_type_expression
3458 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3460 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3461 Report.FeatureIsNotSupported (lexer.Location, "anonymous types");
3462 else if (RootContext.Version <= LanguageVersion.ISO_2)
3463 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3465 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3469 anonymous_type_parameters_opt_comma
3470 : anonymous_type_parameters_opt
3471 | anonymous_type_parameters COMMA
3474 anonymous_type_parameters_opt
3476 | anonymous_type_parameters
3479 anonymous_type_parameters
3480 : anonymous_type_parameter
3482 ArrayList a = new ArrayList (4);
3486 | anonymous_type_parameters COMMA anonymous_type_parameter
3488 ArrayList a = (ArrayList) $1;
3494 anonymous_type_parameter
3495 : IDENTIFIER ASSIGN variable_initializer
3497 LocatedToken lt = (LocatedToken)$1;
3498 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3502 LocatedToken lt = (LocatedToken)$1;
3503 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3504 lt.Value, lt.Location);
3506 | BASE DOT IDENTIFIER opt_type_argument_list
3508 LocatedToken lt = (LocatedToken) $3;
3509 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3510 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3514 MemberAccess ma = (MemberAccess) $1;
3515 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3519 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3520 "Anonymous type members must be a member assignment, simple name or member access expression");
3535 opt_rank_specifier_or_nullable
3543 | opt_nullable rank_specifiers
3546 $$ = "?" + (string) $2;
3554 | rank_specifier rank_specifiers
3556 $$ = (string) $2 + (string) $1;
3561 : OPEN_BRACKET CLOSE_BRACKET
3565 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3567 $$ = "[" + (string) $2 + "]";
3569 | OPEN_BRACKET error CLOSE_BRACKET
3571 ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1));
3581 | dim_separators COMMA
3583 $$ = (string) $1 + ",";
3587 opt_array_initializer
3599 : OPEN_BRACE CLOSE_BRACE
3601 ArrayList list = new ArrayList (4);
3604 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3606 $$ = (ArrayList) $2;
3610 variable_initializer_list
3611 : variable_initializer
3613 ArrayList list = new ArrayList (4);
3617 | variable_initializer_list COMMA variable_initializer
3619 ArrayList list = (ArrayList) $1;
3625 Error_SyntaxError (yyToken);
3626 $$ = new ArrayList ();
3633 pushed_current_array_type = current_array_type;
3634 lexer.TypeOfParsing = true;
3636 open_parens_any typeof_type_expression CLOSE_PARENS
3638 lexer.TypeOfParsing = false;
3639 Expression type = (Expression)$4;
3640 if (type == TypeManager.system_void_expr)
3641 $$ = new TypeOfVoid ((Location) $1);
3643 $$ = new TypeOf (type, (Location) $1);
3644 current_array_type = pushed_current_array_type;
3648 typeof_type_expression
3653 Error_TypeExpected (lexer.Location);
3659 : IDENTIFIER generic_dimension
3661 LocatedToken lt = (LocatedToken) $1;
3663 $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
3665 | qualified_alias_member IDENTIFIER generic_dimension
3667 LocatedToken lt1 = (LocatedToken) $1;
3668 LocatedToken lt2 = (LocatedToken) $2;
3670 $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
3672 | unbound_type_name DOT IDENTIFIER
3674 LocatedToken lt = (LocatedToken) $3;
3676 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3678 | unbound_type_name DOT IDENTIFIER generic_dimension
3680 LocatedToken lt = (LocatedToken) $3;
3682 $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3684 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3686 LocatedToken lt = (LocatedToken) $3;
3687 MemberName name = (MemberName) $1;
3689 $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3696 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3697 Report.FeatureIsNotSupported (lexer.Location, "generics");
3698 else if (RootContext.Version < LanguageVersion.ISO_2)
3699 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3705 qualified_alias_member
3706 : IDENTIFIER DOUBLE_COLON
3708 LocatedToken lt = (LocatedToken) $1;
3709 if (RootContext.Version == LanguageVersion.ISO_1)
3710 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3717 : SIZEOF open_parens_any type CLOSE_PARENS {
3718 $$ = new SizeOf ((Expression) $3, (Location) $1);
3723 : CHECKED open_parens_any expression CLOSE_PARENS
3725 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3729 unchecked_expression
3730 : UNCHECKED open_parens_any expression CLOSE_PARENS
3732 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3736 pointer_member_access
3737 : primary_expression OP_PTR IDENTIFIER
3740 LocatedToken lt = (LocatedToken) $3;
3742 deref = new Indirection ((Expression) $1, lt.Location);
3743 $$ = new MemberAccess (deref, lt.Value);
3747 anonymous_method_expression
3748 : DELEGATE opt_anonymous_method_signature
3750 start_anonymous (false, (ParametersCompiled) $2, (Location) $1);
3754 $$ = end_anonymous ((ToplevelBlock) $4);
3758 opt_anonymous_method_signature
3761 $$ = ParametersCompiled.Undefined;
3763 | anonymous_method_signature
3766 anonymous_method_signature
3769 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3771 opt_formal_parameter_list CLOSE_PARENS
3773 valid_param_mod = 0;
3778 default_value_expression
3779 : DEFAULT open_parens_any type CLOSE_PARENS
3781 if (RootContext.Version < LanguageVersion.ISO_2)
3782 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3784 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3789 : primary_expression
3790 | BANG prefixed_unary_expression
3792 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
3794 | TILDE prefixed_unary_expression
3796 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
3802 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3804 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3806 | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
3808 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3813 // The idea to split this out is from Rhys' grammar
3814 // to solve the problem with casts.
3816 prefixed_unary_expression
3818 | PLUS prefixed_unary_expression
3820 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
3822 | MINUS prefixed_unary_expression
3824 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
3826 | OP_INC prefixed_unary_expression
3828 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
3830 | OP_DEC prefixed_unary_expression
3832 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
3834 | STAR prefixed_unary_expression
3836 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3838 | BITWISE_AND prefixed_unary_expression
3840 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
3844 multiplicative_expression
3845 : prefixed_unary_expression
3846 | multiplicative_expression STAR prefixed_unary_expression
3848 $$ = new Binary (Binary.Operator.Multiply,
3849 (Expression) $1, (Expression) $3);
3851 | multiplicative_expression DIV prefixed_unary_expression
3853 $$ = new Binary (Binary.Operator.Division,
3854 (Expression) $1, (Expression) $3);
3856 | multiplicative_expression PERCENT prefixed_unary_expression
3858 $$ = new Binary (Binary.Operator.Modulus,
3859 (Expression) $1, (Expression) $3);
3864 : multiplicative_expression
3865 | additive_expression PLUS multiplicative_expression
3867 $$ = new Binary (Binary.Operator.Addition,
3868 (Expression) $1, (Expression) $3);
3870 | additive_expression MINUS multiplicative_expression
3872 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3874 | parenthesized_expression MINUS multiplicative_expression
3876 // Shift/Reduce conflict
3877 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3879 | additive_expression AS type
3881 $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
3883 | additive_expression IS type
3885 $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
3890 : additive_expression
3891 | shift_expression OP_SHIFT_LEFT additive_expression
3893 $$ = new Binary (Binary.Operator.LeftShift,
3894 (Expression) $1, (Expression) $3);
3896 | shift_expression OP_SHIFT_RIGHT additive_expression
3898 $$ = new Binary (Binary.Operator.RightShift,
3899 (Expression) $1, (Expression) $3);
3903 relational_expression
3905 | relational_expression OP_LT shift_expression
3907 $$ = new Binary (Binary.Operator.LessThan,
3908 (Expression) $1, (Expression) $3);
3910 | relational_expression OP_GT shift_expression
3912 $$ = new Binary (Binary.Operator.GreaterThan,
3913 (Expression) $1, (Expression) $3);
3915 | relational_expression OP_LE shift_expression
3917 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3918 (Expression) $1, (Expression) $3);
3920 | relational_expression OP_GE shift_expression
3922 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3923 (Expression) $1, (Expression) $3);
3928 : relational_expression
3929 | equality_expression OP_EQ relational_expression
3931 $$ = new Binary (Binary.Operator.Equality,
3932 (Expression) $1, (Expression) $3);
3934 | equality_expression OP_NE relational_expression
3936 $$ = new Binary (Binary.Operator.Inequality,
3937 (Expression) $1, (Expression) $3);
3942 : equality_expression
3943 | and_expression BITWISE_AND equality_expression
3945 $$ = new Binary (Binary.Operator.BitwiseAnd,
3946 (Expression) $1, (Expression) $3);
3950 exclusive_or_expression
3952 | exclusive_or_expression CARRET and_expression
3954 $$ = new Binary (Binary.Operator.ExclusiveOr,
3955 (Expression) $1, (Expression) $3);
3959 inclusive_or_expression
3960 : exclusive_or_expression
3961 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3963 $$ = new Binary (Binary.Operator.BitwiseOr,
3964 (Expression) $1, (Expression) $3);
3968 conditional_and_expression
3969 : inclusive_or_expression
3970 | conditional_and_expression OP_AND inclusive_or_expression
3972 $$ = new Binary (Binary.Operator.LogicalAnd,
3973 (Expression) $1, (Expression) $3);
3977 conditional_or_expression
3978 : conditional_and_expression
3979 | conditional_or_expression OP_OR conditional_and_expression
3981 $$ = new Binary (Binary.Operator.LogicalOr,
3982 (Expression) $1, (Expression) $3);
3986 null_coalescing_expression
3987 : conditional_or_expression
3988 | conditional_or_expression OP_COALESCING null_coalescing_expression
3990 if (RootContext.Version < LanguageVersion.ISO_2)
3991 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3993 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
3997 conditional_expression
3998 : null_coalescing_expression
3999 | null_coalescing_expression INTERR expression COLON expression
4001 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
4005 assignment_expression
4006 : prefixed_unary_expression ASSIGN expression
4008 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4010 | prefixed_unary_expression OP_MULT_ASSIGN expression
4012 $$ = new CompoundAssign (
4013 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4015 | prefixed_unary_expression OP_DIV_ASSIGN expression
4017 $$ = new CompoundAssign (
4018 Binary.Operator.Division, (Expression) $1, (Expression) $3);
4020 | prefixed_unary_expression OP_MOD_ASSIGN expression
4022 $$ = new CompoundAssign (
4023 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4025 | prefixed_unary_expression OP_ADD_ASSIGN expression
4027 $$ = new CompoundAssign (
4028 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4030 | prefixed_unary_expression OP_SUB_ASSIGN expression
4032 $$ = new CompoundAssign (
4033 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4035 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4037 $$ = new CompoundAssign (
4038 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4040 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4042 $$ = new CompoundAssign (
4043 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4045 | prefixed_unary_expression OP_AND_ASSIGN expression
4047 $$ = new CompoundAssign (
4048 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4050 | prefixed_unary_expression OP_OR_ASSIGN expression
4052 $$ = new CompoundAssign (
4053 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4055 | prefixed_unary_expression OP_XOR_ASSIGN expression
4057 $$ = new CompoundAssign (
4058 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4062 lambda_parameter_list
4065 ArrayList pars = new ArrayList (4);
4070 | lambda_parameter_list COMMA lambda_parameter
4072 ArrayList pars = (ArrayList) $1;
4073 Parameter p = (Parameter)$3;
4074 if (pars[0].GetType () != p.GetType ()) {
4075 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4084 : parameter_modifier type IDENTIFIER
4086 LocatedToken lt = (LocatedToken) $3;
4088 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4092 LocatedToken lt = (LocatedToken) $2;
4094 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4098 LocatedToken lt = (LocatedToken) $1;
4099 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4103 opt_lambda_parameter_list
4104 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4105 | lambda_parameter_list {
4106 ArrayList pars_list = (ArrayList) $1;
4107 $$ = new ParametersCompiled ((Parameter[])pars_list.ToArray (typeof (Parameter)));
4111 lambda_expression_body
4113 start_block (lexer.Location);
4117 Block b = end_block (lexer.Location);
4118 b.AddStatement (new ContextualReturn ((Expression) $2));
4129 LocatedToken lt = (LocatedToken) $1;
4130 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4131 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
4133 lambda_expression_body
4135 $$ = end_anonymous ((ToplevelBlock) $4);
4137 | OPEN_PARENS_LAMBDA
4139 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4141 opt_lambda_parameter_list CLOSE_PARENS ARROW
4143 valid_param_mod = 0;
4144 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4146 lambda_expression_body
4148 $$ = end_anonymous ((ToplevelBlock) $7);
4153 : assignment_expression
4154 | non_assignment_expression
4157 non_assignment_expression
4158 : conditional_expression
4180 lexer.ConstraintsParsing = true;
4182 type_declaration_name
4184 MemberName name = MakeName ((MemberName) $6);
4185 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4188 opt_type_parameter_constraints_clauses
4190 lexer.ConstraintsParsing = false;
4192 current_class.SetParameterInfo ((ArrayList) $9);
4194 if (RootContext.Documentation != null) {
4195 current_container.DocComment = Lexer.consume_doc_comment ();
4196 Lexer.doc_state = XmlCommentState.Allowed;
4201 --lexer.parsing_declaration;
4202 if (RootContext.Documentation != null)
4203 Lexer.doc_state = XmlCommentState.Allowed;
4207 $$ = pop_current_class ();
4215 { $$ = $1; } // location
4219 : /* empty */ { $$ = (int) 0; }
4225 | modifiers modifier
4230 if ((m1 & m2) != 0) {
4231 Location l = lexer.Location;
4232 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4234 $$ = (int) (m1 | m2);
4242 if (current_container == RootContext.ToplevelTypes)
4243 Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
4245 | PUBLIC { $$ = Modifiers.PUBLIC; }
4246 | PROTECTED { $$ = Modifiers.PROTECTED; }
4247 | INTERNAL { $$ = Modifiers.INTERNAL; }
4248 | PRIVATE { $$ = Modifiers.PRIVATE; }
4249 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4250 | SEALED { $$ = Modifiers.SEALED; }
4251 | STATIC { $$ = Modifiers.STATIC; }
4252 | READONLY { $$ = Modifiers.READONLY; }
4253 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4254 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4255 | EXTERN { $$ = Modifiers.EXTERN; }
4256 | VOLATILE { $$ = Modifiers.VOLATILE; }
4257 | UNSAFE { $$ = Modifiers.UNSAFE; }
4266 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4269 opt_type_parameter_constraints_clauses
4270 : /* empty */ { $$ = null; }
4271 | type_parameter_constraints_clauses
4275 type_parameter_constraints_clauses
4276 : type_parameter_constraints_clause {
4277 ArrayList constraints = new ArrayList (1);
4278 constraints.Add ($1);
4281 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4282 ArrayList constraints = (ArrayList) $1;
4283 Constraints new_constraint = (Constraints)$2;
4285 foreach (Constraints c in constraints) {
4286 if (new_constraint.TypeParameter == c.TypeParameter) {
4287 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4288 new_constraint.TypeParameter);
4292 constraints.Add (new_constraint);
4297 type_parameter_constraints_clause
4298 : WHERE IDENTIFIER COLON type_parameter_constraints {
4299 LocatedToken lt = (LocatedToken) $2;
4300 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4304 type_parameter_constraints
4305 : type_parameter_constraint {
4306 ArrayList constraints = new ArrayList (1);
4307 constraints.Add ($1);
4310 | type_parameter_constraints COMMA type_parameter_constraint {
4311 ArrayList constraints = (ArrayList) $1;
4313 constraints.Add ($3);
4318 type_parameter_constraint
4320 | NEW OPEN_PARENS CLOSE_PARENS {
4321 $$ = SpecialConstraint.Constructor;
4324 $$ = SpecialConstraint.ReferenceType;
4327 $$ = SpecialConstraint.ValueType;
4331 opt_type_parameter_variance
4336 | type_parameter_variance
4338 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
4339 Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
4340 else if (RootContext.Version <= LanguageVersion.V_3)
4341 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4347 type_parameter_variance
4350 $$ = Variance.Covariant;
4354 $$ = Variance.Contravariant;
4363 // A block is "contained" on the following places:
4365 // property_declaration as part of the accessor body (get/set)
4366 // operator_declaration
4367 // constructor_declaration
4368 // destructor_declaration
4369 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4374 ++lexer.parsing_block;
4375 start_block ((Location) $1);
4377 opt_statement_list block_end
4386 --lexer.parsing_block;
4387 $$ = end_block ((Location) $1);
4389 | COMPLETE_COMPLETION
4391 --lexer.parsing_block;
4392 $$ = end_block (lexer.Location);
4400 ++lexer.parsing_block;
4401 current_block.StartLocation = GetLocation ($1);
4403 opt_statement_list CLOSE_BRACE
4405 --lexer.parsing_block;
4406 $$ = end_block ((Location) $4);
4417 | statement_list statement
4421 : declaration_statement
4423 if ($1 != null && (Block) $1 != current_block){
4424 current_block.AddStatement ((Statement) $1);
4425 current_block = (Block) $1;
4428 | valid_declaration_statement
4430 current_block.AddStatement ((Statement) $1);
4436 // The interactive_statement and its derivatives are only
4437 // used to provide a special version of `expression_statement'
4438 // that has a side effect of assigning the expression to
4441 interactive_statement_list
4442 : interactive_statement
4443 | interactive_statement_list interactive_statement
4446 interactive_statement
4447 : declaration_statement
4449 if ($1 != null && (Block) $1 != current_block){
4450 current_block.AddStatement ((Statement) $1);
4451 current_block = (Block) $1;
4454 | interactive_valid_declaration_statement
4456 current_block.AddStatement ((Statement) $1);
4461 valid_declaration_statement
4464 | expression_statement
4465 | selection_statement
4466 | iteration_statement
4470 | unchecked_statement
4477 interactive_valid_declaration_statement
4480 | interactive_expression_statement
4481 | selection_statement
4482 | iteration_statement
4486 | unchecked_statement
4494 : valid_declaration_statement
4495 | declaration_statement
4497 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4502 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4510 $$ = EmptyStatement.Value;
4517 LocatedToken lt = (LocatedToken) $1;
4518 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4520 if (current_block.AddLabel (labeled))
4521 current_block.AddStatement (labeled);
4526 declaration_statement
4527 : local_variable_declaration SEMICOLON
4529 current_array_type = null;
4531 DictionaryEntry de = (DictionaryEntry) $1;
4532 Expression e = (Expression) de.Key;
4534 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4538 | local_constant_declaration SEMICOLON
4540 current_array_type = null;
4542 DictionaryEntry de = (DictionaryEntry) $1;
4544 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4550 * The following is from Rhys' grammar:
4551 * > Types in local variable declarations must be recognized as
4552 * > expressions to prevent reduce/reduce errors in the grammar.
4553 * > The expressions are converted into types during semantic analysis.
4556 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4558 // FIXME: Do something smart here regarding the composition of the type.
4560 // Ok, the above "primary_expression" is there to get rid of
4561 // both reduce/reduce and shift/reduces in the grammar, it should
4562 // really just be "type_name". If you use type_name, a reduce/reduce
4563 // creeps up. If you use namespace_or_type_name (which is all we need
4564 // really) two shift/reduces appear.
4567 // So the super-trick is that primary_expression
4568 // can only be either a SimpleName or a MemberAccess.
4569 // The MemberAccess case arises when you have a fully qualified type-name like :
4571 // SimpleName is when you have
4574 Expression expr = (Expression) $1;
4575 string rank_or_nullable = (string) $2;
4577 if (expr is ComposedCast){
4578 $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4579 } else if (expr is ATypeNameExpression){
4581 // So we extract the string corresponding to the SimpleName
4584 if (rank_or_nullable.Length == 0) {
4585 SimpleName sn = expr as SimpleName;
4586 if (sn != null && sn.Name == "var")
4587 $$ = current_array_type = new VarExpr (sn.Location);
4591 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4594 Error_ExpectingTypeName (expr);
4595 $$ = TypeManager.system_object_expr;
4598 | builtin_types opt_rank_specifier_or_nullable
4600 if ((string) $2 == "")
4603 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4605 | VOID opt_rank_specifier
4607 Expression.Error_VoidInvalidInTheContext (lexer.Location);
4608 $$ = TypeManager.system_void_expr;
4612 local_variable_pointer_type
4613 : primary_expression_no_array_creation STAR
4615 ATypeNameExpression expr = $1 as ATypeNameExpression;
4618 $$ = new ComposedCast (expr, "*");
4620 Error_ExpectingTypeName ((Expression)$1);
4624 | builtin_types STAR
4626 $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
4630 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4632 | local_variable_pointer_type STAR
4634 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4640 | local_variable_pointer_type opt_rank_specifier
4643 string rank = (string)$2;
4648 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
4655 local_variable_declaration
4656 : local_variable_type local_variable_declarators
4659 VarExpr ve = $1 as VarExpr;
4661 ve.VariableInitializer = (ArrayList)$2;
4663 $$ = new DictionaryEntry ($1, $2);
4669 local_constant_declaration
4670 : CONST variable_type constant_declarators
4673 $$ = new DictionaryEntry ($2, $3);
4679 expression_statement
4680 : statement_expression SEMICOLON { $$ = $1; }
4681 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4684 interactive_expression_statement
4685 : interactive_statement_expression SEMICOLON { $$ = $1; }
4686 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4690 // We have to do the wrapping here and not in the case above,
4691 // because statement_expression is used for example in for_statement
4693 statement_expression
4696 ExpressionStatement s = $1 as ExpressionStatement;
4698 ((Expression) $1).Error_InvalidExpressionStatement ();
4699 s = EmptyExpressionStatement.Instance;
4702 $$ = new StatementExpression (s);
4706 Error_SyntaxError (yyToken);
4711 interactive_statement_expression
4714 Expression expr = (Expression) $1;
4715 ExpressionStatement s;
4717 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4718 $$ = new StatementExpression (s);
4722 Error_SyntaxError (yyToken);
4733 : IF open_parens_any boolean_expression CLOSE_PARENS
4736 Location l = (Location) $1;
4738 $$ = new If ((Expression) $3, (Statement) $5, l);
4740 // FIXME: location for warning should be loc property of $5.
4741 if ($5 == EmptyStatement.Value)
4742 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4745 | IF open_parens_any boolean_expression CLOSE_PARENS
4746 embedded_statement ELSE embedded_statement
4748 Location l = (Location) $1;
4750 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4752 // FIXME: location for warning should be loc property of $5 and $7.
4753 if ($5 == EmptyStatement.Value)
4754 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4755 if ($7 == EmptyStatement.Value)
4756 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4761 : SWITCH open_parens_any
4763 if (switch_stack == null)
4764 switch_stack = new Stack (2);
4765 switch_stack.Push (current_block);
4767 expression CLOSE_PARENS
4770 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4771 current_block = (Block) switch_stack.Pop ();
4787 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4788 $$ = new ArrayList ();
4796 ArrayList sections = new ArrayList (4);
4801 | switch_sections switch_section
4803 ArrayList sections = (ArrayList) $1;
4813 current_block = current_block.CreateSwitchBlock (lexer.Location);
4817 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4824 ArrayList labels = new ArrayList (4);
4829 | switch_labels switch_label
4831 ArrayList labels = (ArrayList) ($1);
4839 : CASE constant_expression COLON
4841 $$ = new SwitchLabel ((Expression) $2, (Location) $1);
4845 $$ = new SwitchLabel (null, (Location) $1);
4857 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
4859 Location l = (Location) $1;
4860 $$ = new While ((Expression) $3, (Statement) $5, l);
4865 : DO embedded_statement
4866 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
4868 Location l = (Location) $1;
4870 $$ = new Do ((Statement) $2, (Expression) $5, l);
4875 : FOR open_parens_any opt_for_initializer SEMICOLON
4877 Location l = lexer.Location;
4879 Block assign_block = current_block;
4881 if ($3 is DictionaryEntry){
4882 DictionaryEntry de = (DictionaryEntry) $3;
4884 Expression type = (Expression) de.Key;
4885 ArrayList var_declarators = (ArrayList) de.Value;
4887 foreach (VariableDeclaration decl in var_declarators){
4891 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4895 Expression expr = decl.expression_or_array_initializer;
4897 LocalVariableReference var;
4898 var = new LocalVariableReference (assign_block, decl.identifier, l);
4901 Assign a = new SimpleAssign (var, expr, decl.Location);
4903 assign_block.AddStatement (new StatementExpression (a));
4907 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4908 // This can be referred to as $5 below.
4914 opt_for_condition SEMICOLON
4915 opt_for_iterator CLOSE_PARENS
4918 Location l = (Location) $1;
4920 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4922 current_block.AddStatement (f);
4924 $$ = end_block (lexer.Location);
4929 : /* empty */ { $$ = EmptyStatement.Value; }
4934 : local_variable_declaration
4935 | statement_expression_list
4939 : /* empty */ { $$ = null; }
4940 | boolean_expression
4944 : /* empty */ { $$ = EmptyStatement.Value; }
4949 : statement_expression_list
4952 statement_expression_list
4953 : statement_expression
4955 // CHANGE: was `null'
4956 Statement s = (Statement) $1;
4957 Block b = new Block (current_block, s.loc, lexer.Location);
4962 | statement_expression_list COMMA statement_expression
4964 Block b = (Block) $1;
4966 b.AddStatement ((Statement) $3);
4972 : FOREACH open_parens_any type IN expression CLOSE_PARENS
4974 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4977 | FOREACH open_parens_any type IDENTIFIER IN
4978 expression CLOSE_PARENS
4980 start_block (lexer.Location);
4981 Block foreach_block = current_block;
4983 LocatedToken lt = (LocatedToken) $4;
4984 Location l = lt.Location;
4985 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4987 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4989 // Get a writable reference to this read-only variable.
4991 // Note that the $$ here refers to the value of _this_ code block,
4992 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4993 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
5000 LocalVariableReference v = (LocalVariableReference) $8;
5001 Location l = (Location) $1;
5004 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
5005 current_block.AddStatement (f);
5008 $$ = end_block (lexer.Location);
5014 | continue_statement
5024 $$ = new Break ((Location) $1);
5029 : CONTINUE SEMICOLON
5031 $$ = new Continue ((Location) $1);
5036 : GOTO IDENTIFIER SEMICOLON
5038 LocatedToken lt = (LocatedToken) $2;
5039 $$ = new Goto (lt.Value, lt.Location);
5041 | GOTO CASE constant_expression SEMICOLON
5043 $$ = new GotoCase ((Expression) $3, (Location) $1);
5045 | GOTO DEFAULT SEMICOLON
5047 $$ = new GotoDefault ((Location) $1);
5052 : RETURN opt_expression SEMICOLON
5054 $$ = new Return ((Expression) $2, (Location) $1);
5059 : THROW opt_expression SEMICOLON
5061 $$ = new Throw ((Expression) $2, (Location) $1);
5066 : IDENTIFIER RETURN expression SEMICOLON
5068 LocatedToken lt = (LocatedToken) $1;
5069 string s = lt.Value;
5071 Report.Error (1003, lt.Location, "; expected");
5074 if (RootContext.Version == LanguageVersion.ISO_1){
5075 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5078 current_block.Toplevel.IsIterator = true;
5079 $$ = new Yield ((Expression) $3, lt.Location);
5081 | IDENTIFIER RETURN SEMICOLON
5083 Report.Error (1627, (Location) $2, "Expression expected after yield return");
5086 | IDENTIFIER BREAK SEMICOLON
5088 LocatedToken lt = (LocatedToken) $1;
5089 string s = lt.Value;
5091 Report.Error (1003, lt.Location, "; expected");
5094 if (RootContext.Version == LanguageVersion.ISO_1){
5095 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5099 current_block.Toplevel.IsIterator = true;
5100 $$ = new YieldBreak (lt.Location);
5110 : TRY block catch_clauses
5112 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
5114 | TRY block FINALLY block
5116 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
5118 | TRY block catch_clauses FINALLY block
5120 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
5124 Report.Error (1524, (Location) $1, "Expected catch or finally");
5132 ArrayList l = new ArrayList (4);
5137 | catch_clauses catch_clause
5139 ArrayList l = (ArrayList) $1;
5147 : /* empty */ { $$ = null; }
5152 : CATCH opt_catch_args
5154 Expression type = null;
5157 DictionaryEntry cc = (DictionaryEntry) $2;
5158 type = (Expression) cc.Key;
5159 LocatedToken lt = (LocatedToken) cc.Value;
5162 ArrayList one = new ArrayList (4);
5164 one.Add (new VariableDeclaration (lt, null));
5166 start_block (lexer.Location);
5167 current_block = declare_local_variables (type, one, lt.Location);
5171 Expression type = null;
5173 Block var_block = null;
5176 DictionaryEntry cc = (DictionaryEntry) $2;
5177 type = (Expression) cc.Key;
5178 LocatedToken lt = (LocatedToken) cc.Value;
5182 var_block = end_block (lexer.Location);
5186 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5191 : /* empty */ { $$ = null; }
5196 : open_parens_any type opt_identifier CLOSE_PARENS
5198 $$ = new DictionaryEntry ($2, $3);
5200 | open_parens_any CLOSE_PARENS
5202 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5209 $$ = new Checked ((Block) $2);
5216 $$ = new Unchecked ((Block) $2);
5223 RootContext.CheckUnsafeOption ((Location) $1);
5225 $$ = new Unsafe ((Block) $3);
5230 : FIXED open_parens_any
5231 type_and_void fixed_pointer_declarators
5234 ArrayList list = (ArrayList) $4;
5235 Expression type = (Expression) $3;
5236 Location l = (Location) $1;
5237 int top = list.Count;
5239 start_block (lexer.Location);
5241 for (int i = 0; i < top; i++){
5242 Pair p = (Pair) list [i];
5245 v = current_block.AddVariable (type, (string) p.First, l);
5249 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5257 Location l = (Location) $1;
5259 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5261 current_block.AddStatement (f);
5263 $$ = end_block (lexer.Location);
5267 fixed_pointer_declarators
5268 : fixed_pointer_declarator {
5269 ArrayList declarators = new ArrayList (4);
5271 declarators.Add ($1);
5274 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5276 ArrayList declarators = (ArrayList) $1;
5278 declarators.Add ($3);
5283 fixed_pointer_declarator
5284 : IDENTIFIER ASSIGN expression
5286 LocatedToken lt = (LocatedToken) $1;
5287 // FIXME: keep location
5288 $$ = new Pair (lt.Value, $3);
5292 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5298 : LOCK open_parens_any expression CLOSE_PARENS
5304 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5309 : USING open_parens_any local_variable_declaration CLOSE_PARENS
5311 start_block (lexer.Location);
5312 Block assign_block = current_block;
5314 DictionaryEntry de = (DictionaryEntry) $3;
5315 Location l = (Location) $1;
5317 Expression type = (Expression) de.Key;
5318 ArrayList var_declarators = (ArrayList) de.Value;
5320 Stack vars = new Stack ();
5322 foreach (VariableDeclaration decl in var_declarators) {
5323 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5326 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5328 Expression expr = decl.expression_or_array_initializer;
5330 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5333 LocalVariableReference var;
5335 // Get a writable reference to this read-only variable.
5336 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5338 // This is so that it is not a warning on using variables
5341 vars.Push (new DictionaryEntry (var, expr));
5343 // Assign a = new SimpleAssign (var, expr, decl.Location);
5344 // assign_block.AddStatement (new StatementExpression (a));
5347 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5348 // It can be referred to as $5 below.
5353 Statement stmt = (Statement) $6;
5354 Stack vars = (Stack) $5;
5355 Location l = (Location) $1;
5357 while (vars.Count > 0) {
5358 DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5359 stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5361 current_block.AddStatement (stmt);
5362 $$ = end_block (lexer.Location);
5364 | USING open_parens_any expression CLOSE_PARENS
5366 start_block (lexer.Location);
5370 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5371 $$ = end_block (lexer.Location);
5379 : first_from_clause query_body
5381 lexer.query_parsing = false;
5383 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5385 from.Tail.Next = (Linq.AQueryClause)$2;
5388 current_block.SetEndLocation (lexer.Location);
5389 current_block = current_block.Parent;
5391 | nested_from_clause query_body
5393 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5395 from.Tail.Next = (Linq.AQueryClause)$2;
5398 current_block.SetEndLocation (lexer.Location);
5399 current_block = current_block.Parent;
5404 : FROM_FIRST IDENTIFIER IN expression
5406 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5407 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5409 | FROM_FIRST type IDENTIFIER IN expression
5411 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5412 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5417 : FROM IDENTIFIER IN expression
5419 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5420 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5422 | FROM type IDENTIFIER IN expression
5424 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5425 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5430 : FROM IDENTIFIER IN
5432 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5436 LocatedToken lt = (LocatedToken) $2;
5437 $$ = new Linq.SelectMany (current_block.Toplevel, lt, (Expression)$5);
5439 current_block.SetEndLocation (lexer.Location);
5440 current_block = current_block.Parent;
5442 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5444 | FROM type IDENTIFIER IN
5446 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5450 LocatedToken lt = (LocatedToken) $3;
5451 FullNamedExpression type = (FullNamedExpression)$2;
5453 $$ = new Linq.SelectMany (current_block.Toplevel, lt, new Linq.Cast (type, (FullNamedExpression)$6));
5455 current_block.SetEndLocation (lexer.Location);
5456 current_block = current_block.Parent;
5458 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5463 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5465 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5468 head.Next = (Linq.AQueryClause)$3;
5471 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5472 clause.Tail.Next = head;
5480 select_or_group_clause
5483 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5487 $$ = new Linq.Select (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5489 current_block.SetEndLocation (lexer.Location);
5490 current_block = current_block.Parent;
5494 if (linq_clause_blocks == null)
5495 linq_clause_blocks = new Stack ();
5497 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5498 linq_clause_blocks.Push (current_block);
5502 current_block.SetEndLocation (lexer.Location);
5503 current_block = current_block.Parent;
5505 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5509 $$ = new Linq.GroupBy (current_block.Toplevel, (Expression)$3, (ToplevelBlock) linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5511 current_block.SetEndLocation (lexer.Location);
5512 current_block = current_block.Parent;
5516 opt_query_body_clauses
5518 | query_body_clauses
5523 | query_body_clauses query_body_clause
5525 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5539 : LET IDENTIFIER ASSIGN
5541 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5545 LocatedToken lt = (LocatedToken) $2;
5546 $$ = new Linq.Let (current_block.Toplevel, current_container, lt, (Expression)$5);
5548 current_block.SetEndLocation (lexer.Location);
5549 current_block = current_block.Parent;
5551 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5558 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5562 $$ = new Linq.Where (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5564 current_block.SetEndLocation (lexer.Location);
5565 current_block = current_block.Parent;
5570 : JOIN IDENTIFIER IN
5572 if (linq_clause_blocks == null)
5573 linq_clause_blocks = new Stack ();
5575 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5576 linq_clause_blocks.Push (current_block);
5580 current_block.SetEndLocation (lexer.Location);
5581 current_block = current_block.Parent;
5583 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5584 linq_clause_blocks.Push (current_block);
5588 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5589 current_block.SetEndLocation (lexer.Location);
5590 current_block = current_block.Parent;
5592 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, lexer.Location);
5594 expression opt_join_into
5596 LocatedToken lt = (LocatedToken) $2;
5598 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5599 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5602 $$ = new Linq.Join (block, lt, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
5604 $$ = new Linq.GroupJoin (block, lt, (Expression)$5, outer_selector, current_block.Toplevel,
5605 (LocatedToken) $12, GetLocation ($1));
5608 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5609 current_block.SetEndLocation (lexer.Location);
5610 current_block = current_block.Parent;
5613 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5615 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $12);
5617 | JOIN type IDENTIFIER IN
5619 if (linq_clause_blocks == null)
5620 linq_clause_blocks = new Stack ();
5622 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5623 linq_clause_blocks.Push (current_block);
5627 current_block.SetEndLocation (lexer.Location);
5628 current_block = current_block.Parent;
5630 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5631 linq_clause_blocks.Push (current_block);
5635 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5636 current_block.SetEndLocation (lexer.Location);
5637 current_block = current_block.Parent;
5639 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, lexer.Location);
5641 expression opt_join_into
5643 LocatedToken lt = (LocatedToken) $3;
5644 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5645 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5647 Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
5649 $$ = new Linq.Join (block, lt, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
5651 $$ = new Linq.GroupJoin (block, lt, cast, outer_selector, current_block.Toplevel,
5652 (LocatedToken) $13, GetLocation ($1));
5655 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5656 current_block.SetEndLocation (lexer.Location);
5657 current_block = current_block.Parent;
5660 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5662 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $13);
5677 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5681 current_block.SetEndLocation (lexer.Location);
5682 current_block = current_block.Parent;
5692 current_block.SetEndLocation (lexer.Location);
5693 current_block = current_block.Parent;
5695 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5699 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5706 | orderings_then_by COMMA
5708 current_block.SetEndLocation (lexer.Location);
5709 current_block = current_block.Parent;
5711 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5715 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5723 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5725 | expression ASCENDING
5727 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5729 | expression DESCENDING
5731 $$ = new Linq.OrderByDescending (current_block.Toplevel, (Expression)$1);
5738 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5740 | expression ASCENDING
5742 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5744 | expression DESCENDING
5746 $$ = new Linq.ThenByDescending (current_block.Toplevel, (Expression)$1);
5751 opt_query_continuation
5755 // query continuation block is not linked with query block but with block
5756 // before. This means each query can use same range variable names for
5757 // different identifiers.
5759 current_block.SetEndLocation (GetLocation ($1));
5760 current_block = current_block.Parent;
5762 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5766 $$ = new Linq.QueryExpression (current_block, (Linq.AQueryClause)$4);
5771 // Support for using the compiler as an interactive parser
5773 // The INTERACTIVE_PARSER token is first sent to parse our
5774 // productions; If the result is a Statement, the parsing
5775 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5776 // to setup the blocks in advance.
5778 // This setup is here so that in the future we can add
5779 // support for other constructs (type parsing, namespaces, etc)
5780 // that do not require a block to be setup in advance
5784 : EVAL_STATEMENT_PARSER EOF
5785 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5786 | EVAL_STATEMENT_PARSER {
5787 Evaluator.LoadAliases (current_namespace);
5789 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5790 Modifiers.PUBLIC, null), null);
5792 ArrayList baseclass_list = new ArrayList ();
5793 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5794 current_container.AddBasesForPart (current_class, baseclass_list);
5796 // (ref object retval)
5797 Parameter [] mpar = new Parameter [1];
5798 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5800 ParametersCompiled pars = new ParametersCompiled (mpar);
5801 current_local_parameters = pars;
5802 Method method = new Method (
5805 TypeManager.system_void_expr,
5806 Modifiers.PUBLIC | Modifiers.STATIC,
5807 new MemberName ("Host"),
5809 null /* attributes */);
5811 oob_stack.Push (method);
5812 ++lexer.parsing_block;
5813 start_block (lexer.Location);
5815 interactive_statement_list opt_COMPLETE_COMPLETION
5817 --lexer.parsing_block;
5818 Method method = (Method) oob_stack.Pop ();
5820 method.Block = (ToplevelBlock) end_block(lexer.Location);
5821 current_container.AddMethod (method);
5823 --lexer.parsing_declaration;
5824 InteractiveResult = pop_current_class ();
5825 current_local_parameters = null;
5827 | EVAL_COMPILATION_UNIT_PARSER {
5828 Evaluator.LoadAliases (current_namespace);
5830 interactive_compilation_unit
5833 interactive_compilation_unit
5834 : outer_declarations
5835 | outer_declarations global_attributes
5840 opt_COMPLETE_COMPLETION
5842 | COMPLETE_COMPLETION
5845 close_brace_or_complete_completion
5847 | COMPLETE_COMPLETION
5852 // A class used to pass around variable declarations and constants
5854 public class VariableDeclaration {
5855 public string identifier;
5856 public Expression expression_or_array_initializer;
5857 public Location Location;
5858 public Attributes OptAttributes;
5859 public string DocComment;
5861 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5863 this.identifier = lt.Value;
5864 if (eoai is ArrayList) {
5865 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5867 this.expression_or_array_initializer = (Expression)eoai;
5869 this.Location = lt.Location;
5870 this.OptAttributes = opt_attrs;
5873 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5878 class VariableMemberDeclaration
5880 public readonly MemberName MemberName;
5881 public Expression expression_or_array_initializer;
5883 public VariableMemberDeclaration (MemberName mn, object initializer)
5887 if (initializer is ArrayList) {
5888 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
5890 this.expression_or_array_initializer = (Expression)initializer;
5897 // A class used to hold info about an operator declarator
5899 struct OperatorDeclaration {
5900 public readonly Operator.OpType optype;
5901 public readonly FullNamedExpression ret_type;
5902 public readonly Location location;
5904 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5907 this.ret_type = ret_type;
5908 this.location = location;
5912 static void Error_ExpectingTypeName (Expression expr)
5914 if (expr is Invocation){
5915 Report.Error (1002, expr.Location, "Expecting `;'");
5917 expr.Error_InvalidExpressionStatement ();
5921 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5923 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5927 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5929 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5930 Parameter.GetModifierSignature (mod));
5933 static void Error_TypeExpected (Location loc)
5935 Report.Error (1031, loc, "Type expected");
5938 static void Error_NamedArgumentExpected (NamedArgument a)
5940 Report.Error (1738, a.Name.Location, "Named arguments must appear after the positional arguments");
5943 void push_current_class (TypeContainer tc, object partial_token)
5945 if (RootContext.EvalMode){
5946 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5947 undo.AddTypeContainer (current_container, tc);
5950 if (partial_token != null)
5951 current_container = current_container.AddPartial (tc);
5953 current_container = current_container.AddTypeContainer (tc);
5955 ++lexer.parsing_declaration;
5959 DeclSpace pop_current_class ()
5961 DeclSpace retval = current_class;
5963 current_class = current_class.Parent;
5964 current_container = current_class.PartialContainer;
5970 // Given the @class_name name, it creates a fully qualified name
5971 // based on the containing declaration space
5974 MakeName (MemberName class_name)
5976 Namespace ns = current_namespace.NS;
5978 if (current_container == RootContext.ToplevelTypes) {
5979 if (ns.Name.Length != 0)
5980 return new MemberName (ns.MemberName, class_name);
5984 return new MemberName (current_container.MemberName, class_name);
5988 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5990 Block implicit_block;
5991 ArrayList inits = null;
5994 // If we are doing interactive editing, we want variable declarations
5995 // that are in the top block to be added instead to the class as
5998 if (RootContext.StatementMode){
6001 for (Block b = current_block; b != null; b = b.Parent){
6002 if (b is ExplicitBlock && !(b is ToplevelBlock)){
6003 // There has been an explicit block, we cant add to the class
6010 // We can use "current_block" since we know there are no explicit blocks
6012 foreach (VariableDeclaration decl in variable_declarators){
6013 // We can not use the super-handy f.Initializer, because
6014 // multiple lines would force code to be executed out of sync
6015 if (decl.expression_or_array_initializer != null){
6016 string id = "$" + decl.identifier;
6017 current_block.AddVariable (type, id, decl.Location);
6019 LocalVariableReference var;
6020 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
6021 Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
6022 current_block.AddStatement (new StatementExpression (assign));
6023 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
6024 current_block.AddStatement (new StatementExpression (assign));
6026 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
6027 new MemberName (decl.identifier, loc), null);
6028 current_container.AddField (f);
6030 // Register the field to be visible later as a global variable
6031 Evaluator.QueueField (f);
6035 return current_block;
6040 // We use the `Used' property to check whether statements
6041 // have been added to the current block. If so, we need
6042 // to create another block to contain the new declaration
6043 // otherwise, as an optimization, we use the same block to
6044 // add the declaration.
6046 // FIXME: A further optimization is to check if the statements
6047 // that were added were added as part of the initialization
6048 // below. In which case, no other statements have been executed
6049 // and we might be able to reduce the number of blocks for
6050 // situations like this:
6052 // int j = 1; int k = j + 1;
6054 if (current_block.Used)
6055 implicit_block = new Block (current_block, loc, lexer.Location);
6057 implicit_block = current_block;
6059 foreach (VariableDeclaration decl in variable_declarators){
6061 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
6062 if (decl.expression_or_array_initializer != null){
6064 inits = new ArrayList (4);
6071 return implicit_block;
6073 foreach (VariableDeclaration decl in inits){
6075 Expression expr = decl.expression_or_array_initializer;
6077 LocalVariableReference var;
6078 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
6080 assign = new SimpleAssign (var, expr, decl.Location);
6082 implicit_block.AddStatement (new StatementExpression (assign));
6085 return implicit_block;
6088 Block declare_local_constants (Expression type, ArrayList declarators)
6090 Block implicit_block;
6092 if (current_block.Used)
6093 implicit_block = new Block (current_block);
6095 implicit_block = current_block;
6097 foreach (VariableDeclaration decl in declarators){
6098 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
6101 return implicit_block;
6104 string CheckAttributeTarget (string a, Location l)
6107 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6111 Report.Warning (658, 1, l,
6112 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6113 return string.Empty;
6116 static bool IsUnaryOperator (Operator.OpType op)
6120 case Operator.OpType.LogicalNot:
6121 case Operator.OpType.OnesComplement:
6122 case Operator.OpType.Increment:
6123 case Operator.OpType.Decrement:
6124 case Operator.OpType.True:
6125 case Operator.OpType.False:
6126 case Operator.OpType.UnaryPlus:
6127 case Operator.OpType.UnaryNegation:
6133 void syntax_error (Location l, string msg)
6135 Report.Error (1003, l, "Syntax error, " + msg);
6140 public Tokenizer Lexer {
6146 static CSharpParser ()
6148 oob_stack = new Stack ();
6151 public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
6153 if (RootContext.EvalMode)
6157 current_namespace = new NamespaceEntry (null, file, null);
6158 current_class = current_namespace.SlaveDeclSpace;
6159 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6161 lexer = new Tokenizer (reader, file);
6164 public void parse ()
6166 eof_token = Token.EOF;
6169 if (yacc_verbose_flag > 1)
6170 yyparse (lexer, new yydebug.yyDebugSimple ());
6173 } catch (Exception e){
6174 if (e is yyParser.yyUnexpectedEof)
6175 UnexpectedEOF = true;
6176 else if (yacc_verbose_flag > 0)
6177 Console.WriteLine (e);
6178 if (e is yyParser.yyException)
6179 Report.Error (-25, lexer.Location, "Parsing error");
6181 Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
6183 Tokenizer tokenizer = lexer as Tokenizer;
6184 tokenizer.cleanup ();
6186 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6187 throw new InternalErrorException ("who set it?");
6190 static void CheckToken (int error, int yyToken, string msg, Location loc)
6192 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6193 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6195 Report.Error (error, loc, msg);
6198 void CheckIdentifierToken (int yyToken, Location loc)
6200 CheckToken (1041, yyToken, "Identifier expected", loc);
6203 string ConsumeStoredComment ()
6205 string s = tmpComment;
6207 Lexer.doc_state = XmlCommentState.Allowed;
6211 Location GetLocation (object obj)
6213 if (obj is MemberCore)
6214 return ((MemberCore) obj).Location;
6215 if (obj is MemberName)
6216 return ((MemberName) obj).Location;
6217 if (obj is LocatedToken)
6218 return ((LocatedToken) obj).Location;
6219 if (obj is Location)
6220 return (Location) obj;
6221 return lexer.Location;
6224 void start_block (Location loc)
6226 if (current_block == null || parsing_anonymous_method) {
6227 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
6228 parsing_anonymous_method = false;
6230 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6235 end_block (Location loc)
6237 Block retval = current_block.Explicit;
6238 retval.SetEndLocation (loc);
6239 current_block = retval.Parent;
6244 start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6246 if (RootContext.Version == LanguageVersion.ISO_1){
6247 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6250 oob_stack.Push (current_anonymous_method);
6251 oob_stack.Push (current_local_parameters);
6253 current_local_parameters = parameters;
6255 current_anonymous_method = lambda
6256 ? new LambdaExpression (loc)
6257 : new AnonymousMethodExpression (loc);
6259 // Force the next block to be created as a ToplevelBlock
6260 parsing_anonymous_method = true;
6264 * Completes the anonymous method processing, if lambda_expr is null, this
6265 * means that we have a Statement instead of an Expression embedded
6267 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
6269 AnonymousMethodExpression retval;
6271 current_anonymous_method.Block = anon_block;
6272 retval = current_anonymous_method;
6274 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6275 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6280 public NamespaceEntry CurrentNamespace {
6282 return current_namespace;
6287 void Error_SyntaxError (int token)
6289 Error_SyntaxError (0, token);
6292 void Error_SyntaxError (int error_code, int token)
6294 string symbol = GetSymbolName (token);
6295 string expecting = GetExpecting ();
6297 if (error_code == 0) {
6298 if (expecting == "`)'")
6304 if (expecting != null)
6305 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
6308 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
6311 string GetExpecting ()
6313 int [] tokens = yyExpectingTokens (yyExpectingState);
6314 ArrayList names = new ArrayList (tokens.Length);
6315 bool has_type = false;
6316 bool has_identifier = false;
6317 for (int i = 0; i < tokens.Length; i++){
6318 int token = tokens [i];
6319 has_identifier |= token == Token.IDENTIFIER;
6321 string name = GetTokenName (token);
6322 if (name == "<internal>")
6325 has_type |= name == "type";
6326 if (names.Contains (name))
6333 // Too many tokens to enumerate
6335 if (names.Count > 8)
6338 if (has_type && has_identifier)
6339 names.Remove ("identifier");
6341 if (names.Count == 1)
6342 return "`" + GetTokenName (tokens [0]) + "'";
6344 StringBuilder sb = new StringBuilder ();
6346 int count = names.Count;
6347 for (int i = 0; i < count; i++){
6348 bool last = i + 1 == count;
6352 sb.Append (names [i]);
6353 sb.Append (last ? "'" : "', ");
6355 return sb.ToString ();
6359 string GetSymbolName (int token)
6362 case Token.LITERAL_FLOAT:
6363 case Token.LITERAL_INTEGER:
6364 case Token.LITERAL_DOUBLE:
6365 case Token.LITERAL_DECIMAL:
6366 case Token.LITERAL_CHARACTER:
6367 case Token.LITERAL_STRING:
6368 return lexer.Value.ToString ();
6369 case Token.IDENTIFIER:
6370 return ((LocatedToken)lexer.Value).Value;
6412 case Token.BITWISE_AND:
6414 case Token.BITWISE_OR:
6428 case Token.OP_SHIFT_LEFT:
6430 case Token.OP_SHIFT_RIGHT:
6450 case Token.OP_COALESCING:
6452 case Token.OP_MULT_ASSIGN:
6454 case Token.OP_DIV_ASSIGN:
6456 case Token.OP_MOD_ASSIGN:
6458 case Token.OP_ADD_ASSIGN:
6460 case Token.OP_SUB_ASSIGN:
6462 case Token.OP_SHIFT_LEFT_ASSIGN:
6464 case Token.OP_SHIFT_RIGHT_ASSIGN:
6466 case Token.OP_AND_ASSIGN:
6468 case Token.OP_XOR_ASSIGN:
6470 case Token.OP_OR_ASSIGN:
6474 return GetTokenName (token);
6477 static string GetTokenName (int token)
6480 case Token.ABSTRACT:
6500 case Token.CONTINUE:
6504 case Token.DELEGATE:
6514 case Token.EXPLICIT:
6532 case Token.IMPLICIT:
6536 case Token.INTERFACE:
6538 case Token.INTERNAL:
6544 case Token.NAMESPACE:
6550 case Token.OPERATOR:
6554 case Token.OVERRIDE:
6560 case Token.PROTECTED:
6564 case Token.READONLY:
6576 case Token.STACKALLOC:
6577 return "stackalloc";
6594 case Token.UNCHECKED:
6602 case Token.VOLATILE:
6615 case Token.FROM_FIRST:
6633 case Token.ASCENDING:
6635 case Token.DESCENDING:
6636 return "descending";
6643 case Token.OPEN_BRACE:
6645 case Token.CLOSE_BRACE:
6647 case Token.OPEN_BRACKET:
6649 case Token.CLOSE_BRACKET:
6651 case Token.OPEN_PARENS_CAST:
6652 case Token.OPEN_PARENS_LAMBDA:
6653 case Token.OPEN_PARENS:
6655 case Token.CLOSE_PARENS:
6661 case Token.DEFAULT_COLON:
6665 case Token.SEMICOLON:
6676 case Token.BITWISE_AND:
6677 case Token.BITWISE_OR:
6684 case Token.OP_SHIFT_LEFT:
6685 case Token.OP_SHIFT_RIGHT:
6693 case Token.OP_COALESCING:
6694 case Token.OP_MULT_ASSIGN:
6695 case Token.OP_DIV_ASSIGN:
6696 case Token.OP_MOD_ASSIGN:
6697 case Token.OP_ADD_ASSIGN:
6698 case Token.OP_SUB_ASSIGN:
6699 case Token.OP_SHIFT_LEFT_ASSIGN:
6700 case Token.OP_SHIFT_RIGHT_ASSIGN:
6701 case Token.OP_AND_ASSIGN:
6702 case Token.OP_XOR_ASSIGN:
6703 case Token.OP_OR_ASSIGN:
6704 return "<operator>";
6726 case Token.OP_GENERICS_LT:
6727 case Token.GENERIC_DIMENSION:
6729 case Token.OP_GENERICS_GT:
6732 case Token.INTERR_NULLABLE:
6734 case Token.DOUBLE_COLON:
6736 case Token.LITERAL_FLOAT:
6737 case Token.LITERAL_INTEGER:
6738 case Token.LITERAL_DOUBLE:
6739 case Token.LITERAL_DECIMAL:
6740 case Token.LITERAL_CHARACTER:
6741 case Token.LITERAL_STRING:
6743 case Token.IDENTIFIER:
6744 return "identifier";
6746 // All of these are internal.
6749 case Token.FIRST_KEYWORD:
6751 case Token.EVAL_COMPILATION_UNIT_PARSER:
6752 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6753 case Token.EVAL_STATEMENT_PARSER:
6754 case Token.LAST_KEYWORD:
6755 case Token.GENERATE_COMPLETION:
6756 case Token.COMPLETE_COMPLETION:
6757 return "<internal>";
6759 // A bit more robust.
6761 return yyNames [token];