3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnome.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-2011 Novell, Inc
13 // Copyright 2011-2012 Xamarin Inc.
19 using System.Collections.Generic;
26 public class CSharpParser
29 enum ParameterModifierType
36 DefaultValue = 1 << 6,
38 All = Ref | Out | This | Params | Arglist | DefaultValue
41 static readonly object ModifierNone = 0;
43 NamespaceContainer current_namespace;
44 TypeContainer current_container;
45 TypeDefinition current_type;
46 PropertyBase current_property;
47 EventProperty current_event;
48 EventField current_event_field;
49 FieldBase current_field;
52 /// Current block is used to add statements as we find
57 BlockVariableDeclaration current_variable;
59 Delegate current_delegate;
61 AnonymousMethodExpression current_anonymous_method;
64 /// This is used by the unary_expression code to resolve
65 /// a name against a parameter.
68 // FIXME: This is very ugly and it's very hard to reset it correctly
69 // on all places, especially when some parameters are autogenerated.
70 ParametersCompiled current_local_parameters;
72 bool parsing_anonymous_method;
77 /// An out-of-band stack.
79 Stack<object> oob_stack;
82 /// Controls the verbosity of the errors produced by the parser
84 int yacc_verbose_flag;
87 /// Used by the interactive shell, flags whether EOF was reached
88 /// and an error was produced
90 public bool UnexpectedEOF;
95 readonly CompilationSourceFile file;
98 /// Temporary Xml documentation cache.
99 /// For enum types, we need one more temporary store.
102 string enumTypeComment;
104 /// Current attribute target
105 string current_attr_target;
107 ParameterModifierType valid_param_mod;
109 bool default_parameter_used;
111 /// When using the interactive parser, this holds the
112 /// resulting expression
113 public Class InteractiveResult;
116 // Keeps track of global data changes to undo on parser error
120 Stack<Linq.QueryBlock> linq_clause_blocks;
122 ModuleContainer module;
124 readonly CompilerContext compiler;
125 readonly LanguageVersion lang_version;
126 readonly bool doc_support;
127 readonly CompilerSettings settings;
128 readonly Report report;
131 // Instead of allocating carrier array everytime we
132 // share the bucket for very common constructs which can never
135 List<Parameter> parameters_bucket;
138 // Full AST support members
141 List<Tuple<Modifiers, Location>> mod_locations;
145 %token NONE /* This token is never returned by our lexer */
146 %token ERROR // This is used not by the parser, but by the tokenizer.
150 *These are the C# keywords
249 %token INTERR_NULLABLE
257 /* C# keywords which are not really keywords */
263 /* C# single character operators/punctuation. */
291 /* C# multi-character operators. */
296 %token OP_SHIFT_RIGHT
303 %token OP_MULT_ASSIGN
308 %token OP_SHIFT_LEFT_ASSIGN
309 %token OP_SHIFT_RIGHT_ASSIGN
316 /* Generics <,> tokens */
317 %token OP_GENERICS_LT
318 %token OP_GENERICS_LT_DECL
319 %token OP_GENERICS_GT
324 %token OPEN_PARENS_LAMBDA
325 %token OPEN_PARENS_CAST
326 %token GENERIC_DIMENSION
328 %token OPEN_BRACKET_EXPR
330 // Make the parser go into eval mode parsing (statements and compilation units).
331 %token EVAL_STATEMENT_PARSER
332 %token EVAL_COMPILATION_UNIT_PARSER
333 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
338 // This token is generated to trigger the completion engine at this point
340 %token GENERATE_COMPLETION
343 // This token is return repeatedly after the first GENERATE_COMPLETION
344 // token is produced and before the final EOF
346 %token COMPLETE_COMPLETION
348 /* Add precedence rules to solve dangling else s/r conflict */
352 /* Define the operator tokens and their precedences */
360 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
362 %left STAR DIV PERCENT
363 %right BANG CARRET UMINUS
364 %nonassoc OP_INC OP_DEC
366 %left OPEN_BRACKET OPEN_BRACE
369 %start compilation_unit
373 : outer_declaration opt_EOF
375 Lexer.check_incorrect_doc_comment ();
377 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
378 | documentation_parsing
382 : opt_extern_alias_directives opt_using_directives
383 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
386 Attributes attrs = (Attributes) $4;
387 report.Error (1730, attrs.Attrs [0].Location,
388 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
390 current_namespace.UnattachedAttributes = attrs;
393 | opt_extern_alias_directives opt_using_directives attribute_sections
395 module.AddAttributes ((Attributes) $3, current_namespace);
399 if (yyToken == Token.EXTERN_ALIAS)
400 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
402 Error_SyntaxError (yyToken);
411 extern_alias_directives
412 : extern_alias_directive
413 | extern_alias_directives extern_alias_directive
416 extern_alias_directive
417 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
419 var lt = (Tokenizer.LocatedToken) $2;
422 syntax_error (lt.Location, "`alias' expected");
424 if (lang_version == LanguageVersion.ISO_1)
425 FeatureIsNotAvailable (lt.Location, "external alias");
427 lt = (Tokenizer.LocatedToken) $3;
428 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
429 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
432 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
433 current_namespace.AddUsing (na);
435 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
440 Error_SyntaxError (yyToken);
446 | using_directives using_directive
453 Lexer.doc_state = XmlCommentState.Allowed;
458 : USING namespace_or_type_expr SEMICOLON
460 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
461 current_namespace.AddUsing (un);
463 lbag.AddLocation (un, GetLocation ($3));
465 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
467 var lt = (Tokenizer.LocatedToken) $2;
468 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
469 report.Warning (440, 2, lt.Location,
470 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
473 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
474 current_namespace.AddUsing (un);
476 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
480 Error_SyntaxError (yyToken);
486 // Strictly speaking, namespaces don't have attributes but
487 // we parse global attributes along with namespace declarations and then
490 namespace_declaration
491 : opt_attributes NAMESPACE namespace_name
493 Attributes attrs = (Attributes) $1;
494 var name = (MemberName) $3;
496 bool valid_global_attrs = true;
497 if ((current_namespace.DeclarationFound || current_namespace != file)) {
498 valid_global_attrs = false;
500 foreach (var a in attrs.Attrs) {
501 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
504 valid_global_attrs = false;
509 if (!valid_global_attrs)
510 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
513 module.AddAttributes (attrs, current_namespace);
515 var ns = new NamespaceContainer (name, current_namespace);
516 current_namespace.AddTypeContainer (ns);
517 current_container = current_namespace = ns;
522 Lexer.doc_state = XmlCommentState.Allowed;
524 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon
527 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
529 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
531 current_container = current_namespace = current_namespace.Parent;
533 | opt_attributes NAMESPACE namespace_name
535 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
537 var name = (MemberName) $3;
538 var ns = new NamespaceContainer (name, current_namespace);
539 lbag.AddLocation (ns, GetLocation ($2));
540 current_namespace.AddTypeContainer (ns);
547 var lt = (Tokenizer.LocatedToken) $1;
548 $$ = new MemberName (lt.Value, lt.Location);
550 | namespace_name DOT IDENTIFIER
552 var lt = (Tokenizer.LocatedToken) $3;
553 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
557 Error_SyntaxError (yyToken);
558 $$ = new MemberName ("<invalid>", lexer.Location);
577 opt_extern_alias_directives
579 | extern_alias_directives
582 opt_namespace_or_type_declarations
584 | namespace_or_type_declarations
587 namespace_or_type_declarations
588 : namespace_or_type_declaration
589 | namespace_or_type_declarations namespace_or_type_declaration
592 namespace_or_type_declaration
596 TypeContainer ds = (TypeContainer)$1;
598 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
599 report.Error (1527, ds.Location,
600 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
603 // Here is a trick, for explicit attributes we don't know where they belong to until
604 // we parse succeeding declaration hence we parse them as normal and re-attach them
605 // when we know whether they are global (assembly:, module:) or local (type:).
606 if (ds.OptAttributes != null) {
607 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
610 current_namespace.DeclarationFound = true;
612 | namespace_declaration
614 current_namespace.DeclarationFound = true;
616 | attribute_sections CLOSE_BRACE {
617 current_namespace.UnattachedAttributes = (Attributes) $1;
618 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
626 | interface_declaration
628 | delegate_declaration
630 // Enable this when we have handled all errors, because this acts as a generic fallback
633 // Console.WriteLine ("Token=" + yyToken);
634 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
650 var sect = (List<Attribute>) $1;
651 $$ = new Attributes (sect);
653 | attribute_sections attribute_section
655 Attributes attrs = $1 as Attributes;
656 var sect = (List<Attribute>) $2;
658 attrs = new Attributes (sect);
660 attrs.AddAttributes (sect);
668 lexer.parsing_attribute_section = true;
670 attribute_section_cont
672 lexer.parsing_attribute_section = false;
677 attribute_section_cont
678 : attribute_target COLON
680 current_attr_target = (string) $1;
681 if (current_attr_target == "assembly" || current_attr_target == "module") {
682 Lexer.check_incorrect_doc_comment ();
685 attribute_list opt_comma CLOSE_BRACKET
687 // when attribute target is invalid
688 if (current_attr_target == string.Empty)
689 $$ = new List<Attribute> (0);
693 current_attr_target = null;
694 lexer.parsing_attribute_section = false;
696 | attribute_list opt_comma CLOSE_BRACKET
705 var lt = (Tokenizer.LocatedToken) $1;
706 $$ = CheckAttributeTarget (lt.Value, lt.Location);
708 | EVENT { $$ = "event"; }
709 | RETURN { $$ = "return"; }
712 if (yyToken == Token.IDENTIFIER) {
713 Error_SyntaxError (yyToken);
716 string name = GetTokenName (yyToken);
717 $$ = CheckAttributeTarget (name, GetLocation ($1));
725 $$ = new List<Attribute> (4) { (Attribute) $1 };
727 | attribute_list COMMA attribute
729 var attrs = (List<Attribute>) $1;
730 attrs.Add ((Attribute) $3);
739 ++lexer.parsing_block;
741 opt_attribute_arguments
743 --lexer.parsing_block;
745 var tne = (ATypeNameExpression) $1;
746 if (tne.HasTypeArguments) {
747 report.Error (404, tne.Location, "Attributes cannot be generic");
750 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
755 : namespace_or_type_expr
758 opt_attribute_arguments
759 : /* empty */ { $$ = null; }
760 | OPEN_PARENS attribute_arguments CLOSE_PARENS
768 : /* empty */ { $$ = null; }
769 | positional_or_named_argument
771 Arguments a = new Arguments (4);
772 a.Add ((Argument) $1);
773 $$ = new Arguments [] { a, null };
775 | named_attribute_argument
777 Arguments a = new Arguments (4);
778 a.Add ((Argument) $1);
779 $$ = new Arguments [] { null, a };
781 | attribute_arguments COMMA positional_or_named_argument
783 Arguments[] o = (Arguments[]) $1;
785 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
786 o [0] = new Arguments (4);
789 Arguments args = ((Arguments) o [0]);
790 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
791 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
793 args.Add ((Argument) $3);
795 | attribute_arguments COMMA named_attribute_argument
797 Arguments[] o = (Arguments[]) $1;
799 o [1] = new Arguments (4);
802 ((Arguments) o [1]).Add ((Argument) $3);
806 positional_or_named_argument
809 $$ = new Argument ((Expression) $1);
814 named_attribute_argument
817 ++lexer.parsing_block;
821 --lexer.parsing_block;
822 var lt = (Tokenizer.LocatedToken) $1;
823 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
824 lbag.AddLocation ($$, GetLocation($2));
829 : identifier_inside_body COLON opt_named_modifier expression
831 if (lang_version <= LanguageVersion.V_3)
832 FeatureIsNotAvailable (GetLocation ($1), "named argument");
834 // Avoid boxing in common case (no modifier)
835 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
837 var lt = (Tokenizer.LocatedToken) $1;
838 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
839 lbag.AddLocation ($$, GetLocation($2));
844 : /* empty */ { $$ = null; }
847 $$ = Argument.AType.Ref;
851 $$ = Argument.AType.Out;
855 opt_class_member_declarations
857 | class_member_declarations
860 class_member_declarations
861 : class_member_declaration
863 lexer.parsing_modifiers = true;
865 | class_member_declarations class_member_declaration
867 lexer.parsing_modifiers = true;
871 class_member_declaration
872 : constant_declaration
875 | property_declaration
877 | indexer_declaration
878 | operator_declaration
879 | constructor_declaration
880 | destructor_declaration
882 | attributes_without_members
885 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
886 GetSymbolName (yyToken));
888 lexer.parsing_generic_declaration = false;
898 lexer.ConstraintsParsing = true;
900 type_declaration_name
902 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
905 opt_type_parameter_constraints_clauses
907 lexer.ConstraintsParsing = false;
910 current_container.SetConstraints ((List<Constraints>) $9);
913 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
915 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
917 lexer.parsing_modifiers = true;
922 Lexer.doc_state = XmlCommentState.Allowed;
924 opt_class_member_declarations CLOSE_BRACE
926 --lexer.parsing_declaration;
928 Lexer.doc_state = XmlCommentState.Allowed;
932 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
933 $$ = pop_current_class ();
935 | opt_attributes opt_modifiers opt_partial STRUCT error
937 Error_SyntaxError (yyToken);
944 CONST type IDENTIFIER
946 var lt = (Tokenizer.LocatedToken) $5;
947 var mod = (Modifiers) $2;
948 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
949 current_type.AddMember (current_field);
951 if ((mod & Modifiers.STATIC) != 0) {
952 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
957 constant_initializer opt_constant_declarators SEMICOLON
960 current_field.DocComment = Lexer.consume_doc_comment ();
961 Lexer.doc_state = XmlCommentState.Allowed;
964 current_field.Initializer = (ConstInitializer) $7;
965 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
966 current_field = null;
972 Error_SyntaxError (yyToken);
974 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
978 opt_constant_declarators
980 | constant_declarators
984 : constant_declarator
986 current_field.AddDeclarator ((FieldDeclarator) $1);
988 | constant_declarators constant_declarator
990 current_field.AddDeclarator ((FieldDeclarator) $2);
995 : COMMA IDENTIFIER constant_initializer
997 var lt = (Tokenizer.LocatedToken) $2;
998 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
999 lbag.AddLocation ($$, GetLocation ($1));
1003 constant_initializer
1006 ++lexer.parsing_block;
1008 constant_initializer_expr
1010 --lexer.parsing_block;
1011 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1015 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1020 constant_initializer_expr
1021 : constant_expression
1028 member_type IDENTIFIER
1030 lexer.parsing_generic_declaration = false;
1032 FullNamedExpression type = (FullNamedExpression) $3;
1033 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1034 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1036 var lt = (Tokenizer.LocatedToken) $4;
1037 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1038 current_type.AddField (current_field);
1041 opt_field_initializer
1042 opt_field_declarators
1046 current_field.DocComment = Lexer.consume_doc_comment ();
1047 Lexer.doc_state = XmlCommentState.Allowed;
1050 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1052 current_field = null;
1056 FIXED simple_type IDENTIFIER
1058 if (lang_version < LanguageVersion.ISO_2)
1059 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1061 var lt = (Tokenizer.LocatedToken) $5;
1062 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1063 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1065 current_type.AddField (current_field);
1067 fixed_field_size opt_fixed_field_declarators SEMICOLON
1070 current_field.DocComment = Lexer.consume_doc_comment ();
1071 Lexer.doc_state = XmlCommentState.Allowed;
1074 current_field.Initializer = (ConstInitializer) $7;
1075 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1077 current_field = null;
1081 FIXED simple_type error
1084 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1088 opt_field_initializer
1092 ++lexer.parsing_block;
1093 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1094 start_block (GetLocation ($1));
1096 variable_initializer
1098 --lexer.parsing_block;
1099 current_field.Initializer = (Expression) $3;
1100 end_block (lexer.Location);
1101 current_local_parameters = null;
1105 opt_field_declarators
1113 current_field.AddDeclarator ((FieldDeclarator) $1);
1115 | field_declarators field_declarator
1117 current_field.AddDeclarator ((FieldDeclarator) $2);
1124 var lt = (Tokenizer.LocatedToken) $2;
1125 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1126 lbag.AddLocation ($$, GetLocation ($1));
1128 | COMMA IDENTIFIER ASSIGN
1130 ++lexer.parsing_block;
1132 variable_initializer
1134 --lexer.parsing_block;
1135 var lt = (Tokenizer.LocatedToken) $2;
1136 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1137 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1141 opt_fixed_field_declarators
1143 | fixed_field_declarators
1146 fixed_field_declarators
1147 : fixed_field_declarator
1149 current_field.AddDeclarator ((FieldDeclarator) $1);
1151 | fixed_field_declarators fixed_field_declarator
1153 current_field.AddDeclarator ((FieldDeclarator) $2);
1157 fixed_field_declarator
1158 : COMMA IDENTIFIER fixed_field_size
1160 var lt = (Tokenizer.LocatedToken) $2;
1161 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1162 lbag.AddLocation ($$, GetLocation ($1));
1169 ++lexer.parsing_block;
1171 expression CLOSE_BRACKET
1173 --lexer.parsing_block;
1174 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1175 lbag.AddLocation ($$, GetLocation ($4));
1177 | OPEN_BRACKET error
1179 report.Error (443, lexer.Location, "Value or constant expected");
1184 variable_initializer
1189 // It has to be here for the parent to safely restore artificial block
1190 Error_SyntaxError (yyToken);
1199 Lexer.doc_state = XmlCommentState.NotAllowed;
1201 // Was added earlier in the case of body being eof for full ast
1205 Method method = (Method) $1;
1206 method.Block = (ToplevelBlock) $3;
1207 async_block = false;
1209 if (method.Block == null) {
1210 method.ParameterInfo.CheckParameters (method);
1212 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1213 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1214 method.GetSignatureForError ());
1217 if (current_container.Kind == MemberKind.Interface) {
1218 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1219 method.GetSignatureForError ());
1223 current_local_parameters = null;
1226 Lexer.doc_state = XmlCommentState.Allowed;
1234 method_declaration_name OPEN_PARENS
1236 valid_param_mod = ParameterModifierType.All;
1238 opt_formal_parameter_list CLOSE_PARENS
1240 valid_param_mod = 0;
1241 MemberName name = (MemberName) $4;
1242 current_local_parameters = (ParametersCompiled) $7;
1244 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1245 name, current_local_parameters, (Attributes) $1);
1247 current_type.AddMember (method);
1249 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1252 method.DocComment = Lexer.consume_doc_comment ();
1254 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1258 lexer.ConstraintsParsing = true;
1260 opt_type_parameter_constraints_clauses
1262 lexer.ConstraintsParsing = false;
1265 var method = (Method) $9;
1266 method.SetConstraints ((List<Constraints>) $10);
1276 lexer.parsing_generic_declaration = true;
1278 method_declaration_name
1281 lexer.parsing_generic_declaration = false;
1282 valid_param_mod = ParameterModifierType.All;
1284 opt_formal_parameter_list CLOSE_PARENS
1286 lexer.ConstraintsParsing = true;
1288 opt_type_parameter_constraints_clauses
1290 lexer.ConstraintsParsing = false;
1291 valid_param_mod = 0;
1293 MemberName name = (MemberName) $6;
1294 current_local_parameters = (ParametersCompiled) $9;
1296 var modifiers = (Modifiers) $2;
1297 modifiers |= Modifiers.PARTIAL;
1299 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1300 modifiers, name, current_local_parameters, (Attributes) $1);
1302 current_type.AddMember (method);
1305 method.SetConstraints ((List<Constraints>) $11);
1308 method.DocComment = Lexer.consume_doc_comment ();
1310 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1311 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1317 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1319 MemberName name = (MemberName) $5;
1320 report.Error (1585, name.Location,
1321 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1323 var method = Method.Create (current_type, (FullNamedExpression) $3,
1324 0, name, (ParametersCompiled) $7, (Attributes) $1);
1326 current_type.AddMember (method);
1328 current_local_parameters = (ParametersCompiled) $7;
1331 method.DocComment = Lexer.consume_doc_comment ();
1338 method_declaration_name error
1340 Error_SyntaxError (yyToken);
1341 current_local_parameters = ParametersCompiled.Undefined;
1343 MemberName name = (MemberName) $4;
1344 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1345 name, current_local_parameters, (Attributes) $1);
1347 current_type.AddMember (method);
1350 method.DocComment = Lexer.consume_doc_comment ();
1358 | SEMICOLON { $$ = null; }
1361 opt_formal_parameter_list
1362 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1363 | formal_parameter_list
1366 formal_parameter_list
1369 var pars_list = (List<Parameter>) $1;
1370 $$ = new ParametersCompiled (pars_list.ToArray ());
1372 | fixed_parameters COMMA parameter_array
1374 var pars_list = (List<Parameter>) $1;
1375 pars_list.Add ((Parameter) $3);
1377 $$ = new ParametersCompiled (pars_list.ToArray ());
1379 | fixed_parameters COMMA arglist_modifier
1381 var pars_list = (List<Parameter>) $1;
1382 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1383 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1385 | parameter_array COMMA error
1388 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1390 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1392 | fixed_parameters COMMA parameter_array COMMA error
1395 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1397 var pars_list = (List<Parameter>) $1;
1398 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1400 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1402 | arglist_modifier COMMA error
1404 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1406 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1408 | fixed_parameters COMMA ARGLIST COMMA error
1410 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1412 var pars_list = (List<Parameter>) $1;
1413 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1415 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1419 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1423 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1427 Error_SyntaxError (yyToken);
1428 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1435 parameters_bucket.Clear ();
1436 Parameter p = (Parameter) $1;
1437 parameters_bucket.Add (p);
1439 default_parameter_used = p.HasDefaultValue;
1440 $$ = parameters_bucket;
1442 | fixed_parameters COMMA fixed_parameter
1444 var pars = (List<Parameter>) $1;
1445 Parameter p = (Parameter) $3;
1447 if (p.HasExtensionMethodModifier)
1448 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1449 else if (!p.HasDefaultValue && default_parameter_used)
1450 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1452 default_parameter_used |= p.HasDefaultValue;
1455 lbag.AddLocation (p, GetLocation ($2));
1464 opt_parameter_modifier
1468 var lt = (Tokenizer.LocatedToken) $4;
1469 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1472 opt_parameter_modifier
1474 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1476 var lt = (Tokenizer.LocatedToken) $4;
1477 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1478 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1480 | attribute_sections error
1482 Error_SyntaxError (yyToken);
1483 Location l = GetLocation ($2);
1484 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1487 opt_parameter_modifier
1491 Error_SyntaxError (yyToken);
1492 Location l = GetLocation ($4);
1493 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1496 opt_parameter_modifier
1501 ++lexer.parsing_block;
1505 --lexer.parsing_block;
1506 if (lang_version <= LanguageVersion.V_3) {
1507 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1510 Parameter.Modifier mod = (Parameter.Modifier) $2;
1511 if (mod != Parameter.Modifier.NONE) {
1513 case Parameter.Modifier.REF:
1514 case Parameter.Modifier.OUT:
1515 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1516 Parameter.GetModifierSignature (mod));
1519 case Parameter.Modifier.This:
1520 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1521 Parameter.GetModifierSignature (mod));
1524 throw new NotImplementedException (mod.ToString ());
1527 mod = Parameter.Modifier.NONE;
1530 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1531 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1533 var lt = (Tokenizer.LocatedToken) $4;
1534 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1535 lbag.AddLocation ($$, GetLocation ($5));
1538 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1542 opt_parameter_modifier
1543 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1544 | parameter_modifiers
1548 : parameter_modifier
1552 | parameter_modifiers parameter_modifier
1554 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1555 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1556 if (((Parameter.Modifier)$1 & p2) == p2) {
1557 Error_DuplicateParameterModifier (lexer.Location, p2);
1559 switch (mod & ~Parameter.Modifier.This) {
1560 case Parameter.Modifier.REF:
1561 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1563 case Parameter.Modifier.OUT:
1564 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1567 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1578 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1579 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1581 $$ = Parameter.Modifier.REF;
1585 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1586 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1588 $$ = Parameter.Modifier.OUT;
1592 if ((valid_param_mod & ParameterModifierType.This) == 0)
1593 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1595 if (lang_version <= LanguageVersion.ISO_2)
1596 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1598 $$ = Parameter.Modifier.This;
1603 : opt_attributes params_modifier type IDENTIFIER
1605 var lt = (Tokenizer.LocatedToken) $4;
1606 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1608 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1610 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1612 var lt = (Tokenizer.LocatedToken) $4;
1613 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1615 | opt_attributes params_modifier type error
1617 Error_SyntaxError (yyToken);
1619 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1626 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1627 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1629 | PARAMS parameter_modifier
1631 Parameter.Modifier mod = (Parameter.Modifier)$2;
1632 if ((mod & Parameter.Modifier.This) != 0) {
1633 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1635 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1638 | PARAMS params_modifier
1640 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1647 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1648 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1652 property_declaration
1656 member_declaration_name
1659 tmpComment = Lexer.consume_doc_comment ();
1663 var type = (FullNamedExpression) $3;
1664 current_property = new Property (current_type, type, (Modifiers) $2,
1665 (MemberName) $4, (Attributes) $1);
1667 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1668 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1670 current_type.AddMember (current_property);
1671 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1673 lexer.PropertyParsing = true;
1675 accessor_declarations
1677 lexer.PropertyParsing = false;
1680 current_property.DocComment = ConsumeStoredComment ();
1684 lbag.AppendToMember (current_property, GetLocation ($10));
1685 current_property = null;
1691 : opt_attributes opt_modifiers
1692 member_type indexer_declaration_name OPEN_BRACKET
1694 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1696 opt_formal_parameter_list CLOSE_BRACKET
1698 valid_param_mod = 0;
1699 var type = (FullNamedExpression) $3;
1700 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1702 current_property = indexer;
1704 current_type.AddIndexer (indexer);
1705 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1707 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1708 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1710 if (indexer.ParameterInfo.IsEmpty) {
1711 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1715 tmpComment = Lexer.consume_doc_comment ();
1716 Lexer.doc_state = XmlCommentState.Allowed;
1719 lexer.PropertyParsing = true;
1721 OPEN_BRACE accessor_declarations
1723 lexer.PropertyParsing = false;
1727 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1728 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1731 current_property.DocComment = ConsumeStoredComment ();
1733 lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
1734 current_property = null;
1739 accessor_declarations
1740 : get_accessor_declaration
1741 | get_accessor_declaration accessor_declarations
1742 | set_accessor_declaration
1743 | set_accessor_declaration accessor_declarations
1746 if (yyToken == Token.CLOSE_BRACE) {
1747 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1749 if (yyToken == Token.SEMICOLON)
1750 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1752 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1757 get_accessor_declaration
1758 : opt_attributes opt_modifiers GET
1760 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1761 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1764 if (current_property.Get != null) {
1765 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1768 if (current_property is Indexer) {
1769 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1770 (Attributes) $1, GetLocation ($3));
1772 current_property.Get = new Property.GetMethod (current_property,
1773 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1776 current_local_parameters = current_property.Get.ParameterInfo;
1777 lbag.AddMember (current_property.Get, mod_locations);
1778 lexer.PropertyParsing = false;
1783 current_property.Get.Block = (ToplevelBlock) $5;
1785 if (current_container.Kind == MemberKind.Interface) {
1786 report.Error (531, current_property.Get.Block.StartLocation,
1787 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1791 current_local_parameters = null;
1792 lexer.PropertyParsing = true;
1795 if (Lexer.doc_state == XmlCommentState.Error)
1796 Lexer.doc_state = XmlCommentState.NotAllowed;
1800 set_accessor_declaration
1801 : opt_attributes opt_modifiers SET
1803 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1804 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1807 if (current_property.Set != null) {
1808 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1811 if (current_property is Indexer) {
1812 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1813 ParametersCompiled.MergeGenerated (compiler,
1814 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1815 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1817 (Attributes) $1, GetLocation ($3));
1819 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1820 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1821 (Attributes) $1, GetLocation ($3));
1824 current_local_parameters = current_property.Set.ParameterInfo;
1825 lbag.AddMember (current_property.Set, mod_locations);
1826 lexer.PropertyParsing = false;
1831 current_property.Set.Block = (ToplevelBlock) $5;
1833 if (current_container.Kind == MemberKind.Interface) {
1834 report.Error (531, current_property.Set.Block.StartLocation,
1835 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1839 current_local_parameters = null;
1840 lexer.PropertyParsing = true;
1843 && Lexer.doc_state == XmlCommentState.Error)
1844 Lexer.doc_state = XmlCommentState.NotAllowed;
1857 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1862 interface_declaration
1868 lexer.ConstraintsParsing = true;
1870 type_declaration_name
1872 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1873 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1876 opt_type_parameter_constraints_clauses
1878 lexer.ConstraintsParsing = false;
1881 current_container.SetConstraints ((List<Constraints>) $9);
1884 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1885 Lexer.doc_state = XmlCommentState.Allowed;
1888 lexer.parsing_modifiers = true;
1890 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1892 --lexer.parsing_declaration;
1894 Lexer.doc_state = XmlCommentState.Allowed;
1898 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1899 $$ = pop_current_class ();
1901 | opt_attributes opt_modifiers opt_partial INTERFACE error
1903 Error_SyntaxError (yyToken);
1907 opt_interface_member_declarations
1909 | interface_member_declarations
1912 interface_member_declarations
1913 : interface_member_declaration
1915 lexer.parsing_modifiers = true;
1917 | interface_member_declarations interface_member_declaration
1919 lexer.parsing_modifiers = true;
1923 interface_member_declaration
1924 : constant_declaration
1926 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1930 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1932 | method_declaration
1933 | property_declaration
1935 | indexer_declaration
1936 | operator_declaration
1938 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1940 | constructor_declaration
1942 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1946 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1950 operator_declaration
1951 : opt_attributes opt_modifiers operator_declarator
1956 OperatorDeclaration decl = (OperatorDeclaration) $3;
1958 Operator op = new Operator (
1959 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
1960 current_local_parameters,
1961 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1963 if (op.Block == null)
1964 op.ParameterInfo.CheckParameters (op);
1967 op.DocComment = tmpComment;
1968 Lexer.doc_state = XmlCommentState.Allowed;
1971 // Note again, checking is done in semantic analysis
1972 current_type.AddOperator (op);
1974 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1977 current_local_parameters = null;
1983 | SEMICOLON { $$ = null; }
1987 : type_expression_or_array
1990 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
1991 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
1996 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1998 valid_param_mod = ParameterModifierType.DefaultValue;
2000 opt_formal_parameter_list CLOSE_PARENS
2002 valid_param_mod = 0;
2004 Location loc = GetLocation ($2);
2005 Operator.OpType op = (Operator.OpType) $3;
2006 current_local_parameters = (ParametersCompiled)$6;
2008 int p_count = current_local_parameters.Count;
2010 if (op == Operator.OpType.Addition)
2011 op = Operator.OpType.UnaryPlus;
2012 else if (op == Operator.OpType.Subtraction)
2013 op = Operator.OpType.UnaryNegation;
2016 if (IsUnaryOperator (op)) {
2018 report.Error (1020, loc, "Overloadable binary operator expected");
2019 } else if (p_count != 1) {
2020 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2021 Operator.GetName (op));
2025 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2026 Operator.GetName (op));
2027 } else if (p_count != 2) {
2028 report.Error (1019, loc, "Overloadable unary operator expected");
2033 tmpComment = Lexer.consume_doc_comment ();
2034 Lexer.doc_state = XmlCommentState.NotAllowed;
2037 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2038 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2040 | conversion_operator_declarator
2043 overloadable_operator
2045 : BANG { $$ = Operator.OpType.LogicalNot; }
2046 | TILDE { $$ = Operator.OpType.OnesComplement; }
2047 | OP_INC { $$ = Operator.OpType.Increment; }
2048 | OP_DEC { $$ = Operator.OpType.Decrement; }
2049 | TRUE { $$ = Operator.OpType.True; }
2050 | FALSE { $$ = Operator.OpType.False; }
2051 // Unary and binary:
2052 | PLUS { $$ = Operator.OpType.Addition; }
2053 | MINUS { $$ = Operator.OpType.Subtraction; }
2055 | STAR { $$ = Operator.OpType.Multiply; }
2056 | DIV { $$ = Operator.OpType.Division; }
2057 | PERCENT { $$ = Operator.OpType.Modulus; }
2058 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2059 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2060 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2061 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2062 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2063 | OP_EQ { $$ = Operator.OpType.Equality; }
2064 | OP_NE { $$ = Operator.OpType.Inequality; }
2065 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2066 | OP_LT { $$ = Operator.OpType.LessThan; }
2067 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2068 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2071 conversion_operator_declarator
2072 : IMPLICIT OPERATOR type OPEN_PARENS
2074 valid_param_mod = ParameterModifierType.DefaultValue;
2076 opt_formal_parameter_list CLOSE_PARENS
2078 valid_param_mod = 0;
2080 Location loc = GetLocation ($2);
2081 current_local_parameters = (ParametersCompiled)$6;
2083 if (current_local_parameters.Count != 1) {
2084 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2088 tmpComment = Lexer.consume_doc_comment ();
2089 Lexer.doc_state = XmlCommentState.NotAllowed;
2092 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2093 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2095 | EXPLICIT OPERATOR type OPEN_PARENS
2097 valid_param_mod = ParameterModifierType.DefaultValue;
2099 opt_formal_parameter_list CLOSE_PARENS
2101 valid_param_mod = 0;
2103 Location loc = GetLocation ($2);
2104 current_local_parameters = (ParametersCompiled)$6;
2106 if (current_local_parameters.Count != 1) {
2107 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2111 tmpComment = Lexer.consume_doc_comment ();
2112 Lexer.doc_state = XmlCommentState.NotAllowed;
2115 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2116 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2120 Error_SyntaxError (yyToken);
2121 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2122 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2126 Error_SyntaxError (yyToken);
2127 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2128 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2132 constructor_declaration
2133 : constructor_declarator
2136 Constructor c = (Constructor) $1;
2137 c.Block = (ToplevelBlock) $2;
2140 c.DocComment = ConsumeStoredComment ();
2142 current_local_parameters = null;
2144 Lexer.doc_state = XmlCommentState.Allowed;
2148 constructor_declarator
2154 tmpComment = Lexer.consume_doc_comment ();
2155 Lexer.doc_state = XmlCommentState.Allowed;
2158 valid_param_mod = ParameterModifierType.All;
2160 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2162 valid_param_mod = 0;
2163 current_local_parameters = (ParametersCompiled) $6;
2165 var lt = (Tokenizer.LocatedToken) $3;
2166 var mods = (Modifiers) $2;
2167 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2169 if (lt.Value != current_container.MemberName.Name) {
2170 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2171 } else if ((mods & Modifiers.STATIC) != 0) {
2172 if ((mods & Modifiers.AccessibilityMask) != 0){
2173 report.Error (515, c.Location,
2174 "`{0}': static constructor cannot have an access modifier",
2175 c.GetSignatureForError ());
2179 current_type.AddConstructor (c);
2180 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2184 // start block here, so possible anonymous methods inside
2185 // constructor initializer can get correct parent block
2187 start_block (lexer.Location);
2189 opt_constructor_initializer
2192 var c = (Constructor) $8;
2193 c.Initializer = (ConstructorInitializer) $9;
2196 report.Error (514, c.Location,
2197 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2198 c.GetSignatureForError ());
2208 | SEMICOLON { current_block = null; $$ = null; }
2211 opt_constructor_initializer
2213 | constructor_initializer
2216 constructor_initializer
2217 : COLON BASE OPEN_PARENS
2219 ++lexer.parsing_block;
2221 opt_argument_list CLOSE_PARENS
2223 --lexer.parsing_block;
2224 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2225 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2227 | COLON THIS OPEN_PARENS
2229 ++lexer.parsing_block;
2231 opt_argument_list CLOSE_PARENS
2233 --lexer.parsing_block;
2234 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2235 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2239 Error_SyntaxError (yyToken);
2240 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2241 lbag.AddLocation ($$, GetLocation ($1));
2245 Error_SyntaxError (yyToken);
2250 destructor_declaration
2251 : opt_attributes opt_modifiers TILDE
2254 tmpComment = Lexer.consume_doc_comment ();
2255 Lexer.doc_state = XmlCommentState.NotAllowed;
2258 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2260 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2262 var lt = (Tokenizer.LocatedToken) $5;
2263 if (lt.Value != current_container.MemberName.Name){
2264 report.Error (574, lt.Location, "Name of destructor must match name of class");
2265 } else if (current_container.Kind != MemberKind.Class){
2266 report.Error (575, lt.Location, "Only class types can contain destructor");
2269 Destructor d = new Destructor (current_type, (Modifiers) $2,
2270 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2272 d.DocComment = ConsumeStoredComment ();
2274 d.Block = (ToplevelBlock) $8;
2275 current_type.AddMember (d);
2276 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2278 current_local_parameters = null;
2285 EVENT type member_declaration_name
2287 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2288 current_type.AddMember (current_event_field);
2290 if (current_event_field.MemberName.ExplicitInterface != null) {
2291 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2292 current_event_field.GetSignatureForError ());
2295 $$ = current_event_field;
2297 opt_event_initializer
2298 opt_event_declarators
2302 current_event_field.DocComment = Lexer.consume_doc_comment ();
2303 Lexer.doc_state = XmlCommentState.Allowed;
2306 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2307 current_event_field = null;
2311 EVENT type member_declaration_name
2314 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2315 current_type.AddMember (current_event);
2316 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2318 lexer.EventParsing = true;
2320 event_accessor_declarations
2322 if (current_container.Kind == MemberKind.Interface)
2323 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2325 lexer.EventParsing = false;
2330 current_event.DocComment = Lexer.consume_doc_comment ();
2331 Lexer.doc_state = XmlCommentState.Allowed;
2334 lbag.AppendToMember (current_event, GetLocation ($9));
2335 current_event = null;
2336 current_local_parameters = null;
2342 Error_SyntaxError (yyToken);
2344 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2348 opt_event_initializer
2352 ++lexer.parsing_block;
2354 event_variable_initializer
2356 --lexer.parsing_block;
2357 current_event_field.Initializer = (Expression) $3;
2361 opt_event_declarators
2369 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2371 | event_declarators event_declarator
2373 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2380 var lt = (Tokenizer.LocatedToken) $2;
2381 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2382 lbag.AddLocation ($$, GetLocation ($1));
2384 | COMMA IDENTIFIER ASSIGN
2386 ++lexer.parsing_block;
2388 event_variable_initializer
2390 --lexer.parsing_block;
2391 var lt = (Tokenizer.LocatedToken) $2;
2392 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2393 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2397 event_variable_initializer
2399 if (current_container.Kind == MemberKind.Interface) {
2400 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2401 current_event_field.GetSignatureForError ());
2404 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2405 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2406 current_event_field.GetSignatureForError ());
2409 variable_initializer
2415 event_accessor_declarations
2416 : add_accessor_declaration remove_accessor_declaration
2417 | remove_accessor_declaration add_accessor_declaration
2418 | add_accessor_declaration
2420 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2421 current_event.GetSignatureForError ());
2423 | remove_accessor_declaration
2425 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2426 current_event.GetSignatureForError ());
2430 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2435 add_accessor_declaration
2436 : opt_attributes opt_modifiers ADD
2438 if ($2 != ModifierNone) {
2439 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2442 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2443 current_local_parameters = current_event.Add.ParameterInfo;
2445 lbag.AddMember (current_event.Add, mod_locations);
2446 lexer.EventParsing = false;
2448 event_accessor_block
2450 lexer.EventParsing = true;
2452 current_event.Add.Block = (ToplevelBlock) $5;
2454 if (current_container.Kind == MemberKind.Interface) {
2455 report.Error (531, current_event.Add.Block.StartLocation,
2456 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2459 current_local_parameters = null;
2463 remove_accessor_declaration
2464 : opt_attributes opt_modifiers REMOVE
2466 if ($2 != ModifierNone) {
2467 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2470 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2471 current_local_parameters = current_event.Remove.ParameterInfo;
2473 lbag.AddMember (current_event.Remove, mod_locations);
2474 lexer.EventParsing = false;
2476 event_accessor_block
2478 lexer.EventParsing = true;
2480 current_event.Remove.Block = (ToplevelBlock) $5;
2482 if (current_container.Kind == MemberKind.Interface) {
2483 report.Error (531, current_event.Remove.Block.StartLocation,
2484 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2487 current_local_parameters = null;
2491 event_accessor_block
2494 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2500 attributes_without_members
2501 : attribute_sections CLOSE_BRACE
2503 current_type.UnattachedAttributes = (Attributes) $1;
2504 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2505 lexer.putback ('}');
2512 ENUM type_declaration_name
2516 enumTypeComment = Lexer.consume_doc_comment ();
2521 Lexer.doc_state = XmlCommentState.Allowed;
2523 MemberName name = (MemberName) $4;
2524 if (name.IsGeneric) {
2525 report.Error (1675, name.Location, "Enums cannot have type parameters");
2528 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2530 opt_enum_member_declarations
2532 // here will be evaluated after CLOSE_BLACE is consumed.
2534 Lexer.doc_state = XmlCommentState.Allowed;
2536 CLOSE_BRACE opt_semicolon
2539 current_container.DocComment = enumTypeComment;
2541 --lexer.parsing_declaration;
2544 // em.DocComment = ev.DocComment;
2546 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2547 $$ = pop_current_class ();
2555 var te = $2 as TypeExpression;
2556 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2557 Enum.Error_1008 (GetLocation ($2), report);
2563 Error_TypeExpected (GetLocation ($1));
2568 opt_enum_member_declarations
2570 | enum_member_declarations
2571 | enum_member_declarations COMMA
2573 lbag.AddLocation ($1, GetLocation ($2));
2577 enum_member_declarations
2578 : enum_member_declaration
2579 | enum_member_declarations COMMA enum_member_declaration
2581 lbag.AddLocation ($1, GetLocation ($2));
2586 enum_member_declaration
2587 : opt_attributes IDENTIFIER
2589 var lt = (Tokenizer.LocatedToken) $2;
2590 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2591 ((Enum) current_type).AddEnumMember (em);
2594 em.DocComment = Lexer.consume_doc_comment ();
2595 Lexer.doc_state = XmlCommentState.Allowed;
2600 | opt_attributes IDENTIFIER
2602 ++lexer.parsing_block;
2604 tmpComment = Lexer.consume_doc_comment ();
2605 Lexer.doc_state = XmlCommentState.NotAllowed;
2608 ASSIGN constant_expression
2610 --lexer.parsing_block;
2612 var lt = (Tokenizer.LocatedToken) $2;
2613 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2614 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2615 ((Enum) current_type).AddEnumMember (em);
2618 em.DocComment = ConsumeStoredComment ();
2622 | opt_attributes IDENTIFIER error
2624 Error_SyntaxError (yyToken);
2626 var lt = (Tokenizer.LocatedToken) $2;
2627 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2628 ((Enum) current_type).AddEnumMember (em);
2631 em.DocComment = Lexer.consume_doc_comment ();
2632 Lexer.doc_state = XmlCommentState.Allowed;
2637 | attributes_without_members
2640 delegate_declaration
2644 member_type type_declaration_name
2647 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2649 opt_formal_parameter_list CLOSE_PARENS
2651 valid_param_mod = 0;
2653 ParametersCompiled p = (ParametersCompiled) $8;
2655 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2657 p.CheckParameters (del);
2659 current_container.AddTypeContainer (del);
2661 current_delegate = del;
2662 lexer.ConstraintsParsing = true;
2664 opt_type_parameter_constraints_clauses
2666 lexer.ConstraintsParsing = false;
2671 current_delegate.DocComment = Lexer.consume_doc_comment ();
2672 Lexer.doc_state = XmlCommentState.Allowed;
2676 current_delegate.SetConstraints ((List<Constraints>) $11);
2677 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2679 $$ = current_delegate;
2681 current_delegate = null;
2689 if (lang_version < LanguageVersion.ISO_2)
2690 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2692 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2696 namespace_or_type_expr
2698 | qualified_alias_member IDENTIFIER opt_type_argument_list
2700 var lt1 = (Tokenizer.LocatedToken) $1;
2701 var lt2 = (Tokenizer.LocatedToken) $2;
2703 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2704 lbag.AddLocation ($$, GetLocation ($2));
2710 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2712 var lt = (Tokenizer.LocatedToken) $3;
2713 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2714 lbag.AddLocation ($$, GetLocation ($2));
2719 : IDENTIFIER opt_type_argument_list
2721 var lt = (Tokenizer.LocatedToken) $1;
2722 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2727 // Generics arguments (any type, without attributes)
2729 opt_type_argument_list
2731 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2733 if (lang_version < LanguageVersion.ISO_2)
2734 FeatureIsNotAvailable (GetLocation ($1), "generics");
2738 | OP_GENERICS_LT error
2740 Error_TypeExpected (lexer.Location);
2741 $$ = new TypeArguments ();
2748 TypeArguments type_args = new TypeArguments ();
2749 type_args.Add ((FullNamedExpression) $1);
2752 | type_arguments COMMA type
2754 TypeArguments type_args = (TypeArguments) $1;
2755 type_args.Add ((FullNamedExpression) $3);
2761 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2763 type_declaration_name
2766 lexer.parsing_generic_declaration = true;
2768 opt_type_parameter_list
2770 lexer.parsing_generic_declaration = false;
2771 var lt = (Tokenizer.LocatedToken) $1;
2772 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2776 member_declaration_name
2777 : method_declaration_name
2779 MemberName mn = (MemberName)$1;
2780 if (mn.TypeParameters != null)
2781 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2782 mn.GetSignatureForError ()));
2786 method_declaration_name
2787 : type_declaration_name
2788 | explicit_interface IDENTIFIER opt_type_parameter_list
2790 lexer.parsing_generic_declaration = false;
2791 var lt = (Tokenizer.LocatedToken) $2;
2792 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2796 indexer_declaration_name
2799 lexer.parsing_generic_declaration = false;
2800 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2802 | explicit_interface THIS
2804 lexer.parsing_generic_declaration = false;
2805 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2810 : IDENTIFIER opt_type_argument_list DOT
2812 var lt = (Tokenizer.LocatedToken) $1;
2813 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2814 lbag.AddLocation ($$, GetLocation ($3));
2816 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2818 var lt1 = (Tokenizer.LocatedToken) $1;
2819 var lt2 = (Tokenizer.LocatedToken) $2;
2821 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2822 lbag.AddLocation ($$, GetLocation ($4));
2824 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2826 var lt = (Tokenizer.LocatedToken) $2;
2827 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2828 lbag.AddLocation ($$, GetLocation ($4));
2832 opt_type_parameter_list
2834 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2836 if (lang_version < LanguageVersion.ISO_2)
2837 FeatureIsNotAvailable (GetLocation ($1), "generics");
2840 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2847 var tparams = new TypeParameters ();
2848 tparams.Add ((TypeParameter)$1);
2851 | type_parameters COMMA type_parameter
2853 var tparams = (TypeParameters) $1;
2854 tparams.Add ((TypeParameter)$3);
2856 lbag.AddLocation ($3, GetLocation ($3));
2861 : opt_attributes opt_type_parameter_variance IDENTIFIER
2863 var lt = (Tokenizer.LocatedToken)$3;
2864 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2868 if (GetTokenName (yyToken) == "type")
2869 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2871 Error_SyntaxError (yyToken);
2873 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2878 // All types where void is allowed
2881 : type_expression_or_array
2884 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2891 lexer.parsing_generic_declaration = true;
2896 // A type which does not allow `void' to be used
2899 : type_expression_or_array
2902 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2903 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2911 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2912 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2917 : type_expression_or_array
2920 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2921 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2925 type_expression_or_array
2927 | type_expression rank_specifiers
2929 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2934 : namespace_or_type_expr opt_nullable
2937 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2939 var sn = $1 as SimpleName;
2940 if (sn != null && sn.Name == "var")
2941 $$ = new VarExpr (sn.Location);
2946 | namespace_or_type_expr pointer_stars
2948 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2950 | builtin_types opt_nullable
2953 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2955 | builtin_types pointer_stars
2957 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2959 | VOID pointer_stars
2961 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2968 var types = new List<FullNamedExpression> (2);
2969 types.Add ((FullNamedExpression) $1);
2972 | type_list COMMA base_type_name
2974 var types = (List<FullNamedExpression>) $1;
2975 types.Add ((FullNamedExpression) $3);
2983 if ($1 is ComposedCast) {
2984 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2991 * replaces all the productions for isolating the various
2992 * simple types, but we need this to reuse it easily in variable_type
2995 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
2996 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
2997 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
2998 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
2999 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3000 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3005 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3006 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3007 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3008 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3009 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3010 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3011 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3012 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3013 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3017 // Expressions, section 7.5
3022 : primary_expression_or_type
3024 | array_creation_expression
3025 | parenthesized_expression
3026 | default_value_expression
3027 | invocation_expression
3031 | post_increment_expression
3032 | post_decrement_expression
3033 | object_or_delegate_creation_expression
3034 | anonymous_type_expression
3037 | checked_expression
3038 | unchecked_expression
3039 | pointer_member_access
3040 | anonymous_method_expression
3041 | undocumented_expressions
3044 primary_expression_or_type
3045 : IDENTIFIER opt_type_argument_list
3047 var lt = (Tokenizer.LocatedToken) $1;
3048 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3050 | IDENTIFIER GENERATE_COMPLETION {
3051 var lt = (Tokenizer.LocatedToken) $1;
3052 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3060 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3064 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3065 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3070 // Here is the trick, tokenizer may think that parens is a special but
3071 // parser is interested in open parens only, so we merge them.
3072 // Consider: if (a)foo ();
3080 // Use this production to accept closing parenthesis or
3081 // performing completion
3085 | COMPLETE_COMPLETION
3089 parenthesized_expression
3090 : OPEN_PARENS expression CLOSE_PARENS
3092 $$ = new ParenthesizedExpression ((Expression) $2);
3093 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3095 | OPEN_PARENS expression COMPLETE_COMPLETION
3097 $$ = new ParenthesizedExpression ((Expression) $2);
3102 : primary_expression DOT IDENTIFIER opt_type_argument_list
3104 var lt = (Tokenizer.LocatedToken) $3;
3105 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3106 lbag.AddLocation ($$, GetLocation ($2));
3108 | builtin_types DOT IDENTIFIER opt_type_argument_list
3110 var lt = (Tokenizer.LocatedToken) $3;
3111 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3112 lbag.AddLocation ($$, GetLocation ($2));
3114 | BASE DOT IDENTIFIER opt_type_argument_list
3116 var lt = (Tokenizer.LocatedToken) $3;
3117 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3118 lbag.AddLocation ($$, GetLocation ($2));
3120 | qualified_alias_member IDENTIFIER opt_type_argument_list
3122 var lt1 = (Tokenizer.LocatedToken) $1;
3123 var lt2 = (Tokenizer.LocatedToken) $2;
3125 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3126 lbag.AddLocation ($$, GetLocation ($2));
3128 | primary_expression DOT GENERATE_COMPLETION {
3129 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3131 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3132 var lt = (Tokenizer.LocatedToken) $3;
3133 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3135 | builtin_types DOT GENERATE_COMPLETION
3137 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3139 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3140 var lt = (Tokenizer.LocatedToken) $3;
3141 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3145 invocation_expression
3146 : primary_expression open_parens_any opt_argument_list close_parens
3148 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3149 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3151 | primary_expression open_parens_any argument_list error
3153 Error_SyntaxError (yyToken);
3155 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3156 lbag.AddLocation ($$, GetLocation ($2));
3158 | primary_expression open_parens_any error
3160 Error_SyntaxError (yyToken);
3162 $$ = new Invocation ((Expression) $1, null);
3163 lbag.AddLocation ($$, GetLocation ($2));
3167 opt_object_or_collection_initializer
3168 : /* empty */ { $$ = null; }
3169 | object_or_collection_initializer
3172 object_or_collection_initializer
3173 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3176 $$ = CollectionOrObjectInitializers.Empty;
3179 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3180 lbag.AddLocation ($$, GetLocation ($3));
3183 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3185 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3186 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3190 opt_member_initializer_list
3191 : /* empty */ { $$ = null; }
3192 | member_initializer_list
3198 member_initializer_list
3199 : member_initializer
3201 var a = new List<Expression> ();
3202 a.Add ((Expression) $1);
3205 | member_initializer_list COMMA member_initializer
3207 var a = (List<Expression>)$1;
3208 a.Add ((Expression) $3);
3211 | member_initializer_list error {
3212 Error_SyntaxError (yyToken);
3218 : IDENTIFIER ASSIGN initializer_value
3220 var lt = (Tokenizer.LocatedToken) $1;
3221 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3222 lbag.AddLocation ($$, GetLocation ($2));
3224 | GENERATE_COMPLETION
3226 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3228 | non_assignment_expression opt_COMPLETE_COMPLETION {
3229 CompletionSimpleName csn = $1 as CompletionSimpleName;
3231 $$ = new CollectionElementInitializer ((Expression)$1);
3233 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3235 | OPEN_BRACE expression_list CLOSE_BRACE
3240 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3242 | OPEN_BRACE CLOSE_BRACE
3244 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3251 | object_or_collection_initializer
3255 : /* empty */ { $$ = null; }
3260 : argument_or_named_argument
3262 Arguments list = new Arguments (4);
3263 list.Add ((Argument) $1);
3266 | argument_list COMMA argument
3268 Arguments list = (Arguments) $1;
3269 if (list [list.Count - 1] is NamedArgument)
3270 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3272 list.Add ((Argument) $3);
3275 | argument_list COMMA named_argument
3277 Arguments list = (Arguments) $1;
3278 NamedArgument a = (NamedArgument) $3;
3279 for (int i = 0; i < list.Count; ++i) {
3280 NamedArgument na = list [i] as NamedArgument;
3281 if (na != null && na.Name == a.Name)
3282 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3289 | argument_list COMMA error
3291 if (lexer.putback_char == -1)
3292 lexer.putback (')'); // TODO: Wrong but what can I do
3293 Error_SyntaxError (yyToken);
3298 report.Error (839, GetLocation ($1), "An argument is missing");
3306 $$ = new Argument ((Expression) $1);
3308 | non_simple_argument
3311 argument_or_named_argument
3317 : REF variable_reference
3319 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3320 lbag.AddLocation ($$, GetLocation ($1));
3322 | OUT variable_reference
3324 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3325 lbag.AddLocation ($$, GetLocation ($1));
3327 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3329 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3330 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3332 | ARGLIST OPEN_PARENS CLOSE_PARENS
3334 $$ = new Argument (new Arglist (GetLocation ($1)));
3335 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3344 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3346 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3347 lbag.AddLocation ($$, GetLocation ($4));
3349 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3351 Error_SyntaxError (yyToken);
3352 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3354 | primary_expression OPEN_BRACKET_EXPR error
3356 Error_SyntaxError (yyToken);
3357 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3364 var list = new List<Expression> (4);
3365 list.Add ((Expression) $1);
3368 | expression_list COMMA expression
3370 var list = (List<Expression>) $1;
3371 list.Add ((Expression) $3);
3374 | expression_list error {
3375 Error_SyntaxError (yyToken);
3380 expression_list_arguments
3381 : expression_list_argument
3383 Arguments args = new Arguments (4);
3384 args.Add ((Argument) $1);
3387 | expression_list_arguments COMMA expression_list_argument
3389 Arguments args = (Arguments) $1;
3390 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3391 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3393 args.Add ((Argument) $3);
3398 expression_list_argument
3401 $$ = new Argument ((Expression) $1);
3409 $$ = new This (GetLocation ($1));
3414 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3416 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3417 lbag.AddLocation ($$, GetLocation ($4));
3419 | BASE OPEN_BRACKET error
3421 Error_SyntaxError (yyToken);
3422 $$ = new ElementAccess (null, null, GetLocation ($2));
3426 post_increment_expression
3427 : primary_expression OP_INC
3429 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3433 post_decrement_expression
3434 : primary_expression OP_DEC
3436 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3440 object_or_delegate_creation_expression
3441 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3444 if (lang_version <= LanguageVersion.ISO_2)
3445 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3447 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3449 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3452 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3454 | NEW new_expr_type object_or_collection_initializer
3456 if (lang_version <= LanguageVersion.ISO_2)
3457 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3459 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3463 array_creation_expression
3464 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3466 opt_array_initializer
3468 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3469 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3470 Next = (ComposedTypeSpecifier) $6
3471 }, (ArrayInitializer) $7, GetLocation ($1));
3472 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3474 | NEW new_expr_type rank_specifiers opt_array_initializer
3477 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3479 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3481 | NEW rank_specifier array_initializer
3483 if (lang_version <= LanguageVersion.ISO_2)
3484 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3486 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3488 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3490 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3491 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3493 | NEW new_expr_type error
3495 Error_SyntaxError (yyToken);
3496 // It can be any of new expression, create the most common one
3497 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3503 ++lexer.parsing_type;
3507 --lexer.parsing_type;
3512 anonymous_type_expression
3513 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3515 if (lang_version <= LanguageVersion.ISO_2)
3516 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3518 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3520 // TODO: lbag comma location
3521 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3525 anonymous_type_parameters_opt_comma
3526 : anonymous_type_parameters_opt
3527 | anonymous_type_parameters COMMA
3530 anonymous_type_parameters_opt
3532 | anonymous_type_parameters
3535 anonymous_type_parameters
3536 : anonymous_type_parameter
3538 var a = new List<AnonymousTypeParameter> (4);
3539 a.Add ((AnonymousTypeParameter) $1);
3542 | anonymous_type_parameters COMMA anonymous_type_parameter
3544 var a = (List<AnonymousTypeParameter>) $1;
3545 a.Add ((AnonymousTypeParameter) $3);
3550 anonymous_type_parameter
3551 : IDENTIFIER ASSIGN variable_initializer
3553 var lt = (Tokenizer.LocatedToken)$1;
3554 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3555 lbag.AddLocation ($$, GetLocation ($2));
3559 var lt = (Tokenizer.LocatedToken)$1;
3560 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3561 lt.Value, lt.Location);
3565 MemberAccess ma = (MemberAccess) $1;
3566 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3570 report.Error (746, lexer.Location,
3571 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3583 | rank_specifier rank_specifiers
3585 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3591 : OPEN_BRACKET CLOSE_BRACKET
3593 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3594 lbag.AddLocation ($$, GetLocation ($2));
3596 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3598 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3599 lbag.AddLocation ($$, GetLocation ($3));
3608 | dim_separators COMMA
3610 $$ = ((int) $1) + 1;
3614 opt_array_initializer
3626 : OPEN_BRACE CLOSE_BRACE
3628 var ai = new ArrayInitializer (0, GetLocation ($1));
3629 ai.VariableDeclaration = current_variable;
3630 lbag.AddLocation (ai, GetLocation ($2));
3633 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3635 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3636 ai.VariableDeclaration = current_variable;
3638 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3640 lbag.AddLocation (ai, GetLocation ($4));
3646 variable_initializer_list
3647 : variable_initializer
3649 var list = new List<Expression> (4);
3650 list.Add ((Expression) $1);
3653 | variable_initializer_list COMMA variable_initializer
3655 var list = (List<Expression>) $1;
3656 list.Add ((Expression) $3);
3664 lexer.TypeOfParsing = true;
3666 open_parens_any typeof_type_expression CLOSE_PARENS
3668 lexer.TypeOfParsing = false;
3669 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3670 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3674 typeof_type_expression
3679 Error_TypeExpected (lexer.Location);
3685 : identifier_inside_body generic_dimension
3687 var lt = (Tokenizer.LocatedToken) $1;
3689 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3691 | qualified_alias_member identifier_inside_body generic_dimension
3693 var lt1 = (Tokenizer.LocatedToken) $1;
3694 var lt2 = (Tokenizer.LocatedToken) $2;
3696 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3697 lbag.AddLocation ($$, GetLocation ($2));
3699 | unbound_type_name DOT identifier_inside_body
3701 var lt = (Tokenizer.LocatedToken) $3;
3703 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3705 | unbound_type_name DOT identifier_inside_body generic_dimension
3707 var lt = (Tokenizer.LocatedToken) $3;
3709 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3711 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3713 var tne = (ATypeNameExpression) $1;
3714 if (tne.HasTypeArguments)
3715 Error_TypeExpected (GetLocation ($4));
3717 var lt = (Tokenizer.LocatedToken) $3;
3718 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3725 if (lang_version < LanguageVersion.ISO_2)
3726 FeatureIsNotAvailable (GetLocation ($1), "generics");
3732 qualified_alias_member
3733 : IDENTIFIER DOUBLE_COLON
3735 var lt = (Tokenizer.LocatedToken) $1;
3736 if (lang_version == LanguageVersion.ISO_1)
3737 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3744 : SIZEOF open_parens_any type CLOSE_PARENS
3746 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3747 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3749 | SIZEOF open_parens_any type error
3751 Error_SyntaxError (yyToken);
3753 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3754 lbag.AddLocation ($$, GetLocation ($2));
3759 : CHECKED open_parens_any expression CLOSE_PARENS
3761 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3762 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3766 Error_SyntaxError (yyToken);
3768 $$ = new CheckedExpr (null, GetLocation ($1));
3772 unchecked_expression
3773 : UNCHECKED open_parens_any expression CLOSE_PARENS
3775 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3776 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3780 Error_SyntaxError (yyToken);
3782 $$ = new UnCheckedExpr (null, GetLocation ($1));
3786 pointer_member_access
3787 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3789 var lt = (Tokenizer.LocatedToken) $3;
3790 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3794 anonymous_method_expression
3795 : DELEGATE opt_anonymous_method_signature
3797 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3801 $$ = end_anonymous ((ParametersBlock) $4);
3803 | ASYNC DELEGATE opt_anonymous_method_signature
3805 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3809 $$ = end_anonymous ((ParametersBlock) $5);
3813 opt_anonymous_method_signature
3816 $$ = ParametersCompiled.Undefined;
3818 | anonymous_method_signature
3821 anonymous_method_signature
3824 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3826 opt_formal_parameter_list CLOSE_PARENS
3828 valid_param_mod = 0;
3833 default_value_expression
3834 : DEFAULT open_parens_any type CLOSE_PARENS
3836 if (lang_version < LanguageVersion.ISO_2)
3837 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3839 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3840 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3845 : primary_expression
3846 | BANG prefixed_unary_expression
3848 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3850 | TILDE prefixed_unary_expression
3852 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3854 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3856 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3857 lbag.AddLocation ($$, GetLocation ($3));
3859 | AWAIT prefixed_unary_expression
3862 if (current_anonymous_method is LambdaExpression) {
3863 report.Error (4034, GetLocation ($1),
3864 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3865 } else if (current_anonymous_method is AnonymousMethodExpression) {
3866 report.Error (4035, GetLocation ($1),
3867 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3869 report.Error (4033, GetLocation ($1),
3870 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3873 current_block.Explicit.RegisterAsyncAwait ();
3876 $$ = new Await ((Expression) $2, GetLocation ($1));
3880 Error_SyntaxError (yyToken);
3882 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
3886 Error_SyntaxError (yyToken);
3888 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
3890 | OPEN_PARENS_CAST type CLOSE_PARENS error
3892 Error_SyntaxError (yyToken);
3894 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
3895 lbag.AddLocation ($$, GetLocation ($3));
3899 Error_SyntaxError (yyToken);
3901 $$ = new Await (null, GetLocation ($1));
3906 // The idea to split this out is from Rhys' grammar
3907 // to solve the problem with casts.
3909 prefixed_unary_expression
3911 | PLUS prefixed_unary_expression
3913 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3915 | MINUS prefixed_unary_expression
3917 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3919 | OP_INC prefixed_unary_expression
3921 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3923 | OP_DEC prefixed_unary_expression
3925 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3927 | STAR prefixed_unary_expression
3929 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3931 | BITWISE_AND prefixed_unary_expression
3933 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3937 Error_SyntaxError (yyToken);
3939 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
3943 Error_SyntaxError (yyToken);
3945 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
3949 Error_SyntaxError (yyToken);
3951 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
3955 Error_SyntaxError (yyToken);
3957 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
3961 Error_SyntaxError (yyToken);
3963 $$ = new Indirection (null, GetLocation ($1));
3967 Error_SyntaxError (yyToken);
3969 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
3973 multiplicative_expression
3974 : prefixed_unary_expression
3975 | multiplicative_expression STAR prefixed_unary_expression
3977 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3978 lbag.AddLocation ($$, GetLocation ($2));
3980 | multiplicative_expression DIV prefixed_unary_expression
3982 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
3983 lbag.AddLocation ($$, GetLocation ($2));
3985 | multiplicative_expression PERCENT prefixed_unary_expression
3987 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3988 lbag.AddLocation ($$, GetLocation ($2));
3990 | multiplicative_expression STAR error
3992 Error_SyntaxError (yyToken);
3994 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
3995 lbag.AddLocation ($$, GetLocation ($2));
3997 | multiplicative_expression DIV error
3999 Error_SyntaxError (yyToken);
4001 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4002 lbag.AddLocation ($$, GetLocation ($2));
4004 | multiplicative_expression PERCENT error
4006 Error_SyntaxError (yyToken);
4008 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4009 lbag.AddLocation ($$, GetLocation ($2));
4014 : multiplicative_expression
4015 | additive_expression PLUS multiplicative_expression
4017 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4018 lbag.AddLocation ($$, GetLocation ($2));
4020 | additive_expression MINUS multiplicative_expression
4022 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4023 lbag.AddLocation ($$, GetLocation ($2));
4025 | additive_expression AS type
4027 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4029 | additive_expression IS type
4031 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4033 | additive_expression PLUS error
4035 Error_SyntaxError (yyToken);
4037 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4038 lbag.AddLocation ($$, GetLocation ($2));
4040 | additive_expression MINUS error
4042 Error_SyntaxError (yyToken);
4044 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4045 lbag.AddLocation ($$, GetLocation ($2));
4047 | additive_expression AS error
4049 Error_SyntaxError (yyToken);
4051 $$ = new As ((Expression) $1, null, GetLocation ($2));
4053 | additive_expression IS error
4055 Error_SyntaxError (yyToken);
4057 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4062 : additive_expression
4063 | shift_expression OP_SHIFT_LEFT additive_expression
4065 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4066 lbag.AddLocation ($$, GetLocation ($2));
4068 | shift_expression OP_SHIFT_RIGHT additive_expression
4070 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4071 lbag.AddLocation ($$, GetLocation ($2));
4073 | shift_expression OP_SHIFT_LEFT error
4075 Error_SyntaxError (yyToken);
4077 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4078 lbag.AddLocation ($$, GetLocation ($2));
4080 | shift_expression OP_SHIFT_RIGHT error
4082 Error_SyntaxError (yyToken);
4084 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4085 lbag.AddLocation ($$, GetLocation ($2));
4089 relational_expression
4091 | relational_expression OP_LT shift_expression
4093 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4094 lbag.AddLocation ($$, GetLocation ($2));
4096 | relational_expression OP_GT shift_expression
4098 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4099 lbag.AddLocation ($$, GetLocation ($2));
4101 | relational_expression OP_LE shift_expression
4103 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4104 lbag.AddLocation ($$, GetLocation ($2));
4106 | relational_expression OP_GE shift_expression
4108 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4109 lbag.AddLocation ($$, GetLocation ($2));
4111 | relational_expression OP_LT error
4113 Error_SyntaxError (yyToken);
4115 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4116 lbag.AddLocation ($$, GetLocation ($2));
4118 | relational_expression OP_GT error
4120 Error_SyntaxError (yyToken);
4122 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4123 lbag.AddLocation ($$, GetLocation ($2));
4125 | relational_expression OP_LE error
4127 Error_SyntaxError (yyToken);
4129 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4130 lbag.AddLocation ($$, GetLocation ($2));
4132 | relational_expression OP_GE error
4134 Error_SyntaxError (yyToken);
4136 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4137 lbag.AddLocation ($$, GetLocation ($2));
4142 : relational_expression
4143 | equality_expression OP_EQ relational_expression
4145 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4146 lbag.AddLocation ($$, GetLocation ($2));
4148 | equality_expression OP_NE relational_expression
4150 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4151 lbag.AddLocation ($$, GetLocation ($2));
4153 | equality_expression OP_EQ error
4155 Error_SyntaxError (yyToken);
4157 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4158 lbag.AddLocation ($$, GetLocation ($2));
4160 | equality_expression OP_NE error
4162 Error_SyntaxError (yyToken);
4164 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4165 lbag.AddLocation ($$, GetLocation ($2));
4170 : equality_expression
4171 | and_expression BITWISE_AND equality_expression
4173 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4174 lbag.AddLocation ($$, GetLocation ($2));
4176 | and_expression BITWISE_AND error
4178 Error_SyntaxError (yyToken);
4180 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4181 lbag.AddLocation ($$, GetLocation ($2));
4185 exclusive_or_expression
4187 | exclusive_or_expression CARRET and_expression
4189 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4190 lbag.AddLocation ($$, GetLocation ($2));
4192 | exclusive_or_expression CARRET error
4194 Error_SyntaxError (yyToken);
4196 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4197 lbag.AddLocation ($$, GetLocation ($2));
4201 inclusive_or_expression
4202 : exclusive_or_expression
4203 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4205 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4206 lbag.AddLocation ($$, GetLocation ($2));
4208 | inclusive_or_expression BITWISE_OR error
4210 Error_SyntaxError (yyToken);
4212 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4213 lbag.AddLocation ($$, GetLocation ($2));
4217 conditional_and_expression
4218 : inclusive_or_expression
4219 | conditional_and_expression OP_AND inclusive_or_expression
4221 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4222 lbag.AddLocation ($$, GetLocation ($2));
4224 | conditional_and_expression OP_AND error
4226 Error_SyntaxError (yyToken);
4228 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4229 lbag.AddLocation ($$, GetLocation ($2));
4233 conditional_or_expression
4234 : conditional_and_expression
4235 | conditional_or_expression OP_OR conditional_and_expression
4237 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4238 lbag.AddLocation ($$, GetLocation ($2));
4240 | conditional_or_expression OP_OR error
4242 Error_SyntaxError (yyToken);
4244 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4245 lbag.AddLocation ($$, GetLocation ($2));
4249 null_coalescing_expression
4250 : conditional_or_expression
4251 | conditional_or_expression OP_COALESCING null_coalescing_expression
4253 if (lang_version < LanguageVersion.ISO_2)
4254 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4256 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4257 lbag.AddLocation ($$, GetLocation ($2));
4261 conditional_expression
4262 : null_coalescing_expression
4263 | null_coalescing_expression INTERR expression COLON expression
4265 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4266 lbag.AddLocation ($$, GetLocation ($4));
4268 | null_coalescing_expression INTERR expression error
4270 Error_SyntaxError (yyToken);
4272 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4274 | null_coalescing_expression INTERR expression COLON error
4276 Error_SyntaxError (yyToken);
4278 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4279 lbag.AddLocation ($$, GetLocation ($4));
4283 assignment_expression
4284 : prefixed_unary_expression ASSIGN expression
4286 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4287 lbag.AddLocation ($$, GetLocation ($2));
4289 | prefixed_unary_expression OP_MULT_ASSIGN expression
4291 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4292 lbag.AddLocation ($$, GetLocation ($2));
4294 | prefixed_unary_expression OP_DIV_ASSIGN expression
4296 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4297 lbag.AddLocation ($$, GetLocation ($2));
4299 | prefixed_unary_expression OP_MOD_ASSIGN expression
4301 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4302 lbag.AddLocation ($$, GetLocation ($2));
4304 | prefixed_unary_expression OP_ADD_ASSIGN expression
4306 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4307 lbag.AddLocation ($$, GetLocation ($2));
4309 | prefixed_unary_expression OP_SUB_ASSIGN expression
4311 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4312 lbag.AddLocation ($$, GetLocation ($2));
4314 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4316 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4317 lbag.AddLocation ($$, GetLocation ($2));
4319 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4321 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4322 lbag.AddLocation ($$, GetLocation ($2));
4324 | prefixed_unary_expression OP_AND_ASSIGN expression
4326 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4327 lbag.AddLocation ($$, GetLocation ($2));
4329 | prefixed_unary_expression OP_OR_ASSIGN expression
4331 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4332 lbag.AddLocation ($$, GetLocation ($2));
4334 | prefixed_unary_expression OP_XOR_ASSIGN expression
4336 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4337 lbag.AddLocation ($$, GetLocation ($2));
4341 lambda_parameter_list
4344 var pars = new List<Parameter> (4);
4345 pars.Add ((Parameter) $1);
4349 | lambda_parameter_list COMMA lambda_parameter
4351 var pars = (List<Parameter>) $1;
4352 Parameter p = (Parameter)$3;
4353 if (pars[0].GetType () != p.GetType ()) {
4354 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4363 : parameter_modifier parameter_type identifier_inside_body
4365 var lt = (Tokenizer.LocatedToken) $3;
4367 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4369 | parameter_type identifier_inside_body
4371 var lt = (Tokenizer.LocatedToken) $2;
4373 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4377 var lt = (Tokenizer.LocatedToken) $1;
4378 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4382 opt_lambda_parameter_list
4383 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4384 | lambda_parameter_list {
4385 var pars_list = (List<Parameter>) $1;
4386 $$ = new ParametersCompiled (pars_list.ToArray ());
4390 lambda_expression_body
4392 start_block (Location.Null);
4394 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4396 Block b = end_block (Location.Null);
4397 b.IsCompilerGenerated = true;
4398 b.AddStatement (new ContextualReturn ((Expression) $2));
4404 // Handles only cases like foo = x.FirstOrDefault (l => );
4405 // where we must restore current_variable
4407 Error_SyntaxError (yyToken);
4416 Error_SyntaxError (yyToken);
4424 var lt = (Tokenizer.LocatedToken) $1;
4425 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4426 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4428 lambda_expression_body
4430 $$ = end_anonymous ((ParametersBlock) $4);
4431 lbag.AddLocation ($$, GetLocation ($2));
4433 | ASYNC identifier_inside_body ARROW
4435 var lt = (Tokenizer.LocatedToken) $2;
4436 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4437 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4439 lambda_expression_body
4441 $$ = end_anonymous ((ParametersBlock) $5);
4442 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4444 | OPEN_PARENS_LAMBDA
4446 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4448 opt_lambda_parameter_list CLOSE_PARENS ARROW
4450 valid_param_mod = 0;
4451 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4453 lambda_expression_body
4455 $$ = end_anonymous ((ParametersBlock) $7);
4456 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4458 | ASYNC OPEN_PARENS_LAMBDA
4460 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4462 opt_lambda_parameter_list CLOSE_PARENS ARROW
4464 valid_param_mod = 0;
4465 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4467 lambda_expression_body
4469 $$ = end_anonymous ((ParametersBlock) $8);
4470 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4475 : assignment_expression
4476 | non_assignment_expression
4479 non_assignment_expression
4480 : conditional_expression
4485 $$ = new ArglistAccess (GetLocation ($1));
4489 undocumented_expressions
4490 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4492 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4493 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4495 | REFTYPE open_parens_any expression CLOSE_PARENS
4497 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4498 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4500 | MAKEREF open_parens_any expression CLOSE_PARENS
4502 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4503 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4514 $$ = new BooleanExpression ((Expression) $1);
4527 lexer.ConstraintsParsing = true;
4529 type_declaration_name
4531 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4532 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4533 FeatureIsNotAvailable (c.Location, "static classes");
4536 push_current_container (c, $3);
4539 opt_type_parameter_constraints_clauses
4541 lexer.ConstraintsParsing = false;
4544 current_container.SetConstraints ((List<Constraints>) $9);
4545 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4548 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4549 Lexer.doc_state = XmlCommentState.Allowed;
4552 lexer.parsing_modifiers = true;
4554 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4556 --lexer.parsing_declaration;
4558 Lexer.doc_state = XmlCommentState.Allowed;
4562 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4563 $$ = pop_current_class ();
4571 { $$ = $1; } // location
4577 mod_locations = null;
4579 lexer.parsing_modifiers = false;
4583 lexer.parsing_modifiers = false;
4589 | modifiers modifier
4591 var m1 = (Modifiers) $1;
4592 var m2 = (Modifiers) $2;
4594 if ((m1 & m2) != 0) {
4595 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4596 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4597 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4598 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4599 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4600 "More than one protection modifier specified");
4611 StoreModifierLocation ($$, GetLocation ($1));
4613 if (current_container.Kind == MemberKind.Namespace)
4614 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4618 $$ = Modifiers.PUBLIC;
4619 StoreModifierLocation ($$, GetLocation ($1));
4623 $$ = Modifiers.PROTECTED;
4624 StoreModifierLocation ($$, GetLocation ($1));
4628 $$ = Modifiers.INTERNAL;
4629 StoreModifierLocation ($$, GetLocation ($1));
4633 $$ = Modifiers.PRIVATE;
4634 StoreModifierLocation ($$, GetLocation ($1));
4638 $$ = Modifiers.ABSTRACT;
4639 StoreModifierLocation ($$, GetLocation ($1));
4643 $$ = Modifiers.SEALED;
4644 StoreModifierLocation ($$, GetLocation ($1));
4648 $$ = Modifiers.STATIC;
4649 StoreModifierLocation ($$, GetLocation ($1));
4653 $$ = Modifiers.READONLY;
4654 StoreModifierLocation ($$, GetLocation ($1));
4658 $$ = Modifiers.VIRTUAL;
4659 StoreModifierLocation ($$, GetLocation ($1));
4663 $$ = Modifiers.OVERRIDE;
4664 StoreModifierLocation ($$, GetLocation ($1));
4668 $$ = Modifiers.EXTERN;
4669 StoreModifierLocation ($$, GetLocation ($1));
4673 $$ = Modifiers.VOLATILE;
4674 StoreModifierLocation ($$, GetLocation ($1));
4678 $$ = Modifiers.UNSAFE;
4679 StoreModifierLocation ($$, GetLocation ($1));
4680 if (!settings.Unsafe)
4681 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4685 $$ = Modifiers.ASYNC;
4686 StoreModifierLocation ($$, GetLocation ($1));
4694 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4696 | COLON type_list error
4698 Error_SyntaxError (yyToken);
4700 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4704 opt_type_parameter_constraints_clauses
4706 | type_parameter_constraints_clauses
4712 type_parameter_constraints_clauses
4713 : type_parameter_constraints_clause
4715 var constraints = new List<Constraints> (1);
4716 constraints.Add ((Constraints) $1);
4719 | type_parameter_constraints_clauses type_parameter_constraints_clause
4721 var constraints = (List<Constraints>) $1;
4722 Constraints new_constraint = (Constraints)$2;
4724 foreach (Constraints c in constraints) {
4725 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4726 report.Error (409, new_constraint.Location,
4727 "A constraint clause has already been specified for type parameter `{0}'",
4728 new_constraint.TypeParameter.Value);
4732 constraints.Add (new_constraint);
4737 type_parameter_constraints_clause
4738 : WHERE IDENTIFIER COLON type_parameter_constraints
4740 var lt = (Tokenizer.LocatedToken) $2;
4741 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4742 lbag.AddLocation ($$, GetLocation ($3));
4744 | WHERE IDENTIFIER error
4746 Error_SyntaxError (yyToken);
4748 var lt = (Tokenizer.LocatedToken) $2;
4749 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4753 type_parameter_constraints
4754 : type_parameter_constraint
4756 var constraints = new List<FullNamedExpression> (1);
4757 constraints.Add ((FullNamedExpression) $1);
4760 | type_parameter_constraints COMMA type_parameter_constraint
4762 var constraints = (List<FullNamedExpression>) $1;
4763 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4764 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4765 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4768 prev = $3 as SpecialContraintExpr;
4770 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4771 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4773 prev = constraints [0] as SpecialContraintExpr;
4774 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4775 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4780 constraints.Add ((FullNamedExpression) $3);
4785 type_parameter_constraint
4788 if ($1 is ComposedCast)
4789 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4793 | NEW OPEN_PARENS CLOSE_PARENS
4795 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4796 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4800 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4804 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4808 opt_type_parameter_variance
4813 | type_parameter_variance
4815 if (lang_version <= LanguageVersion.V_3)
4816 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4822 type_parameter_variance
4825 $$ = Variance.Covariant;
4829 $$ = Variance.Contravariant;
4838 // A block is "contained" on the following places:
4840 // property_declaration as part of the accessor body (get/set)
4841 // operator_declaration
4842 // constructor_declaration
4843 // destructor_declaration
4844 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4849 ++lexer.parsing_block;
4850 start_block (GetLocation ($1));
4852 opt_statement_list block_end
4861 --lexer.parsing_block;
4862 $$ = end_block (GetLocation ($1));
4864 | COMPLETE_COMPLETION
4866 --lexer.parsing_block;
4867 $$ = end_block (lexer.Location);
4875 ++lexer.parsing_block;
4876 current_block.StartLocation = GetLocation ($1);
4878 opt_statement_list CLOSE_BRACE
4880 --lexer.parsing_block;
4881 $$ = end_block (GetLocation ($4));
4892 | statement_list statement
4896 : block_variable_declaration
4898 current_block.AddStatement ((Statement) $1);
4900 | valid_declaration_statement
4902 current_block.AddStatement ((Statement) $1);
4907 Error_SyntaxError (yyToken);
4913 // The interactive_statement and its derivatives are only
4914 // used to provide a special version of `expression_statement'
4915 // that has a side effect of assigning the expression to
4918 interactive_statement_list
4919 : interactive_statement
4920 | interactive_statement_list interactive_statement
4923 interactive_statement
4924 : block_variable_declaration
4926 current_block.AddStatement ((Statement) $1);
4928 | interactive_valid_declaration_statement
4930 current_block.AddStatement ((Statement) $1);
4935 valid_declaration_statement
4938 | expression_statement
4939 | selection_statement
4940 | iteration_statement
4944 | unchecked_statement
4951 interactive_valid_declaration_statement
4954 | interactive_expression_statement
4955 | selection_statement
4956 | iteration_statement
4960 | unchecked_statement
4968 : valid_declaration_statement
4969 | block_variable_declaration
4971 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4976 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4981 Error_SyntaxError (yyToken);
4982 $$ = new EmptyStatement (GetLocation ($1));
4989 // Uses lexer.Location because semicolon location is not kept in quick mode
4990 $$ = new EmptyStatement (lexer.Location);
4995 : identifier_inside_body COLON
4997 var lt = (Tokenizer.LocatedToken) $1;
4998 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4999 lbag.AddLocation (labeled, GetLocation ($2));
5000 current_block.AddLabel (labeled);
5001 current_block.AddStatement (labeled);
5007 : variable_type_simple
5008 | variable_type_simple rank_specifiers
5011 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5013 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5018 * The following is from Rhys' grammar:
5019 * > Types in local variable declarations must be recognized as
5020 * > expressions to prevent reduce/reduce errors in the grammar.
5021 * > The expressions are converted into types during semantic analysis.
5023 variable_type_simple
5024 : primary_expression_or_type opt_nullable
5026 // Ok, the above "primary_expression" is there to get rid of
5027 // both reduce/reduce and shift/reduces in the grammar, it should
5028 // really just be "type_name". If you use type_name, a reduce/reduce
5029 // creeps up. If you use namespace_or_type_name (which is all we need
5030 // really) two shift/reduces appear.
5033 // So the super-trick is that primary_expression
5034 // can only be either a SimpleName or a MemberAccess.
5035 // The MemberAccess case arises when you have a fully qualified type-name like :
5037 // SimpleName is when you have
5040 Expression expr = (Expression) $1;
5042 SimpleName sn = expr as SimpleName;
5043 if (sn != null && sn.Name == "var")
5044 $$ = new VarExpr (sn.Location);
5047 } else if (expr is ATypeNameExpression) {
5048 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5050 Error_ExpectingTypeName (expr);
5054 | primary_expression_or_type pointer_stars
5056 ATypeNameExpression expr = $1 as ATypeNameExpression;
5059 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5061 Error_ExpectingTypeName ((Expression)$1);
5065 | builtin_types opt_nullable
5070 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5072 | builtin_types pointer_stars
5074 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5076 | VOID pointer_stars
5078 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5082 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5083 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5089 | pointer_star pointer_stars
5091 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5099 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5103 identifier_inside_body
5108 report.Error (4003, GetLocation ($1), "`await' cannot be used as an identifier within an async method or lambda expression");
5109 $$ = new Tokenizer.LocatedToken ("await", GetLocation ($1));
5114 block_variable_declaration
5115 : variable_type identifier_inside_body
5117 var lt = (Tokenizer.LocatedToken) $2;
5118 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5119 current_block.AddLocalName (li);
5120 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5122 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5124 $$ = current_variable;
5125 current_variable = null;
5126 lbag.AddLocation ($$, GetLocation ($6));
5128 | CONST variable_type identifier_inside_body
5130 var lt = (Tokenizer.LocatedToken) $3;
5131 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5132 current_block.AddLocalName (li);
5133 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
5135 const_variable_initializer opt_const_declarators SEMICOLON
5137 $$ = current_variable;
5138 current_variable = null;
5139 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5143 opt_local_variable_initializer
5145 | ASSIGN block_variable_initializer
5147 current_variable.Initializer = (Expression) $2;
5152 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5153 report.Error (650, lexer.Location,
5154 "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");
5156 Error_SyntaxError (yyToken);
5161 opt_variable_declarators
5163 | variable_declarators
5166 opt_using_or_fixed_variable_declarators
5168 | variable_declarators
5170 foreach (var d in current_variable.Declarators) {
5171 if (d.Initializer == null)
5172 Error_MissingInitializer (d.Variable.Location);
5177 variable_declarators
5178 : variable_declarator
5179 | variable_declarators variable_declarator
5183 : COMMA identifier_inside_body
5185 var lt = (Tokenizer.LocatedToken) $2;
5186 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5187 var d = new BlockVariableDeclaration.Declarator (li, null);
5188 current_variable.AddDeclarator (d);
5189 current_block.AddLocalName (li);
5190 lbag.AddLocation (d, GetLocation ($1));
5192 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5194 var lt = (Tokenizer.LocatedToken) $2;
5195 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5196 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5197 current_variable.AddDeclarator (d);
5198 current_block.AddLocalName (li);
5199 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5203 const_variable_initializer
5206 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5208 | ASSIGN constant_initializer_expr
5210 current_variable.Initializer = (Expression) $2;
5214 opt_const_declarators
5221 | const_declarators const_declarator
5225 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5227 var lt = (Tokenizer.LocatedToken) $2;
5228 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5229 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5230 current_variable.AddDeclarator (d);
5231 current_block.AddLocalName (li);
5232 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5236 block_variable_initializer
5237 : variable_initializer
5238 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5240 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5241 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5243 | STACKALLOC simple_type
5245 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5246 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5250 expression_statement
5251 : statement_expression SEMICOLON
5254 lbag.AddStatement ($$, GetLocation ($2));
5256 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5257 | statement_expression CLOSE_BRACE
5260 report.Error (1002, GetLocation ($2), "; expected");
5261 lexer.putback ('}');
5265 interactive_expression_statement
5266 : interactive_statement_expression SEMICOLON { $$ = $1; }
5267 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5271 // We have to do the wrapping here and not in the case above,
5272 // because statement_expression is used for example in for_statement
5274 statement_expression
5277 ExpressionStatement s = $1 as ExpressionStatement;
5279 Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
5280 $$ = new StatementErrorExpression ($1 as Expression);
5282 $$ = new StatementExpression (s);
5287 interactive_statement_expression
5290 Expression expr = (Expression) $1;
5291 ExpressionStatement s;
5293 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
5294 $$ = new StatementExpression (s);
5298 Error_SyntaxError (yyToken);
5299 $$ = new EmptyStatement (GetLocation ($1));
5309 : IF open_parens_any boolean_expression CLOSE_PARENS
5312 if ($5 is EmptyStatement)
5313 Warning_EmptyStatement (GetLocation ($5));
5315 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5316 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5318 | IF open_parens_any boolean_expression CLOSE_PARENS
5319 embedded_statement ELSE embedded_statement
5321 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5322 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5324 if ($5 is EmptyStatement)
5325 Warning_EmptyStatement (GetLocation ($5));
5326 if ($7 is EmptyStatement)
5327 Warning_EmptyStatement (GetLocation ($7));
5329 | IF open_parens_any boolean_expression error
5331 Error_SyntaxError (yyToken);
5333 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5334 lbag.AddStatement ($$, GetLocation ($2));
5339 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5341 start_block (GetLocation ($5));
5343 opt_switch_sections CLOSE_BRACE
5345 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
5346 end_block (GetLocation ($8));
5347 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5349 | SWITCH open_parens_any expression error
5351 Error_SyntaxError (yyToken);
5353 $$ = new Switch ((Expression) $3, null, null, GetLocation ($1));
5354 lbag.AddStatement ($$, GetLocation ($2));
5361 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5362 $$ = new List<SwitchSection> ();
5370 var sections = new List<SwitchSection> (4);
5372 sections.Add ((SwitchSection) $1);
5375 | switch_sections switch_section
5377 var sections = (List<SwitchSection>) $1;
5379 sections.Add ((SwitchSection) $2);
5384 Error_SyntaxError (yyToken);
5385 $$ = new List<SwitchSection> ();
5392 current_block = current_block.CreateSwitchBlock (lexer.Location);
5396 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
5403 var labels = new List<SwitchLabel> (2);
5405 labels.Add ((SwitchLabel) $1);
5408 | switch_labels switch_label
5410 var labels = (List<SwitchLabel>) ($1);
5411 labels.Add ((SwitchLabel) $2);
5418 : CASE constant_expression COLON
5420 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5421 lbag.AddLocation ($$, GetLocation ($3));
5423 | CASE constant_expression error
5425 Error_SyntaxError (yyToken);
5426 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5430 $$ = new SwitchLabel (null, GetLocation ($1));
5442 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5444 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5445 Warning_EmptyStatement (GetLocation ($5));
5447 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5448 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5450 | WHILE open_parens_any boolean_expression error
5452 Error_SyntaxError (yyToken);
5454 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5455 lbag.AddStatement ($$, GetLocation ($2));
5460 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5462 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5463 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5465 | DO embedded_statement error
5467 Error_SyntaxError (yyToken);
5468 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5470 | DO embedded_statement WHILE open_parens_any boolean_expression error
5472 Error_SyntaxError (yyToken);
5474 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5475 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5480 : FOR open_parens_any
5482 start_block (GetLocation ($2));
5483 current_block.IsCompilerGenerated = true;
5484 For f = new For (GetLocation ($1));
5485 current_block.AddStatement (f);
5494 // Has to use be extra rule to recover started block
5496 : opt_for_initializer SEMICOLON
5498 ((For) $0).Initializer = (Statement) $1;
5500 // Pass the "For" object to the iterator_part4
5501 oob_stack.Push ($0);
5503 for_condition_and_iterator_part
5506 var locations = (Tuple<Location,Location>) $4;
5508 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5509 Warning_EmptyStatement (GetLocation ($5));
5512 f.Statement = (Statement) $5;
5513 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5515 $$ = end_block (GetLocation ($2));
5519 Error_SyntaxError (yyToken);
5520 $$ = end_block (current_block.StartLocation);
5524 for_condition_and_iterator_part
5525 : opt_for_condition SEMICOLON
5527 For f = (For) oob_stack.Peek ();
5528 f.Condition = (BooleanExpression) $1;
5531 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5534 // Handle errors in the case of opt_for_condition being followed by
5535 // a close parenthesis
5536 | opt_for_condition close_parens_close_brace {
5537 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5538 For f = (For) oob_stack.Peek ();
5539 f.Condition = (BooleanExpression) $1;
5540 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5545 : opt_for_iterator CLOSE_PARENS {
5546 For f = (For) oob_stack.Peek ();
5547 f.Iterator = (Statement) $1;
5548 $$ = GetLocation ($2);
5550 | opt_for_iterator CLOSE_BRACE {
5551 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5552 For f = (For) oob_stack.Peek ();
5553 f.Iterator = (Statement) $1;
5554 $$ = GetLocation ($2);
5558 close_parens_close_brace
5560 | CLOSE_BRACE { lexer.putback ('}'); }
5564 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5569 : variable_type identifier_inside_body
5571 var lt = (Tokenizer.LocatedToken) $2;
5572 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5573 current_block.AddLocalName (li);
5574 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5576 opt_local_variable_initializer opt_variable_declarators
5578 $$ = current_variable;
5579 current_variable = null;
5581 | statement_expression_list
5585 : /* empty */ { $$ = null; }
5586 | boolean_expression
5590 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5595 : statement_expression_list
5598 statement_expression_list
5599 : statement_expression
5600 | statement_expression_list COMMA statement_expression
5602 var sl = $1 as StatementList;
5604 sl = new StatementList ((Statement) $1, (Statement) $3);
5605 lbag.AddStatement (sl, GetLocation ($2));
5607 sl.Add ((Statement) $3);
5608 lbag.AppendTo (sl, GetLocation ($2));
5616 : FOREACH open_parens_any type error
5618 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5620 start_block (GetLocation ($2));
5621 current_block.IsCompilerGenerated = true;
5623 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5624 current_block.AddStatement (f);
5626 lbag.AddStatement (f, GetLocation ($2));
5627 $$ = end_block (GetLocation ($4));
5629 | FOREACH open_parens_any type identifier_inside_body error
5631 Error_SyntaxError (yyToken);
5633 start_block (GetLocation ($2));
5634 current_block.IsCompilerGenerated = true;
5636 var lt = (Tokenizer.LocatedToken) $4;
5637 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5638 current_block.AddLocalName (li);
5640 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5641 current_block.AddStatement (f);
5643 lbag.AddStatement (f, GetLocation ($2));
5644 $$ = end_block (GetLocation ($5));
5646 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5648 start_block (GetLocation ($2));
5649 current_block.IsCompilerGenerated = true;
5651 var lt = (Tokenizer.LocatedToken) $4;
5652 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5653 current_block.AddLocalName (li);
5658 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5659 Warning_EmptyStatement (GetLocation ($9));
5661 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5662 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5663 end_block (GetLocation ($7));
5671 | continue_statement
5681 $$ = new Break (GetLocation ($1));
5682 lbag.AddStatement ($$, GetLocation ($2));
5687 : CONTINUE SEMICOLON
5689 $$ = new Continue (GetLocation ($1));
5690 lbag.AddStatement ($$, GetLocation ($2));
5694 Error_SyntaxError (yyToken);
5695 $$ = new Continue (GetLocation ($1));
5700 : GOTO identifier_inside_body SEMICOLON
5702 var lt = (Tokenizer.LocatedToken) $2;
5703 $$ = new Goto (lt.Value, GetLocation ($1));
5704 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5706 | GOTO CASE constant_expression SEMICOLON
5708 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5709 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5711 | GOTO DEFAULT SEMICOLON
5713 $$ = new GotoDefault (GetLocation ($1));
5714 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5719 : RETURN opt_expression SEMICOLON
5721 $$ = new Return ((Expression) $2, GetLocation ($1));
5722 lbag.AddStatement ($$, GetLocation ($3));
5724 | RETURN expression error
5726 Error_SyntaxError (yyToken);
5727 $$ = new Return ((Expression) $2, GetLocation ($1));
5731 Error_SyntaxError (yyToken);
5732 $$ = new Return (null, GetLocation ($1));
5737 : THROW opt_expression SEMICOLON
5739 $$ = new Throw ((Expression) $2, GetLocation ($1));
5740 lbag.AddStatement ($$, GetLocation ($3));
5744 Error_SyntaxError (yyToken);
5745 $$ = new Throw (null, GetLocation ($1));
5750 : identifier_inside_body RETURN opt_expression SEMICOLON
5752 var lt = (Tokenizer.LocatedToken) $1;
5753 string s = lt.Value;
5755 report.Error (1003, lt.Location, "; expected");
5756 } else if ($3 == null) {
5757 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5758 } else if (lang_version == LanguageVersion.ISO_1){
5759 FeatureIsNotAvailable (lt.Location, "iterators");
5762 current_block.Explicit.RegisterIteratorYield ();
5763 $$ = new Yield ((Expression) $3, lt.Location);
5764 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5766 | identifier_inside_body RETURN expression error
5768 Error_SyntaxError (yyToken);
5770 var lt = (Tokenizer.LocatedToken) $1;
5771 string s = lt.Value;
5773 report.Error (1003, lt.Location, "; expected");
5774 } else if ($3 == null) {
5775 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5776 } else if (lang_version == LanguageVersion.ISO_1){
5777 FeatureIsNotAvailable (lt.Location, "iterators");
5780 current_block.Explicit.RegisterIteratorYield ();
5781 $$ = new Yield ((Expression) $3, lt.Location);
5782 lbag.AddStatement ($$, GetLocation ($2));
5784 | identifier_inside_body BREAK SEMICOLON
5786 var lt = (Tokenizer.LocatedToken) $1;
5787 string s = lt.Value;
5789 report.Error (1003, lt.Location, "; expected");
5790 } else if (lang_version == LanguageVersion.ISO_1){
5791 FeatureIsNotAvailable (lt.Location, "iterators");
5794 current_block.Explicit.RegisterIteratorYield ();
5795 $$ = new YieldBreak (lt.Location);
5796 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5806 : TRY block catch_clauses
5808 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5810 | TRY block FINALLY block
5812 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5813 lbag.AddStatement ($$, GetLocation ($3));
5815 | TRY block catch_clauses FINALLY block
5817 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5818 lbag.AddStatement ($$, GetLocation ($4));
5822 Error_SyntaxError (1524, yyToken);
5823 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5830 var l = new List<Catch> (2);
5835 | catch_clauses catch_clause
5837 var l = (List<Catch>) $1;
5839 Catch c = (Catch) $2;
5840 if (l [l.Count - 1].IsGeneral) {
5841 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5851 | identifier_inside_body
5857 $$ = new Catch ((Block) $2, GetLocation ($1));
5859 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5861 start_block (GetLocation ($2));
5862 var c = new Catch (current_block, GetLocation ($1));
5863 c.TypeExpression = (FullNamedExpression) $3;
5866 var lt = (Tokenizer.LocatedToken) $4;
5867 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5868 current_block.AddLocalName (c.Variable);
5871 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5878 | CATCH open_parens_any error
5880 if (yyToken == Token.CLOSE_PARENS) {
5881 report.Error (1015, lexer.Location,
5882 "A type that derives from `System.Exception', `object', or `string' expected");
5884 Error_SyntaxError (yyToken);
5887 $$ = new Catch (null, GetLocation ($1));
5889 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
5891 Error_SyntaxError (yyToken);
5893 // Required otherwise missing block could not be detected because
5894 // start_block is run early
5895 var c = new Catch (null, GetLocation ($1));
5896 c.TypeExpression = (FullNamedExpression) $3;
5899 var lt = (Tokenizer.LocatedToken) $4;
5900 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5903 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5912 $$ = new Checked ((Block) $2, GetLocation ($1));
5919 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5926 if (!settings.Unsafe)
5927 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5929 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5934 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5936 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5937 Warning_EmptyStatement (GetLocation ($5));
5939 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5940 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5942 | LOCK open_parens_any expression error
5944 Error_SyntaxError (yyToken);
5946 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
5947 lbag.AddStatement ($$, GetLocation ($2));
5952 : FIXED open_parens_any variable_type identifier_inside_body
5954 start_block (GetLocation ($2));
5956 current_block.IsCompilerGenerated = true;
5957 var lt = (Tokenizer.LocatedToken) $4;
5958 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5959 current_block.AddLocalName (li);
5960 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5962 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
5964 $$ = current_variable;
5965 current_variable = null;
5969 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5970 Warning_EmptyStatement (GetLocation ($10));
5972 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5973 current_block.AddStatement (f);
5974 $$ = end_block (GetLocation ($8));
5979 : USING open_parens_any variable_type identifier_inside_body
5981 start_block (GetLocation ($2));
5983 current_block.IsCompilerGenerated = true;
5984 var lt = (Tokenizer.LocatedToken) $4;
5985 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5986 current_block.AddLocalName (li);
5987 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5989 using_initialization CLOSE_PARENS
5991 $$ = current_variable;
5992 current_variable = null;
5996 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5997 Warning_EmptyStatement (GetLocation ($9));
5999 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6000 current_block.AddStatement (u);
6001 $$ = end_block (GetLocation ($7));
6003 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6005 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6006 Warning_EmptyStatement (GetLocation ($5));
6008 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6009 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6011 | USING open_parens_any expression error
6013 Error_SyntaxError (yyToken);
6015 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6016 lbag.AddStatement ($$, GetLocation ($2));
6020 using_initialization
6021 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6024 // It has to be here for the parent to safely restore artificial block
6025 Error_SyntaxError (yyToken);
6029 using_or_fixed_variable_initializer
6032 Error_MissingInitializer (lexer.Location);
6034 | ASSIGN variable_initializer
6036 current_variable.Initializer = (Expression) $2;
6037 $$ = current_variable;
6045 : first_from_clause query_body
6047 lexer.query_parsing = false;
6049 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6051 from.Tail.Next = (Linq.AQueryClause)$2;
6054 current_block.SetEndLocation (lexer.Location);
6055 current_block = current_block.Parent;
6057 | nested_from_clause query_body
6059 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6061 from.Tail.Next = (Linq.AQueryClause)$2;
6064 current_block.SetEndLocation (lexer.Location);
6065 current_block = current_block.Parent;
6068 // Bubble up COMPLETE_COMPLETION productions
6069 | first_from_clause COMPLETE_COMPLETION {
6070 lexer.query_parsing = false;
6073 current_block.SetEndLocation (lexer.Location);
6074 current_block = current_block.Parent;
6076 | nested_from_clause COMPLETE_COMPLETION {
6078 current_block.SetEndLocation (lexer.Location);
6079 current_block = current_block.Parent;
6084 : FROM_FIRST identifier_inside_body IN expression
6086 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6088 var lt = (Tokenizer.LocatedToken) $2;
6089 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6090 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6092 | FROM_FIRST type identifier_inside_body IN expression
6094 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6096 var lt = (Tokenizer.LocatedToken) $3;
6097 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6098 $$ = new Linq.QueryExpression (
6099 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6100 IdentifierType = (FullNamedExpression)$2
6107 : FROM identifier_inside_body IN expression
6109 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6111 var lt = (Tokenizer.LocatedToken) $2;
6112 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6113 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6115 | FROM type identifier_inside_body IN expression
6117 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6119 var lt = (Tokenizer.LocatedToken) $3;
6120 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6121 $$ = new Linq.QueryExpression (
6122 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6123 IdentifierType = (FullNamedExpression)$2
6130 : FROM identifier_inside_body IN
6132 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6136 var lt = (Tokenizer.LocatedToken) $2;
6137 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6138 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6140 current_block.SetEndLocation (lexer.Location);
6141 current_block = current_block.Parent;
6143 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6145 | FROM type identifier_inside_body IN
6147 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6151 var lt = (Tokenizer.LocatedToken) $3;
6152 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6154 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6155 IdentifierType = (FullNamedExpression)$2
6158 current_block.SetEndLocation (lexer.Location);
6159 current_block = current_block.Parent;
6161 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6166 : query_body_clauses select_or_group_clause opt_query_continuation
6168 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6171 head.Next = (Linq.AQueryClause)$3;
6174 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6175 clause.Tail.Next = head;
6181 | select_or_group_clause opt_query_continuation
6183 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6186 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6187 clause.Tail.Next = head;
6193 | query_body_clauses COMPLETE_COMPLETION
6194 | query_body_clauses error
6196 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6201 Error_SyntaxError (yyToken);
6206 select_or_group_clause
6209 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6213 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6215 current_block.SetEndLocation (lexer.Location);
6216 current_block = current_block.Parent;
6220 if (linq_clause_blocks == null)
6221 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6223 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6224 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6228 current_block.SetEndLocation (lexer.Location);
6229 current_block = current_block.Parent;
6231 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6233 BY expression_or_error
6235 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
6236 lbag.AddLocation ($$, GetLocation ($5));
6238 current_block.SetEndLocation (lexer.Location);
6239 current_block = current_block.Parent;
6245 | query_body_clauses query_body_clause
6247 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6261 : LET identifier_inside_body ASSIGN
6263 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6267 var lt = (Tokenizer.LocatedToken) $2;
6268 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6269 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6270 lbag.AddLocation ($$, GetLocation ($3));
6272 current_block.SetEndLocation (lexer.Location);
6273 current_block = current_block.Parent;
6275 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6282 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6286 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6288 current_block.SetEndLocation (lexer.Location);
6289 current_block = current_block.Parent;
6294 : JOIN identifier_inside_body IN
6296 if (linq_clause_blocks == null)
6297 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6299 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6300 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6302 expression_or_error ON
6304 current_block.SetEndLocation (lexer.Location);
6305 current_block = current_block.Parent;
6307 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6308 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6310 expression_or_error EQUALS
6312 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6313 current_block.SetEndLocation (lexer.Location);
6314 current_block = current_block.Parent;
6316 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6318 expression_or_error opt_join_into
6320 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6321 current_block.SetEndLocation (lexer.Location);
6323 var outer_selector = linq_clause_blocks.Pop ();
6324 var block = linq_clause_blocks.Pop ();
6326 var lt = (Tokenizer.LocatedToken) $2;
6327 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6328 Linq.RangeVariable into;
6332 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6333 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6336 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6338 var parent = block.Parent;
6339 while (parent is Linq.QueryBlock) {
6340 parent = parent.Parent;
6342 current_block.Parent = parent;
6344 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6346 lt = (Tokenizer.LocatedToken) $12;
6347 into = new Linq.RangeVariable (lt.Value, lt.Location);
6349 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6350 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6353 current_block = block.Parent;
6354 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6356 | JOIN type identifier_inside_body IN
6358 if (linq_clause_blocks == null)
6359 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6361 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6362 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6364 expression_or_error ON
6366 current_block.SetEndLocation (lexer.Location);
6367 current_block = current_block.Parent;
6369 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6370 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6372 expression_or_error EQUALS
6374 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6375 current_block.SetEndLocation (lexer.Location);
6376 current_block = current_block.Parent;
6378 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6380 expression_or_error opt_join_into
6382 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6383 current_block.SetEndLocation (lexer.Location);
6385 var outer_selector = linq_clause_blocks.Pop ();
6386 var block = linq_clause_blocks.Pop ();
6388 var lt = (Tokenizer.LocatedToken) $3;
6389 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6390 Linq.RangeVariable into;
6394 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6395 IdentifierType = (FullNamedExpression)$2
6399 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6401 var parent = block.Parent;
6402 while (parent is Linq.QueryBlock) {
6403 parent = parent.Parent;
6405 current_block.Parent = parent;
6407 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6409 lt = (Tokenizer.LocatedToken) $13;
6410 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6412 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6413 IdentifierType = (FullNamedExpression)$2
6417 current_block = block.Parent;
6418 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6424 | INTO identifier_inside_body
6433 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6437 current_block.SetEndLocation (lexer.Location);
6438 current_block = current_block.Parent;
6448 current_block.SetEndLocation (lexer.Location);
6449 current_block = current_block.Parent;
6451 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6455 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6462 | orderings_then_by COMMA
6464 current_block.SetEndLocation (lexer.Location);
6465 current_block = current_block.Parent;
6467 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6471 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6479 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6481 | expression ASCENDING
6483 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6484 lbag.AddLocation ($$, GetLocation ($2));
6486 | expression DESCENDING
6488 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6489 lbag.AddLocation ($$, GetLocation ($2));
6496 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6498 | expression ASCENDING
6500 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6501 lbag.AddLocation ($$, GetLocation ($2));
6503 | expression DESCENDING
6505 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6506 lbag.AddLocation ($$, GetLocation ($2));
6511 opt_query_continuation
6513 | INTO identifier_inside_body
6515 // query continuation block is not linked with query block but with block
6516 // before. This means each query can use same range variable names for
6517 // different identifiers.
6519 current_block.SetEndLocation (GetLocation ($1));
6520 current_block = current_block.Parent;
6522 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6524 if (linq_clause_blocks == null)
6525 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6527 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6531 var current_block = linq_clause_blocks.Pop ();
6532 var lt = (Tokenizer.LocatedToken) $2;
6533 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6534 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6535 next = (Linq.AQueryClause)$4
6541 // Support for using the compiler as an interactive parser
6543 // The INTERACTIVE_PARSER token is first sent to parse our
6544 // productions; If the result is a Statement, the parsing
6545 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6546 // to setup the blocks in advance.
6548 // This setup is here so that in the future we can add
6549 // support for other constructs (type parsing, namespaces, etc)
6550 // that do not require a block to be setup in advance
6554 : EVAL_STATEMENT_PARSER EOF
6555 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6556 | EVAL_STATEMENT_PARSER
6558 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6560 // (ref object retval)
6561 Parameter [] mpar = new Parameter [1];
6562 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6564 ParametersCompiled pars = new ParametersCompiled (mpar);
6565 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6566 if (settings.Unsafe)
6567 mods |= Modifiers.UNSAFE;
6569 current_local_parameters = pars;
6570 Method method = new Method (
6572 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6574 new MemberName ("Host"),
6576 null /* attributes */);
6578 current_type.AddMember (method);
6580 oob_stack.Push (method);
6581 ++lexer.parsing_block;
6582 start_block (lexer.Location);
6584 interactive_statement_list opt_COMPLETE_COMPLETION
6586 --lexer.parsing_block;
6587 Method method = (Method) oob_stack.Pop ();
6589 method.Block = (ToplevelBlock) end_block(lexer.Location);
6591 InteractiveResult = (Class) pop_current_class ();
6592 current_local_parameters = null;
6594 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6597 interactive_compilation_unit
6598 : opt_extern_alias_directives opt_using_directives
6599 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6602 opt_COMPLETE_COMPLETION
6604 | COMPLETE_COMPLETION
6607 close_brace_or_complete_completion
6609 | COMPLETE_COMPLETION
6613 // XML documentation code references micro parser
6615 documentation_parsing
6618 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6623 : doc_type_declaration_name opt_doc_method_sig
6625 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6627 | builtin_types opt_doc_method_sig
6629 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6630 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6633 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6635 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6636 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6637 var lt = (Tokenizer.LocatedToken) $3;
6638 $$ = new MemberName (lt.Value);
6640 | doc_type_declaration_name DOT THIS
6642 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6644 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6646 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6648 opt_doc_parameters CLOSE_BRACKET
6650 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6651 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6653 | EXPLICIT OPERATOR type opt_doc_method_sig
6655 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6656 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6657 module.DocumentationBuilder.ParsedParameters = p;
6658 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6661 | IMPLICIT OPERATOR type opt_doc_method_sig
6663 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6664 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6665 module.DocumentationBuilder.ParsedParameters = p;
6666 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6669 | OPERATOR overloadable_operator opt_doc_method_sig
6671 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6672 module.DocumentationBuilder.ParsedParameters = p;
6673 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6678 doc_type_declaration_name
6679 : type_declaration_name
6680 | doc_type_declaration_name DOT type_declaration_name
6682 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6690 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6692 opt_doc_parameters CLOSE_PARENS
6701 $$ = new List<DocumentationParameter> (0);
6709 var parameters = new List<DocumentationParameter> ();
6710 parameters.Add ((DocumentationParameter) $1);
6713 | doc_parameters COMMA doc_parameter
6715 var parameters = $1 as List<DocumentationParameter>;
6716 parameters.Add ((DocumentationParameter) $3);
6722 : opt_parameter_modifier parameter_type
6725 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6727 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6734 // A class used to hold info about an operator declarator
6736 class OperatorDeclaration {
6737 public readonly Operator.OpType optype;
6738 public readonly FullNamedExpression ret_type;
6739 public readonly Location location;
6741 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6744 this.ret_type = ret_type;
6745 this.location = location;
6749 void Error_ExpectingTypeName (Expression expr)
6751 if (expr is Invocation){
6752 report.Error (1002, expr.Location, "Expecting `;'");
6754 Expression.Error_InvalidExpressionStatement (report, expr.Location);
6758 void Error_ParameterModifierNotValid (string modifier, Location loc)
6760 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6764 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6766 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6767 Parameter.GetModifierSignature (mod));
6770 void Error_TypeExpected (Location loc)
6772 report.Error (1031, loc, "Type expected");
6775 void Error_UnsafeCodeNotAllowed (Location loc)
6777 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6780 void Warning_EmptyStatement (Location loc)
6782 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6785 void Error_NamedArgumentExpected (NamedArgument a)
6787 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6790 void Error_MissingInitializer (Location loc)
6792 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6795 void push_current_container (TypeDefinition tc, object partial_token)
6797 if (module.Evaluator != null){
6798 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6802 undo.AddTypeContainer (current_container, tc);
6805 if (partial_token != null)
6806 current_container.AddPartial (tc);
6808 current_container.AddTypeContainer (tc);
6810 ++lexer.parsing_declaration;
6811 current_container = tc;
6815 TypeContainer pop_current_class ()
6817 var retval = current_container;
6819 current_container = current_container.Parent;
6820 current_type = current_type.Parent as TypeDefinition;
6825 [System.Diagnostics.Conditional ("FULL_AST")]
6826 void StoreModifierLocation (object token, Location loc)
6831 if (mod_locations == null)
6832 mod_locations = new List<Tuple<Modifiers, Location>> ();
6834 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6837 string CheckAttributeTarget (string a, Location l)
6840 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6844 report.Warning (658, 1, l,
6845 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6846 return string.Empty;
6849 static bool IsUnaryOperator (Operator.OpType op)
6853 case Operator.OpType.LogicalNot:
6854 case Operator.OpType.OnesComplement:
6855 case Operator.OpType.Increment:
6856 case Operator.OpType.Decrement:
6857 case Operator.OpType.True:
6858 case Operator.OpType.False:
6859 case Operator.OpType.UnaryPlus:
6860 case Operator.OpType.UnaryNegation:
6866 void syntax_error (Location l, string msg)
6868 report.Error (1003, l, "Syntax error, " + msg);
6873 public Tokenizer Lexer {
6879 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
6880 : this (reader, file, file.Compiler.Report, session)
6884 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
6887 current_container = current_namespace = file;
6889 this.module = file.Module;
6890 this.compiler = file.Compiler;
6891 this.settings = compiler.Settings;
6892 this.report = report;
6894 lang_version = settings.Version;
6895 yacc_verbose_flag = settings.VerboseParserFlag;
6896 doc_support = settings.DocumentationFile != null;
6897 lexer = new Tokenizer (reader, file, session);
6898 oob_stack = new Stack<object> ();
6899 lbag = session.LocationsBag;
6900 use_global_stacks = session.UseJayGlobalArrays;
6901 parameters_bucket = session.ParametersStack;
6904 public void parse ()
6906 eof_token = Token.EOF;
6909 if (yacc_verbose_flag > 1)
6910 yyparse (lexer, new yydebug.yyDebugSimple ());
6914 Tokenizer tokenizer = lexer as Tokenizer;
6915 tokenizer.cleanup ();
6916 } catch (Exception e){
6917 if (e is yyParser.yyUnexpectedEof) {
6918 Error_SyntaxError (yyToken);
6919 UnexpectedEOF = true;
6923 if (e is yyParser.yyException) {
6924 if (report.Errors == 0)
6925 report.Error (-25, lexer.Location, "Parsing error");
6927 // Used by compiler-tester to test internal errors
6928 if (yacc_verbose_flag > 0 || e is FatalException)
6931 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
6936 void CheckToken (int error, int yyToken, string msg, Location loc)
6938 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6939 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6941 report.Error (error, loc, msg);
6944 string ConsumeStoredComment ()
6946 string s = tmpComment;
6948 Lexer.doc_state = XmlCommentState.Allowed;
6952 void FeatureIsNotAvailable (Location loc, string feature)
6954 report.FeatureIsNotAvailable (compiler, loc, feature);
6957 Location GetLocation (object obj)
6959 var lt = obj as Tokenizer.LocatedToken;
6963 var mn = obj as MemberName;
6967 var expr = obj as Expression;
6969 return expr.Location;
6971 return lexer.Location;
6974 void start_block (Location loc)
6976 if (current_block == null) {
6977 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6978 parsing_anonymous_method = false;
6979 } else if (parsing_anonymous_method) {
6980 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6981 parsing_anonymous_method = false;
6983 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6988 end_block (Location loc)
6990 Block retval = current_block.Explicit;
6991 retval.SetEndLocation (loc);
6992 current_block = retval.Parent;
6996 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
6998 oob_stack.Push (current_anonymous_method);
6999 oob_stack.Push (current_local_parameters);
7000 oob_stack.Push (current_variable);
7001 oob_stack.Push (async_block);
7003 current_local_parameters = parameters;
7005 if (lang_version <= LanguageVersion.ISO_2)
7006 FeatureIsNotAvailable (loc, "lambda expressions");
7008 current_anonymous_method = new LambdaExpression (loc);
7010 if (lang_version == LanguageVersion.ISO_1)
7011 FeatureIsNotAvailable (loc, "anonymous methods");
7013 current_anonymous_method = new AnonymousMethodExpression (loc);
7016 async_block = isAsync;
7017 // Force the next block to be created as a ToplevelBlock
7018 parsing_anonymous_method = true;
7022 * Completes the anonymous method processing, if lambda_expr is null, this
7023 * means that we have a Statement instead of an Expression embedded
7025 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7027 AnonymousMethodExpression retval;
7030 anon_block.IsAsync = true;
7032 current_anonymous_method.Block = anon_block;
7033 retval = current_anonymous_method;
7035 async_block = (bool) oob_stack.Pop ();
7036 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
7037 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7038 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7043 void Error_SyntaxError (int token)
7045 Error_SyntaxError (0, token);
7048 void Error_SyntaxError (int error_code, int token)
7050 Error_SyntaxError (error_code, token, "Unexpected symbol");
7053 void Error_SyntaxError (int error_code, int token, string msg)
7055 Lexer.CompleteOnEOF = false;
7057 // An error message has been reported by tokenizer
7058 if (token == Token.ERROR)
7061 // Avoid duplicit error message after unterminated string literals
7062 if (token == Token.LITERAL && lexer.Location.Column == 0)
7065 string symbol = GetSymbolName (token);
7066 string expecting = GetExpecting ();
7067 var loc = lexer.Location - symbol.Length;
7069 if (error_code == 0) {
7070 if (expecting == "`identifier'") {
7071 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7072 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7077 expecting = "identifier";
7078 } else if (expecting == "`)'") {
7085 if (string.IsNullOrEmpty (expecting))
7086 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7088 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7091 string GetExpecting ()
7093 int [] tokens = yyExpectingTokens (yyExpectingState);
7094 var names = new List<string> (tokens.Length);
7095 bool has_type = false;
7096 bool has_identifier = false;
7097 for (int i = 0; i < tokens.Length; i++){
7098 int token = tokens [i];
7099 has_identifier |= token == Token.IDENTIFIER;
7101 string name = GetTokenName (token);
7102 if (name == "<internal>")
7105 has_type |= name == "type";
7106 if (names.Contains (name))
7113 // Too many tokens to enumerate
7115 if (names.Count > 8)
7118 if (has_type && has_identifier)
7119 names.Remove ("identifier");
7121 if (names.Count == 1)
7122 return "`" + GetTokenName (tokens [0]) + "'";
7124 StringBuilder sb = new StringBuilder ();
7126 int count = names.Count;
7127 for (int i = 0; i < count; i++){
7128 bool last = i + 1 == count;
7132 sb.Append (names [i]);
7133 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7135 return sb.ToString ();
7139 string GetSymbolName (int token)
7143 return ((Constant)lexer.Value).GetValue ().ToString ();
7144 case Token.IDENTIFIER:
7145 return ((Tokenizer.LocatedToken)lexer.Value).Value;
7187 case Token.BITWISE_AND:
7189 case Token.BITWISE_OR:
7203 case Token.OP_SHIFT_LEFT:
7205 case Token.OP_SHIFT_RIGHT:
7225 case Token.OP_COALESCING:
7227 case Token.OP_MULT_ASSIGN:
7229 case Token.OP_DIV_ASSIGN:
7231 case Token.OP_MOD_ASSIGN:
7233 case Token.OP_ADD_ASSIGN:
7235 case Token.OP_SUB_ASSIGN:
7237 case Token.OP_SHIFT_LEFT_ASSIGN:
7239 case Token.OP_SHIFT_RIGHT_ASSIGN:
7241 case Token.OP_AND_ASSIGN:
7243 case Token.OP_XOR_ASSIGN:
7245 case Token.OP_OR_ASSIGN:
7249 return GetTokenName (token);
7252 static string GetTokenName (int token)
7255 case Token.ABSTRACT:
7277 case Token.CONTINUE:
7281 case Token.DELEGATE:
7291 case Token.EXPLICIT:
7294 case Token.EXTERN_ALIAS:
7310 case Token.IMPLICIT:
7314 case Token.INTERFACE:
7316 case Token.INTERNAL:
7322 case Token.NAMESPACE:
7328 case Token.OPERATOR:
7332 case Token.OVERRIDE:
7338 case Token.PROTECTED:
7342 case Token.READONLY:
7354 case Token.STACKALLOC:
7355 return "stackalloc";
7372 case Token.UNCHECKED:
7380 case Token.VOLATILE:
7388 case Token.REFVALUE:
7389 return "__refvalue";
7399 case Token.FROM_FIRST:
7417 case Token.ASCENDING:
7419 case Token.DESCENDING:
7420 return "descending";
7427 case Token.OPEN_BRACE:
7429 case Token.CLOSE_BRACE:
7431 case Token.OPEN_BRACKET:
7432 case Token.OPEN_BRACKET_EXPR:
7434 case Token.CLOSE_BRACKET:
7436 case Token.OPEN_PARENS_CAST:
7437 case Token.OPEN_PARENS_LAMBDA:
7438 case Token.OPEN_PARENS:
7440 case Token.CLOSE_PARENS:
7446 case Token.DEFAULT_COLON:
7450 case Token.SEMICOLON:
7461 case Token.BITWISE_AND:
7462 case Token.BITWISE_OR:
7469 case Token.OP_SHIFT_LEFT:
7470 case Token.OP_SHIFT_RIGHT:
7478 case Token.OP_COALESCING:
7479 case Token.OP_MULT_ASSIGN:
7480 case Token.OP_DIV_ASSIGN:
7481 case Token.OP_MOD_ASSIGN:
7482 case Token.OP_ADD_ASSIGN:
7483 case Token.OP_SUB_ASSIGN:
7484 case Token.OP_SHIFT_LEFT_ASSIGN:
7485 case Token.OP_SHIFT_RIGHT_ASSIGN:
7486 case Token.OP_AND_ASSIGN:
7487 case Token.OP_XOR_ASSIGN:
7488 case Token.OP_OR_ASSIGN:
7489 return "<operator>";
7511 case Token.OP_GENERICS_LT:
7512 case Token.GENERIC_DIMENSION:
7514 case Token.OP_GENERICS_GT:
7517 case Token.INTERR_NULLABLE:
7519 case Token.DOUBLE_COLON:
7523 case Token.IDENTIFIER:
7525 return "identifier";
7528 return "end-of-file";
7530 // All of these are internal.
7533 case Token.FIRST_KEYWORD:
7534 case Token.EVAL_COMPILATION_UNIT_PARSER:
7535 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7536 case Token.EVAL_STATEMENT_PARSER:
7537 case Token.LAST_KEYWORD:
7538 case Token.GENERATE_COMPLETION:
7539 case Token.COMPLETE_COMPLETION:
7540 return "<internal>";
7542 // A bit more robust.
7544 return yyNames [token];