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 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
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:
23 using System.Collections.Generic;
30 public class CSharpParser
33 enum ParameterModifierType
40 DefaultValue = 1 << 6,
42 All = Ref | Out | This | Params | Arglist | DefaultValue
45 static readonly object ModifierNone = 0;
47 NamespaceEntry current_namespace;
48 TypeContainer current_container;
49 DeclSpace current_class;
50 PropertyBase current_property;
51 EventProperty current_event;
52 EventField current_event_field;
53 FieldBase current_field;
56 /// Current block is used to add statements as we find
61 BlockVariableDeclaration current_variable;
63 Delegate current_delegate;
65 AnonymousMethodExpression current_anonymous_method;
68 /// This is used by the unary_expression code to resolve
69 /// a name against a parameter.
72 // FIXME: This is very ugly and it's very hard to reset it correctly
73 // on all places, especially when some parameters are autogenerated.
74 ParametersCompiled current_local_parameters;
76 bool parsing_anonymous_method;
79 /// An out-of-band stack.
81 static Stack<object> oob_stack;
84 /// Controls the verbosity of the errors produced by the parser
86 static public int yacc_verbose_flag;
89 /// Used by the interactive shell, flags whether EOF was reached
90 /// and an error was produced
92 public bool UnexpectedEOF;
100 /// Temporary Xml documentation cache.
101 /// For enum types, we need one more temporary store.
104 string enumTypeComment;
106 /// Current attribute target
107 string current_attr_target;
109 /// assembly and module attribute definitions are enabled
110 bool global_attrs_enabled = true;
112 ParameterModifierType valid_param_mod;
114 bool default_parameter_used;
116 /// When using the interactive parser, this holds the
117 /// resulting expression
118 public object InteractiveResult;
121 // Keeps track of global data changes to undo on parser error
125 Stack<Linq.QueryBlock> linq_clause_blocks;
127 // A counter to create new class names in interactive mode
128 static int class_count;
130 CompilerContext compiler;
133 // Instead of allocating carrier array everytime we
134 // share the bucket for very common constructs which can never
137 static List<Parameter> parameters_bucket = new List<Parameter> (6);
140 // Full AST support members
143 List<Tuple<Modifiers, Location>> mod_locations;
147 %token NONE /* This token is never returned by our lexer */
148 %token ERROR // This is used not by the parser, but by the tokenizer.
152 *These are the C# keywords
251 %token INTERR_NULLABLE
254 /* C# keywords which are not really keywords */
260 /* C# single character operators/punctuation. */
288 /* C# multi-character operators. */
293 %token OP_SHIFT_RIGHT
300 %token OP_MULT_ASSIGN
305 %token OP_SHIFT_LEFT_ASSIGN
306 %token OP_SHIFT_RIGHT_ASSIGN
313 /* Generics <,> tokens */
314 %token OP_GENERICS_LT
315 %token OP_GENERICS_LT_DECL
316 %token OP_GENERICS_GT
321 %token OPEN_PARENS_LAMBDA
322 %token OPEN_PARENS_CAST
323 %token GENERIC_DIMENSION
325 %token OPEN_BRACKET_EXPR
327 // Make the parser go into eval mode parsing (statements and compilation units).
328 %token EVAL_STATEMENT_PARSER
329 %token EVAL_COMPILATION_UNIT_PARSER
330 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
333 // This token is generated to trigger the completion engine at this point
335 %token GENERATE_COMPLETION
338 // This token is return repeatedly after the first GENERATE_COMPLETION
339 // token is produced and before the final EOF
341 %token COMPLETE_COMPLETION
343 /* Add precedence rules to solve dangling else s/r conflict */
347 /* Define the operator tokens and their precedences */
355 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
357 %left STAR DIV PERCENT
358 %right BANG CARRET UMINUS
359 %nonassoc OP_INC OP_DEC
361 %left OPEN_BRACKET OPEN_BRACE
364 %start compilation_unit
368 : outer_declarations opt_EOF
369 | outer_declarations global_attributes opt_EOF
370 | global_attributes opt_EOF
371 | opt_EOF /* allow empty files */
372 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
378 Lexer.check_incorrect_doc_comment ();
382 Lexer.check_incorrect_doc_comment ();
388 | outer_declarations outer_declaration
392 : extern_alias_directive
394 | namespace_member_declaration
397 extern_alias_directives
398 : extern_alias_directive
399 | extern_alias_directives extern_alias_directive
402 extern_alias_directive
403 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
405 var lt = (Tokenizer.LocatedToken) $2;
408 syntax_error (lt.Location, "`alias' expected");
409 } else if (RootContext.Version == LanguageVersion.ISO_1) {
410 Report.FeatureIsNotAvailable (lt.Location, "external alias");
412 lt = (Tokenizer.LocatedToken) $3;
413 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
418 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
424 | using_directives using_directive
428 : using_alias_directive
430 if (RootContext.Documentation != null)
431 Lexer.doc_state = XmlCommentState.Allowed;
433 | using_namespace_directive
435 if (RootContext.Documentation != null)
436 Lexer.doc_state = XmlCommentState.Allowed;
440 using_alias_directive
441 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
443 var lt = (Tokenizer.LocatedToken) $2;
444 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
448 Error_SyntaxError (yyToken);
453 using_namespace_directive
454 : USING namespace_name SEMICOLON
456 current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
461 // Strictly speaking, namespaces don't have attributes but
462 // we parse global attributes along with namespace declarations and then
465 namespace_declaration
466 : opt_attributes NAMESPACE qualified_identifier
468 MemberName name = (MemberName) $3;
471 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
474 current_namespace = new NamespaceEntry (compiler,
475 current_namespace, file, name.GetName ());
476 current_class = current_namespace.SlaveDeclSpace;
477 current_container = current_class.PartialContainer;
479 namespace_body opt_semicolon
481 current_namespace = current_namespace.Parent;
482 current_class = current_namespace.SlaveDeclSpace;
483 current_container = current_class.PartialContainer;
490 var lt = (Tokenizer.LocatedToken) $1;
491 $$ = new MemberName (lt.Value, lt.Location);
493 | qualified_identifier DOT IDENTIFIER
495 var lt = (Tokenizer.LocatedToken) $3;
496 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
500 Error_SyntaxError (yyToken);
501 $$ = new MemberName ("<invalid>", lexer.Location);
516 : namespace_or_type_name
518 MemberName name = (MemberName) $1;
520 if (name.TypeArguments != null)
521 syntax_error (lexer.Location, "namespace name expected");
530 if (RootContext.Documentation != null)
531 Lexer.doc_state = XmlCommentState.Allowed;
537 : opt_extern_alias_directives
539 opt_namespace_member_declarations
543 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
545 | opt_extern_alias_directives
547 opt_namespace_member_declarations
550 Report.Error (1513, lexer.Location, "Expected `}'");
559 opt_extern_alias_directives
561 | extern_alias_directives
564 opt_namespace_member_declarations
566 | namespace_member_declarations
569 namespace_member_declarations
570 : namespace_member_declaration
571 | namespace_member_declarations namespace_member_declaration
574 namespace_member_declaration
578 DeclSpace ds = (DeclSpace)$1;
580 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
581 Report.Error (1527, ds.Location,
582 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
585 current_namespace.DeclarationFound = true;
587 | namespace_declaration {
588 current_namespace.DeclarationFound = true;
591 | field_declaration {
592 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
594 | method_declaration {
595 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
602 | interface_declaration
604 | delegate_declaration
606 // Enable this when we have handled all errors, because this acts as a generic fallback
609 // Console.WriteLine ("Token=" + yyToken);
610 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
622 Attributes attrs = (Attributes)$1;
623 if (global_attrs_enabled) {
624 CodeGen.Assembly.AddAttributes (attrs.Attrs, current_namespace);
626 foreach (Attribute a in attrs.Attrs) {
627 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
638 global_attrs_enabled = false;
643 global_attrs_enabled = false;
652 if (current_attr_target != String.Empty) {
653 var sect = (List<Attribute>) $1;
655 if (global_attrs_enabled) {
656 if (current_attr_target == "module") {
657 current_container.Module.Compiled.AddAttributes (sect);
659 } else if (current_attr_target != null && current_attr_target.Length > 0) {
660 CodeGen.Assembly.AddAttributes (sect, current_namespace);
663 $$ = new Attributes (sect);
666 if (RootContext.Documentation != null) {
667 Lexer.check_incorrect_doc_comment ();
669 XmlCommentState.Allowed;
673 $$ = new Attributes (sect);
678 current_attr_target = null;
680 | attribute_sections attribute_section
682 if (current_attr_target != String.Empty) {
683 Attributes attrs = $1 as Attributes;
684 var sect = (List<Attribute>) $2;
686 if (global_attrs_enabled) {
687 if (current_attr_target == "module") {
688 current_container.Module.Compiled.AddAttributes (sect);
690 } else if (current_attr_target == "assembly") {
691 CodeGen.Assembly.AddAttributes (sect, current_namespace);
695 attrs = new Attributes (sect);
697 attrs.AddAttributes (sect);
701 attrs = new Attributes (sect);
703 attrs.AddAttributes (sect);
709 current_attr_target = null;
714 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
718 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
724 attribute_target_specifier
725 : attribute_target COLON
727 current_attr_target = (string)$1;
735 var lt = (Tokenizer.LocatedToken) $1;
736 $$ = CheckAttributeTarget (lt.Value, lt.Location);
738 | EVENT { $$ = "event"; }
739 | RETURN { $$ = "return"; }
742 string name = GetTokenName (yyToken);
743 $$ = CheckAttributeTarget (name, GetLocation ($1));
750 $$ = new List<Attribute> (4) { (Attribute) $1 };
752 | attribute_list COMMA attribute
754 var attrs = (List<Attribute>) $1;
755 attrs.Add ((Attribute) $3);
764 ++lexer.parsing_block;
766 opt_attribute_arguments
768 --lexer.parsing_block;
769 MemberName mname = (MemberName) $1;
770 if (mname.IsGeneric) {
771 Report.Error (404, lexer.Location,
772 "'<' unexpected: attributes cannot be generic");
775 Arguments [] arguments = (Arguments []) $3;
776 ATypeNameExpression expr = mname.GetTypeExpression ();
778 if (current_attr_target == String.Empty)
780 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
781 // FIXME: supply "nameEscaped" parameter here.
782 $$ = new GlobalAttribute (current_namespace, current_attr_target,
783 expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
785 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
790 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
793 opt_attribute_arguments
794 : /* empty */ { $$ = null; }
795 | OPEN_PARENS attribute_arguments CLOSE_PARENS
803 : /* empty */ { $$ = null; }
804 | positional_or_named_argument
806 Arguments a = new Arguments (4);
807 a.Add ((Argument) $1);
808 $$ = new Arguments [] { a, null };
810 | named_attribute_argument
812 Arguments a = new Arguments (4);
813 a.Add ((Argument) $1);
814 $$ = new Arguments [] { null, a };
816 | attribute_arguments COMMA positional_or_named_argument
818 Arguments[] o = (Arguments[]) $1;
820 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
821 o [0] = new Arguments (4);
824 Arguments args = ((Arguments) o [0]);
825 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
826 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
828 args.Add ((Argument) $3);
830 | attribute_arguments COMMA named_attribute_argument
832 Arguments[] o = (Arguments[]) $1;
834 o [1] = new Arguments (4);
837 ((Arguments) o [1]).Add ((Argument) $3);
841 positional_or_named_argument
844 $$ = new Argument ((Expression) $1);
849 named_attribute_argument
852 ++lexer.parsing_block;
856 --lexer.parsing_block;
857 var lt = (Tokenizer.LocatedToken) $1;
858 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
863 : IDENTIFIER COLON opt_named_modifier expression
865 if (RootContext.Version <= LanguageVersion.V_3)
866 Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
868 // Avoid boxing in common case (no modifier)
869 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
871 var lt = (Tokenizer.LocatedToken) $1;
872 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
877 : /* empty */ { $$ = null; }
880 $$ = Argument.AType.Ref;
884 $$ = Argument.AType.Out;
888 opt_class_member_declarations
890 | class_member_declarations
893 class_member_declarations
894 : class_member_declaration
895 | class_member_declarations
896 class_member_declaration
899 class_member_declaration
900 : constant_declaration // done
901 | field_declaration // done
902 | method_declaration // done
903 | property_declaration // done
904 | event_declaration // done
905 | indexer_declaration // done
906 | operator_declaration // done
907 | constructor_declaration // done
908 | destructor_declaration // done
912 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
913 GetSymbolName (yyToken));
915 lexer.parsing_generic_declaration = false;
925 lexer.ConstraintsParsing = true;
927 type_declaration_name
929 MemberName name = MakeName ((MemberName) $6);
930 push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
933 opt_type_parameter_constraints_clauses
935 lexer.ConstraintsParsing = false;
937 current_class.SetParameterInfo ((List<Constraints>) $9);
939 if (RootContext.Documentation != null)
940 current_container.DocComment = Lexer.consume_doc_comment ();
942 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
946 --lexer.parsing_declaration;
947 if (RootContext.Documentation != null)
948 Lexer.doc_state = XmlCommentState.Allowed;
952 lbag.AppendToMember (current_class, GetLocation ($13));
953 $$ = pop_current_class ();
955 | opt_attributes opt_modifiers opt_partial STRUCT error
957 Error_SyntaxError (yyToken);
964 if (RootContext.Documentation != null)
965 Lexer.doc_state = XmlCommentState.Allowed;
967 opt_struct_member_declarations CLOSE_BRACE
969 lbag.AppendToMember (current_class, GetLocation ($1), GetLocation ($4));
973 opt_struct_member_declarations
975 | struct_member_declarations
978 struct_member_declarations
979 : struct_member_declaration
980 | struct_member_declarations struct_member_declaration
983 struct_member_declaration
984 : constant_declaration
987 | property_declaration
989 | indexer_declaration
990 | operator_declaration
991 | constructor_declaration
995 * This is only included so we can flag error 575:
996 * destructors only allowed on class types
998 | destructor_declaration
1001 constant_declaration
1004 CONST type IDENTIFIER
1006 var lt = (Tokenizer.LocatedToken) $5;
1007 var mod = (Modifiers) $2;
1008 current_field = new Const (current_class, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1009 current_container.AddConstant ((Const) current_field);
1011 if ((mod & Modifiers.STATIC) != 0) {
1012 Report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1017 constant_initializer opt_constant_declarators SEMICOLON
1019 if (RootContext.Documentation != null) {
1020 current_field.DocComment = Lexer.consume_doc_comment ();
1021 Lexer.doc_state = XmlCommentState.Allowed;
1024 current_field.Initializer = (ConstInitializer) $7;
1025 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1026 current_field = null;
1030 opt_constant_declarators
1032 | constant_declarators
1035 constant_declarators
1036 : constant_declarator
1038 current_field.AddDeclarator ((FieldDeclarator) $1);
1040 | constant_declarators constant_declarator
1042 current_field.AddDeclarator ((FieldDeclarator) $2);
1047 : COMMA IDENTIFIER constant_initializer
1049 var lt = (Tokenizer.LocatedToken) $2;
1050 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1051 lbag.AddLocation ($$, GetLocation ($1));
1055 constant_initializer
1058 ++lexer.parsing_block;
1060 constant_initializer_expr
1062 --lexer.parsing_block;
1063 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1067 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
1072 constant_initializer_expr
1073 : constant_expression
1080 member_type IDENTIFIER
1082 lexer.parsing_generic_declaration = false;
1084 FullNamedExpression type = (FullNamedExpression) $3;
1085 if (type.Type == TypeManager.void_type)
1086 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1088 var lt = (Tokenizer.LocatedToken) $4;
1089 current_field = new Field (current_class, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1090 current_container.AddField (current_field);
1093 opt_field_initializer
1094 opt_field_declarators
1097 if (RootContext.Documentation != null) {
1098 current_field.DocComment = Lexer.consume_doc_comment ();
1099 Lexer.doc_state = XmlCommentState.Allowed;
1102 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1104 current_field = null;
1108 FIXED simple_type IDENTIFIER
1110 if (RootContext.Version < LanguageVersion.ISO_2)
1111 Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1113 var lt = (Tokenizer.LocatedToken) $5;
1114 current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
1115 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1117 current_container.AddField (current_field);
1119 fixed_field_size opt_fixed_field_declarators SEMICOLON
1121 if (RootContext.Documentation != null) {
1122 current_field.DocComment = Lexer.consume_doc_comment ();
1123 Lexer.doc_state = XmlCommentState.Allowed;
1126 current_field.Initializer = (ConstInitializer) $7;
1127 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1129 current_field = null;
1133 FIXED simple_type error
1136 Report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1140 opt_field_initializer
1144 ++lexer.parsing_block;
1145 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1146 start_block (GetLocation ($1));
1148 variable_initializer
1150 --lexer.parsing_block;
1151 current_field.Initializer = (Expression) $3;
1152 end_block (lexer.Location);
1153 current_local_parameters = null;
1157 opt_field_declarators
1165 current_field.AddDeclarator ((FieldDeclarator) $1);
1167 | field_declarators field_declarator
1169 current_field.AddDeclarator ((FieldDeclarator) $2);
1176 var lt = (Tokenizer.LocatedToken) $2;
1177 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1178 lbag.AddLocation ($$, GetLocation ($1));
1180 | COMMA IDENTIFIER ASSIGN
1182 ++lexer.parsing_block;
1184 variable_initializer
1186 --lexer.parsing_block;
1187 var lt = (Tokenizer.LocatedToken) $2;
1188 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1189 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1193 opt_fixed_field_declarators
1195 | fixed_field_declarators
1198 fixed_field_declarators
1199 : fixed_field_declarator
1201 current_field.AddDeclarator ((FieldDeclarator) $1);
1203 | fixed_field_declarators fixed_field_declarator
1205 current_field.AddDeclarator ((FieldDeclarator) $2);
1209 fixed_field_declarator
1210 : COMMA IDENTIFIER fixed_field_size
1212 var lt = (Tokenizer.LocatedToken) $2;
1213 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1214 lbag.AddLocation ($$, GetLocation ($1));
1221 ++lexer.parsing_block;
1223 expression CLOSE_BRACKET
1225 --lexer.parsing_block;
1226 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1227 lbag.AddLocation ($$, GetLocation ($4));
1229 | OPEN_BRACKET error
1231 Report.Error (443, lexer.Location, "Value or constant expected");
1236 variable_initializer
1241 // It has to be here for the parent to safely restore artificial block
1242 Error_SyntaxError (yyToken);
1249 if (RootContext.Documentation != null)
1250 Lexer.doc_state = XmlCommentState.NotAllowed;
1254 Method method = (Method) $1;
1255 method.Block = (ToplevelBlock) $3;
1256 current_container.AddMethod (method);
1258 if (current_container.Kind == MemberKind.Interface && method.Block != null) {
1259 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1262 current_local_parameters = null;
1264 if (RootContext.Documentation != null)
1265 Lexer.doc_state = XmlCommentState.Allowed;
1273 method_declaration_name OPEN_PARENS
1275 valid_param_mod = ParameterModifierType.All;
1277 opt_formal_parameter_list CLOSE_PARENS
1279 lexer.ConstraintsParsing = true;
1281 opt_type_parameter_constraints_clauses
1283 lexer.ConstraintsParsing = false;
1284 valid_param_mod = 0;
1285 MemberName name = (MemberName) $4;
1286 current_local_parameters = (ParametersCompiled) $7;
1288 GenericMethod generic = null;
1289 if (name.TypeArguments != null) {
1290 generic = new GenericMethod (current_namespace, current_class, name,
1291 (FullNamedExpression) $3, current_local_parameters);
1293 generic.SetParameterInfo ((List<Constraints>) $10);
1294 } else if ($10 != null) {
1295 Report.Error (80, GetLocation ($10),
1296 "Constraints are not allowed on non-generic declarations");
1299 Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
1300 name, current_local_parameters, (Attributes) $1);
1302 if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
1303 Report.Error (460, method.Location,
1304 "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
1305 method.GetSignatureForError ());
1308 if (RootContext.Documentation != null)
1309 method.DocComment = Lexer.consume_doc_comment ();
1311 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1317 VOID method_declaration_name
1320 valid_param_mod = ParameterModifierType.All;
1322 opt_formal_parameter_list CLOSE_PARENS
1324 lexer.ConstraintsParsing = true;
1326 opt_type_parameter_constraints_clauses
1328 lexer.ConstraintsParsing = false;
1329 valid_param_mod = 0;
1331 MemberName name = (MemberName) $5;
1332 current_local_parameters = (ParametersCompiled) $8;
1334 if ($10 != null && name.TypeArguments == null)
1335 Report.Error (80, lexer.Location,
1336 "Constraints are not allowed on non-generic declarations");
1339 GenericMethod generic = null;
1340 if (name.TypeArguments != null) {
1341 generic = new GenericMethod (current_namespace, current_class, name,
1342 new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1343 current_local_parameters);
1345 generic.SetParameterInfo ((List<Constraints>) $11);
1348 var modifiers = (Modifiers) $2;
1351 const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
1352 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1354 if ((modifiers & invalid_partial_mod) != 0) {
1355 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1356 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1357 modifiers &= ~invalid_partial_mod;
1360 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1361 Report.Error (751, name.Location, "A partial method must be declared within a " +
1362 "partial class or partial struct");
1365 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1367 method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1368 modifiers, name, current_local_parameters, (Attributes) $1);
1370 if (RootContext.Documentation != null)
1371 method.DocComment = Lexer.consume_doc_comment ();
1373 // TODO: lbag, push void
1374 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1375 lbag.AddMember (method, mod_locations, GetLocation ($6), GetLocation ($9));
1381 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1383 MemberName name = (MemberName) $5;
1384 Report.Error (1585, name.Location,
1385 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1387 Method method = new Method (current_class, null, (FullNamedExpression) $3,
1388 0, name, (ParametersCompiled) $7, (Attributes) $1);
1390 current_local_parameters = (ParametersCompiled) $7;
1392 if (RootContext.Documentation != null)
1393 method.DocComment = Lexer.consume_doc_comment ();
1401 | SEMICOLON { $$ = null; }
1404 opt_formal_parameter_list
1405 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1406 | formal_parameter_list
1409 formal_parameter_list
1412 var pars_list = (List<Parameter>) $1;
1413 $$ = new ParametersCompiled (pars_list.ToArray ());
1415 | fixed_parameters COMMA parameter_array
1417 var pars_list = (List<Parameter>) $1;
1418 pars_list.Add ((Parameter) $3);
1420 $$ = new ParametersCompiled (pars_list.ToArray ());
1422 | fixed_parameters COMMA arglist_modifier
1424 var pars_list = (List<Parameter>) $1;
1425 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1426 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1428 | parameter_array COMMA error
1431 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1433 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1435 | fixed_parameters COMMA parameter_array COMMA error
1438 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1440 var pars_list = (List<Parameter>) $1;
1441 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1443 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1445 | arglist_modifier COMMA error
1447 Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1449 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1451 | fixed_parameters COMMA ARGLIST COMMA error
1453 Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1455 var pars_list = (List<Parameter>) $1;
1456 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1458 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1462 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1466 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1470 Error_SyntaxError (yyToken);
1471 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1478 parameters_bucket.Clear ();
1479 Parameter p = (Parameter) $1;
1480 parameters_bucket.Add (p);
1482 default_parameter_used = p.HasDefaultValue;
1483 $$ = parameters_bucket;
1485 | fixed_parameters COMMA fixed_parameter
1487 var pars = (List<Parameter>) $1;
1488 Parameter p = (Parameter) $3;
1490 if (p.HasExtensionMethodModifier)
1491 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1492 else if (!p.HasDefaultValue && default_parameter_used)
1493 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1495 default_parameter_used |= p.HasDefaultValue;
1498 lbag.AddLocation (p, GetLocation ($2));
1507 opt_parameter_modifier
1511 var lt = (Tokenizer.LocatedToken) $4;
1512 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1515 opt_parameter_modifier
1517 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1519 var lt = (Tokenizer.LocatedToken) $4;
1520 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1521 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1524 opt_parameter_modifier
1528 Error_SyntaxError (yyToken);
1529 Location l = GetLocation ($4);
1530 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1533 opt_parameter_modifier
1538 ++lexer.parsing_block;
1542 --lexer.parsing_block;
1543 if (RootContext.Version <= LanguageVersion.V_3) {
1544 Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1547 Parameter.Modifier mod = (Parameter.Modifier) $2;
1548 if (mod != Parameter.Modifier.NONE) {
1550 case Parameter.Modifier.REF:
1551 case Parameter.Modifier.OUT:
1552 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1553 Parameter.GetModifierSignature (mod));
1556 case Parameter.Modifier.This:
1557 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1558 Parameter.GetModifierSignature (mod));
1561 throw new NotImplementedException (mod.ToString ());
1564 mod = Parameter.Modifier.NONE;
1567 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1568 Report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1570 var lt = (Tokenizer.LocatedToken) $4;
1571 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1572 lbag.AddLocation ($$, GetLocation ($5));
1575 ((Parameter) $$).DefaultValue = (Expression) $7;
1579 opt_parameter_modifier
1580 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1581 | parameter_modifiers
1585 : parameter_modifier
1589 | parameter_modifiers parameter_modifier
1591 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1592 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1593 if (((Parameter.Modifier)$1 & p2) == p2) {
1594 Error_DuplicateParameterModifier (lexer.Location, p2);
1596 switch (mod & ~Parameter.Modifier.This) {
1597 case Parameter.Modifier.REF:
1598 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1600 case Parameter.Modifier.OUT:
1601 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1604 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1615 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1616 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1618 $$ = Parameter.Modifier.REF;
1622 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1623 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1625 $$ = Parameter.Modifier.OUT;
1629 if ((valid_param_mod & ParameterModifierType.This) == 0)
1630 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1632 if (RootContext.Version <= LanguageVersion.ISO_2)
1633 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1635 $$ = Parameter.Modifier.This;
1640 : opt_attributes params_modifier type IDENTIFIER
1642 var lt = (Tokenizer.LocatedToken) $4;
1643 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1645 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1647 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1649 var lt = (Tokenizer.LocatedToken) $4;
1650 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1652 | opt_attributes params_modifier type error
1654 Error_SyntaxError (yyToken);
1662 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1663 Report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1665 | PARAMS parameter_modifier
1667 Parameter.Modifier mod = (Parameter.Modifier)$2;
1668 if ((mod & Parameter.Modifier.This) != 0) {
1669 Report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1671 Report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1674 | PARAMS params_modifier
1676 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1683 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1684 Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1688 property_declaration
1692 member_declaration_name
1694 if (RootContext.Documentation != null)
1695 tmpComment = Lexer.consume_doc_comment ();
1699 current_property = new Property (current_class, (FullNamedExpression) $3, (Modifiers) $2,
1700 (MemberName) $4, (Attributes) $1);
1702 if (current_property.TypeExpression.Type == TypeManager.void_type)
1703 Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1705 current_container.AddProperty ((Property)current_property);
1706 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1708 lexer.PropertyParsing = true;
1710 accessor_declarations
1712 lexer.PropertyParsing = false;
1714 if (RootContext.Documentation != null)
1715 current_property.DocComment = ConsumeStoredComment ();
1719 lbag.AppendToMember (current_property, GetLocation ($10));
1720 current_property = null;
1726 : opt_attributes opt_modifiers
1727 member_type indexer_declaration_name OPEN_BRACKET
1729 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1731 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1733 valid_param_mod = 0;
1735 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
1736 (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1738 current_property = indexer;
1740 current_container.AddIndexer (indexer);
1741 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1743 if (indexer.TypeExpression.Type == TypeManager.void_type)
1744 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1746 if (indexer.Parameters.IsEmpty) {
1747 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1750 if (RootContext.Documentation != null) {
1751 tmpComment = Lexer.consume_doc_comment ();
1752 Lexer.doc_state = XmlCommentState.Allowed;
1755 lexer.PropertyParsing = true;
1757 accessor_declarations
1759 lexer.PropertyParsing = false;
1763 if (RootContext.Documentation != null)
1764 current_property.DocComment = ConsumeStoredComment ();
1766 lbag.AppendToMember (current_property, GetLocation ($12));
1767 current_property = null;
1772 accessor_declarations
1773 : get_accessor_declaration
1774 | get_accessor_declaration accessor_declarations
1775 | set_accessor_declaration
1776 | set_accessor_declaration accessor_declarations
1779 if (yyToken == Token.CLOSE_BRACE) {
1780 Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1782 if (yyToken == Token.SEMICOLON)
1783 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1785 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1790 get_accessor_declaration
1791 : opt_attributes opt_modifiers GET
1793 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1794 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1797 if (current_property.Get != null) {
1798 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1801 if (current_property is Indexer) {
1802 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1803 (Attributes) $1, GetLocation ($3));
1805 current_property.Get = new Property.GetMethod (current_property,
1806 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1809 current_local_parameters = current_property.Get.ParameterInfo;
1810 lbag.AddMember (current_property.Get, mod_locations);
1811 lexer.PropertyParsing = false;
1816 current_property.Get.Block = (ToplevelBlock) $5;
1818 if (current_container.Kind == MemberKind.Interface) {
1819 Report.Error (531, current_property.Get.Block.StartLocation,
1820 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1824 current_local_parameters = null;
1825 lexer.PropertyParsing = true;
1827 if (RootContext.Documentation != null)
1828 if (Lexer.doc_state == XmlCommentState.Error)
1829 Lexer.doc_state = XmlCommentState.NotAllowed;
1833 set_accessor_declaration
1834 : opt_attributes opt_modifiers SET
1836 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1837 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1840 if (current_property.Set != null) {
1841 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1844 if (current_property is Indexer) {
1845 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1846 ParametersCompiled.MergeGenerated (compiler,
1847 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1848 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1850 (Attributes) $1, GetLocation ($3));
1852 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1853 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1854 (Attributes) $1, GetLocation ($3));
1857 current_local_parameters = current_property.Set.ParameterInfo;
1858 lbag.AddMember (current_property.Set, mod_locations);
1859 lexer.PropertyParsing = false;
1864 current_property.Set.Block = (ToplevelBlock) $5;
1866 if (current_container.Kind == MemberKind.Interface) {
1867 Report.Error (531, current_property.Set.Block.StartLocation,
1868 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1872 current_local_parameters = null;
1873 lexer.PropertyParsing = true;
1875 if (RootContext.Documentation != null
1876 && Lexer.doc_state == XmlCommentState.Error)
1877 Lexer.doc_state = XmlCommentState.NotAllowed;
1890 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1895 interface_declaration
1901 lexer.ConstraintsParsing = true;
1903 type_declaration_name
1905 MemberName name = MakeName ((MemberName) $6);
1906 push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
1907 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
1910 opt_type_parameter_constraints_clauses
1912 lexer.ConstraintsParsing = false;
1914 current_class.SetParameterInfo ((List<Constraints>) $9);
1916 if (RootContext.Documentation != null) {
1917 current_container.DocComment = Lexer.consume_doc_comment ();
1918 Lexer.doc_state = XmlCommentState.Allowed;
1921 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1923 --lexer.parsing_declaration;
1924 if (RootContext.Documentation != null)
1925 Lexer.doc_state = XmlCommentState.Allowed;
1929 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
1930 $$ = pop_current_class ();
1932 | opt_attributes opt_modifiers opt_partial INTERFACE error
1934 Error_SyntaxError (yyToken);
1938 opt_interface_member_declarations
1940 | interface_member_declarations
1943 interface_member_declarations
1944 : interface_member_declaration
1945 | interface_member_declarations interface_member_declaration
1948 interface_member_declaration
1949 : constant_declaration
1951 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1955 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1957 | method_declaration
1958 | property_declaration
1960 | indexer_declaration
1961 | operator_declaration
1963 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1965 | constructor_declaration
1967 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1971 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1975 operator_declaration
1976 : opt_attributes opt_modifiers operator_declarator
1981 OperatorDeclaration decl = (OperatorDeclaration) $3;
1983 Operator op = new Operator (
1984 current_class, decl.optype, decl.ret_type, (Modifiers) $2,
1985 current_local_parameters,
1986 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1988 if (RootContext.Documentation != null) {
1989 op.DocComment = tmpComment;
1990 Lexer.doc_state = XmlCommentState.Allowed;
1993 // Note again, checking is done in semantic analysis
1994 current_container.AddOperator (op);
1996 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1999 current_local_parameters = null;
2005 | SEMICOLON { $$ = null; }
2009 : type_expression_or_array
2012 Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2013 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2018 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2020 valid_param_mod = ParameterModifierType.DefaultValue;
2022 opt_formal_parameter_list CLOSE_PARENS
2024 valid_param_mod = 0;
2026 Location loc = GetLocation ($2);
2027 Operator.OpType op = (Operator.OpType) $3;
2028 current_local_parameters = (ParametersCompiled)$6;
2030 int p_count = current_local_parameters.Count;
2032 if (op == Operator.OpType.Addition)
2033 op = Operator.OpType.UnaryPlus;
2034 else if (op == Operator.OpType.Subtraction)
2035 op = Operator.OpType.UnaryNegation;
2038 if (IsUnaryOperator (op)) {
2040 Report.Error (1020, loc, "Overloadable binary operator expected");
2041 } else if (p_count != 1) {
2042 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2043 Operator.GetName (op));
2047 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2048 Operator.GetName (op));
2049 } else if (p_count != 2) {
2050 Report.Error (1019, loc, "Overloadable unary operator expected");
2054 if (RootContext.Documentation != null) {
2055 tmpComment = Lexer.consume_doc_comment ();
2056 Lexer.doc_state = XmlCommentState.NotAllowed;
2059 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2060 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2062 | conversion_operator_declarator
2065 overloadable_operator
2067 : BANG { $$ = Operator.OpType.LogicalNot; }
2068 | TILDE { $$ = Operator.OpType.OnesComplement; }
2069 | OP_INC { $$ = Operator.OpType.Increment; }
2070 | OP_DEC { $$ = Operator.OpType.Decrement; }
2071 | TRUE { $$ = Operator.OpType.True; }
2072 | FALSE { $$ = Operator.OpType.False; }
2073 // Unary and binary:
2074 | PLUS { $$ = Operator.OpType.Addition; }
2075 | MINUS { $$ = Operator.OpType.Subtraction; }
2077 | STAR { $$ = Operator.OpType.Multiply; }
2078 | DIV { $$ = Operator.OpType.Division; }
2079 | PERCENT { $$ = Operator.OpType.Modulus; }
2080 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2081 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2082 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2083 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2084 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2085 | OP_EQ { $$ = Operator.OpType.Equality; }
2086 | OP_NE { $$ = Operator.OpType.Inequality; }
2087 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2088 | OP_LT { $$ = Operator.OpType.LessThan; }
2089 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2090 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2093 conversion_operator_declarator
2094 : IMPLICIT OPERATOR type OPEN_PARENS
2096 valid_param_mod = ParameterModifierType.DefaultValue;
2098 opt_formal_parameter_list CLOSE_PARENS
2100 valid_param_mod = 0;
2102 Location loc = GetLocation ($2);
2103 current_local_parameters = (ParametersCompiled)$6;
2105 if (RootContext.Documentation != null) {
2106 tmpComment = Lexer.consume_doc_comment ();
2107 Lexer.doc_state = XmlCommentState.NotAllowed;
2110 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2111 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2113 | EXPLICIT OPERATOR type OPEN_PARENS
2115 valid_param_mod = ParameterModifierType.DefaultValue;
2117 opt_formal_parameter_list CLOSE_PARENS
2119 valid_param_mod = 0;
2121 Location loc = GetLocation ($2);
2122 current_local_parameters = (ParametersCompiled)$6;
2124 if (RootContext.Documentation != null) {
2125 tmpComment = Lexer.consume_doc_comment ();
2126 Lexer.doc_state = XmlCommentState.NotAllowed;
2129 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2130 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2134 Error_SyntaxError (yyToken);
2135 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2136 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2140 Error_SyntaxError (yyToken);
2141 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2142 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2146 constructor_declaration
2147 : constructor_declarator
2150 Constructor c = (Constructor) $1;
2151 c.Block = (ToplevelBlock) $2;
2153 if (RootContext.Documentation != null)
2154 c.DocComment = ConsumeStoredComment ();
2156 current_container.AddConstructor (c);
2158 current_local_parameters = null;
2159 if (RootContext.Documentation != null)
2160 Lexer.doc_state = XmlCommentState.Allowed;
2164 constructor_declarator
2169 if (RootContext.Documentation != null) {
2170 tmpComment = Lexer.consume_doc_comment ();
2171 Lexer.doc_state = XmlCommentState.Allowed;
2174 valid_param_mod = ParameterModifierType.All;
2176 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2178 valid_param_mod = 0;
2179 current_local_parameters = (ParametersCompiled) $6;
2182 // start block here, so possible anonymous methods inside
2183 // constructor initializer can get correct parent block
2185 start_block (lexer.Location);
2187 opt_constructor_initializer
2189 var lt = (Tokenizer.LocatedToken) $3;
2190 var mods = (Modifiers) $2;
2191 ConstructorInitializer ci = (ConstructorInitializer) $9;
2193 Constructor c = new Constructor (current_class, lt.Value, mods,
2194 (Attributes) $1, current_local_parameters, ci, lt.Location);
2196 if (lt.Value != current_container.MemberName.Name) {
2197 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2198 } else if ((mods & Modifiers.STATIC) != 0) {
2199 if ((mods & Modifiers.AccessibilityMask) != 0){
2200 Report.Error (515, c.Location,
2201 "`{0}': static constructor cannot have an access modifier",
2202 c.GetSignatureForError ());
2205 Report.Error (514, c.Location,
2206 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2207 c.GetSignatureForError ());
2212 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2219 | SEMICOLON { current_block = null; $$ = null; }
2222 opt_constructor_initializer
2224 | constructor_initializer
2227 constructor_initializer
2228 : COLON BASE OPEN_PARENS
2230 ++lexer.parsing_block;
2232 opt_argument_list CLOSE_PARENS
2234 --lexer.parsing_block;
2235 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2236 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2238 | COLON THIS OPEN_PARENS
2240 ++lexer.parsing_block;
2242 opt_argument_list CLOSE_PARENS
2244 --lexer.parsing_block;
2245 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2246 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2249 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2254 destructor_declaration
2255 : opt_attributes opt_modifiers TILDE
2257 if (RootContext.Documentation != null) {
2258 tmpComment = Lexer.consume_doc_comment ();
2259 Lexer.doc_state = XmlCommentState.NotAllowed;
2262 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2264 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2266 var lt = (Tokenizer.LocatedToken) $5;
2267 if (lt.Value != current_container.MemberName.Name){
2268 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2269 } else if (current_container.Kind != MemberKind.Class){
2270 Report.Error (575, lt.Location, "Only class types can contain destructor");
2273 Destructor d = new Destructor (current_class, (Modifiers) $2,
2274 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2275 if (RootContext.Documentation != null)
2276 d.DocComment = ConsumeStoredComment ();
2278 d.Block = (ToplevelBlock) $8;
2279 current_container.AddMethod (d);
2280 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2282 current_local_parameters = null;
2289 EVENT type member_declaration_name
2291 current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2292 current_container.AddEvent (current_event_field);
2294 if (current_event_field.MemberName.Left != null) {
2295 Report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2296 current_event_field.GetSignatureForError ());
2299 $$ = current_event_field;
2301 opt_event_initializer
2302 opt_event_declarators
2305 if (RootContext.Documentation != null) {
2306 current_event_field.DocComment = Lexer.consume_doc_comment ();
2307 Lexer.doc_state = XmlCommentState.Allowed;
2310 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2311 current_event_field = null;
2315 EVENT type member_declaration_name
2318 current_event = new EventProperty (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2319 current_container.AddEvent (current_event);
2320 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2322 lexer.EventParsing = true;
2324 event_accessor_declarations
2326 if (current_container.Kind == MemberKind.Interface)
2327 Report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2329 lexer.EventParsing = false;
2333 if (RootContext.Documentation != null) {
2334 current_event.DocComment = Lexer.consume_doc_comment ();
2335 Lexer.doc_state = XmlCommentState.Allowed;
2338 lbag.AppendToMember (current_event, GetLocation ($9));
2339 current_event = null;
2340 current_local_parameters = null;
2344 opt_event_initializer
2348 ++lexer.parsing_block;
2350 event_variable_initializer
2352 --lexer.parsing_block;
2353 current_event_field.Initializer = (Expression) $3;
2357 opt_event_declarators
2365 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2367 | event_declarators event_declarator
2369 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2376 var lt = (Tokenizer.LocatedToken) $2;
2377 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2378 lbag.AddLocation ($$, GetLocation ($1));
2380 | COMMA IDENTIFIER ASSIGN
2382 ++lexer.parsing_block;
2384 event_variable_initializer
2386 --lexer.parsing_block;
2387 var lt = (Tokenizer.LocatedToken) $2;
2388 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2389 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2393 event_variable_initializer
2395 if (current_container.Kind == MemberKind.Interface) {
2396 Report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2397 current_event_field.GetSignatureForError ());
2400 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2401 Report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2402 current_event_field.GetSignatureForError ());
2405 variable_initializer
2411 event_accessor_declarations
2412 : add_accessor_declaration remove_accessor_declaration
2413 | remove_accessor_declaration add_accessor_declaration
2414 | add_accessor_declaration
2416 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2417 current_event.GetSignatureForError ());
2419 | remove_accessor_declaration
2421 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2422 current_event.GetSignatureForError ());
2426 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2431 add_accessor_declaration
2432 : opt_attributes opt_modifiers ADD
2434 if ($2 != ModifierNone) {
2435 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2438 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2439 current_local_parameters = current_event.Add.ParameterInfo;
2441 lbag.AddMember (current_event.Add, mod_locations);
2442 lexer.EventParsing = false;
2444 event_accessor_block
2446 lexer.EventParsing = true;
2448 current_event.Add.Block = (ToplevelBlock) $5;
2450 if (current_container.Kind == MemberKind.Interface) {
2451 Report.Error (531, current_event.Add.Block.StartLocation,
2452 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2455 current_local_parameters = null;
2459 remove_accessor_declaration
2460 : opt_attributes opt_modifiers REMOVE
2462 if ($2 != ModifierNone) {
2463 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2466 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2467 current_local_parameters = current_event.Remove.ParameterInfo;
2469 lbag.AddMember (current_event.Remove, mod_locations);
2470 lexer.EventParsing = false;
2472 event_accessor_block
2474 lexer.EventParsing = true;
2476 current_event.Remove.Block = (ToplevelBlock) $5;
2478 if (current_container.Kind == MemberKind.Interface) {
2479 Report.Error (531, current_event.Remove.Block.StartLocation,
2480 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2483 current_local_parameters = null;
2487 event_accessor_block
2490 Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2499 ENUM type_declaration_name
2502 if (RootContext.Documentation != null)
2503 enumTypeComment = Lexer.consume_doc_comment ();
2507 if (RootContext.Documentation != null)
2508 Lexer.doc_state = XmlCommentState.Allowed;
2510 MemberName name = (MemberName) $4;
2511 if (name.IsGeneric) {
2512 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2515 push_current_class (new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2, MakeName (name), (Attributes) $1), null);
2517 opt_enum_member_declarations
2519 // here will be evaluated after CLOSE_BLACE is consumed.
2520 if (RootContext.Documentation != null)
2521 Lexer.doc_state = XmlCommentState.Allowed;
2523 CLOSE_BRACE opt_semicolon
2525 if (RootContext.Documentation != null)
2526 current_class.DocComment = enumTypeComment;
2528 --lexer.parsing_declaration;
2530 // if (RootContext.Documentation != null)
2531 // em.DocComment = ev.DocComment;
2533 lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2534 $$ = pop_current_class ();
2542 var te = $2 as TypeExpression;
2544 (te.Type != TypeManager.int32_type && te.Type != TypeManager.uint32_type &&
2545 te.Type != TypeManager.int64_type && te.Type != TypeManager.uint64_type &&
2546 te.Type != TypeManager.short_type && te.Type != TypeManager.ushort_type &&
2547 te.Type != TypeManager.byte_type && te.Type != TypeManager.sbyte_type)) {
2548 Enum.Error_1008 (GetLocation ($2), Report);
2556 Error_TypeExpected (GetLocation ($1));
2561 opt_enum_member_declarations
2563 | enum_member_declarations
2564 | enum_member_declarations COMMA
2566 lbag.AddLocation ($1, GetLocation ($2));
2570 enum_member_declarations
2571 : enum_member_declaration
2572 | enum_member_declarations COMMA enum_member_declaration
2574 lbag.AddLocation ($1, GetLocation ($2));
2579 enum_member_declaration
2580 : opt_attributes IDENTIFIER
2582 var lt = (Tokenizer.LocatedToken) $2;
2583 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2584 ((Enum) current_class).AddEnumMember (em);
2586 if (RootContext.Documentation != null) {
2587 em.DocComment = Lexer.consume_doc_comment ();
2588 Lexer.doc_state = XmlCommentState.Allowed;
2593 | opt_attributes IDENTIFIER
2595 ++lexer.parsing_block;
2596 if (RootContext.Documentation != null) {
2597 tmpComment = Lexer.consume_doc_comment ();
2598 Lexer.doc_state = XmlCommentState.NotAllowed;
2601 ASSIGN constant_expression
2603 --lexer.parsing_block;
2605 var lt = (Tokenizer.LocatedToken) $2;
2606 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2607 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2608 ((Enum) current_class).AddEnumMember (em);
2610 if (RootContext.Documentation != null)
2611 em.DocComment = ConsumeStoredComment ();
2617 delegate_declaration
2621 member_type type_declaration_name
2624 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2626 opt_formal_parameter_list CLOSE_PARENS
2628 valid_param_mod = 0;
2630 MemberName name = MakeName ((MemberName) $5);
2631 ParametersCompiled p = (ParametersCompiled) $8;
2633 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2634 (Modifiers) $2, name, p, (Attributes) $1);
2636 if (RootContext.Documentation != null) {
2637 del.DocComment = Lexer.consume_doc_comment ();
2638 Lexer.doc_state = XmlCommentState.Allowed;
2641 current_container.AddDelegate (del);
2642 current_delegate = del;
2643 lexer.ConstraintsParsing = true;
2645 opt_type_parameter_constraints_clauses
2647 lexer.ConstraintsParsing = false;
2651 current_delegate.SetParameterInfo ((List<Constraints>) $11);
2652 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2654 $$ = current_delegate;
2656 current_delegate = null;
2664 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2665 Report.FeatureIsNotSupported (GetLocation ($1), "nullable types");
2666 else if (RootContext.Version < LanguageVersion.ISO_2)
2667 Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2669 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2673 namespace_or_type_name
2675 | qualified_alias_member IDENTIFIER opt_type_argument_list
2677 var lt1 = (Tokenizer.LocatedToken) $1;
2678 var lt2 = (Tokenizer.LocatedToken) $2;
2680 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2686 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2688 var lt = (Tokenizer.LocatedToken) $3;
2689 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2690 lbag.AddLocation ($$, GetLocation ($2));
2695 : IDENTIFIER opt_type_argument_list
2697 var lt = (Tokenizer.LocatedToken) $1;
2698 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2703 // Generics arguments (any type, without attributes)
2705 opt_type_argument_list
2707 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2709 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2710 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
2711 else if (RootContext.Version < LanguageVersion.ISO_2)
2712 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2716 | OP_GENERICS_LT error
2718 Error_TypeExpected (lexer.Location);
2719 $$ = new TypeArguments ();
2726 TypeArguments type_args = new TypeArguments ();
2727 type_args.Add ((FullNamedExpression) $1);
2730 | type_arguments COMMA type
2732 TypeArguments type_args = (TypeArguments) $1;
2733 type_args.Add ((FullNamedExpression) $3);
2739 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2741 type_declaration_name
2744 lexer.parsing_generic_declaration = true;
2746 opt_type_parameter_list
2748 lexer.parsing_generic_declaration = false;
2749 var lt = (Tokenizer.LocatedToken) $1;
2750 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2754 member_declaration_name
2755 : method_declaration_name
2757 MemberName mn = (MemberName)$1;
2758 if (mn.TypeArguments != null)
2759 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2760 mn.GetSignatureForError ()));
2764 method_declaration_name
2765 : type_declaration_name
2766 | explicit_interface IDENTIFIER opt_type_parameter_list
2768 lexer.parsing_generic_declaration = false;
2769 var lt = (Tokenizer.LocatedToken) $2;
2770 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2774 indexer_declaration_name
2777 lexer.parsing_generic_declaration = false;
2778 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2780 | explicit_interface THIS
2782 lexer.parsing_generic_declaration = false;
2783 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2788 : IDENTIFIER opt_type_argument_list DOT
2790 var lt = (Tokenizer.LocatedToken) $1;
2791 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2792 lbag.AddLocation ($$, GetLocation ($3));
2794 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2796 var lt1 = (Tokenizer.LocatedToken) $1;
2797 var lt2 = (Tokenizer.LocatedToken) $2;
2799 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2800 lbag.AddLocation ($$, GetLocation ($4));
2802 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2804 var lt = (Tokenizer.LocatedToken) $2;
2805 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2806 lbag.AddLocation ($$, GetLocation ($4));
2810 opt_type_parameter_list
2812 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2814 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2815 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
2816 else if (RootContext.Version < LanguageVersion.ISO_2)
2817 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2820 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2827 TypeArguments type_args = new TypeArguments ();
2828 type_args.Add ((FullNamedExpression)$1);
2831 | type_parameters COMMA type_parameter
2833 TypeArguments type_args = (TypeArguments) $1;
2834 type_args.Add ((FullNamedExpression)$3);
2836 lbag.AddLocation ($3, GetLocation ($3));
2841 : opt_attributes opt_type_parameter_variance IDENTIFIER
2843 var lt = (Tokenizer.LocatedToken)$3;
2844 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2848 if (GetTokenName (yyToken) == "type")
2849 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2851 Error_SyntaxError (yyToken);
2853 $$ = new TypeParameterName ("", null, lexer.Location);
2858 // All types where void is allowed
2861 : type_expression_or_array
2864 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2871 lexer.parsing_generic_declaration = true;
2876 // A type which does not allow `void' to be used
2879 : type_expression_or_array
2882 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2883 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2891 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2892 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2897 : type_expression_or_array
2900 Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2901 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2905 type_expression_or_array
2907 | type_expression rank_specifiers
2909 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2914 : namespace_or_type_name opt_nullable
2916 MemberName name = (MemberName) $1;
2919 $$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
2921 if (name.Left == null && name.Name == "var")
2922 $$ = new VarExpr (name.Location);
2924 $$ = name.GetTypeExpression ();
2927 | namespace_or_type_name pointer_stars
2929 $$ = new ComposedCast (((MemberName) $1).GetTypeExpression (), (ComposedTypeSpecifier) $2);
2931 | builtin_types opt_nullable
2934 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2936 | builtin_types pointer_stars
2938 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2940 | VOID pointer_stars
2942 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2949 var types = new List<FullNamedExpression> (2);
2950 types.Add ((FullNamedExpression) $1);
2953 | type_list COMMA base_type_name
2955 var types = (List<FullNamedExpression>) $1;
2956 types.Add ((FullNamedExpression) $3);
2964 if ($1 is ComposedCast) {
2965 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2971 Error_TypeExpected (lexer.Location);
2977 * replaces all the productions for isolating the various
2978 * simple types, but we need this to reuse it easily in variable_type
2981 : OBJECT { $$ = new TypeExpression (TypeManager.object_type, GetLocation ($1)); }
2982 | STRING { $$ = new TypeExpression (TypeManager.string_type, GetLocation ($1)); }
2983 | BOOL { $$ = new TypeExpression (TypeManager.bool_type, GetLocation ($1)); }
2984 | DECIMAL { $$ = new TypeExpression (TypeManager.decimal_type, GetLocation ($1)); }
2985 | FLOAT { $$ = new TypeExpression (TypeManager.float_type, GetLocation ($1)); }
2986 | DOUBLE { $$ = new TypeExpression (TypeManager.double_type, GetLocation ($1)); }
2991 : SBYTE { $$ = new TypeExpression (TypeManager.sbyte_type, GetLocation ($1)); }
2992 | BYTE { $$ = new TypeExpression (TypeManager.byte_type, GetLocation ($1)); }
2993 | SHORT { $$ = new TypeExpression (TypeManager.short_type, GetLocation ($1)); }
2994 | USHORT { $$ = new TypeExpression (TypeManager.ushort_type, GetLocation ($1)); }
2995 | INT { $$ = new TypeExpression (TypeManager.int32_type, GetLocation ($1)); }
2996 | UINT { $$ = new TypeExpression (TypeManager.uint32_type, GetLocation ($1)); }
2997 | LONG { $$ = new TypeExpression (TypeManager.int64_type, GetLocation ($1)); }
2998 | ULONG { $$ = new TypeExpression (TypeManager.uint64_type, GetLocation ($1)); }
2999 | CHAR { $$ = new TypeExpression (TypeManager.char_type, GetLocation ($1)); }
3003 // Expressions, section 7.5
3008 : primary_expression_or_type
3010 | array_creation_expression
3011 | parenthesized_expression
3012 | default_value_expression
3013 | invocation_expression
3017 | post_increment_expression
3018 | post_decrement_expression
3019 | object_or_delegate_creation_expression
3020 | anonymous_type_expression
3023 | checked_expression
3024 | unchecked_expression
3025 | pointer_member_access
3026 | anonymous_method_expression
3029 primary_expression_or_type
3030 : IDENTIFIER opt_type_argument_list
3032 var lt = (Tokenizer.LocatedToken) $1;
3033 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3035 | IDENTIFIER GENERATE_COMPLETION {
3036 var lt = (Tokenizer.LocatedToken) $1;
3037 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3045 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3049 : TRUE { $$ = new BoolLiteral (true, GetLocation ($1)); }
3050 | FALSE { $$ = new BoolLiteral (false, GetLocation ($1)); }
3055 // Here is the trick, tokenizer may think that parens is a special but
3056 // parser is interested in open parens only, so we merge them.
3057 // Consider: if (a)foo ();
3065 // Use this production to accept closing parenthesis or
3066 // performing completion
3070 | COMPLETE_COMPLETION
3074 parenthesized_expression
3075 : OPEN_PARENS expression CLOSE_PARENS
3077 $$ = new ParenthesizedExpression ((Expression) $2);
3078 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3080 | OPEN_PARENS expression COMPLETE_COMPLETION
3082 $$ = new ParenthesizedExpression ((Expression) $2);
3087 : primary_expression DOT IDENTIFIER opt_type_argument_list
3089 var lt = (Tokenizer.LocatedToken) $3;
3090 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3091 lbag.AddLocation ($$, GetLocation ($2));
3093 | builtin_types DOT IDENTIFIER opt_type_argument_list
3095 var lt = (Tokenizer.LocatedToken) $3;
3096 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3097 lbag.AddLocation ($$, GetLocation ($2));
3099 | BASE DOT IDENTIFIER opt_type_argument_list
3101 var lt = (Tokenizer.LocatedToken) $3;
3102 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3103 lbag.AddLocation ($$, GetLocation ($2));
3105 | qualified_alias_member IDENTIFIER opt_type_argument_list
3107 var lt1 = (Tokenizer.LocatedToken) $1;
3108 var lt2 = (Tokenizer.LocatedToken) $2;
3110 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3112 | primary_expression DOT GENERATE_COMPLETION {
3113 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3115 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3116 var lt = (Tokenizer.LocatedToken) $3;
3117 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3119 | builtin_types DOT GENERATE_COMPLETION
3121 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3123 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3124 var lt = (Tokenizer.LocatedToken) $3;
3125 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3129 invocation_expression
3130 : primary_expression open_parens_any opt_argument_list close_parens
3132 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3133 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3137 opt_object_or_collection_initializer
3138 : /* empty */ { $$ = null; }
3139 | object_or_collection_initializer
3142 object_or_collection_initializer
3143 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3146 $$ = CollectionOrObjectInitializers.Empty;
3149 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3150 lbag.AddLocation ($$, GetLocation ($3));
3153 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3155 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3156 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3160 opt_member_initializer_list
3161 : /* empty */ { $$ = null; }
3162 | member_initializer_list
3168 member_initializer_list
3169 : member_initializer
3171 var a = new List<Expression> ();
3172 a.Add ((Expression) $1);
3175 | member_initializer_list COMMA member_initializer
3177 var a = (List<Expression>)$1;
3178 a.Add ((Expression) $3);
3181 | member_initializer_list error {
3182 Error_SyntaxError (yyToken);
3188 : IDENTIFIER ASSIGN initializer_value
3190 var lt = (Tokenizer.LocatedToken) $1;
3191 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3192 lbag.AddLocation ($$, GetLocation ($2));
3194 | GENERATE_COMPLETION
3196 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3198 | non_assignment_expression opt_COMPLETE_COMPLETION {
3199 CompletionSimpleName csn = $1 as CompletionSimpleName;
3201 $$ = new CollectionElementInitializer ((Expression)$1);
3203 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3205 | OPEN_BRACE expression_list CLOSE_BRACE
3210 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3212 | OPEN_BRACE CLOSE_BRACE
3214 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3221 | object_or_collection_initializer
3225 : /* empty */ { $$ = null; }
3230 : argument_or_named_argument
3232 Arguments list = new Arguments (4);
3233 list.Add ((Argument) $1);
3236 | argument_list COMMA argument
3238 Arguments list = (Arguments) $1;
3239 if (list [list.Count - 1] is NamedArgument)
3240 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3242 list.Add ((Argument) $3);
3245 | argument_list COMMA named_argument
3247 Arguments list = (Arguments) $1;
3248 NamedArgument a = (NamedArgument) $3;
3249 for (int i = 0; i < list.Count; ++i) {
3250 NamedArgument na = list [i] as NamedArgument;
3251 if (na != null && na.Name == a.Name)
3252 Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3259 | argument_list COMMA
3261 Report.Error (839, GetLocation ($2), "An argument is missing");
3266 Report.Error (839, GetLocation ($1), "An argument is missing");
3274 $$ = new Argument ((Expression) $1);
3276 | non_simple_argument
3279 argument_or_named_argument
3285 : REF variable_reference
3287 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3288 lbag.AddLocation ($$, GetLocation ($1));
3290 | OUT variable_reference
3292 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3293 lbag.AddLocation ($$, GetLocation ($1));
3295 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3297 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3298 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3300 | ARGLIST OPEN_PARENS CLOSE_PARENS
3302 $$ = new Argument (new Arglist (GetLocation ($1)));
3303 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3312 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3314 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3315 lbag.AddLocation ($$, GetLocation ($4));
3322 var list = new List<Expression> (4);
3323 list.Add ((Expression) $1);
3326 | expression_list COMMA expression
3328 var list = (List<Expression>) $1;
3329 list.Add ((Expression) $3);
3332 | expression_list error {
3333 Error_SyntaxError (yyToken);
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 (GetLocation ($1));
3369 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3371 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3372 lbag.AddLocation ($$, GetLocation ($4));
3374 | BASE OPEN_BRACKET error
3376 Error_SyntaxError (yyToken);
3377 $$ = new ElementAccess (null, null, GetLocation ($2));
3381 post_increment_expression
3382 : primary_expression OP_INC
3384 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3388 post_decrement_expression
3389 : primary_expression OP_DEC
3391 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3395 object_or_delegate_creation_expression
3396 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3399 if (RootContext.Version <= LanguageVersion.ISO_2)
3400 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3402 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3404 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3407 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3409 | NEW new_expr_type object_or_collection_initializer
3411 if (RootContext.Version <= LanguageVersion.ISO_2)
3412 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3414 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3418 array_creation_expression
3419 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3421 opt_array_initializer
3423 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3424 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3425 Next = (ComposedTypeSpecifier) $6
3426 }, (ArrayInitializer) $7, GetLocation ($1));
3427 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3429 | NEW new_expr_type rank_specifiers opt_array_initializer
3432 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3434 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3436 | NEW rank_specifiers array_initializer
3438 if (RootContext.Version <= LanguageVersion.ISO_2)
3439 Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3441 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3443 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3445 Report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3446 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3448 | NEW new_expr_type error
3450 Error_SyntaxError (1526, yyToken, "Unexpected symbol");
3451 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3457 ++lexer.parsing_type;
3461 --lexer.parsing_type;
3466 anonymous_type_expression
3467 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3469 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3470 Report.FeatureIsNotSupported (GetLocation ($1), "anonymous types");
3471 else if (RootContext.Version <= LanguageVersion.ISO_2)
3472 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3474 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3476 // TODO: lbag comma location
3477 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3481 anonymous_type_parameters_opt_comma
3482 : anonymous_type_parameters_opt
3483 | anonymous_type_parameters COMMA
3486 anonymous_type_parameters_opt
3488 | anonymous_type_parameters
3491 anonymous_type_parameters
3492 : anonymous_type_parameter
3494 var a = new List<AnonymousTypeParameter> (4);
3495 a.Add ((AnonymousTypeParameter) $1);
3498 | anonymous_type_parameters COMMA anonymous_type_parameter
3500 var a = (List<AnonymousTypeParameter>) $1;
3501 a.Add ((AnonymousTypeParameter) $3);
3506 anonymous_type_parameter
3507 : IDENTIFIER ASSIGN variable_initializer
3509 var lt = (Tokenizer.LocatedToken)$1;
3510 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3511 lbag.AddLocation ($$, GetLocation ($2));
3515 var lt = (Tokenizer.LocatedToken)$1;
3516 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3517 lt.Value, lt.Location);
3521 MemberAccess ma = (MemberAccess) $1;
3522 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3526 Report.Error (746, lexer.Location,
3527 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3539 | rank_specifier rank_specifiers
3541 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3547 : OPEN_BRACKET CLOSE_BRACKET
3549 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3551 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3553 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3562 | dim_separators COMMA
3564 $$ = ((int) $1) + 1;
3568 opt_array_initializer
3580 : OPEN_BRACE CLOSE_BRACE
3582 var ai = new ArrayInitializer (0, GetLocation ($1));
3583 ai.VariableDeclaration = current_variable;
3584 lbag.AddLocation (ai, GetLocation ($2));
3587 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3589 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3590 ai.VariableDeclaration = current_variable;
3591 lbag.AddLocation (ai, GetLocation ($3));
3596 variable_initializer_list
3597 : variable_initializer
3599 var list = new List<Expression> (4);
3600 list.Add ((Expression) $1);
3603 | variable_initializer_list COMMA variable_initializer
3605 var list = (List<Expression>) $1;
3606 list.Add ((Expression) $3);
3614 lexer.TypeOfParsing = true;
3616 open_parens_any typeof_type_expression CLOSE_PARENS
3618 lexer.TypeOfParsing = false;
3619 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3620 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3624 typeof_type_expression
3629 Error_TypeExpected (lexer.Location);
3635 : IDENTIFIER generic_dimension
3637 var lt = (Tokenizer.LocatedToken) $1;
3639 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3641 | qualified_alias_member IDENTIFIER generic_dimension
3643 var lt1 = (Tokenizer.LocatedToken) $1;
3644 var lt2 = (Tokenizer.LocatedToken) $2;
3646 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3648 | unbound_type_name DOT IDENTIFIER
3650 var lt = (Tokenizer.LocatedToken) $3;
3652 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3654 | unbound_type_name DOT IDENTIFIER generic_dimension
3656 var lt = (Tokenizer.LocatedToken) $3;
3658 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3660 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3662 var te = ((MemberName) $1).GetTypeExpression ();
3663 if (te.HasTypeArguments)
3664 Error_TypeExpected (GetLocation ($4));
3666 var lt = (Tokenizer.LocatedToken) $3;
3667 $$ = new MemberAccess (te, lt.Value, (int) $4, lt.Location);
3674 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3675 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
3676 else if (RootContext.Version < LanguageVersion.ISO_2)
3677 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
3683 qualified_alias_member
3684 : IDENTIFIER DOUBLE_COLON
3686 var lt = (Tokenizer.LocatedToken) $1;
3687 if (RootContext.Version == LanguageVersion.ISO_1)
3688 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3695 : SIZEOF open_parens_any type CLOSE_PARENS
3697 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3698 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3703 : CHECKED open_parens_any expression CLOSE_PARENS
3705 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3706 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3710 unchecked_expression
3711 : UNCHECKED open_parens_any expression CLOSE_PARENS
3713 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3714 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3718 pointer_member_access
3719 : primary_expression OP_PTR IDENTIFIER
3721 var lt = (Tokenizer.LocatedToken) $3;
3722 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, lt.Location);
3726 anonymous_method_expression
3727 : DELEGATE opt_anonymous_method_signature
3729 start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1));
3733 $$ = end_anonymous ((ParametersBlock) $4);
3737 opt_anonymous_method_signature
3740 $$ = ParametersCompiled.Undefined;
3742 | anonymous_method_signature
3745 anonymous_method_signature
3748 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3750 opt_formal_parameter_list CLOSE_PARENS
3752 valid_param_mod = 0;
3757 default_value_expression
3758 : DEFAULT open_parens_any type CLOSE_PARENS
3760 if (RootContext.Version < LanguageVersion.ISO_2)
3761 Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3763 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3764 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3769 : primary_expression
3770 | BANG prefixed_unary_expression
3772 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3774 | TILDE prefixed_unary_expression
3776 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3782 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3784 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3785 lbag.AddLocation ($$, GetLocation ($3));
3790 // The idea to split this out is from Rhys' grammar
3791 // to solve the problem with casts.
3793 prefixed_unary_expression
3795 | PLUS prefixed_unary_expression
3797 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3799 | MINUS prefixed_unary_expression
3801 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3803 | OP_INC prefixed_unary_expression
3805 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3807 | OP_DEC prefixed_unary_expression
3809 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3811 | STAR prefixed_unary_expression
3813 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3815 | BITWISE_AND prefixed_unary_expression
3817 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3821 multiplicative_expression
3822 : prefixed_unary_expression
3823 | multiplicative_expression STAR prefixed_unary_expression
3825 $$ = new Binary (Binary.Operator.Multiply,
3826 (Expression) $1, (Expression) $3, GetLocation ($2));
3828 | multiplicative_expression DIV prefixed_unary_expression
3830 $$ = new Binary (Binary.Operator.Division,
3831 (Expression) $1, (Expression) $3, GetLocation ($2));
3833 | multiplicative_expression PERCENT prefixed_unary_expression
3835 $$ = new Binary (Binary.Operator.Modulus,
3836 (Expression) $1, (Expression) $3, GetLocation ($2));
3841 : multiplicative_expression
3842 | additive_expression PLUS multiplicative_expression
3844 $$ = new Binary (Binary.Operator.Addition,
3845 (Expression) $1, (Expression) $3, GetLocation ($2));
3847 | additive_expression MINUS multiplicative_expression
3849 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3851 | parenthesized_expression MINUS multiplicative_expression
3853 // Shift/Reduce conflict
3854 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3856 | additive_expression AS type
3858 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3860 | additive_expression IS type
3862 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3867 : additive_expression
3868 | shift_expression OP_SHIFT_LEFT additive_expression
3870 $$ = new Binary (Binary.Operator.LeftShift,
3871 (Expression) $1, (Expression) $3, GetLocation ($2));
3873 | shift_expression OP_SHIFT_RIGHT additive_expression
3875 $$ = new Binary (Binary.Operator.RightShift,
3876 (Expression) $1, (Expression) $3, GetLocation ($2));
3880 relational_expression
3882 | relational_expression OP_LT shift_expression
3884 $$ = new Binary (Binary.Operator.LessThan,
3885 (Expression) $1, (Expression) $3, GetLocation ($2));
3887 | relational_expression OP_GT shift_expression
3889 $$ = new Binary (Binary.Operator.GreaterThan,
3890 (Expression) $1, (Expression) $3, GetLocation ($2));
3892 | relational_expression OP_LE shift_expression
3894 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3895 (Expression) $1, (Expression) $3, GetLocation ($2));
3897 | relational_expression OP_GE shift_expression
3899 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3900 (Expression) $1, (Expression) $3, GetLocation ($2));
3905 : relational_expression
3906 | equality_expression OP_EQ relational_expression
3908 $$ = new Binary (Binary.Operator.Equality,
3909 (Expression) $1, (Expression) $3, GetLocation ($2));
3911 | equality_expression OP_NE relational_expression
3913 $$ = new Binary (Binary.Operator.Inequality,
3914 (Expression) $1, (Expression) $3, GetLocation ($2));
3919 : equality_expression
3920 | and_expression BITWISE_AND equality_expression
3922 $$ = new Binary (Binary.Operator.BitwiseAnd,
3923 (Expression) $1, (Expression) $3, GetLocation ($2));
3927 exclusive_or_expression
3929 | exclusive_or_expression CARRET and_expression
3931 $$ = new Binary (Binary.Operator.ExclusiveOr,
3932 (Expression) $1, (Expression) $3, GetLocation ($2));
3936 inclusive_or_expression
3937 : exclusive_or_expression
3938 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3940 $$ = new Binary (Binary.Operator.BitwiseOr,
3941 (Expression) $1, (Expression) $3, GetLocation ($2));
3945 conditional_and_expression
3946 : inclusive_or_expression
3947 | conditional_and_expression OP_AND inclusive_or_expression
3949 $$ = new Binary (Binary.Operator.LogicalAnd,
3950 (Expression) $1, (Expression) $3, GetLocation ($2));
3954 conditional_or_expression
3955 : conditional_and_expression
3956 | conditional_or_expression OP_OR conditional_and_expression
3958 $$ = new Binary (Binary.Operator.LogicalOr,
3959 (Expression) $1, (Expression) $3, GetLocation ($2));
3963 null_coalescing_expression
3964 : conditional_or_expression
3965 | conditional_or_expression OP_COALESCING null_coalescing_expression
3967 if (RootContext.Version < LanguageVersion.ISO_2)
3968 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3970 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3974 conditional_expression
3975 : null_coalescing_expression
3976 | null_coalescing_expression INTERR expression COLON expression
3978 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3979 lbag.AddLocation ($$, GetLocation ($4));
3983 assignment_expression
3984 : prefixed_unary_expression ASSIGN expression
3986 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3988 | prefixed_unary_expression OP_MULT_ASSIGN expression
3990 $$ = new CompoundAssign (
3991 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
3993 | prefixed_unary_expression OP_DIV_ASSIGN expression
3995 $$ = new CompoundAssign (
3996 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
3998 | prefixed_unary_expression OP_MOD_ASSIGN expression
4000 $$ = new CompoundAssign (
4001 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
4003 | prefixed_unary_expression OP_ADD_ASSIGN expression
4005 $$ = new CompoundAssign (
4006 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
4008 | prefixed_unary_expression OP_SUB_ASSIGN expression
4010 $$ = new CompoundAssign (
4011 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4013 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4015 $$ = new CompoundAssign (
4016 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4018 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4020 $$ = new CompoundAssign (
4021 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4023 | prefixed_unary_expression OP_AND_ASSIGN expression
4025 $$ = new CompoundAssign (
4026 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4028 | prefixed_unary_expression OP_OR_ASSIGN expression
4030 $$ = new CompoundAssign (
4031 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4033 | prefixed_unary_expression OP_XOR_ASSIGN expression
4035 $$ = new CompoundAssign (
4036 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4040 lambda_parameter_list
4043 var pars = new List<Parameter> (4);
4044 pars.Add ((Parameter) $1);
4048 | lambda_parameter_list COMMA lambda_parameter
4050 var pars = (List<Parameter>) $1;
4051 Parameter p = (Parameter)$3;
4052 if (pars[0].GetType () != p.GetType ()) {
4053 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4062 : parameter_modifier parameter_type IDENTIFIER
4064 var lt = (Tokenizer.LocatedToken) $3;
4066 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4068 | parameter_type IDENTIFIER
4070 var lt = (Tokenizer.LocatedToken) $2;
4072 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4076 var lt = (Tokenizer.LocatedToken) $1;
4077 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4081 opt_lambda_parameter_list
4082 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4083 | lambda_parameter_list {
4084 var pars_list = (List<Parameter>) $1;
4085 $$ = new ParametersCompiled (pars_list.ToArray ());
4089 lambda_expression_body
4091 start_block (lexer.Location);
4095 Block b = end_block (lexer.Location);
4096 b.AddStatement (new ContextualReturn ((Expression) $2));
4108 var lt = (Tokenizer.LocatedToken) $1;
4109 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4110 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
4112 lambda_expression_body
4114 $$ = end_anonymous ((ParametersBlock) $4);
4115 lbag.AddLocation ($$, GetLocation ($2));
4117 | OPEN_PARENS_LAMBDA
4119 if (RootContext.Version <= LanguageVersion.ISO_2)
4120 Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
4122 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4124 opt_lambda_parameter_list CLOSE_PARENS ARROW
4126 valid_param_mod = 0;
4127 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4129 lambda_expression_body
4131 $$ = end_anonymous ((ParametersBlock) $7);
4132 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
4137 : assignment_expression
4138 | non_assignment_expression
4141 non_assignment_expression
4142 : conditional_expression
4147 $$ = new ArglistAccess (GetLocation ($1));
4158 $$ = new BooleanExpression ((Expression) $1);
4171 lexer.ConstraintsParsing = true;
4173 type_declaration_name
4175 MemberName name = MakeName ((MemberName) $6);
4176 push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
4179 opt_type_parameter_constraints_clauses
4181 lexer.ConstraintsParsing = false;
4183 current_class.SetParameterInfo ((List<Constraints>) $9);
4184 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
4186 if (RootContext.Documentation != null) {
4187 current_container.DocComment = Lexer.consume_doc_comment ();
4188 Lexer.doc_state = XmlCommentState.Allowed;
4191 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4193 --lexer.parsing_declaration;
4194 if (RootContext.Documentation != null)
4195 Lexer.doc_state = XmlCommentState.Allowed;
4199 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4200 $$ = pop_current_class ();
4208 { $$ = $1; } // location
4214 mod_locations = null;
4222 | modifiers modifier
4224 var m1 = (Modifiers) $1;
4225 var m2 = (Modifiers) $2;
4227 if ((m1 & m2) != 0) {
4228 Report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4229 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4230 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4231 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4232 Report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4233 "More than one protection modifier specified");
4244 StoreModifierLocation ($$, GetLocation ($1));
4246 if (current_container == RootContext.ToplevelTypes)
4247 Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4251 $$ = Modifiers.PUBLIC;
4252 StoreModifierLocation ($$, GetLocation ($1));
4256 $$ = Modifiers.PROTECTED;
4257 StoreModifierLocation ($$, GetLocation ($1));
4261 $$ = Modifiers.INTERNAL;
4262 StoreModifierLocation ($$, GetLocation ($1));
4266 $$ = Modifiers.PRIVATE;
4267 StoreModifierLocation ($$, GetLocation ($1));
4271 $$ = Modifiers.ABSTRACT;
4272 StoreModifierLocation ($$, GetLocation ($1));
4276 $$ = Modifiers.SEALED;
4277 StoreModifierLocation ($$, GetLocation ($1));
4281 $$ = Modifiers.STATIC;
4282 StoreModifierLocation ($$, GetLocation ($1));
4286 $$ = Modifiers.READONLY;
4287 StoreModifierLocation ($$, GetLocation ($1));
4291 $$ = Modifiers.VIRTUAL;
4292 StoreModifierLocation ($$, GetLocation ($1));
4296 $$ = Modifiers.OVERRIDE;
4297 StoreModifierLocation ($$, GetLocation ($1));
4301 $$ = Modifiers.EXTERN;
4302 StoreModifierLocation ($$, GetLocation ($1));
4306 $$ = Modifiers.VOLATILE;
4307 StoreModifierLocation ($$, GetLocation ($1));
4311 $$ = Modifiers.UNSAFE;
4312 StoreModifierLocation ($$, GetLocation ($1));
4313 if (!RootContext.Unsafe)
4314 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4322 current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
4326 opt_type_parameter_constraints_clauses
4328 | type_parameter_constraints_clauses
4334 type_parameter_constraints_clauses
4335 : type_parameter_constraints_clause
4337 var constraints = new List<Constraints> (1);
4338 constraints.Add ((Constraints) $1);
4341 | type_parameter_constraints_clauses type_parameter_constraints_clause
4343 var constraints = (List<Constraints>) $1;
4344 Constraints new_constraint = (Constraints)$2;
4346 foreach (Constraints c in constraints) {
4347 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4348 Report.Error (409, new_constraint.Location,
4349 "A constraint clause has already been specified for type parameter `{0}'",
4350 new_constraint.TypeParameter.Value);
4354 constraints.Add (new_constraint);
4359 type_parameter_constraints_clause
4360 : WHERE IDENTIFIER COLON type_parameter_constraints
4362 var lt = (Tokenizer.LocatedToken) $2;
4363 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4367 type_parameter_constraints
4368 : type_parameter_constraint
4370 var constraints = new List<FullNamedExpression> (1);
4371 constraints.Add ((FullNamedExpression) $1);
4374 | type_parameter_constraints COMMA type_parameter_constraint
4376 var constraints = (List<FullNamedExpression>) $1;
4377 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4378 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4379 Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4382 prev = $3 as SpecialContraintExpr;
4384 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4385 Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4387 prev = constraints [0] as SpecialContraintExpr;
4388 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4389 Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4394 constraints.Add ((FullNamedExpression) $3);
4399 type_parameter_constraint
4402 if ($1 is ComposedCast)
4403 Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4407 | NEW OPEN_PARENS CLOSE_PARENS
4409 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4410 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4414 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4418 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4422 opt_type_parameter_variance
4427 | type_parameter_variance
4429 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
4430 Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
4431 else if (RootContext.Version <= LanguageVersion.V_3)
4432 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4438 type_parameter_variance
4441 $$ = Variance.Covariant;
4445 $$ = Variance.Contravariant;
4454 // A block is "contained" on the following places:
4456 // property_declaration as part of the accessor body (get/set)
4457 // operator_declaration
4458 // constructor_declaration
4459 // destructor_declaration
4460 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4465 ++lexer.parsing_block;
4466 start_block (GetLocation ($1));
4468 opt_statement_list block_end
4477 --lexer.parsing_block;
4478 $$ = end_block (GetLocation ($1));
4480 | COMPLETE_COMPLETION
4482 --lexer.parsing_block;
4483 $$ = end_block (lexer.Location);
4491 ++lexer.parsing_block;
4492 current_block.StartLocation = GetLocation ($1);
4494 opt_statement_list CLOSE_BRACE
4496 --lexer.parsing_block;
4497 $$ = end_block (GetLocation ($4));
4508 | statement_list statement
4512 : block_variable_declaration
4514 current_block.AddStatement ((Statement) $1);
4516 | valid_declaration_statement
4518 current_block.AddStatement ((Statement) $1);
4523 Error_SyntaxError (yyToken);
4529 // The interactive_statement and its derivatives are only
4530 // used to provide a special version of `expression_statement'
4531 // that has a side effect of assigning the expression to
4534 interactive_statement_list
4535 : interactive_statement
4536 | interactive_statement_list interactive_statement
4539 interactive_statement
4540 : block_variable_declaration
4542 current_block.AddStatement ((Statement) $1);
4544 | interactive_valid_declaration_statement
4546 current_block.AddStatement ((Statement) $1);
4551 valid_declaration_statement
4554 | expression_statement
4555 | selection_statement
4556 | iteration_statement
4560 | unchecked_statement
4567 interactive_valid_declaration_statement
4570 | interactive_expression_statement
4571 | selection_statement
4572 | iteration_statement
4576 | unchecked_statement
4584 : valid_declaration_statement
4585 | block_variable_declaration
4587 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4592 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4597 Error_SyntaxError (yyToken);
4598 $$ = new EmptyStatement (GetLocation ($1));
4605 $$ = new EmptyStatement (GetLocation ($1));
4612 var lt = (Tokenizer.LocatedToken) $1;
4613 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4615 current_block.AddLabel (labeled);
4616 current_block.AddStatement (labeled);
4622 : variable_type_simple
4623 | variable_type_simple rank_specifiers
4626 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4628 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4633 * The following is from Rhys' grammar:
4634 * > Types in local variable declarations must be recognized as
4635 * > expressions to prevent reduce/reduce errors in the grammar.
4636 * > The expressions are converted into types during semantic analysis.
4638 variable_type_simple
4639 : primary_expression_or_type opt_nullable
4641 // Ok, the above "primary_expression" is there to get rid of
4642 // both reduce/reduce and shift/reduces in the grammar, it should
4643 // really just be "type_name". If you use type_name, a reduce/reduce
4644 // creeps up. If you use namespace_or_type_name (which is all we need
4645 // really) two shift/reduces appear.
4648 // So the super-trick is that primary_expression
4649 // can only be either a SimpleName or a MemberAccess.
4650 // The MemberAccess case arises when you have a fully qualified type-name like :
4652 // SimpleName is when you have
4655 Expression expr = (Expression) $1;
4657 SimpleName sn = expr as SimpleName;
4658 if (sn != null && sn.Name == "var")
4659 $$ = new VarExpr (sn.Location);
4662 } else if (expr is ATypeNameExpression) {
4663 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4665 Error_ExpectingTypeName (expr);
4669 | primary_expression_or_type pointer_stars
4671 ATypeNameExpression expr = $1 as ATypeNameExpression;
4674 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4676 Error_ExpectingTypeName ((Expression)$1);
4680 | builtin_types opt_nullable
4685 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4687 | builtin_types pointer_stars
4689 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4691 | VOID pointer_stars
4693 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4697 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
4698 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
4704 | pointer_star pointer_stars
4706 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4714 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4718 block_variable_declaration
4719 : variable_type IDENTIFIER
4721 var lt = (Tokenizer.LocatedToken) $2;
4722 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4723 current_block.AddLocalName (li);
4724 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4726 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4728 $$ = current_variable;
4729 current_variable = null;
4730 lbag.AddLocation ($$, GetLocation ($6));
4732 | CONST variable_type IDENTIFIER
4734 var lt = (Tokenizer.LocatedToken) $3;
4735 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4736 current_block.AddLocalName (li);
4737 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4739 const_variable_initializer opt_const_declarators SEMICOLON
4741 $$ = current_variable;
4742 current_variable = null;
4743 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4747 opt_local_variable_initializer
4749 | ASSIGN block_variable_initializer
4751 current_variable.Initializer = (Expression) $2;
4756 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4757 Report.Error (650, lexer.Location,
4758 "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type");
4760 Error_SyntaxError (yyToken);
4765 opt_variable_declarators
4767 | variable_declarators
4770 variable_declarators
4771 : variable_declarator
4772 | variable_declarators variable_declarator
4778 var lt = (Tokenizer.LocatedToken) $2;
4779 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4780 var d = new BlockVariableDeclaration.Declarator (li, null);
4781 current_variable.AddDeclarator (d);
4782 current_block.AddLocalName (li);
4783 lbag.AddLocation (d, GetLocation ($1));
4785 | COMMA IDENTIFIER ASSIGN block_variable_initializer
4787 var lt = (Tokenizer.LocatedToken) $2;
4788 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4789 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4790 current_variable.AddDeclarator (d);
4791 current_block.AddLocalName (li);
4792 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4796 const_variable_initializer
4799 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
4801 | ASSIGN constant_initializer_expr
4803 current_variable.Initializer = (Expression) $2;
4807 opt_const_declarators
4814 | const_declarators const_declarator
4818 : COMMA IDENTIFIER ASSIGN constant_initializer_expr
4820 var lt = (Tokenizer.LocatedToken) $2;
4821 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4822 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4823 current_variable.AddDeclarator (d);
4824 current_block.AddLocalName (li);
4825 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4829 block_variable_initializer
4830 : variable_initializer
4831 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4833 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4834 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4836 | STACKALLOC simple_type
4838 Report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4839 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4843 expression_statement
4844 : statement_expression SEMICOLON
4847 lbag.AddStatement ($$, GetLocation ($2));
4849 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4852 interactive_expression_statement
4853 : interactive_statement_expression SEMICOLON { $$ = $1; }
4854 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4858 // We have to do the wrapping here and not in the case above,
4859 // because statement_expression is used for example in for_statement
4861 statement_expression
4864 ExpressionStatement s = $1 as ExpressionStatement;
4866 Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
4867 s = EmptyExpressionStatement.Instance;
4870 $$ = new StatementExpression (s);
4874 interactive_statement_expression
4877 Expression expr = (Expression) $1;
4878 ExpressionStatement s;
4880 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4881 $$ = new StatementExpression (s);
4885 Error_SyntaxError (yyToken);
4886 $$ = new EmptyStatement (GetLocation ($1));
4896 : IF open_parens_any boolean_expression CLOSE_PARENS
4899 if ($5 is EmptyStatement)
4900 Warning_EmptyStatement (GetLocation ($5));
4902 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4903 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4905 | IF open_parens_any boolean_expression CLOSE_PARENS
4906 embedded_statement ELSE embedded_statement
4908 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
4909 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4911 if ($5 is EmptyStatement)
4912 Warning_EmptyStatement (GetLocation ($5));
4913 if ($7 is EmptyStatement)
4914 Warning_EmptyStatement (GetLocation ($7));
4919 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
4921 start_block (GetLocation ($5));
4923 opt_switch_sections CLOSE_BRACE
4925 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
4926 end_block (GetLocation ($8));
4927 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4934 Report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
4935 $$ = new List<SwitchSection> ();
4943 var sections = new List<SwitchSection> (4);
4945 sections.Add ((SwitchSection) $1);
4948 | switch_sections switch_section
4950 var sections = (List<SwitchSection>) $1;
4952 sections.Add ((SwitchSection) $2);
4957 Error_SyntaxError (yyToken);
4958 $$ = new List<SwitchSection> ();
4965 current_block = current_block.CreateSwitchBlock (lexer.Location);
4969 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
4976 var labels = new List<SwitchLabel> (4);
4978 labels.Add ((SwitchLabel) $1);
4981 | switch_labels switch_label
4983 var labels = (List<SwitchLabel>) ($1);
4984 labels.Add ((SwitchLabel) $2);
4991 : CASE constant_expression COLON
4993 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
4994 lbag.AddLocation ($$, GetLocation ($3));
4998 $$ = new SwitchLabel (null, GetLocation ($1));
5010 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5012 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5013 Warning_EmptyStatement (GetLocation ($5));
5015 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5016 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5021 : DO embedded_statement
5022 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5024 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5025 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5030 : FOR open_parens_any
5032 start_block (GetLocation ($2));
5033 current_block.IsCompilerGenerated = true;
5035 opt_for_initializer SEMICOLON
5036 opt_for_condition SEMICOLON
5037 opt_for_iterator CLOSE_PARENS
5040 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5041 Warning_EmptyStatement (GetLocation ($10));
5043 For f = new For ((Statement) $4, (BooleanExpression) $6, (Statement) $8, (Statement) $10, GetLocation ($1));
5044 current_block.AddStatement (f);
5046 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7), GetLocation ($9));
5048 $$ = end_block (GetLocation ($5));
5053 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5058 : variable_type IDENTIFIER
5060 var lt = (Tokenizer.LocatedToken) $2;
5061 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5062 current_block.AddLocalName (li);
5063 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5065 opt_local_variable_initializer opt_variable_declarators
5067 $$ = current_variable;
5068 current_variable = null;
5070 | statement_expression_list
5074 : /* empty */ { $$ = null; }
5075 | boolean_expression
5079 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5084 : statement_expression_list
5087 statement_expression_list
5088 : statement_expression
5089 | statement_expression_list COMMA statement_expression
5091 var sl = $1 as StatementList;
5093 sl = new StatementList ((Statement) $1, (Statement) $3);
5094 lbag.AddStatement (sl, GetLocation ($2));
5096 sl.Add ((Statement) $3);
5097 lbag.AppendTo (sl, GetLocation ($2));
5105 : FOREACH open_parens_any type IN expression CLOSE_PARENS
5107 Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5110 | FOREACH open_parens_any type IDENTIFIER IN expression CLOSE_PARENS
5112 start_block (GetLocation ($2));
5113 current_block.IsCompilerGenerated = true;
5115 var lt = (Tokenizer.LocatedToken) $4;
5116 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5117 current_block.AddLocalName (li);
5122 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5123 Warning_EmptyStatement (GetLocation ($9));
5125 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, GetLocation ($1));
5126 current_block.AddStatement (f);
5128 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5129 $$ = end_block (GetLocation ($7));
5135 | continue_statement
5145 $$ = new Break (GetLocation ($1));
5146 lbag.AddStatement ($$, GetLocation ($2));
5151 : CONTINUE SEMICOLON
5153 $$ = new Continue (GetLocation ($1));
5154 lbag.AddStatement ($$, GetLocation ($2));
5159 : GOTO IDENTIFIER SEMICOLON
5161 var lt = (Tokenizer.LocatedToken) $2;
5162 $$ = new Goto (lt.Value, lt.Location);
5163 lbag.AddStatement ($$, GetLocation ($1), GetLocation ($3));
5165 | GOTO CASE constant_expression SEMICOLON
5167 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5168 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5170 | GOTO DEFAULT SEMICOLON
5172 $$ = new GotoDefault (GetLocation ($1));
5173 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5178 : RETURN opt_expression SEMICOLON
5180 $$ = new Return ((Expression) $2, GetLocation ($1));
5181 lbag.AddStatement ($$, GetLocation ($3));
5186 : THROW opt_expression SEMICOLON
5188 $$ = new Throw ((Expression) $2, GetLocation ($1));
5189 lbag.AddStatement ($$, GetLocation ($3));
5194 : IDENTIFIER RETURN opt_expression SEMICOLON
5196 var lt = (Tokenizer.LocatedToken) $1;
5197 string s = lt.Value;
5199 Report.Error (1003, lt.Location, "; expected");
5200 } else if ($3 == null) {
5201 Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5202 } else if (RootContext.Version == LanguageVersion.ISO_1){
5203 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5206 current_block.ParametersBlock.TopBlock.IsIterator = true;
5207 $$ = new Yield ((Expression) $3, lt.Location);
5208 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5210 | IDENTIFIER BREAK SEMICOLON
5212 var lt = (Tokenizer.LocatedToken) $1;
5213 string s = lt.Value;
5215 Report.Error (1003, lt.Location, "; expected");
5216 } else if (RootContext.Version == LanguageVersion.ISO_1){
5217 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5220 current_block.ParametersBlock.TopBlock.IsIterator = true;
5221 $$ = new YieldBreak (lt.Location);
5222 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5232 : TRY block catch_clauses
5234 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5236 | TRY block FINALLY block
5238 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5239 lbag.AddStatement ($$, GetLocation ($3));
5241 | TRY block catch_clauses FINALLY block
5243 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
5244 lbag.AddStatement ($$, GetLocation ($4));
5248 Report.Error (1524, GetLocation ($1), "Expected catch or finally");
5256 var l = new List<Catch> (2);
5261 | catch_clauses catch_clause
5263 var l = (List<Catch>) $1;
5265 Catch c = (Catch) $2;
5266 if (l [0].IsGeneral) {
5267 Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5287 $$ = new Catch ((Block) $2, GetLocation ($1));
5289 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5291 start_block (GetLocation ($2));
5292 var c = new Catch (current_block, GetLocation ($1));
5293 c.TypeExpression = (FullNamedExpression) $3;
5296 var lt = (Tokenizer.LocatedToken) $4;
5297 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5298 current_block.AddLocalName (c.Variable);
5301 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5308 | CATCH open_parens_any error
5310 if (yyToken == Token.CLOSE_PARENS) {
5311 Report.Error (1015, lexer.Location,
5312 "A type that derives from `System.Exception', `object', or `string' expected");
5314 Error_SyntaxError (yyToken);
5317 $$ = new Catch (null, GetLocation ($1));
5324 $$ = new Checked ((Block) $2, GetLocation ($1));
5331 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5338 if (!RootContext.Unsafe)
5339 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5341 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5346 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5348 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5349 Warning_EmptyStatement (GetLocation ($5));
5351 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5352 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5357 : FIXED open_parens_any variable_type IDENTIFIER
5359 start_block (GetLocation ($2));
5361 var lt = (Tokenizer.LocatedToken) $4;
5362 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5363 current_block.AddLocalName (li);
5364 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5366 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5368 $$ = current_variable;
5369 current_variable = null;
5373 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5374 Warning_EmptyStatement (GetLocation ($10));
5376 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5377 current_block.AddStatement (f);
5378 $$ = end_block (GetLocation ($8));
5383 : USING open_parens_any variable_type IDENTIFIER
5385 start_block (GetLocation ($2));
5387 var lt = (Tokenizer.LocatedToken) $4;
5388 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5389 current_block.AddLocalName (li);
5390 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5392 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5394 $$ = current_variable;
5395 current_variable = null;
5399 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5400 Warning_EmptyStatement (GetLocation ($10));
5402 Using u = new Using ((Using.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5403 current_block.AddStatement (u);
5404 $$ = end_block (GetLocation ($8));
5406 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5408 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5409 Warning_EmptyStatement (GetLocation ($5));
5411 Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5412 lbag.AddStatement (u, GetLocation ($2), GetLocation ($4));
5417 using_or_fixed_variable_initializer
5420 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
5422 | ASSIGN variable_initializer
5424 current_variable.Initializer = (Expression) $2;
5425 $$ = current_variable;
5433 : first_from_clause query_body
5435 lexer.query_parsing = false;
5437 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5439 from.Tail.Next = (Linq.AQueryClause)$2;
5442 current_block.SetEndLocation (lexer.Location);
5443 current_block = current_block.Parent;
5445 | nested_from_clause query_body
5447 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5449 from.Tail.Next = (Linq.AQueryClause)$2;
5452 current_block.SetEndLocation (lexer.Location);
5453 current_block = current_block.Parent;
5456 // Bubble up COMPLETE_COMPLETION productions
5457 | first_from_clause COMPLETE_COMPLETION {
5458 lexer.query_parsing = false;
5461 current_block.SetEndLocation (lexer.Location);
5462 current_block = current_block.Parent;
5464 | nested_from_clause COMPLETE_COMPLETION {
5466 current_block.SetEndLocation (lexer.Location);
5467 current_block = current_block.Parent;
5472 : FROM_FIRST IDENTIFIER IN expression
5474 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5476 var lt = (Tokenizer.LocatedToken) $2;
5477 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5478 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5480 | FROM_FIRST type IDENTIFIER IN expression
5482 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5484 var lt = (Tokenizer.LocatedToken) $3;
5485 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5486 $$ = new Linq.QueryExpression (
5487 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5488 IdentifierType = (FullNamedExpression)$2
5495 : FROM IDENTIFIER IN expression
5497 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5499 var lt = (Tokenizer.LocatedToken) $2;
5500 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5501 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5503 | FROM type IDENTIFIER IN expression
5505 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5507 var lt = (Tokenizer.LocatedToken) $3;
5508 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5509 $$ = new Linq.QueryExpression (
5510 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5511 IdentifierType = (FullNamedExpression)$2
5518 : FROM IDENTIFIER IN
5520 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5524 var lt = (Tokenizer.LocatedToken) $2;
5525 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5526 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5528 current_block.SetEndLocation (lexer.Location);
5529 current_block = current_block.Parent;
5531 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5533 | FROM type IDENTIFIER IN
5535 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5539 var lt = (Tokenizer.LocatedToken) $3;
5540 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5542 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5543 IdentifierType = (FullNamedExpression)$2
5546 current_block.SetEndLocation (lexer.Location);
5547 current_block = current_block.Parent;
5549 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5554 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5556 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5559 head.Next = (Linq.AQueryClause)$3;
5562 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5563 clause.Tail.Next = head;
5569 | opt_query_body_clauses COMPLETE_COMPLETION
5572 select_or_group_clause
5575 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5579 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5581 current_block.SetEndLocation (lexer.Location);
5582 current_block = current_block.Parent;
5586 if (linq_clause_blocks == null)
5587 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5589 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5590 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5594 current_block.SetEndLocation (lexer.Location);
5595 current_block = current_block.Parent;
5597 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5601 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5603 current_block.SetEndLocation (lexer.Location);
5604 current_block = current_block.Parent;
5608 opt_query_body_clauses
5610 | query_body_clauses
5615 | query_body_clauses query_body_clause
5617 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5631 : LET IDENTIFIER ASSIGN
5633 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5637 var lt = (Tokenizer.LocatedToken) $2;
5638 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5639 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5641 current_block.SetEndLocation (lexer.Location);
5642 current_block = current_block.Parent;
5644 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5651 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5655 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
5657 current_block.SetEndLocation (lexer.Location);
5658 current_block = current_block.Parent;
5663 : JOIN IDENTIFIER IN
5665 if (linq_clause_blocks == null)
5666 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5668 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5669 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5673 current_block.SetEndLocation (lexer.Location);
5674 current_block = current_block.Parent;
5676 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5677 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5681 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5682 current_block.SetEndLocation (lexer.Location);
5683 current_block = current_block.Parent;
5685 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5687 expression opt_join_into
5689 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5690 current_block.SetEndLocation (lexer.Location);
5692 var outer_selector = linq_clause_blocks.Pop ();
5693 var block = linq_clause_blocks.Pop ();
5695 var lt = (Tokenizer.LocatedToken) $2;
5696 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5697 Linq.RangeVariable into;
5701 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5704 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5706 var parent = block.Parent;
5707 while (parent is Linq.QueryBlock) {
5708 parent = parent.Parent;
5710 current_block.Parent = parent;
5712 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5714 lt = (Tokenizer.LocatedToken) $12;
5715 into = new Linq.RangeVariable (lt.Value, lt.Location);
5717 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
5720 current_block = block.Parent;
5721 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5723 | JOIN type IDENTIFIER IN
5725 if (linq_clause_blocks == null)
5726 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5728 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5729 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5733 current_block.SetEndLocation (lexer.Location);
5734 current_block = current_block.Parent;
5736 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5737 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5741 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5742 current_block.SetEndLocation (lexer.Location);
5743 current_block = current_block.Parent;
5745 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5747 expression opt_join_into
5749 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5750 current_block.SetEndLocation (lexer.Location);
5752 var outer_selector = linq_clause_blocks.Pop ();
5753 var block = linq_clause_blocks.Pop ();
5755 var lt = (Tokenizer.LocatedToken) $3;
5756 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5757 Linq.RangeVariable into;
5761 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
5762 IdentifierType = (FullNamedExpression)$2
5766 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5768 var parent = block.Parent;
5769 while (parent is Linq.QueryBlock) {
5770 parent = parent.Parent;
5772 current_block.Parent = parent;
5774 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5776 lt = (Tokenizer.LocatedToken) $13;
5777 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
5779 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
5780 IdentifierType = (FullNamedExpression)$2
5784 current_block = block.Parent;
5785 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5800 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5804 current_block.SetEndLocation (lexer.Location);
5805 current_block = current_block.Parent;
5815 current_block.SetEndLocation (lexer.Location);
5816 current_block = current_block.Parent;
5818 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5822 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5829 | orderings_then_by COMMA
5831 current_block.SetEndLocation (lexer.Location);
5832 current_block = current_block.Parent;
5834 current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);
5838 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
5846 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5848 | expression ASCENDING
5850 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5852 | expression DESCENDING
5854 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5861 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5863 | expression ASCENDING
5865 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5867 | expression DESCENDING
5869 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5874 opt_query_continuation
5878 // query continuation block is not linked with query block but with block
5879 // before. This means each query can use same range variable names for
5880 // different identifiers.
5882 current_block.SetEndLocation (GetLocation ($1));
5883 current_block = current_block.Parent;
5885 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5887 if (linq_clause_blocks == null)
5888 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5890 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5894 var current_block = linq_clause_blocks.Pop ();
5895 var lt = (Tokenizer.LocatedToken) $2;
5896 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5897 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
5898 next = (Linq.AQueryClause)$4
5904 // Support for using the compiler as an interactive parser
5906 // The INTERACTIVE_PARSER token is first sent to parse our
5907 // productions; If the result is a Statement, the parsing
5908 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5909 // to setup the blocks in advance.
5911 // This setup is here so that in the future we can add
5912 // support for other constructs (type parsing, namespaces, etc)
5913 // that do not require a block to be setup in advance
5917 : EVAL_STATEMENT_PARSER EOF
5918 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
5919 | EVAL_STATEMENT_PARSER {
5920 Evaluator.LoadAliases (current_namespace);
5922 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5923 Modifiers.PUBLIC, null), null);
5925 var baseclass_list = new List<FullNamedExpression> ();
5926 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5927 current_container.AddBasesForPart (current_class, baseclass_list);
5929 // (ref object retval)
5930 Parameter [] mpar = new Parameter [1];
5931 mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
5933 ParametersCompiled pars = new ParametersCompiled (mpar);
5934 current_local_parameters = pars;
5935 Method method = new Method (
5938 new TypeExpression (TypeManager.void_type, Location.Null),
5939 Modifiers.PUBLIC | Modifiers.STATIC,
5940 new MemberName ("Host"),
5942 null /* attributes */);
5944 oob_stack.Push (method);
5945 ++lexer.parsing_block;
5946 start_block (lexer.Location);
5948 interactive_statement_list opt_COMPLETE_COMPLETION
5950 --lexer.parsing_block;
5951 Method method = (Method) oob_stack.Pop ();
5953 method.Block = (ToplevelBlock) end_block(lexer.Location);
5954 current_container.AddMethod (method);
5956 --lexer.parsing_declaration;
5957 InteractiveResult = pop_current_class ();
5958 current_local_parameters = null;
5960 | EVAL_COMPILATION_UNIT_PARSER {
5961 Evaluator.LoadAliases (current_namespace);
5963 interactive_compilation_unit
5966 interactive_compilation_unit
5967 : outer_declarations
5968 | outer_declarations global_attributes
5973 opt_COMPLETE_COMPLETION
5975 | COMPLETE_COMPLETION
5978 close_brace_or_complete_completion
5980 | COMPLETE_COMPLETION
5985 // A class used to hold info about an operator declarator
5987 class OperatorDeclaration {
5988 public readonly Operator.OpType optype;
5989 public readonly FullNamedExpression ret_type;
5990 public readonly Location location;
5992 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5995 this.ret_type = ret_type;
5996 this.location = location;
6000 void Error_ExpectingTypeName (Expression expr)
6002 if (expr is Invocation){
6003 Report.Error (1002, expr.Location, "Expecting `;'");
6005 Expression.Error_InvalidExpressionStatement (Report, expr.Location);
6009 void Error_ParameterModifierNotValid (string modifier, Location loc)
6011 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6015 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6017 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6018 Parameter.GetModifierSignature (mod));
6021 void Error_TypeExpected (Location loc)
6023 Report.Error (1031, loc, "Type expected");
6026 void Error_UnsafeCodeNotAllowed (Location loc)
6028 Report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6031 void Warning_EmptyStatement (Location loc)
6033 Report.Warning (642, 3, loc, "Possible mistaken empty statement");
6036 void Error_NamedArgumentExpected (NamedArgument a)
6038 Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6041 void push_current_class (TypeContainer tc, object partial_token)
6043 if (RootContext.EvalMode){
6044 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
6045 undo.AddTypeContainer (current_container, tc);
6048 if (partial_token != null)
6049 current_container = current_container.AddPartial (tc);
6051 current_container = current_container.AddTypeContainer (tc);
6053 ++lexer.parsing_declaration;
6057 DeclSpace pop_current_class ()
6059 DeclSpace retval = current_class;
6061 current_class = current_class.Parent;
6062 current_container = current_class.PartialContainer;
6068 // Given the @class_name name, it creates a fully qualified name
6069 // based on the containing declaration space
6072 MakeName (MemberName class_name)
6074 Namespace ns = current_namespace.NS;
6076 if (current_container == RootContext.ToplevelTypes) {
6077 if (ns.Name.Length != 0)
6078 return new MemberName (ns.MemberName, class_name);
6082 return new MemberName (current_container.MemberName, class_name);
6086 [System.Diagnostics.Conditional ("FULL_AST")]
6087 void StoreModifierLocation (object token, Location loc)
6092 if (mod_locations == null)
6093 mod_locations = new List<Tuple<Modifiers, Location>> ();
6095 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6098 string CheckAttributeTarget (string a, Location l)
6101 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6105 Report.Warning (658, 1, l,
6106 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6107 return string.Empty;
6110 static bool IsUnaryOperator (Operator.OpType op)
6114 case Operator.OpType.LogicalNot:
6115 case Operator.OpType.OnesComplement:
6116 case Operator.OpType.Increment:
6117 case Operator.OpType.Decrement:
6118 case Operator.OpType.True:
6119 case Operator.OpType.False:
6120 case Operator.OpType.UnaryPlus:
6121 case Operator.OpType.UnaryNegation:
6127 void syntax_error (Location l, string msg)
6129 Report.Error (1003, l, "Syntax error, " + msg);
6134 public Tokenizer Lexer {
6140 static CSharpParser ()
6142 oob_stack = new Stack<object> ();
6145 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
6147 if (RootContext.EvalMode)
6151 this.compiler = ctx;
6152 current_namespace = new NamespaceEntry (ctx, null, file, null);
6153 current_class = current_namespace.SlaveDeclSpace;
6154 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6156 lexer = new Tokenizer (reader, file, ctx);
6158 use_global_stacks = true;
6161 public void parse ()
6163 eof_token = Token.EOF;
6164 Tokenizer.LocatedToken.Initialize ();
6167 if (yacc_verbose_flag > 1)
6168 yyparse (lexer, new yydebug.yyDebugSimple ());
6172 Tokenizer tokenizer = lexer as Tokenizer;
6173 tokenizer.cleanup ();
6174 } catch (Exception e){
6175 if (e is yyParser.yyUnexpectedEof) {
6176 Error_SyntaxError (yyToken);
6177 UnexpectedEOF = true;
6181 if (e is yyParser.yyException) {
6182 Report.Error (-25, lexer.Location, "Parsing error");
6184 // Used by compiler-tester to test internal errors
6185 if (yacc_verbose_flag > 0)
6188 Report.Error (589, lexer.Location, "Internal compiler error during parsing");
6192 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6193 throw new InternalErrorException ("who set it?");
6196 void CheckToken (int error, int yyToken, string msg, Location loc)
6198 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6199 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6201 Report.Error (error, loc, msg);
6204 string ConsumeStoredComment ()
6206 string s = tmpComment;
6208 Lexer.doc_state = XmlCommentState.Allowed;
6212 Location GetLocation (object obj)
6214 var lt = obj as Tokenizer.LocatedToken;
6218 var mn = obj as MemberName;
6222 var expr = obj as Expression;
6224 return expr.Location;
6226 return lexer.Location;
6230 get { return compiler.Report; }
6233 public LocationsBag LocationsBag {
6242 void start_block (Location loc)
6244 if (current_block == null) {
6245 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6246 } else if (parsing_anonymous_method) {
6247 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6248 parsing_anonymous_method = false;
6250 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6255 end_block (Location loc)
6257 Block retval = current_block.Explicit;
6258 retval.SetEndLocation (loc);
6259 current_block = retval.Parent;
6263 void start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6265 if (RootContext.Version == LanguageVersion.ISO_1){
6266 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6269 oob_stack.Push (current_anonymous_method);
6270 oob_stack.Push (current_local_parameters);
6271 oob_stack.Push (current_variable);
6273 current_local_parameters = parameters;
6275 current_anonymous_method = lambda
6276 ? new LambdaExpression (loc)
6277 : new AnonymousMethodExpression (loc);
6279 // Force the next block to be created as a ToplevelBlock
6280 parsing_anonymous_method = true;
6284 * Completes the anonymous method processing, if lambda_expr is null, this
6285 * means that we have a Statement instead of an Expression embedded
6287 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6289 AnonymousMethodExpression retval;
6291 current_anonymous_method.Block = anon_block;
6292 retval = current_anonymous_method;
6294 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6295 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6296 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6301 public NamespaceEntry CurrentNamespace {
6303 return current_namespace;
6307 void Error_SyntaxError (int token)
6309 Error_SyntaxError (0, token, "Unexpected symbol");
6312 void Error_SyntaxError (int error_code, int token, string msg)
6314 // An error message has been reported by tokenizer
6315 if (token == Token.ERROR)
6318 string symbol = GetSymbolName (token);
6319 string expecting = GetExpecting ();
6320 var loc = lexer.Location - symbol.Length;
6322 if (error_code == 0) {
6323 if (expecting == "`identifier'") {
6324 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6325 Report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6330 expecting = "identifier";
6331 } else if (expecting == "`)'") {
6338 if (string.IsNullOrEmpty (expecting))
6339 Report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6341 Report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6344 string GetExpecting ()
6346 int [] tokens = yyExpectingTokens (yyExpectingState);
6347 var names = new List<string> (tokens.Length);
6348 bool has_type = false;
6349 bool has_identifier = false;
6350 for (int i = 0; i < tokens.Length; i++){
6351 int token = tokens [i];
6352 has_identifier |= token == Token.IDENTIFIER;
6354 string name = GetTokenName (token);
6355 if (name == "<internal>")
6358 has_type |= name == "type";
6359 if (names.Contains (name))
6366 // Too many tokens to enumerate
6368 if (names.Count > 8)
6371 if (has_type && has_identifier)
6372 names.Remove ("identifier");
6374 if (names.Count == 1)
6375 return "`" + GetTokenName (tokens [0]) + "'";
6377 StringBuilder sb = new StringBuilder ();
6379 int count = names.Count;
6380 for (int i = 0; i < count; i++){
6381 bool last = i + 1 == count;
6385 sb.Append (names [i]);
6386 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6388 return sb.ToString ();
6392 string GetSymbolName (int token)
6396 return ((Constant)lexer.Value).GetValue ().ToString ();
6397 case Token.IDENTIFIER:
6398 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6440 case Token.BITWISE_AND:
6442 case Token.BITWISE_OR:
6456 case Token.OP_SHIFT_LEFT:
6458 case Token.OP_SHIFT_RIGHT:
6478 case Token.OP_COALESCING:
6480 case Token.OP_MULT_ASSIGN:
6482 case Token.OP_DIV_ASSIGN:
6484 case Token.OP_MOD_ASSIGN:
6486 case Token.OP_ADD_ASSIGN:
6488 case Token.OP_SUB_ASSIGN:
6490 case Token.OP_SHIFT_LEFT_ASSIGN:
6492 case Token.OP_SHIFT_RIGHT_ASSIGN:
6494 case Token.OP_AND_ASSIGN:
6496 case Token.OP_XOR_ASSIGN:
6498 case Token.OP_OR_ASSIGN:
6502 return GetTokenName (token);
6505 static string GetTokenName (int token)
6508 case Token.ABSTRACT:
6528 case Token.CONTINUE:
6532 case Token.DELEGATE:
6542 case Token.EXPLICIT:
6560 case Token.IMPLICIT:
6564 case Token.INTERFACE:
6566 case Token.INTERNAL:
6572 case Token.NAMESPACE:
6578 case Token.OPERATOR:
6582 case Token.OVERRIDE:
6588 case Token.PROTECTED:
6592 case Token.READONLY:
6604 case Token.STACKALLOC:
6605 return "stackalloc";
6622 case Token.UNCHECKED:
6630 case Token.VOLATILE:
6643 case Token.FROM_FIRST:
6661 case Token.ASCENDING:
6663 case Token.DESCENDING:
6664 return "descending";
6671 case Token.OPEN_BRACE:
6673 case Token.CLOSE_BRACE:
6675 case Token.OPEN_BRACKET:
6676 case Token.OPEN_BRACKET_EXPR:
6678 case Token.CLOSE_BRACKET:
6680 case Token.OPEN_PARENS_CAST:
6681 case Token.OPEN_PARENS_LAMBDA:
6682 case Token.OPEN_PARENS:
6684 case Token.CLOSE_PARENS:
6690 case Token.DEFAULT_COLON:
6694 case Token.SEMICOLON:
6705 case Token.BITWISE_AND:
6706 case Token.BITWISE_OR:
6713 case Token.OP_SHIFT_LEFT:
6714 case Token.OP_SHIFT_RIGHT:
6722 case Token.OP_COALESCING:
6723 case Token.OP_MULT_ASSIGN:
6724 case Token.OP_DIV_ASSIGN:
6725 case Token.OP_MOD_ASSIGN:
6726 case Token.OP_ADD_ASSIGN:
6727 case Token.OP_SUB_ASSIGN:
6728 case Token.OP_SHIFT_LEFT_ASSIGN:
6729 case Token.OP_SHIFT_RIGHT_ASSIGN:
6730 case Token.OP_AND_ASSIGN:
6731 case Token.OP_XOR_ASSIGN:
6732 case Token.OP_OR_ASSIGN:
6733 return "<operator>";
6755 case Token.OP_GENERICS_LT:
6756 case Token.GENERIC_DIMENSION:
6758 case Token.OP_GENERICS_GT:
6761 case Token.INTERR_NULLABLE:
6763 case Token.DOUBLE_COLON:
6767 case Token.IDENTIFIER:
6768 return "identifier";
6771 return "end-of-file";
6773 // All of these are internal.
6776 case Token.FIRST_KEYWORD:
6777 case Token.EVAL_COMPILATION_UNIT_PARSER:
6778 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6779 case Token.EVAL_STATEMENT_PARSER:
6780 case Token.LAST_KEYWORD:
6781 case Token.GENERATE_COMPLETION:
6782 case Token.COMPLETE_COMPLETION:
6783 return "<internal>";
6785 // A bit more robust.
6787 return yyNames [token];