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 static 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 static List<Parameter> parameters_bucket = new List<Parameter> (6);
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;
538 var lt = (Tokenizer.LocatedToken) $1;
539 $$ = new MemberName (lt.Value, lt.Location);
541 | namespace_name DOT IDENTIFIER
543 var lt = (Tokenizer.LocatedToken) $3;
544 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
548 Error_SyntaxError (yyToken);
549 $$ = new MemberName ("<invalid>", lexer.Location);
568 opt_extern_alias_directives
570 | extern_alias_directives
573 opt_namespace_or_type_declarations
575 | namespace_or_type_declarations
578 namespace_or_type_declarations
579 : namespace_or_type_declaration
580 | namespace_or_type_declarations namespace_or_type_declaration
583 namespace_or_type_declaration
587 TypeContainer ds = (TypeContainer)$1;
589 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
590 report.Error (1527, ds.Location,
591 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
594 // Here is a trick, for explicit attributes we don't know where they belong to until
595 // we parse succeeding declaration hence we parse them as normal and re-attach them
596 // when we know whether they are global (assembly:, module:) or local (type:).
597 if (ds.OptAttributes != null) {
598 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
601 current_namespace.DeclarationFound = true;
603 | namespace_declaration
605 current_namespace.DeclarationFound = true;
607 | attribute_sections CLOSE_BRACE {
608 current_namespace.UnattachedAttributes = (Attributes) $1;
609 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
617 | interface_declaration
619 | delegate_declaration
621 // Enable this when we have handled all errors, because this acts as a generic fallback
624 // Console.WriteLine ("Token=" + yyToken);
625 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
641 var sect = (List<Attribute>) $1;
642 $$ = new Attributes (sect);
644 | attribute_sections attribute_section
646 Attributes attrs = $1 as Attributes;
647 var sect = (List<Attribute>) $2;
649 attrs = new Attributes (sect);
651 attrs.AddAttributes (sect);
659 lexer.parsing_attribute_section = true;
661 attribute_section_cont
663 lexer.parsing_attribute_section = false;
668 attribute_section_cont
669 : attribute_target COLON
671 current_attr_target = (string) $1;
672 if (current_attr_target == "assembly" || current_attr_target == "module") {
673 Lexer.check_incorrect_doc_comment ();
676 attribute_list opt_comma CLOSE_BRACKET
678 // when attribute target is invalid
679 if (current_attr_target == string.Empty)
680 $$ = new List<Attribute> (0);
684 current_attr_target = null;
685 lexer.parsing_attribute_section = false;
687 | attribute_list opt_comma CLOSE_BRACKET
696 var lt = (Tokenizer.LocatedToken) $1;
697 $$ = CheckAttributeTarget (lt.Value, lt.Location);
699 | EVENT { $$ = "event"; }
700 | RETURN { $$ = "return"; }
703 if (yyToken == Token.IDENTIFIER) {
704 Error_SyntaxError (yyToken);
707 string name = GetTokenName (yyToken);
708 $$ = CheckAttributeTarget (name, GetLocation ($1));
716 $$ = new List<Attribute> (4) { (Attribute) $1 };
718 | attribute_list COMMA attribute
720 var attrs = (List<Attribute>) $1;
721 attrs.Add ((Attribute) $3);
730 ++lexer.parsing_block;
732 opt_attribute_arguments
734 --lexer.parsing_block;
736 var tne = (ATypeNameExpression) $1;
737 if (tne.HasTypeArguments) {
738 report.Error (404, tne.Location, "Attributes cannot be generic");
741 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
746 : namespace_or_type_expr
749 opt_attribute_arguments
750 : /* empty */ { $$ = null; }
751 | OPEN_PARENS attribute_arguments CLOSE_PARENS
759 : /* empty */ { $$ = null; }
760 | positional_or_named_argument
762 Arguments a = new Arguments (4);
763 a.Add ((Argument) $1);
764 $$ = new Arguments [] { a, null };
766 | named_attribute_argument
768 Arguments a = new Arguments (4);
769 a.Add ((Argument) $1);
770 $$ = new Arguments [] { null, a };
772 | attribute_arguments COMMA positional_or_named_argument
774 Arguments[] o = (Arguments[]) $1;
776 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
777 o [0] = new Arguments (4);
780 Arguments args = ((Arguments) o [0]);
781 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
782 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
784 args.Add ((Argument) $3);
786 | attribute_arguments COMMA named_attribute_argument
788 Arguments[] o = (Arguments[]) $1;
790 o [1] = new Arguments (4);
793 ((Arguments) o [1]).Add ((Argument) $3);
797 positional_or_named_argument
800 $$ = new Argument ((Expression) $1);
805 named_attribute_argument
808 ++lexer.parsing_block;
812 --lexer.parsing_block;
813 var lt = (Tokenizer.LocatedToken) $1;
814 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
815 lbag.AddLocation ($$, GetLocation($2));
820 : identifier_inside_body COLON opt_named_modifier expression
822 if (lang_version <= LanguageVersion.V_3)
823 FeatureIsNotAvailable (GetLocation ($1), "named argument");
825 // Avoid boxing in common case (no modifier)
826 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
828 var lt = (Tokenizer.LocatedToken) $1;
829 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
830 lbag.AddLocation ($$, GetLocation($2));
835 : /* empty */ { $$ = null; }
838 $$ = Argument.AType.Ref;
842 $$ = Argument.AType.Out;
846 opt_class_member_declarations
848 | class_member_declarations
851 class_member_declarations
852 : class_member_declaration
854 lexer.parsing_modifiers = true;
856 | class_member_declarations class_member_declaration
858 lexer.parsing_modifiers = true;
862 class_member_declaration
863 : constant_declaration
866 | property_declaration
868 | indexer_declaration
869 | operator_declaration
870 | constructor_declaration
871 | destructor_declaration
873 | attributes_without_members
876 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
877 GetSymbolName (yyToken));
879 lexer.parsing_generic_declaration = false;
889 lexer.ConstraintsParsing = true;
891 type_declaration_name
893 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
896 opt_type_parameter_constraints_clauses
898 lexer.ConstraintsParsing = false;
901 current_container.SetConstraints ((List<Constraints>) $9);
904 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
906 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
908 lexer.parsing_modifiers = true;
913 Lexer.doc_state = XmlCommentState.Allowed;
915 opt_class_member_declarations CLOSE_BRACE
917 --lexer.parsing_declaration;
919 Lexer.doc_state = XmlCommentState.Allowed;
923 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
924 $$ = pop_current_class ();
926 | opt_attributes opt_modifiers opt_partial STRUCT error
928 Error_SyntaxError (yyToken);
935 CONST type IDENTIFIER
937 var lt = (Tokenizer.LocatedToken) $5;
938 var mod = (Modifiers) $2;
939 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
940 current_type.AddMember (current_field);
942 if ((mod & Modifiers.STATIC) != 0) {
943 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
948 constant_initializer opt_constant_declarators SEMICOLON
951 current_field.DocComment = Lexer.consume_doc_comment ();
952 Lexer.doc_state = XmlCommentState.Allowed;
955 current_field.Initializer = (ConstInitializer) $7;
956 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
957 current_field = null;
961 opt_constant_declarators
963 | constant_declarators
967 : constant_declarator
969 current_field.AddDeclarator ((FieldDeclarator) $1);
971 | constant_declarators constant_declarator
973 current_field.AddDeclarator ((FieldDeclarator) $2);
978 : COMMA IDENTIFIER constant_initializer
980 var lt = (Tokenizer.LocatedToken) $2;
981 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
982 lbag.AddLocation ($$, GetLocation ($1));
989 ++lexer.parsing_block;
991 constant_initializer_expr
993 --lexer.parsing_block;
994 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
998 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1003 constant_initializer_expr
1004 : constant_expression
1011 member_type IDENTIFIER
1013 lexer.parsing_generic_declaration = false;
1015 FullNamedExpression type = (FullNamedExpression) $3;
1016 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1017 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1019 var lt = (Tokenizer.LocatedToken) $4;
1020 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1021 current_type.AddField (current_field);
1024 opt_field_initializer
1025 opt_field_declarators
1029 current_field.DocComment = Lexer.consume_doc_comment ();
1030 Lexer.doc_state = XmlCommentState.Allowed;
1033 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1035 current_field = null;
1039 FIXED simple_type IDENTIFIER
1041 if (lang_version < LanguageVersion.ISO_2)
1042 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1044 var lt = (Tokenizer.LocatedToken) $5;
1045 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1046 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1048 current_type.AddField (current_field);
1050 fixed_field_size opt_fixed_field_declarators SEMICOLON
1053 current_field.DocComment = Lexer.consume_doc_comment ();
1054 Lexer.doc_state = XmlCommentState.Allowed;
1057 current_field.Initializer = (ConstInitializer) $7;
1058 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1060 current_field = null;
1064 FIXED simple_type error
1067 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1071 opt_field_initializer
1075 ++lexer.parsing_block;
1076 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1077 start_block (GetLocation ($1));
1079 variable_initializer
1081 --lexer.parsing_block;
1082 current_field.Initializer = (Expression) $3;
1083 end_block (lexer.Location);
1084 current_local_parameters = null;
1088 opt_field_declarators
1096 current_field.AddDeclarator ((FieldDeclarator) $1);
1098 | field_declarators field_declarator
1100 current_field.AddDeclarator ((FieldDeclarator) $2);
1107 var lt = (Tokenizer.LocatedToken) $2;
1108 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1109 lbag.AddLocation ($$, GetLocation ($1));
1111 | COMMA IDENTIFIER ASSIGN
1113 ++lexer.parsing_block;
1115 variable_initializer
1117 --lexer.parsing_block;
1118 var lt = (Tokenizer.LocatedToken) $2;
1119 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1120 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1124 opt_fixed_field_declarators
1126 | fixed_field_declarators
1129 fixed_field_declarators
1130 : fixed_field_declarator
1132 current_field.AddDeclarator ((FieldDeclarator) $1);
1134 | fixed_field_declarators fixed_field_declarator
1136 current_field.AddDeclarator ((FieldDeclarator) $2);
1140 fixed_field_declarator
1141 : COMMA IDENTIFIER fixed_field_size
1143 var lt = (Tokenizer.LocatedToken) $2;
1144 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1145 lbag.AddLocation ($$, GetLocation ($1));
1152 ++lexer.parsing_block;
1154 expression CLOSE_BRACKET
1156 --lexer.parsing_block;
1157 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1158 lbag.AddLocation ($$, GetLocation ($4));
1160 | OPEN_BRACKET error
1162 report.Error (443, lexer.Location, "Value or constant expected");
1167 variable_initializer
1172 // It has to be here for the parent to safely restore artificial block
1173 Error_SyntaxError (yyToken);
1182 Lexer.doc_state = XmlCommentState.NotAllowed;
1184 // Add it early in the case of body being eof for full ast
1185 Method m = (Method) $1;
1186 async_block = (m.ModFlags & Modifiers.ASYNC) != 0;
1187 current_type.AddMember (m);
1191 Method method = (Method) $1;
1192 method.Block = (ToplevelBlock) $3;
1193 async_block = false;
1195 if (method.Block == null) {
1196 method.ParameterInfo.CheckParameters (method);
1198 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1199 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1200 method.GetSignatureForError ());
1203 if (current_container.Kind == MemberKind.Interface) {
1204 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1205 method.GetSignatureForError ());
1209 current_local_parameters = null;
1212 Lexer.doc_state = XmlCommentState.Allowed;
1220 method_declaration_name OPEN_PARENS
1222 valid_param_mod = ParameterModifierType.All;
1224 opt_formal_parameter_list CLOSE_PARENS
1226 lexer.ConstraintsParsing = true;
1228 opt_type_parameter_constraints_clauses
1230 lexer.ConstraintsParsing = false;
1231 valid_param_mod = 0;
1232 MemberName name = (MemberName) $4;
1233 current_local_parameters = (ParametersCompiled) $7;
1235 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1236 name, current_local_parameters, (Attributes) $1, $10 != null);
1239 method.SetConstraints ((List<Constraints>) $10);
1242 method.DocComment = Lexer.consume_doc_comment ();
1244 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1252 lexer.parsing_generic_declaration = true;
1254 method_declaration_name
1257 lexer.parsing_generic_declaration = false;
1258 valid_param_mod = ParameterModifierType.All;
1260 opt_formal_parameter_list CLOSE_PARENS
1262 lexer.ConstraintsParsing = true;
1264 opt_type_parameter_constraints_clauses
1266 lexer.ConstraintsParsing = false;
1267 valid_param_mod = 0;
1269 MemberName name = (MemberName) $6;
1270 current_local_parameters = (ParametersCompiled) $9;
1272 var modifiers = (Modifiers) $2;
1273 modifiers |= Modifiers.PARTIAL;
1275 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1276 modifiers, name, current_local_parameters, (Attributes) $1, $11 != null);
1279 method.SetConstraints ((List<Constraints>) $11);
1282 method.DocComment = Lexer.consume_doc_comment ();
1284 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1285 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1291 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1293 MemberName name = (MemberName) $5;
1294 report.Error (1585, name.Location,
1295 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1297 var method = Method.Create (current_type, (FullNamedExpression) $3,
1298 0, name, (ParametersCompiled) $7, (Attributes) $1, false);
1300 current_local_parameters = (ParametersCompiled) $7;
1303 method.DocComment = Lexer.consume_doc_comment ();
1310 method_declaration_name error
1312 Error_SyntaxError (yyToken);
1313 current_local_parameters = ParametersCompiled.Undefined;
1315 MemberName name = (MemberName) $4;
1316 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1317 name, current_local_parameters, (Attributes) $1, false);
1320 method.DocComment = Lexer.consume_doc_comment ();
1328 | SEMICOLON { $$ = null; }
1331 opt_formal_parameter_list
1332 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1333 | formal_parameter_list
1336 formal_parameter_list
1339 var pars_list = (List<Parameter>) $1;
1340 $$ = new ParametersCompiled (pars_list.ToArray ());
1342 | fixed_parameters COMMA parameter_array
1344 var pars_list = (List<Parameter>) $1;
1345 pars_list.Add ((Parameter) $3);
1347 $$ = new ParametersCompiled (pars_list.ToArray ());
1349 | fixed_parameters COMMA arglist_modifier
1351 var pars_list = (List<Parameter>) $1;
1352 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1353 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1355 | parameter_array COMMA error
1358 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1360 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1362 | fixed_parameters COMMA parameter_array COMMA error
1365 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1367 var pars_list = (List<Parameter>) $1;
1368 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1370 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1372 | arglist_modifier COMMA error
1374 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1376 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1378 | fixed_parameters COMMA ARGLIST COMMA error
1380 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1382 var pars_list = (List<Parameter>) $1;
1383 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1385 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1389 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1393 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1397 Error_SyntaxError (yyToken);
1398 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1405 parameters_bucket.Clear ();
1406 Parameter p = (Parameter) $1;
1407 parameters_bucket.Add (p);
1409 default_parameter_used = p.HasDefaultValue;
1410 $$ = parameters_bucket;
1412 | fixed_parameters COMMA fixed_parameter
1414 var pars = (List<Parameter>) $1;
1415 Parameter p = (Parameter) $3;
1417 if (p.HasExtensionMethodModifier)
1418 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1419 else if (!p.HasDefaultValue && default_parameter_used)
1420 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1422 default_parameter_used |= p.HasDefaultValue;
1425 lbag.AddLocation (p, GetLocation ($2));
1434 opt_parameter_modifier
1438 var lt = (Tokenizer.LocatedToken) $4;
1439 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1442 opt_parameter_modifier
1444 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1446 var lt = (Tokenizer.LocatedToken) $4;
1447 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1448 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1450 | attribute_sections error
1452 Error_SyntaxError (yyToken);
1453 Location l = GetLocation ($2);
1454 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1457 opt_parameter_modifier
1461 Error_SyntaxError (yyToken);
1462 Location l = GetLocation ($4);
1463 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1466 opt_parameter_modifier
1471 ++lexer.parsing_block;
1475 --lexer.parsing_block;
1476 if (lang_version <= LanguageVersion.V_3) {
1477 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1480 Parameter.Modifier mod = (Parameter.Modifier) $2;
1481 if (mod != Parameter.Modifier.NONE) {
1483 case Parameter.Modifier.REF:
1484 case Parameter.Modifier.OUT:
1485 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1486 Parameter.GetModifierSignature (mod));
1489 case Parameter.Modifier.This:
1490 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1491 Parameter.GetModifierSignature (mod));
1494 throw new NotImplementedException (mod.ToString ());
1497 mod = Parameter.Modifier.NONE;
1500 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1501 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1503 var lt = (Tokenizer.LocatedToken) $4;
1504 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1505 lbag.AddLocation ($$, GetLocation ($5));
1508 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1512 opt_parameter_modifier
1513 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1514 | parameter_modifiers
1518 : parameter_modifier
1522 | parameter_modifiers parameter_modifier
1524 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1525 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1526 if (((Parameter.Modifier)$1 & p2) == p2) {
1527 Error_DuplicateParameterModifier (lexer.Location, p2);
1529 switch (mod & ~Parameter.Modifier.This) {
1530 case Parameter.Modifier.REF:
1531 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1533 case Parameter.Modifier.OUT:
1534 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1537 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1548 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1549 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1551 $$ = Parameter.Modifier.REF;
1555 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1556 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1558 $$ = Parameter.Modifier.OUT;
1562 if ((valid_param_mod & ParameterModifierType.This) == 0)
1563 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1565 if (lang_version <= LanguageVersion.ISO_2)
1566 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1568 $$ = Parameter.Modifier.This;
1573 : opt_attributes params_modifier type IDENTIFIER
1575 var lt = (Tokenizer.LocatedToken) $4;
1576 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1578 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1580 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1582 var lt = (Tokenizer.LocatedToken) $4;
1583 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1585 | opt_attributes params_modifier type error
1587 Error_SyntaxError (yyToken);
1595 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1596 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1598 | PARAMS parameter_modifier
1600 Parameter.Modifier mod = (Parameter.Modifier)$2;
1601 if ((mod & Parameter.Modifier.This) != 0) {
1602 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1604 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1607 | PARAMS params_modifier
1609 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1616 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1617 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1621 property_declaration
1625 member_declaration_name
1628 tmpComment = Lexer.consume_doc_comment ();
1632 var type = (FullNamedExpression) $3;
1633 current_property = new Property (current_type, type, (Modifiers) $2,
1634 (MemberName) $4, (Attributes) $1);
1636 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1637 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1639 current_type.AddMember (current_property);
1640 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1642 lexer.PropertyParsing = true;
1644 accessor_declarations
1646 lexer.PropertyParsing = false;
1649 current_property.DocComment = ConsumeStoredComment ();
1653 lbag.AppendToMember (current_property, GetLocation ($10));
1654 current_property = null;
1660 : opt_attributes opt_modifiers
1661 member_type indexer_declaration_name OPEN_BRACKET
1663 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1665 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1667 valid_param_mod = 0;
1668 var type = (FullNamedExpression) $3;
1669 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1671 current_property = indexer;
1673 current_type.AddIndexer (indexer);
1674 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1676 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1677 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1679 if (indexer.ParameterInfo.IsEmpty) {
1680 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1684 tmpComment = Lexer.consume_doc_comment ();
1685 Lexer.doc_state = XmlCommentState.Allowed;
1688 lexer.PropertyParsing = true;
1690 accessor_declarations
1692 lexer.PropertyParsing = false;
1696 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1697 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1700 current_property.DocComment = ConsumeStoredComment ();
1702 lbag.AppendToMember (current_property, GetLocation ($12));
1703 current_property = null;
1708 accessor_declarations
1709 : get_accessor_declaration
1710 | get_accessor_declaration accessor_declarations
1711 | set_accessor_declaration
1712 | set_accessor_declaration accessor_declarations
1715 if (yyToken == Token.CLOSE_BRACE) {
1716 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1718 if (yyToken == Token.SEMICOLON)
1719 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1721 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1726 get_accessor_declaration
1727 : opt_attributes opt_modifiers GET
1729 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1730 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1733 if (current_property.Get != null) {
1734 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1737 if (current_property is Indexer) {
1738 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1739 (Attributes) $1, GetLocation ($3));
1741 current_property.Get = new Property.GetMethod (current_property,
1742 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1745 current_local_parameters = current_property.Get.ParameterInfo;
1746 lbag.AddMember (current_property.Get, mod_locations);
1747 lexer.PropertyParsing = false;
1752 current_property.Get.Block = (ToplevelBlock) $5;
1754 if (current_container.Kind == MemberKind.Interface) {
1755 report.Error (531, current_property.Get.Block.StartLocation,
1756 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1760 current_local_parameters = null;
1761 lexer.PropertyParsing = true;
1764 if (Lexer.doc_state == XmlCommentState.Error)
1765 Lexer.doc_state = XmlCommentState.NotAllowed;
1769 set_accessor_declaration
1770 : opt_attributes opt_modifiers SET
1772 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1773 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1776 if (current_property.Set != null) {
1777 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1780 if (current_property is Indexer) {
1781 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1782 ParametersCompiled.MergeGenerated (compiler,
1783 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1784 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1786 (Attributes) $1, GetLocation ($3));
1788 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1789 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1790 (Attributes) $1, GetLocation ($3));
1793 current_local_parameters = current_property.Set.ParameterInfo;
1794 lbag.AddMember (current_property.Set, mod_locations);
1795 lexer.PropertyParsing = false;
1800 current_property.Set.Block = (ToplevelBlock) $5;
1802 if (current_container.Kind == MemberKind.Interface) {
1803 report.Error (531, current_property.Set.Block.StartLocation,
1804 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1808 current_local_parameters = null;
1809 lexer.PropertyParsing = true;
1812 && Lexer.doc_state == XmlCommentState.Error)
1813 Lexer.doc_state = XmlCommentState.NotAllowed;
1826 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1831 interface_declaration
1837 lexer.ConstraintsParsing = true;
1839 type_declaration_name
1841 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1842 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1845 opt_type_parameter_constraints_clauses
1847 lexer.ConstraintsParsing = false;
1850 current_container.SetConstraints ((List<Constraints>) $9);
1853 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1854 Lexer.doc_state = XmlCommentState.Allowed;
1857 lexer.parsing_modifiers = true;
1859 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1861 --lexer.parsing_declaration;
1863 Lexer.doc_state = XmlCommentState.Allowed;
1867 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1868 $$ = pop_current_class ();
1870 | opt_attributes opt_modifiers opt_partial INTERFACE error
1872 Error_SyntaxError (yyToken);
1876 opt_interface_member_declarations
1878 | interface_member_declarations
1881 interface_member_declarations
1882 : interface_member_declaration
1884 lexer.parsing_modifiers = true;
1886 | interface_member_declarations interface_member_declaration
1888 lexer.parsing_modifiers = true;
1892 interface_member_declaration
1893 : constant_declaration
1895 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1899 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1901 | method_declaration
1902 | property_declaration
1904 | indexer_declaration
1905 | operator_declaration
1907 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1909 | constructor_declaration
1911 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1915 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1919 operator_declaration
1920 : opt_attributes opt_modifiers operator_declarator
1925 OperatorDeclaration decl = (OperatorDeclaration) $3;
1927 Operator op = new Operator (
1928 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
1929 current_local_parameters,
1930 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1932 if (op.Block == null)
1933 op.ParameterInfo.CheckParameters (op);
1936 op.DocComment = tmpComment;
1937 Lexer.doc_state = XmlCommentState.Allowed;
1940 // Note again, checking is done in semantic analysis
1941 current_type.AddOperator (op);
1943 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1946 current_local_parameters = null;
1952 | SEMICOLON { $$ = null; }
1956 : type_expression_or_array
1959 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
1960 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
1965 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1967 valid_param_mod = ParameterModifierType.DefaultValue;
1969 opt_formal_parameter_list CLOSE_PARENS
1971 valid_param_mod = 0;
1973 Location loc = GetLocation ($2);
1974 Operator.OpType op = (Operator.OpType) $3;
1975 current_local_parameters = (ParametersCompiled)$6;
1977 int p_count = current_local_parameters.Count;
1979 if (op == Operator.OpType.Addition)
1980 op = Operator.OpType.UnaryPlus;
1981 else if (op == Operator.OpType.Subtraction)
1982 op = Operator.OpType.UnaryNegation;
1985 if (IsUnaryOperator (op)) {
1987 report.Error (1020, loc, "Overloadable binary operator expected");
1988 } else if (p_count != 1) {
1989 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1990 Operator.GetName (op));
1994 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1995 Operator.GetName (op));
1996 } else if (p_count != 2) {
1997 report.Error (1019, loc, "Overloadable unary operator expected");
2002 tmpComment = Lexer.consume_doc_comment ();
2003 Lexer.doc_state = XmlCommentState.NotAllowed;
2006 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2007 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2009 | conversion_operator_declarator
2012 overloadable_operator
2014 : BANG { $$ = Operator.OpType.LogicalNot; }
2015 | TILDE { $$ = Operator.OpType.OnesComplement; }
2016 | OP_INC { $$ = Operator.OpType.Increment; }
2017 | OP_DEC { $$ = Operator.OpType.Decrement; }
2018 | TRUE { $$ = Operator.OpType.True; }
2019 | FALSE { $$ = Operator.OpType.False; }
2020 // Unary and binary:
2021 | PLUS { $$ = Operator.OpType.Addition; }
2022 | MINUS { $$ = Operator.OpType.Subtraction; }
2024 | STAR { $$ = Operator.OpType.Multiply; }
2025 | DIV { $$ = Operator.OpType.Division; }
2026 | PERCENT { $$ = Operator.OpType.Modulus; }
2027 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2028 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2029 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2030 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2031 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2032 | OP_EQ { $$ = Operator.OpType.Equality; }
2033 | OP_NE { $$ = Operator.OpType.Inequality; }
2034 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2035 | OP_LT { $$ = Operator.OpType.LessThan; }
2036 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2037 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2040 conversion_operator_declarator
2041 : IMPLICIT OPERATOR type OPEN_PARENS
2043 valid_param_mod = ParameterModifierType.DefaultValue;
2045 opt_formal_parameter_list CLOSE_PARENS
2047 valid_param_mod = 0;
2049 Location loc = GetLocation ($2);
2050 current_local_parameters = (ParametersCompiled)$6;
2053 tmpComment = Lexer.consume_doc_comment ();
2054 Lexer.doc_state = XmlCommentState.NotAllowed;
2057 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2058 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2060 | EXPLICIT OPERATOR type OPEN_PARENS
2062 valid_param_mod = ParameterModifierType.DefaultValue;
2064 opt_formal_parameter_list CLOSE_PARENS
2066 valid_param_mod = 0;
2068 Location loc = GetLocation ($2);
2069 current_local_parameters = (ParametersCompiled)$6;
2072 tmpComment = Lexer.consume_doc_comment ();
2073 Lexer.doc_state = XmlCommentState.NotAllowed;
2076 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2077 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2081 Error_SyntaxError (yyToken);
2082 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2083 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2087 Error_SyntaxError (yyToken);
2088 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2089 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2093 constructor_declaration
2094 : constructor_declarator
2097 Constructor c = (Constructor) $1;
2098 c.Block = (ToplevelBlock) $2;
2101 c.DocComment = ConsumeStoredComment ();
2103 current_local_parameters = null;
2105 Lexer.doc_state = XmlCommentState.Allowed;
2109 constructor_declarator
2115 tmpComment = Lexer.consume_doc_comment ();
2116 Lexer.doc_state = XmlCommentState.Allowed;
2119 valid_param_mod = ParameterModifierType.All;
2121 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2123 valid_param_mod = 0;
2124 current_local_parameters = (ParametersCompiled) $6;
2126 var lt = (Tokenizer.LocatedToken) $3;
2127 var mods = (Modifiers) $2;
2128 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2130 if (lt.Value != current_container.MemberName.Name) {
2131 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2132 } else if ((mods & Modifiers.STATIC) != 0) {
2133 if ((mods & Modifiers.AccessibilityMask) != 0){
2134 report.Error (515, c.Location,
2135 "`{0}': static constructor cannot have an access modifier",
2136 c.GetSignatureForError ());
2140 current_type.AddConstructor (c);
2141 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2145 // start block here, so possible anonymous methods inside
2146 // constructor initializer can get correct parent block
2148 start_block (lexer.Location);
2150 opt_constructor_initializer
2153 var c = (Constructor) $8;
2154 c.Initializer = (ConstructorInitializer) $9;
2157 report.Error (514, c.Location,
2158 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2159 c.GetSignatureForError ());
2169 | SEMICOLON { current_block = null; $$ = null; }
2172 opt_constructor_initializer
2174 | constructor_initializer
2177 constructor_initializer
2178 : COLON BASE OPEN_PARENS
2180 ++lexer.parsing_block;
2182 opt_argument_list CLOSE_PARENS
2184 --lexer.parsing_block;
2185 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2186 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2188 | COLON THIS OPEN_PARENS
2190 ++lexer.parsing_block;
2192 opt_argument_list CLOSE_PARENS
2194 --lexer.parsing_block;
2195 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2196 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2200 Error_SyntaxError (yyToken);
2201 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2202 lbag.AddLocation ($$, GetLocation ($1));
2206 Error_SyntaxError (yyToken);
2211 destructor_declaration
2212 : opt_attributes opt_modifiers TILDE
2215 tmpComment = Lexer.consume_doc_comment ();
2216 Lexer.doc_state = XmlCommentState.NotAllowed;
2219 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2221 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2223 var lt = (Tokenizer.LocatedToken) $5;
2224 if (lt.Value != current_container.MemberName.Name){
2225 report.Error (574, lt.Location, "Name of destructor must match name of class");
2226 } else if (current_container.Kind != MemberKind.Class){
2227 report.Error (575, lt.Location, "Only class types can contain destructor");
2230 Destructor d = new Destructor (current_type, (Modifiers) $2,
2231 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2233 d.DocComment = ConsumeStoredComment ();
2235 d.Block = (ToplevelBlock) $8;
2236 current_type.AddMember (d);
2237 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2239 current_local_parameters = null;
2246 EVENT type member_declaration_name
2248 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2249 current_type.AddMember (current_event_field);
2251 if (current_event_field.MemberName.ExplicitInterface != null) {
2252 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2253 current_event_field.GetSignatureForError ());
2256 $$ = current_event_field;
2258 opt_event_initializer
2259 opt_event_declarators
2263 current_event_field.DocComment = Lexer.consume_doc_comment ();
2264 Lexer.doc_state = XmlCommentState.Allowed;
2267 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2268 current_event_field = null;
2272 EVENT type member_declaration_name
2275 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2276 current_type.AddMember (current_event);
2277 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2279 lexer.EventParsing = true;
2281 event_accessor_declarations
2283 if (current_container.Kind == MemberKind.Interface)
2284 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2286 lexer.EventParsing = false;
2291 current_event.DocComment = Lexer.consume_doc_comment ();
2292 Lexer.doc_state = XmlCommentState.Allowed;
2295 lbag.AppendToMember (current_event, GetLocation ($9));
2296 current_event = null;
2297 current_local_parameters = null;
2301 opt_event_initializer
2305 ++lexer.parsing_block;
2307 event_variable_initializer
2309 --lexer.parsing_block;
2310 current_event_field.Initializer = (Expression) $3;
2314 opt_event_declarators
2322 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2324 | event_declarators event_declarator
2326 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2333 var lt = (Tokenizer.LocatedToken) $2;
2334 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2335 lbag.AddLocation ($$, GetLocation ($1));
2337 | COMMA IDENTIFIER ASSIGN
2339 ++lexer.parsing_block;
2341 event_variable_initializer
2343 --lexer.parsing_block;
2344 var lt = (Tokenizer.LocatedToken) $2;
2345 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2346 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2350 event_variable_initializer
2352 if (current_container.Kind == MemberKind.Interface) {
2353 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2354 current_event_field.GetSignatureForError ());
2357 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2358 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2359 current_event_field.GetSignatureForError ());
2362 variable_initializer
2368 event_accessor_declarations
2369 : add_accessor_declaration remove_accessor_declaration
2370 | remove_accessor_declaration add_accessor_declaration
2371 | add_accessor_declaration
2373 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2374 current_event.GetSignatureForError ());
2376 | remove_accessor_declaration
2378 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2379 current_event.GetSignatureForError ());
2383 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2388 add_accessor_declaration
2389 : opt_attributes opt_modifiers ADD
2391 if ($2 != ModifierNone) {
2392 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2395 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2396 current_local_parameters = current_event.Add.ParameterInfo;
2398 lbag.AddMember (current_event.Add, mod_locations);
2399 lexer.EventParsing = false;
2401 event_accessor_block
2403 lexer.EventParsing = true;
2405 current_event.Add.Block = (ToplevelBlock) $5;
2407 if (current_container.Kind == MemberKind.Interface) {
2408 report.Error (531, current_event.Add.Block.StartLocation,
2409 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2412 current_local_parameters = null;
2416 remove_accessor_declaration
2417 : opt_attributes opt_modifiers REMOVE
2419 if ($2 != ModifierNone) {
2420 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2423 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2424 current_local_parameters = current_event.Remove.ParameterInfo;
2426 lbag.AddMember (current_event.Remove, mod_locations);
2427 lexer.EventParsing = false;
2429 event_accessor_block
2431 lexer.EventParsing = true;
2433 current_event.Remove.Block = (ToplevelBlock) $5;
2435 if (current_container.Kind == MemberKind.Interface) {
2436 report.Error (531, current_event.Remove.Block.StartLocation,
2437 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2440 current_local_parameters = null;
2444 event_accessor_block
2447 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2453 attributes_without_members
2454 : attribute_sections CLOSE_BRACE
2456 current_type.UnattachedAttributes = (Attributes) $1;
2457 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2458 lexer.putback ('}');
2465 ENUM type_declaration_name
2469 enumTypeComment = Lexer.consume_doc_comment ();
2474 Lexer.doc_state = XmlCommentState.Allowed;
2476 MemberName name = (MemberName) $4;
2477 if (name.IsGeneric) {
2478 report.Error (1675, name.Location, "Enums cannot have type parameters");
2481 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2483 opt_enum_member_declarations
2485 // here will be evaluated after CLOSE_BLACE is consumed.
2487 Lexer.doc_state = XmlCommentState.Allowed;
2489 CLOSE_BRACE opt_semicolon
2492 current_container.DocComment = enumTypeComment;
2494 --lexer.parsing_declaration;
2497 // em.DocComment = ev.DocComment;
2499 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2500 $$ = pop_current_class ();
2508 var te = $2 as TypeExpression;
2509 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2510 Enum.Error_1008 (GetLocation ($2), report);
2516 Error_TypeExpected (GetLocation ($1));
2521 opt_enum_member_declarations
2523 | enum_member_declarations
2524 | enum_member_declarations COMMA
2526 lbag.AddLocation ($1, GetLocation ($2));
2530 enum_member_declarations
2531 : enum_member_declaration
2532 | enum_member_declarations COMMA enum_member_declaration
2534 lbag.AddLocation ($1, GetLocation ($2));
2539 enum_member_declaration
2540 : opt_attributes IDENTIFIER
2542 var lt = (Tokenizer.LocatedToken) $2;
2543 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2544 ((Enum) current_type).AddEnumMember (em);
2547 em.DocComment = Lexer.consume_doc_comment ();
2548 Lexer.doc_state = XmlCommentState.Allowed;
2553 | opt_attributes IDENTIFIER
2555 ++lexer.parsing_block;
2557 tmpComment = Lexer.consume_doc_comment ();
2558 Lexer.doc_state = XmlCommentState.NotAllowed;
2561 ASSIGN constant_expression
2563 --lexer.parsing_block;
2565 var lt = (Tokenizer.LocatedToken) $2;
2566 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2567 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2568 ((Enum) current_type).AddEnumMember (em);
2571 em.DocComment = ConsumeStoredComment ();
2575 | attributes_without_members
2578 delegate_declaration
2582 member_type type_declaration_name
2585 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2587 opt_formal_parameter_list CLOSE_PARENS
2589 valid_param_mod = 0;
2591 ParametersCompiled p = (ParametersCompiled) $8;
2593 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2595 p.CheckParameters (del);
2597 current_container.AddTypeContainer (del);
2599 current_delegate = del;
2600 lexer.ConstraintsParsing = true;
2602 opt_type_parameter_constraints_clauses
2604 lexer.ConstraintsParsing = false;
2609 current_delegate.DocComment = Lexer.consume_doc_comment ();
2610 Lexer.doc_state = XmlCommentState.Allowed;
2614 current_delegate.SetConstraints ((List<Constraints>) $11);
2615 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2617 $$ = current_delegate;
2619 current_delegate = null;
2627 if (lang_version < LanguageVersion.ISO_2)
2628 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2630 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2634 namespace_or_type_expr
2636 | qualified_alias_member IDENTIFIER opt_type_argument_list
2638 var lt1 = (Tokenizer.LocatedToken) $1;
2639 var lt2 = (Tokenizer.LocatedToken) $2;
2641 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2642 lbag.AddLocation ($$, GetLocation ($2));
2648 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2650 var lt = (Tokenizer.LocatedToken) $3;
2651 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2652 lbag.AddLocation ($$, GetLocation ($2));
2657 : IDENTIFIER opt_type_argument_list
2659 var lt = (Tokenizer.LocatedToken) $1;
2660 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2665 // Generics arguments (any type, without attributes)
2667 opt_type_argument_list
2669 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2671 if (lang_version < LanguageVersion.ISO_2)
2672 FeatureIsNotAvailable (GetLocation ($1), "generics");
2676 | OP_GENERICS_LT error
2678 Error_TypeExpected (lexer.Location);
2679 $$ = new TypeArguments ();
2686 TypeArguments type_args = new TypeArguments ();
2687 type_args.Add ((FullNamedExpression) $1);
2690 | type_arguments COMMA type
2692 TypeArguments type_args = (TypeArguments) $1;
2693 type_args.Add ((FullNamedExpression) $3);
2699 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2701 type_declaration_name
2704 lexer.parsing_generic_declaration = true;
2706 opt_type_parameter_list
2708 lexer.parsing_generic_declaration = false;
2709 var lt = (Tokenizer.LocatedToken) $1;
2710 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2714 member_declaration_name
2715 : method_declaration_name
2717 MemberName mn = (MemberName)$1;
2718 if (mn.TypeParameters != null)
2719 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2720 mn.GetSignatureForError ()));
2724 method_declaration_name
2725 : type_declaration_name
2726 | explicit_interface IDENTIFIER opt_type_parameter_list
2728 lexer.parsing_generic_declaration = false;
2729 var lt = (Tokenizer.LocatedToken) $2;
2730 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2734 indexer_declaration_name
2737 lexer.parsing_generic_declaration = false;
2738 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2740 | explicit_interface THIS
2742 lexer.parsing_generic_declaration = false;
2743 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2748 : IDENTIFIER opt_type_argument_list DOT
2750 var lt = (Tokenizer.LocatedToken) $1;
2751 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2752 lbag.AddLocation ($$, GetLocation ($3));
2754 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2756 var lt1 = (Tokenizer.LocatedToken) $1;
2757 var lt2 = (Tokenizer.LocatedToken) $2;
2759 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2760 lbag.AddLocation ($$, GetLocation ($4));
2762 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2764 var lt = (Tokenizer.LocatedToken) $2;
2765 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2766 lbag.AddLocation ($$, GetLocation ($4));
2770 opt_type_parameter_list
2772 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2774 if (lang_version < LanguageVersion.ISO_2)
2775 FeatureIsNotAvailable (GetLocation ($1), "generics");
2778 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2785 var tparams = new TypeParameters ();
2786 tparams.Add ((TypeParameter)$1);
2789 | type_parameters COMMA type_parameter
2791 var tparams = (TypeParameters) $1;
2792 tparams.Add ((TypeParameter)$3);
2794 lbag.AddLocation ($3, GetLocation ($3));
2799 : opt_attributes opt_type_parameter_variance IDENTIFIER
2801 var lt = (Tokenizer.LocatedToken)$3;
2802 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2806 if (GetTokenName (yyToken) == "type")
2807 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2809 Error_SyntaxError (yyToken);
2811 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2816 // All types where void is allowed
2819 : type_expression_or_array
2822 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2829 lexer.parsing_generic_declaration = true;
2834 // A type which does not allow `void' to be used
2837 : type_expression_or_array
2840 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2841 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2849 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2850 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2855 : type_expression_or_array
2858 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2859 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2863 type_expression_or_array
2865 | type_expression rank_specifiers
2867 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2872 : namespace_or_type_expr opt_nullable
2875 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2877 var sn = $1 as SimpleName;
2878 if (sn != null && sn.Name == "var")
2879 $$ = new VarExpr (sn.Location);
2884 | namespace_or_type_expr pointer_stars
2886 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2888 | builtin_types opt_nullable
2891 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2893 | builtin_types pointer_stars
2895 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2897 | VOID pointer_stars
2899 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2906 var types = new List<FullNamedExpression> (2);
2907 types.Add ((FullNamedExpression) $1);
2910 | type_list COMMA base_type_name
2912 var types = (List<FullNamedExpression>) $1;
2913 types.Add ((FullNamedExpression) $3);
2921 if ($1 is ComposedCast) {
2922 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2929 * replaces all the productions for isolating the various
2930 * simple types, but we need this to reuse it easily in variable_type
2933 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
2934 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
2935 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
2936 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
2937 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
2938 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
2943 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
2944 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
2945 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
2946 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
2947 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
2948 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
2949 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
2950 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
2951 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
2955 // Expressions, section 7.5
2960 : primary_expression_or_type
2962 | array_creation_expression
2963 | parenthesized_expression
2964 | default_value_expression
2965 | invocation_expression
2969 | post_increment_expression
2970 | post_decrement_expression
2971 | object_or_delegate_creation_expression
2972 | anonymous_type_expression
2975 | checked_expression
2976 | unchecked_expression
2977 | pointer_member_access
2978 | anonymous_method_expression
2979 | undocumented_expressions
2982 primary_expression_or_type
2983 : IDENTIFIER opt_type_argument_list
2985 var lt = (Tokenizer.LocatedToken) $1;
2986 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2988 | IDENTIFIER GENERATE_COMPLETION {
2989 var lt = (Tokenizer.LocatedToken) $1;
2990 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
2998 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3002 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3003 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3008 // Here is the trick, tokenizer may think that parens is a special but
3009 // parser is interested in open parens only, so we merge them.
3010 // Consider: if (a)foo ();
3018 // Use this production to accept closing parenthesis or
3019 // performing completion
3023 | COMPLETE_COMPLETION
3027 parenthesized_expression
3028 : OPEN_PARENS expression CLOSE_PARENS
3030 $$ = new ParenthesizedExpression ((Expression) $2);
3031 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3033 | OPEN_PARENS expression COMPLETE_COMPLETION
3035 $$ = new ParenthesizedExpression ((Expression) $2);
3040 : primary_expression DOT IDENTIFIER opt_type_argument_list
3042 var lt = (Tokenizer.LocatedToken) $3;
3043 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3044 lbag.AddLocation ($$, GetLocation ($2));
3046 | builtin_types DOT IDENTIFIER opt_type_argument_list
3048 var lt = (Tokenizer.LocatedToken) $3;
3049 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3050 lbag.AddLocation ($$, GetLocation ($2));
3052 | BASE DOT IDENTIFIER opt_type_argument_list
3054 var lt = (Tokenizer.LocatedToken) $3;
3055 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3056 lbag.AddLocation ($$, GetLocation ($2));
3058 | qualified_alias_member IDENTIFIER opt_type_argument_list
3060 var lt1 = (Tokenizer.LocatedToken) $1;
3061 var lt2 = (Tokenizer.LocatedToken) $2;
3063 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3064 lbag.AddLocation ($$, GetLocation ($2));
3066 | primary_expression DOT GENERATE_COMPLETION {
3067 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3069 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3070 var lt = (Tokenizer.LocatedToken) $3;
3071 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3073 | builtin_types DOT GENERATE_COMPLETION
3075 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3077 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3078 var lt = (Tokenizer.LocatedToken) $3;
3079 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3083 invocation_expression
3084 : primary_expression open_parens_any opt_argument_list close_parens
3086 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3087 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3089 | primary_expression open_parens_any argument_list error
3091 Error_SyntaxError (yyToken);
3093 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3094 lbag.AddLocation ($$, GetLocation ($2));
3099 opt_object_or_collection_initializer
3100 : /* empty */ { $$ = null; }
3101 | object_or_collection_initializer
3104 object_or_collection_initializer
3105 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3108 $$ = CollectionOrObjectInitializers.Empty;
3111 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3112 lbag.AddLocation ($$, GetLocation ($3));
3115 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3117 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3118 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3122 opt_member_initializer_list
3123 : /* empty */ { $$ = null; }
3124 | member_initializer_list
3130 member_initializer_list
3131 : member_initializer
3133 var a = new List<Expression> ();
3134 a.Add ((Expression) $1);
3137 | member_initializer_list COMMA member_initializer
3139 var a = (List<Expression>)$1;
3140 a.Add ((Expression) $3);
3143 | member_initializer_list error {
3144 Error_SyntaxError (yyToken);
3150 : IDENTIFIER ASSIGN initializer_value
3152 var lt = (Tokenizer.LocatedToken) $1;
3153 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3154 lbag.AddLocation ($$, GetLocation ($2));
3156 | GENERATE_COMPLETION
3158 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3160 | non_assignment_expression opt_COMPLETE_COMPLETION {
3161 CompletionSimpleName csn = $1 as CompletionSimpleName;
3163 $$ = new CollectionElementInitializer ((Expression)$1);
3165 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3167 | OPEN_BRACE expression_list CLOSE_BRACE
3172 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3174 | OPEN_BRACE CLOSE_BRACE
3176 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3183 | object_or_collection_initializer
3187 : /* empty */ { $$ = null; }
3192 : argument_or_named_argument
3194 Arguments list = new Arguments (4);
3195 list.Add ((Argument) $1);
3198 | argument_list COMMA argument
3200 Arguments list = (Arguments) $1;
3201 if (list [list.Count - 1] is NamedArgument)
3202 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3204 list.Add ((Argument) $3);
3207 | argument_list COMMA named_argument
3209 Arguments list = (Arguments) $1;
3210 NamedArgument a = (NamedArgument) $3;
3211 for (int i = 0; i < list.Count; ++i) {
3212 NamedArgument na = list [i] as NamedArgument;
3213 if (na != null && na.Name == a.Name)
3214 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3221 | argument_list COMMA error
3223 lexer.putback (')'); // TODO: Wrong but what can I do
3224 Error_SyntaxError (yyToken);
3229 report.Error (839, GetLocation ($1), "An argument is missing");
3237 $$ = new Argument ((Expression) $1);
3239 | non_simple_argument
3242 argument_or_named_argument
3248 : REF variable_reference
3250 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3251 lbag.AddLocation ($$, GetLocation ($1));
3253 | OUT variable_reference
3255 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3256 lbag.AddLocation ($$, GetLocation ($1));
3258 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3260 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3261 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3263 | ARGLIST OPEN_PARENS CLOSE_PARENS
3265 $$ = new Argument (new Arglist (GetLocation ($1)));
3266 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3275 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3277 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3278 lbag.AddLocation ($$, GetLocation ($4));
3280 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3282 Error_SyntaxError (yyToken);
3283 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3285 | primary_expression OPEN_BRACKET_EXPR error
3287 Error_SyntaxError (yyToken);
3288 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3295 var list = new List<Expression> (4);
3296 list.Add ((Expression) $1);
3299 | expression_list COMMA expression
3301 var list = (List<Expression>) $1;
3302 list.Add ((Expression) $3);
3305 | expression_list error {
3306 Error_SyntaxError (yyToken);
3311 expression_list_arguments
3312 : expression_list_argument
3314 Arguments args = new Arguments (4);
3315 args.Add ((Argument) $1);
3318 | expression_list_arguments COMMA expression_list_argument
3320 Arguments args = (Arguments) $1;
3321 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3322 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3324 args.Add ((Argument) $3);
3329 expression_list_argument
3332 $$ = new Argument ((Expression) $1);
3340 $$ = new This (GetLocation ($1));
3345 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3347 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3348 lbag.AddLocation ($$, GetLocation ($4));
3350 | BASE OPEN_BRACKET error
3352 Error_SyntaxError (yyToken);
3353 $$ = new ElementAccess (null, null, GetLocation ($2));
3357 post_increment_expression
3358 : primary_expression OP_INC
3360 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3364 post_decrement_expression
3365 : primary_expression OP_DEC
3367 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3371 object_or_delegate_creation_expression
3372 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3375 if (lang_version <= LanguageVersion.ISO_2)
3376 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3378 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3380 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3383 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3385 | NEW new_expr_type object_or_collection_initializer
3387 if (lang_version <= LanguageVersion.ISO_2)
3388 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3390 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3394 array_creation_expression
3395 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3397 opt_array_initializer
3399 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3400 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3401 Next = (ComposedTypeSpecifier) $6
3402 }, (ArrayInitializer) $7, GetLocation ($1));
3403 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3405 | NEW new_expr_type rank_specifiers opt_array_initializer
3408 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3410 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3412 | NEW rank_specifier array_initializer
3414 if (lang_version <= LanguageVersion.ISO_2)
3415 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3417 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3419 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3421 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3422 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3424 | NEW new_expr_type error
3426 Error_SyntaxError (yyToken);
3427 // It can be any of new expression, create the most common one
3428 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3434 ++lexer.parsing_type;
3438 --lexer.parsing_type;
3443 anonymous_type_expression
3444 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3446 if (lang_version <= LanguageVersion.ISO_2)
3447 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3449 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3451 // TODO: lbag comma location
3452 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3456 anonymous_type_parameters_opt_comma
3457 : anonymous_type_parameters_opt
3458 | anonymous_type_parameters COMMA
3461 anonymous_type_parameters_opt
3463 | anonymous_type_parameters
3466 anonymous_type_parameters
3467 : anonymous_type_parameter
3469 var a = new List<AnonymousTypeParameter> (4);
3470 a.Add ((AnonymousTypeParameter) $1);
3473 | anonymous_type_parameters COMMA anonymous_type_parameter
3475 var a = (List<AnonymousTypeParameter>) $1;
3476 a.Add ((AnonymousTypeParameter) $3);
3481 anonymous_type_parameter
3482 : IDENTIFIER ASSIGN variable_initializer
3484 var lt = (Tokenizer.LocatedToken)$1;
3485 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3486 lbag.AddLocation ($$, GetLocation ($2));
3490 var lt = (Tokenizer.LocatedToken)$1;
3491 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3492 lt.Value, lt.Location);
3496 MemberAccess ma = (MemberAccess) $1;
3497 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3501 report.Error (746, lexer.Location,
3502 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3514 | rank_specifier rank_specifiers
3516 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3522 : OPEN_BRACKET CLOSE_BRACKET
3524 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3525 lbag.AddLocation ($$, GetLocation ($2));
3527 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3529 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3530 lbag.AddLocation ($$, GetLocation ($3));
3539 | dim_separators COMMA
3541 $$ = ((int) $1) + 1;
3545 opt_array_initializer
3557 : OPEN_BRACE CLOSE_BRACE
3559 var ai = new ArrayInitializer (0, GetLocation ($1));
3560 ai.VariableDeclaration = current_variable;
3561 lbag.AddLocation (ai, GetLocation ($2));
3564 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3566 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3567 ai.VariableDeclaration = current_variable;
3569 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3571 lbag.AddLocation (ai, GetLocation ($4));
3577 variable_initializer_list
3578 : variable_initializer
3580 var list = new List<Expression> (4);
3581 list.Add ((Expression) $1);
3584 | variable_initializer_list COMMA variable_initializer
3586 var list = (List<Expression>) $1;
3587 list.Add ((Expression) $3);
3595 lexer.TypeOfParsing = true;
3597 open_parens_any typeof_type_expression CLOSE_PARENS
3599 lexer.TypeOfParsing = false;
3600 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3601 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3605 typeof_type_expression
3610 Error_TypeExpected (lexer.Location);
3616 : identifier_inside_body generic_dimension
3618 var lt = (Tokenizer.LocatedToken) $1;
3620 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3622 | qualified_alias_member identifier_inside_body generic_dimension
3624 var lt1 = (Tokenizer.LocatedToken) $1;
3625 var lt2 = (Tokenizer.LocatedToken) $2;
3627 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3628 lbag.AddLocation ($$, GetLocation ($2));
3630 | unbound_type_name DOT identifier_inside_body
3632 var lt = (Tokenizer.LocatedToken) $3;
3634 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3636 | unbound_type_name DOT identifier_inside_body generic_dimension
3638 var lt = (Tokenizer.LocatedToken) $3;
3640 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3642 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3644 var tne = (ATypeNameExpression) $1;
3645 if (tne.HasTypeArguments)
3646 Error_TypeExpected (GetLocation ($4));
3648 var lt = (Tokenizer.LocatedToken) $3;
3649 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3656 if (lang_version < LanguageVersion.ISO_2)
3657 FeatureIsNotAvailable (GetLocation ($1), "generics");
3663 qualified_alias_member
3664 : IDENTIFIER DOUBLE_COLON
3666 var lt = (Tokenizer.LocatedToken) $1;
3667 if (lang_version == LanguageVersion.ISO_1)
3668 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3675 : SIZEOF open_parens_any type CLOSE_PARENS
3677 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3678 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3683 : CHECKED open_parens_any expression CLOSE_PARENS
3685 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3686 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3690 unchecked_expression
3691 : UNCHECKED open_parens_any expression CLOSE_PARENS
3693 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3694 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3698 pointer_member_access
3699 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3701 var lt = (Tokenizer.LocatedToken) $3;
3702 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3706 anonymous_method_expression
3707 : DELEGATE opt_anonymous_method_signature
3709 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3713 $$ = end_anonymous ((ParametersBlock) $4);
3715 | ASYNC DELEGATE opt_anonymous_method_signature
3717 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3721 $$ = end_anonymous ((ParametersBlock) $5);
3725 opt_anonymous_method_signature
3728 $$ = ParametersCompiled.Undefined;
3730 | anonymous_method_signature
3733 anonymous_method_signature
3736 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3738 opt_formal_parameter_list CLOSE_PARENS
3740 valid_param_mod = 0;
3745 default_value_expression
3746 : DEFAULT open_parens_any type CLOSE_PARENS
3748 if (lang_version < LanguageVersion.ISO_2)
3749 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3751 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3752 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3757 : primary_expression
3758 | BANG prefixed_unary_expression
3760 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3762 | TILDE prefixed_unary_expression
3764 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3766 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3768 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3769 lbag.AddLocation ($$, GetLocation ($3));
3771 | AWAIT prefixed_unary_expression
3774 if (current_anonymous_method is LambdaExpression) {
3775 report.Error (4034, GetLocation ($1),
3776 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3777 } else if (current_anonymous_method is AnonymousMethodExpression) {
3778 report.Error (4035, GetLocation ($1),
3779 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3781 report.Error (4033, GetLocation ($1),
3782 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3785 current_block.Explicit.RegisterAsyncAwait ();
3788 $$ = new Await ((Expression) $2, GetLocation ($1));
3793 // The idea to split this out is from Rhys' grammar
3794 // to solve the problem with casts.
3796 prefixed_unary_expression
3798 | PLUS prefixed_unary_expression
3800 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3802 | MINUS prefixed_unary_expression
3804 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3806 | OP_INC prefixed_unary_expression
3808 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3810 | OP_DEC prefixed_unary_expression
3812 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3814 | STAR prefixed_unary_expression
3816 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3818 | BITWISE_AND prefixed_unary_expression
3820 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3824 multiplicative_expression
3825 : prefixed_unary_expression
3826 | multiplicative_expression STAR prefixed_unary_expression
3828 $$ = new Binary (Binary.Operator.Multiply,
3829 (Expression) $1, (Expression) $3, GetLocation ($2));
3831 | multiplicative_expression DIV prefixed_unary_expression
3833 $$ = new Binary (Binary.Operator.Division,
3834 (Expression) $1, (Expression) $3, GetLocation ($2));
3836 | multiplicative_expression PERCENT prefixed_unary_expression
3838 $$ = new Binary (Binary.Operator.Modulus,
3839 (Expression) $1, (Expression) $3, GetLocation ($2));
3844 : multiplicative_expression
3845 | additive_expression PLUS multiplicative_expression
3847 $$ = new Binary (Binary.Operator.Addition,
3848 (Expression) $1, (Expression) $3, GetLocation ($2));
3850 | additive_expression MINUS multiplicative_expression
3852 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3854 | parenthesized_expression MINUS multiplicative_expression
3856 // Shift/Reduce conflict
3857 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3859 | additive_expression AS type
3861 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3863 | additive_expression IS type
3865 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3870 : additive_expression
3871 | shift_expression OP_SHIFT_LEFT additive_expression
3873 $$ = new Binary (Binary.Operator.LeftShift,
3874 (Expression) $1, (Expression) $3, GetLocation ($2));
3876 | shift_expression OP_SHIFT_RIGHT additive_expression
3878 $$ = new Binary (Binary.Operator.RightShift,
3879 (Expression) $1, (Expression) $3, GetLocation ($2));
3883 relational_expression
3885 | relational_expression OP_LT shift_expression
3887 $$ = new Binary (Binary.Operator.LessThan,
3888 (Expression) $1, (Expression) $3, GetLocation ($2));
3890 | relational_expression OP_GT shift_expression
3892 $$ = new Binary (Binary.Operator.GreaterThan,
3893 (Expression) $1, (Expression) $3, GetLocation ($2));
3895 | relational_expression OP_LE shift_expression
3897 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3898 (Expression) $1, (Expression) $3, GetLocation ($2));
3900 | relational_expression OP_GE shift_expression
3902 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3903 (Expression) $1, (Expression) $3, GetLocation ($2));
3908 : relational_expression
3909 | equality_expression OP_EQ relational_expression
3911 $$ = new Binary (Binary.Operator.Equality,
3912 (Expression) $1, (Expression) $3, GetLocation ($2));
3914 | equality_expression OP_NE relational_expression
3916 $$ = new Binary (Binary.Operator.Inequality,
3917 (Expression) $1, (Expression) $3, GetLocation ($2));
3922 : equality_expression
3923 | and_expression BITWISE_AND equality_expression
3925 $$ = new Binary (Binary.Operator.BitwiseAnd,
3926 (Expression) $1, (Expression) $3, GetLocation ($2));
3930 exclusive_or_expression
3932 | exclusive_or_expression CARRET and_expression
3934 $$ = new Binary (Binary.Operator.ExclusiveOr,
3935 (Expression) $1, (Expression) $3, GetLocation ($2));
3939 inclusive_or_expression
3940 : exclusive_or_expression
3941 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3943 $$ = new Binary (Binary.Operator.BitwiseOr,
3944 (Expression) $1, (Expression) $3, GetLocation ($2));
3948 conditional_and_expression
3949 : inclusive_or_expression
3950 | conditional_and_expression OP_AND inclusive_or_expression
3952 $$ = new Binary (Binary.Operator.LogicalAnd,
3953 (Expression) $1, (Expression) $3, GetLocation ($2));
3957 conditional_or_expression
3958 : conditional_and_expression
3959 | conditional_or_expression OP_OR conditional_and_expression
3961 $$ = new Binary (Binary.Operator.LogicalOr,
3962 (Expression) $1, (Expression) $3, GetLocation ($2));
3966 null_coalescing_expression
3967 : conditional_or_expression
3968 | conditional_or_expression OP_COALESCING null_coalescing_expression
3970 if (lang_version < LanguageVersion.ISO_2)
3971 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3973 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3977 conditional_expression
3978 : null_coalescing_expression
3979 | null_coalescing_expression INTERR expression COLON expression_or_error
3981 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3982 lbag.AddLocation ($$, GetLocation ($4));
3984 | null_coalescing_expression INTERR expression error
3986 Error_SyntaxError (yyToken);
3987 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
3991 assignment_expression
3992 : prefixed_unary_expression ASSIGN expression
3994 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3996 | prefixed_unary_expression OP_MULT_ASSIGN expression
3998 $$ = new CompoundAssign (
3999 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
4001 | prefixed_unary_expression OP_DIV_ASSIGN expression
4003 $$ = new CompoundAssign (
4004 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
4006 | prefixed_unary_expression OP_MOD_ASSIGN expression
4008 $$ = new CompoundAssign (
4009 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
4011 | prefixed_unary_expression OP_ADD_ASSIGN expression
4013 $$ = new CompoundAssign (
4014 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
4016 | prefixed_unary_expression OP_SUB_ASSIGN expression
4018 $$ = new CompoundAssign (
4019 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4021 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4023 $$ = new CompoundAssign (
4024 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4026 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4028 $$ = new CompoundAssign (
4029 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4031 | prefixed_unary_expression OP_AND_ASSIGN expression
4033 $$ = new CompoundAssign (
4034 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4036 | prefixed_unary_expression OP_OR_ASSIGN expression
4038 $$ = new CompoundAssign (
4039 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4041 | prefixed_unary_expression OP_XOR_ASSIGN expression
4043 $$ = new CompoundAssign (
4044 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4048 lambda_parameter_list
4051 var pars = new List<Parameter> (4);
4052 pars.Add ((Parameter) $1);
4056 | lambda_parameter_list COMMA lambda_parameter
4058 var pars = (List<Parameter>) $1;
4059 Parameter p = (Parameter)$3;
4060 if (pars[0].GetType () != p.GetType ()) {
4061 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4070 : parameter_modifier parameter_type identifier_inside_body
4072 var lt = (Tokenizer.LocatedToken) $3;
4074 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4076 | parameter_type identifier_inside_body
4078 var lt = (Tokenizer.LocatedToken) $2;
4080 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4084 var lt = (Tokenizer.LocatedToken) $1;
4085 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4089 opt_lambda_parameter_list
4090 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4091 | lambda_parameter_list {
4092 var pars_list = (List<Parameter>) $1;
4093 $$ = new ParametersCompiled (pars_list.ToArray ());
4097 lambda_expression_body
4098 : lambda_expression_body_simple
4102 lambda_expression_body_simple
4104 start_block (Location.Null);
4106 expression_or_error // Have to close block when error occurs
4108 Block b = end_block (Location.Null);
4109 b.IsCompilerGenerated = true;
4110 b.AddStatement (new ContextualReturn ((Expression) $2));
4119 Error_SyntaxError (yyToken);
4120 $$ = EmptyExpression.Null;
4127 var lt = (Tokenizer.LocatedToken) $1;
4128 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4129 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4131 lambda_expression_body
4133 $$ = end_anonymous ((ParametersBlock) $4);
4134 lbag.AddLocation ($$, GetLocation ($2));
4136 | ASYNC identifier_inside_body ARROW
4138 var lt = (Tokenizer.LocatedToken) $2;
4139 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4140 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4142 lambda_expression_body
4144 $$ = end_anonymous ((ParametersBlock) $5);
4145 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4147 | OPEN_PARENS_LAMBDA
4149 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4151 opt_lambda_parameter_list CLOSE_PARENS ARROW
4153 valid_param_mod = 0;
4154 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4156 lambda_expression_body
4158 $$ = end_anonymous ((ParametersBlock) $7);
4159 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4161 | ASYNC OPEN_PARENS_LAMBDA
4163 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4165 opt_lambda_parameter_list CLOSE_PARENS ARROW
4167 valid_param_mod = 0;
4168 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4170 lambda_expression_body
4172 $$ = end_anonymous ((ParametersBlock) $8);
4173 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4178 : assignment_expression
4179 | non_assignment_expression
4182 non_assignment_expression
4183 : conditional_expression
4188 $$ = new ArglistAccess (GetLocation ($1));
4192 undocumented_expressions
4193 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4195 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4196 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4198 | REFTYPE open_parens_any expression CLOSE_PARENS
4200 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4201 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4203 | MAKEREF open_parens_any expression CLOSE_PARENS
4205 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4206 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4217 $$ = new BooleanExpression ((Expression) $1);
4230 lexer.ConstraintsParsing = true;
4232 type_declaration_name
4234 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4235 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4236 FeatureIsNotAvailable (c.Location, "static classes");
4239 push_current_container (c, $3);
4242 opt_type_parameter_constraints_clauses
4244 lexer.ConstraintsParsing = false;
4247 current_container.SetConstraints ((List<Constraints>) $9);
4248 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4251 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4252 Lexer.doc_state = XmlCommentState.Allowed;
4255 lexer.parsing_modifiers = true;
4257 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4259 --lexer.parsing_declaration;
4261 Lexer.doc_state = XmlCommentState.Allowed;
4265 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4266 $$ = pop_current_class ();
4274 { $$ = $1; } // location
4280 mod_locations = null;
4282 lexer.parsing_modifiers = false;
4286 lexer.parsing_modifiers = false;
4292 | modifiers modifier
4294 var m1 = (Modifiers) $1;
4295 var m2 = (Modifiers) $2;
4297 if ((m1 & m2) != 0) {
4298 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4299 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4300 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4301 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4302 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4303 "More than one protection modifier specified");
4314 StoreModifierLocation ($$, GetLocation ($1));
4316 if (current_container.Kind == MemberKind.Namespace)
4317 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4321 $$ = Modifiers.PUBLIC;
4322 StoreModifierLocation ($$, GetLocation ($1));
4326 $$ = Modifiers.PROTECTED;
4327 StoreModifierLocation ($$, GetLocation ($1));
4331 $$ = Modifiers.INTERNAL;
4332 StoreModifierLocation ($$, GetLocation ($1));
4336 $$ = Modifiers.PRIVATE;
4337 StoreModifierLocation ($$, GetLocation ($1));
4341 $$ = Modifiers.ABSTRACT;
4342 StoreModifierLocation ($$, GetLocation ($1));
4346 $$ = Modifiers.SEALED;
4347 StoreModifierLocation ($$, GetLocation ($1));
4351 $$ = Modifiers.STATIC;
4352 StoreModifierLocation ($$, GetLocation ($1));
4356 $$ = Modifiers.READONLY;
4357 StoreModifierLocation ($$, GetLocation ($1));
4361 $$ = Modifiers.VIRTUAL;
4362 StoreModifierLocation ($$, GetLocation ($1));
4366 $$ = Modifiers.OVERRIDE;
4367 StoreModifierLocation ($$, GetLocation ($1));
4371 $$ = Modifiers.EXTERN;
4372 StoreModifierLocation ($$, GetLocation ($1));
4376 $$ = Modifiers.VOLATILE;
4377 StoreModifierLocation ($$, GetLocation ($1));
4381 $$ = Modifiers.UNSAFE;
4382 StoreModifierLocation ($$, GetLocation ($1));
4383 if (!settings.Unsafe)
4384 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4388 $$ = Modifiers.ASYNC;
4389 StoreModifierLocation ($$, GetLocation ($1));
4397 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4399 | COLON type_list error
4401 Error_SyntaxError (yyToken);
4403 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4407 opt_type_parameter_constraints_clauses
4409 | type_parameter_constraints_clauses
4415 type_parameter_constraints_clauses
4416 : type_parameter_constraints_clause
4418 var constraints = new List<Constraints> (1);
4419 constraints.Add ((Constraints) $1);
4422 | type_parameter_constraints_clauses type_parameter_constraints_clause
4424 var constraints = (List<Constraints>) $1;
4425 Constraints new_constraint = (Constraints)$2;
4427 foreach (Constraints c in constraints) {
4428 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4429 report.Error (409, new_constraint.Location,
4430 "A constraint clause has already been specified for type parameter `{0}'",
4431 new_constraint.TypeParameter.Value);
4435 constraints.Add (new_constraint);
4440 type_parameter_constraints_clause
4441 : WHERE IDENTIFIER COLON type_parameter_constraints
4443 var lt = (Tokenizer.LocatedToken) $2;
4444 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4445 lbag.AddLocation ($$, GetLocation ($3));
4447 | WHERE IDENTIFIER error
4449 Error_SyntaxError (yyToken);
4451 var lt = (Tokenizer.LocatedToken) $2;
4452 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4456 type_parameter_constraints
4457 : type_parameter_constraint
4459 var constraints = new List<FullNamedExpression> (1);
4460 constraints.Add ((FullNamedExpression) $1);
4463 | type_parameter_constraints COMMA type_parameter_constraint
4465 var constraints = (List<FullNamedExpression>) $1;
4466 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4467 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4468 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4471 prev = $3 as SpecialContraintExpr;
4473 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4474 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4476 prev = constraints [0] as SpecialContraintExpr;
4477 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4478 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4483 constraints.Add ((FullNamedExpression) $3);
4488 type_parameter_constraint
4491 if ($1 is ComposedCast)
4492 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4496 | NEW OPEN_PARENS CLOSE_PARENS
4498 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4499 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4503 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4507 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4511 opt_type_parameter_variance
4516 | type_parameter_variance
4518 if (lang_version <= LanguageVersion.V_3)
4519 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4525 type_parameter_variance
4528 $$ = Variance.Covariant;
4532 $$ = Variance.Contravariant;
4541 // A block is "contained" on the following places:
4543 // property_declaration as part of the accessor body (get/set)
4544 // operator_declaration
4545 // constructor_declaration
4546 // destructor_declaration
4547 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4552 ++lexer.parsing_block;
4553 start_block (GetLocation ($1));
4555 opt_statement_list block_end
4564 --lexer.parsing_block;
4565 $$ = end_block (GetLocation ($1));
4567 | COMPLETE_COMPLETION
4569 --lexer.parsing_block;
4570 $$ = end_block (lexer.Location);
4578 ++lexer.parsing_block;
4579 current_block.StartLocation = GetLocation ($1);
4581 opt_statement_list CLOSE_BRACE
4583 --lexer.parsing_block;
4584 $$ = end_block (GetLocation ($4));
4595 | statement_list statement
4599 : block_variable_declaration
4601 current_block.AddStatement ((Statement) $1);
4603 | valid_declaration_statement
4605 current_block.AddStatement ((Statement) $1);
4610 Error_SyntaxError (yyToken);
4616 // The interactive_statement and its derivatives are only
4617 // used to provide a special version of `expression_statement'
4618 // that has a side effect of assigning the expression to
4621 interactive_statement_list
4622 : interactive_statement
4623 | interactive_statement_list interactive_statement
4626 interactive_statement
4627 : block_variable_declaration
4629 current_block.AddStatement ((Statement) $1);
4631 | interactive_valid_declaration_statement
4633 current_block.AddStatement ((Statement) $1);
4638 valid_declaration_statement
4641 | expression_statement
4642 | selection_statement
4643 | iteration_statement
4647 | unchecked_statement
4654 interactive_valid_declaration_statement
4657 | interactive_expression_statement
4658 | selection_statement
4659 | iteration_statement
4663 | unchecked_statement
4671 : valid_declaration_statement
4672 | block_variable_declaration
4674 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4679 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4684 Error_SyntaxError (yyToken);
4685 $$ = new EmptyStatement (GetLocation ($1));
4692 // Uses lexer.Location because semicolon location is not kept in quick mode
4693 $$ = new EmptyStatement (lexer.Location);
4698 : identifier_inside_body COLON
4700 var lt = (Tokenizer.LocatedToken) $1;
4701 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4702 lbag.AddLocation (labeled, GetLocation ($2));
4703 current_block.AddLabel (labeled);
4704 current_block.AddStatement (labeled);
4710 : variable_type_simple
4711 | variable_type_simple rank_specifiers
4714 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4716 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4721 * The following is from Rhys' grammar:
4722 * > Types in local variable declarations must be recognized as
4723 * > expressions to prevent reduce/reduce errors in the grammar.
4724 * > The expressions are converted into types during semantic analysis.
4726 variable_type_simple
4727 : primary_expression_or_type opt_nullable
4729 // Ok, the above "primary_expression" is there to get rid of
4730 // both reduce/reduce and shift/reduces in the grammar, it should
4731 // really just be "type_name". If you use type_name, a reduce/reduce
4732 // creeps up. If you use namespace_or_type_name (which is all we need
4733 // really) two shift/reduces appear.
4736 // So the super-trick is that primary_expression
4737 // can only be either a SimpleName or a MemberAccess.
4738 // The MemberAccess case arises when you have a fully qualified type-name like :
4740 // SimpleName is when you have
4743 Expression expr = (Expression) $1;
4745 SimpleName sn = expr as SimpleName;
4746 if (sn != null && sn.Name == "var")
4747 $$ = new VarExpr (sn.Location);
4750 } else if (expr is ATypeNameExpression) {
4751 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4753 Error_ExpectingTypeName (expr);
4757 | primary_expression_or_type pointer_stars
4759 ATypeNameExpression expr = $1 as ATypeNameExpression;
4762 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4764 Error_ExpectingTypeName ((Expression)$1);
4768 | builtin_types opt_nullable
4773 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4775 | builtin_types pointer_stars
4777 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4779 | VOID pointer_stars
4781 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4785 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
4786 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
4792 | pointer_star pointer_stars
4794 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4802 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4806 identifier_inside_body
4811 report.Error (4003, GetLocation ($1), "`await' cannot be used as an identifier within an async method or lambda expression");
4812 $$ = Tokenizer.LocatedToken.Create ("await", GetLocation ($1));
4817 block_variable_declaration
4818 : variable_type identifier_inside_body
4820 var lt = (Tokenizer.LocatedToken) $2;
4821 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4822 current_block.AddLocalName (li);
4823 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4825 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4827 $$ = current_variable;
4828 current_variable = null;
4829 lbag.AddLocation ($$, GetLocation ($6));
4831 | CONST variable_type identifier_inside_body
4833 var lt = (Tokenizer.LocatedToken) $3;
4834 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4835 current_block.AddLocalName (li);
4836 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4838 const_variable_initializer opt_const_declarators SEMICOLON
4840 $$ = current_variable;
4841 current_variable = null;
4842 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4846 opt_local_variable_initializer
4848 | ASSIGN block_variable_initializer
4850 current_variable.Initializer = (Expression) $2;
4855 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4856 report.Error (650, lexer.Location,
4857 "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");
4859 Error_SyntaxError (yyToken);
4864 opt_variable_declarators
4866 | variable_declarators
4869 opt_using_or_fixed_variable_declarators
4871 | variable_declarators
4873 foreach (var d in current_variable.Declarators) {
4874 if (d.Initializer == null)
4875 Error_MissingInitializer (d.Variable.Location);
4880 variable_declarators
4881 : variable_declarator
4882 | variable_declarators variable_declarator
4886 : COMMA identifier_inside_body
4888 var lt = (Tokenizer.LocatedToken) $2;
4889 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4890 var d = new BlockVariableDeclaration.Declarator (li, null);
4891 current_variable.AddDeclarator (d);
4892 current_block.AddLocalName (li);
4893 lbag.AddLocation (d, GetLocation ($1));
4895 | COMMA identifier_inside_body ASSIGN block_variable_initializer
4897 var lt = (Tokenizer.LocatedToken) $2;
4898 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4899 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4900 current_variable.AddDeclarator (d);
4901 current_block.AddLocalName (li);
4902 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4906 const_variable_initializer
4909 report.Error (145, lexer.Location, "A const field requires a value to be provided");
4911 | ASSIGN constant_initializer_expr
4913 current_variable.Initializer = (Expression) $2;
4917 opt_const_declarators
4924 | const_declarators const_declarator
4928 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
4930 var lt = (Tokenizer.LocatedToken) $2;
4931 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4932 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4933 current_variable.AddDeclarator (d);
4934 current_block.AddLocalName (li);
4935 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4939 block_variable_initializer
4940 : variable_initializer
4941 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4943 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4944 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4946 | STACKALLOC simple_type
4948 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4949 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4953 expression_statement
4954 : statement_expression SEMICOLON
4957 lbag.AddStatement ($$, GetLocation ($2));
4959 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4960 | statement_expression CLOSE_BRACE
4963 report.Error (1002, GetLocation ($2), "; expected");
4964 lexer.putback ('}');
4968 interactive_expression_statement
4969 : interactive_statement_expression SEMICOLON { $$ = $1; }
4970 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4974 // We have to do the wrapping here and not in the case above,
4975 // because statement_expression is used for example in for_statement
4977 statement_expression
4980 ExpressionStatement s = $1 as ExpressionStatement;
4982 Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
4983 $$ = new StatementErrorExpression ($1 as Expression);
4985 $$ = new StatementExpression (s);
4990 interactive_statement_expression
4993 Expression expr = (Expression) $1;
4994 ExpressionStatement s;
4996 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4997 $$ = new StatementExpression (s);
5001 Error_SyntaxError (yyToken);
5002 $$ = new EmptyStatement (GetLocation ($1));
5012 : IF open_parens_any boolean_expression CLOSE_PARENS
5015 if ($5 is EmptyStatement)
5016 Warning_EmptyStatement (GetLocation ($5));
5018 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5019 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5021 | IF open_parens_any boolean_expression CLOSE_PARENS
5022 embedded_statement ELSE embedded_statement
5024 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5025 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5027 if ($5 is EmptyStatement)
5028 Warning_EmptyStatement (GetLocation ($5));
5029 if ($7 is EmptyStatement)
5030 Warning_EmptyStatement (GetLocation ($7));
5032 | IF open_parens_any boolean_expression error
5034 Error_SyntaxError (yyToken);
5036 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5037 lbag.AddStatement ($$, GetLocation ($2));
5042 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5044 start_block (GetLocation ($5));
5046 opt_switch_sections CLOSE_BRACE
5048 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
5049 end_block (GetLocation ($8));
5050 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5052 | SWITCH open_parens_any expression error
5054 Error_SyntaxError (yyToken);
5056 $$ = new Switch ((Expression) $3, null, null, GetLocation ($1));
5057 lbag.AddStatement ($$, GetLocation ($2));
5064 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5065 $$ = new List<SwitchSection> ();
5073 var sections = new List<SwitchSection> (4);
5075 sections.Add ((SwitchSection) $1);
5078 | switch_sections switch_section
5080 var sections = (List<SwitchSection>) $1;
5082 sections.Add ((SwitchSection) $2);
5087 Error_SyntaxError (yyToken);
5088 $$ = new List<SwitchSection> ();
5095 current_block = current_block.CreateSwitchBlock (lexer.Location);
5099 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
5106 var labels = new List<SwitchLabel> (2);
5108 labels.Add ((SwitchLabel) $1);
5111 | switch_labels switch_label
5113 var labels = (List<SwitchLabel>) ($1);
5114 labels.Add ((SwitchLabel) $2);
5121 : CASE constant_expression COLON
5123 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5124 lbag.AddLocation ($$, GetLocation ($3));
5126 | CASE constant_expression error
5128 Error_SyntaxError (yyToken);
5129 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5133 $$ = new SwitchLabel (null, GetLocation ($1));
5145 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5147 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5148 Warning_EmptyStatement (GetLocation ($5));
5150 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5151 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5153 | WHILE open_parens_any boolean_expression error
5155 Error_SyntaxError (yyToken);
5157 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5158 lbag.AddStatement ($$, GetLocation ($2));
5163 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5165 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5166 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5168 | DO embedded_statement error
5170 Error_SyntaxError (yyToken);
5171 $$ = new Do ((Statement) $2, null, GetLocation ($1));
5173 | DO embedded_statement WHILE open_parens_any boolean_expression error
5175 Error_SyntaxError (yyToken);
5177 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5178 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5183 : FOR open_parens_any
5185 start_block (GetLocation ($2));
5186 current_block.IsCompilerGenerated = true;
5187 For f = new For (GetLocation ($1));
5188 current_block.AddStatement (f);
5197 // Has to use be extra rule to recover started block
5199 : opt_for_initializer SEMICOLON
5201 ((For) $0).Initializer = (Statement) $1;
5203 // Pass the "For" object to the iterator_part4
5204 oob_stack.Push ($0);
5206 for_condition_and_iterator_part
5209 var locations = (Tuple<Location,Location>) $4;
5211 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5212 Warning_EmptyStatement (GetLocation ($5));
5215 f.Statement = (Statement) $5;
5216 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5218 $$ = end_block (GetLocation ($2));
5222 Error_SyntaxError (yyToken);
5223 $$ = end_block (current_block.StartLocation);
5227 for_condition_and_iterator_part
5228 : opt_for_condition SEMICOLON
5230 For f = (For) oob_stack.Peek ();
5231 f.Condition = (BooleanExpression) $1;
5234 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5237 // Handle errors in the case of opt_for_condition being followed by
5238 // a close parenthesis
5239 | opt_for_condition close_parens_close_brace {
5240 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5241 For f = (For) oob_stack.Peek ();
5242 f.Condition = (BooleanExpression) $1;
5243 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5248 : opt_for_iterator CLOSE_PARENS {
5249 For f = (For) oob_stack.Peek ();
5250 f.Iterator = (Statement) $1;
5251 $$ = GetLocation ($2);
5253 | opt_for_iterator CLOSE_BRACE {
5254 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5255 For f = (For) oob_stack.Peek ();
5256 f.Iterator = (Statement) $1;
5257 $$ = GetLocation ($2);
5261 close_parens_close_brace
5263 | CLOSE_BRACE { lexer.putback ('}'); }
5267 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5272 : variable_type identifier_inside_body
5274 var lt = (Tokenizer.LocatedToken) $2;
5275 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5276 current_block.AddLocalName (li);
5277 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5279 opt_local_variable_initializer opt_variable_declarators
5281 $$ = current_variable;
5282 current_variable = null;
5284 | statement_expression_list
5288 : /* empty */ { $$ = null; }
5289 | boolean_expression
5293 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5298 : statement_expression_list
5301 statement_expression_list
5302 : statement_expression
5303 | statement_expression_list COMMA statement_expression
5305 var sl = $1 as StatementList;
5307 sl = new StatementList ((Statement) $1, (Statement) $3);
5308 lbag.AddStatement (sl, GetLocation ($2));
5310 sl.Add ((Statement) $3);
5311 lbag.AppendTo (sl, GetLocation ($2));
5319 : FOREACH open_parens_any type error
5321 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5323 start_block (GetLocation ($2));
5324 current_block.IsCompilerGenerated = true;
5326 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5327 current_block.AddStatement (f);
5329 lbag.AddStatement (f, GetLocation ($2));
5330 $$ = end_block (GetLocation ($4));
5332 | FOREACH open_parens_any type identifier_inside_body error
5334 Error_SyntaxError (yyToken);
5336 start_block (GetLocation ($2));
5337 current_block.IsCompilerGenerated = true;
5339 var lt = (Tokenizer.LocatedToken) $4;
5340 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5341 current_block.AddLocalName (li);
5343 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5344 current_block.AddStatement (f);
5346 lbag.AddStatement (f, GetLocation ($2));
5347 $$ = end_block (GetLocation ($5));
5349 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5351 start_block (GetLocation ($2));
5352 current_block.IsCompilerGenerated = true;
5354 var lt = (Tokenizer.LocatedToken) $4;
5355 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5356 current_block.AddLocalName (li);
5361 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5362 Warning_EmptyStatement (GetLocation ($9));
5364 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5365 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5366 end_block (GetLocation ($7));
5374 | continue_statement
5384 $$ = new Break (GetLocation ($1));
5385 lbag.AddStatement ($$, GetLocation ($2));
5390 : CONTINUE SEMICOLON
5392 $$ = new Continue (GetLocation ($1));
5393 lbag.AddStatement ($$, GetLocation ($2));
5397 Error_SyntaxError (yyToken);
5398 $$ = new Continue (GetLocation ($1));
5403 : GOTO identifier_inside_body SEMICOLON
5405 var lt = (Tokenizer.LocatedToken) $2;
5406 $$ = new Goto (lt.Value, GetLocation ($1));
5407 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5409 | GOTO CASE constant_expression SEMICOLON
5411 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5412 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5414 | GOTO DEFAULT SEMICOLON
5416 $$ = new GotoDefault (GetLocation ($1));
5417 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5422 : RETURN opt_expression SEMICOLON
5424 $$ = new Return ((Expression) $2, GetLocation ($1));
5425 lbag.AddStatement ($$, GetLocation ($3));
5429 Error_SyntaxError (yyToken);
5430 $$ = new Return (null, GetLocation ($1));
5435 : THROW opt_expression SEMICOLON
5437 $$ = new Throw ((Expression) $2, GetLocation ($1));
5438 lbag.AddStatement ($$, GetLocation ($3));
5442 Error_SyntaxError (yyToken);
5443 $$ = new Throw (null, GetLocation ($1));
5448 : identifier_inside_body RETURN opt_expression SEMICOLON
5450 var lt = (Tokenizer.LocatedToken) $1;
5451 string s = lt.Value;
5453 report.Error (1003, lt.Location, "; expected");
5454 } else if ($3 == null) {
5455 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5456 } else if (lang_version == LanguageVersion.ISO_1){
5457 FeatureIsNotAvailable (lt.Location, "iterators");
5460 current_block.Explicit.RegisterIteratorYield ();
5461 $$ = new Yield ((Expression) $3, lt.Location);
5462 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5464 | identifier_inside_body BREAK SEMICOLON
5466 var lt = (Tokenizer.LocatedToken) $1;
5467 string s = lt.Value;
5469 report.Error (1003, lt.Location, "; expected");
5470 } else if (lang_version == LanguageVersion.ISO_1){
5471 FeatureIsNotAvailable (lt.Location, "iterators");
5474 current_block.Explicit.RegisterIteratorYield ();
5475 $$ = new YieldBreak (lt.Location);
5476 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5486 : TRY block catch_clauses
5488 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5490 | TRY block FINALLY block
5492 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5493 lbag.AddStatement ($$, GetLocation ($3));
5495 | TRY block catch_clauses FINALLY block
5497 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5498 lbag.AddStatement ($$, GetLocation ($4));
5502 Error_SyntaxError (1524, yyToken);
5503 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5510 var l = new List<Catch> (2);
5515 | catch_clauses catch_clause
5517 var l = (List<Catch>) $1;
5519 Catch c = (Catch) $2;
5520 if (l [l.Count - 1].IsGeneral) {
5521 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5531 | identifier_inside_body
5537 $$ = new Catch ((Block) $2, GetLocation ($1));
5539 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5541 start_block (GetLocation ($2));
5542 var c = new Catch (current_block, GetLocation ($1));
5543 c.TypeExpression = (FullNamedExpression) $3;
5546 var lt = (Tokenizer.LocatedToken) $4;
5547 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5548 current_block.AddLocalName (c.Variable);
5551 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5558 | CATCH open_parens_any error
5560 if (yyToken == Token.CLOSE_PARENS) {
5561 report.Error (1015, lexer.Location,
5562 "A type that derives from `System.Exception', `object', or `string' expected");
5564 Error_SyntaxError (yyToken);
5567 $$ = new Catch (null, GetLocation ($1));
5574 $$ = new Checked ((Block) $2, GetLocation ($1));
5581 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5588 if (!settings.Unsafe)
5589 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5591 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5596 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5598 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5599 Warning_EmptyStatement (GetLocation ($5));
5601 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5602 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5604 | LOCK open_parens_any expression error
5606 Error_SyntaxError (yyToken);
5608 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
5609 lbag.AddStatement ($$, GetLocation ($2));
5614 : FIXED open_parens_any variable_type identifier_inside_body
5616 start_block (GetLocation ($2));
5618 current_block.IsCompilerGenerated = true;
5619 var lt = (Tokenizer.LocatedToken) $4;
5620 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5621 current_block.AddLocalName (li);
5622 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5624 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
5626 $$ = current_variable;
5627 current_variable = null;
5631 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5632 Warning_EmptyStatement (GetLocation ($10));
5634 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5635 current_block.AddStatement (f);
5636 $$ = end_block (GetLocation ($8));
5641 : USING open_parens_any variable_type identifier_inside_body
5643 start_block (GetLocation ($2));
5645 current_block.IsCompilerGenerated = true;
5646 var lt = (Tokenizer.LocatedToken) $4;
5647 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5648 current_block.AddLocalName (li);
5649 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5651 using_initialization CLOSE_PARENS
5653 $$ = current_variable;
5654 current_variable = null;
5658 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5659 Warning_EmptyStatement (GetLocation ($9));
5661 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
5662 current_block.AddStatement (u);
5663 $$ = end_block (GetLocation ($7));
5665 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5667 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5668 Warning_EmptyStatement (GetLocation ($5));
5670 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5671 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5673 | USING open_parens_any expression error
5675 Error_SyntaxError (yyToken);
5677 $$ = new Using ((Expression) $3, null, GetLocation ($1));
5678 lbag.AddStatement ($$, GetLocation ($2));
5682 using_initialization
5683 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
5686 // It has to be here for the parent to safely restore artificial block
5687 Error_SyntaxError (yyToken);
5691 using_or_fixed_variable_initializer
5694 Error_MissingInitializer (lexer.Location);
5696 | ASSIGN variable_initializer
5698 current_variable.Initializer = (Expression) $2;
5699 $$ = current_variable;
5707 : first_from_clause query_body
5709 lexer.query_parsing = false;
5711 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5713 from.Tail.Next = (Linq.AQueryClause)$2;
5716 current_block.SetEndLocation (lexer.Location);
5717 current_block = current_block.Parent;
5719 | nested_from_clause query_body
5721 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5723 from.Tail.Next = (Linq.AQueryClause)$2;
5726 current_block.SetEndLocation (lexer.Location);
5727 current_block = current_block.Parent;
5730 // Bubble up COMPLETE_COMPLETION productions
5731 | first_from_clause COMPLETE_COMPLETION {
5732 lexer.query_parsing = false;
5735 current_block.SetEndLocation (lexer.Location);
5736 current_block = current_block.Parent;
5738 | nested_from_clause COMPLETE_COMPLETION {
5740 current_block.SetEndLocation (lexer.Location);
5741 current_block = current_block.Parent;
5746 : FROM_FIRST identifier_inside_body IN expression
5748 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5750 var lt = (Tokenizer.LocatedToken) $2;
5751 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5752 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5754 | FROM_FIRST type identifier_inside_body IN expression
5756 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5758 var lt = (Tokenizer.LocatedToken) $3;
5759 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5760 $$ = new Linq.QueryExpression (
5761 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5762 IdentifierType = (FullNamedExpression)$2
5769 : FROM identifier_inside_body IN expression
5771 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5773 var lt = (Tokenizer.LocatedToken) $2;
5774 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5775 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5777 | FROM type identifier_inside_body IN expression
5779 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5781 var lt = (Tokenizer.LocatedToken) $3;
5782 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5783 $$ = new Linq.QueryExpression (
5784 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5785 IdentifierType = (FullNamedExpression)$2
5792 : FROM identifier_inside_body IN
5794 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5798 var lt = (Tokenizer.LocatedToken) $2;
5799 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5800 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5802 current_block.SetEndLocation (lexer.Location);
5803 current_block = current_block.Parent;
5805 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5807 | FROM type identifier_inside_body IN
5809 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5813 var lt = (Tokenizer.LocatedToken) $3;
5814 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5816 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5817 IdentifierType = (FullNamedExpression)$2
5820 current_block.SetEndLocation (lexer.Location);
5821 current_block = current_block.Parent;
5823 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5828 : query_body_clauses select_or_group_clause opt_query_continuation
5830 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5833 head.Next = (Linq.AQueryClause)$3;
5836 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5837 clause.Tail.Next = head;
5843 | select_or_group_clause opt_query_continuation
5845 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5848 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5849 clause.Tail.Next = head;
5855 | query_body_clauses COMPLETE_COMPLETION
5856 | query_body_clauses error
5858 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
5863 Error_SyntaxError (yyToken);
5868 select_or_group_clause
5871 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5875 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5877 current_block.SetEndLocation (lexer.Location);
5878 current_block = current_block.Parent;
5882 if (linq_clause_blocks == null)
5883 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5885 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5886 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5890 current_block.SetEndLocation (lexer.Location);
5891 current_block = current_block.Parent;
5893 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5895 BY expression_or_error
5897 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5898 lbag.AddLocation ($$, GetLocation ($5));
5900 current_block.SetEndLocation (lexer.Location);
5901 current_block = current_block.Parent;
5907 | query_body_clauses query_body_clause
5909 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5923 : LET identifier_inside_body ASSIGN
5925 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5929 var lt = (Tokenizer.LocatedToken) $2;
5930 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5931 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5932 lbag.AddLocation ($$, GetLocation ($3));
5934 current_block.SetEndLocation (lexer.Location);
5935 current_block = current_block.Parent;
5937 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5944 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5948 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5950 current_block.SetEndLocation (lexer.Location);
5951 current_block = current_block.Parent;
5956 : JOIN identifier_inside_body IN
5958 if (linq_clause_blocks == null)
5959 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5961 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5962 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5964 expression_or_error ON
5966 current_block.SetEndLocation (lexer.Location);
5967 current_block = current_block.Parent;
5969 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5970 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5972 expression_or_error EQUALS
5974 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5975 current_block.SetEndLocation (lexer.Location);
5976 current_block = current_block.Parent;
5978 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5980 expression_or_error opt_join_into
5982 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5983 current_block.SetEndLocation (lexer.Location);
5985 var outer_selector = linq_clause_blocks.Pop ();
5986 var block = linq_clause_blocks.Pop ();
5988 var lt = (Tokenizer.LocatedToken) $2;
5989 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5990 Linq.RangeVariable into;
5994 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5995 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
5998 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6000 var parent = block.Parent;
6001 while (parent is Linq.QueryBlock) {
6002 parent = parent.Parent;
6004 current_block.Parent = parent;
6006 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6008 lt = (Tokenizer.LocatedToken) $12;
6009 into = new Linq.RangeVariable (lt.Value, lt.Location);
6011 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6012 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6015 current_block = block.Parent;
6016 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6018 | JOIN type identifier_inside_body IN
6020 if (linq_clause_blocks == null)
6021 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6023 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6024 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6026 expression_or_error ON
6028 current_block.SetEndLocation (lexer.Location);
6029 current_block = current_block.Parent;
6031 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6032 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6034 expression_or_error EQUALS
6036 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6037 current_block.SetEndLocation (lexer.Location);
6038 current_block = current_block.Parent;
6040 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6042 expression_or_error opt_join_into
6044 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6045 current_block.SetEndLocation (lexer.Location);
6047 var outer_selector = linq_clause_blocks.Pop ();
6048 var block = linq_clause_blocks.Pop ();
6050 var lt = (Tokenizer.LocatedToken) $3;
6051 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6052 Linq.RangeVariable into;
6056 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6057 IdentifierType = (FullNamedExpression)$2
6061 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6063 var parent = block.Parent;
6064 while (parent is Linq.QueryBlock) {
6065 parent = parent.Parent;
6067 current_block.Parent = parent;
6069 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6071 lt = (Tokenizer.LocatedToken) $13;
6072 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6074 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6075 IdentifierType = (FullNamedExpression)$2
6079 current_block = block.Parent;
6080 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6086 | INTO identifier_inside_body
6095 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6099 current_block.SetEndLocation (lexer.Location);
6100 current_block = current_block.Parent;
6110 current_block.SetEndLocation (lexer.Location);
6111 current_block = current_block.Parent;
6113 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6117 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6124 | orderings_then_by COMMA
6126 current_block.SetEndLocation (lexer.Location);
6127 current_block = current_block.Parent;
6129 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6133 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6141 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6143 | expression ASCENDING
6145 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6146 lbag.AddLocation ($$, GetLocation ($2));
6148 | expression DESCENDING
6150 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6151 lbag.AddLocation ($$, GetLocation ($2));
6158 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6160 | expression ASCENDING
6162 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6163 lbag.AddLocation ($$, GetLocation ($2));
6165 | expression DESCENDING
6167 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6168 lbag.AddLocation ($$, GetLocation ($2));
6173 opt_query_continuation
6175 | INTO identifier_inside_body
6177 // query continuation block is not linked with query block but with block
6178 // before. This means each query can use same range variable names for
6179 // different identifiers.
6181 current_block.SetEndLocation (GetLocation ($1));
6182 current_block = current_block.Parent;
6184 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6186 if (linq_clause_blocks == null)
6187 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6189 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6193 var current_block = linq_clause_blocks.Pop ();
6194 var lt = (Tokenizer.LocatedToken) $2;
6195 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6196 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6197 next = (Linq.AQueryClause)$4
6203 // Support for using the compiler as an interactive parser
6205 // The INTERACTIVE_PARSER token is first sent to parse our
6206 // productions; If the result is a Statement, the parsing
6207 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6208 // to setup the blocks in advance.
6210 // This setup is here so that in the future we can add
6211 // support for other constructs (type parsing, namespaces, etc)
6212 // that do not require a block to be setup in advance
6216 : EVAL_STATEMENT_PARSER EOF
6217 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6218 | EVAL_STATEMENT_PARSER
6220 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6222 // (ref object retval)
6223 Parameter [] mpar = new Parameter [1];
6224 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6226 ParametersCompiled pars = new ParametersCompiled (mpar);
6227 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6228 if (settings.Unsafe)
6229 mods |= Modifiers.UNSAFE;
6231 current_local_parameters = pars;
6232 Method method = new Method (
6234 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6236 new MemberName ("Host"),
6238 null /* attributes */);
6240 current_type.AddMember (method);
6242 oob_stack.Push (method);
6243 ++lexer.parsing_block;
6244 start_block (lexer.Location);
6246 interactive_statement_list opt_COMPLETE_COMPLETION
6248 --lexer.parsing_block;
6249 Method method = (Method) oob_stack.Pop ();
6251 method.Block = (ToplevelBlock) end_block(lexer.Location);
6253 InteractiveResult = (Class) pop_current_class ();
6254 current_local_parameters = null;
6256 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6259 interactive_compilation_unit
6260 : opt_extern_alias_directives opt_using_directives
6261 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6264 opt_COMPLETE_COMPLETION
6266 | COMPLETE_COMPLETION
6269 close_brace_or_complete_completion
6271 | COMPLETE_COMPLETION
6275 // XML documentation code references micro parser
6277 documentation_parsing
6280 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6285 : doc_type_declaration_name opt_doc_method_sig
6287 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6289 | builtin_types opt_doc_method_sig
6291 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6292 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6295 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6297 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6298 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6299 var lt = (Tokenizer.LocatedToken) $3;
6300 $$ = new MemberName (lt.Value);
6302 | doc_type_declaration_name DOT THIS
6304 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6306 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6308 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6310 opt_doc_parameters CLOSE_BRACKET
6312 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6313 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6315 | EXPLICIT OPERATOR type opt_doc_method_sig
6317 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6318 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6319 module.DocumentationBuilder.ParsedParameters = p;
6320 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6323 | IMPLICIT OPERATOR type opt_doc_method_sig
6325 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6326 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6327 module.DocumentationBuilder.ParsedParameters = p;
6328 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6331 | OPERATOR overloadable_operator opt_doc_method_sig
6333 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6334 module.DocumentationBuilder.ParsedParameters = p;
6335 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6340 doc_type_declaration_name
6341 : type_declaration_name
6342 | doc_type_declaration_name DOT type_declaration_name
6344 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6352 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6354 opt_doc_parameters CLOSE_PARENS
6363 $$ = new List<DocumentationParameter> (0);
6371 var parameters = new List<DocumentationParameter> ();
6372 parameters.Add ((DocumentationParameter) $1);
6375 | doc_parameters COMMA doc_parameter
6377 var parameters = $1 as List<DocumentationParameter>;
6378 parameters.Add ((DocumentationParameter) $3);
6384 : opt_parameter_modifier parameter_type
6387 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6389 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6396 // A class used to hold info about an operator declarator
6398 class OperatorDeclaration {
6399 public readonly Operator.OpType optype;
6400 public readonly FullNamedExpression ret_type;
6401 public readonly Location location;
6403 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6406 this.ret_type = ret_type;
6407 this.location = location;
6411 void Error_ExpectingTypeName (Expression expr)
6413 if (expr is Invocation){
6414 report.Error (1002, expr.Location, "Expecting `;'");
6416 Expression.Error_InvalidExpressionStatement (report, expr.Location);
6420 void Error_ParameterModifierNotValid (string modifier, Location loc)
6422 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6426 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6428 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6429 Parameter.GetModifierSignature (mod));
6432 void Error_TypeExpected (Location loc)
6434 report.Error (1031, loc, "Type expected");
6437 void Error_UnsafeCodeNotAllowed (Location loc)
6439 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6442 void Warning_EmptyStatement (Location loc)
6444 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6447 void Error_NamedArgumentExpected (NamedArgument a)
6449 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6452 void Error_MissingInitializer (Location loc)
6454 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6457 void push_current_container (TypeDefinition tc, object partial_token)
6459 if (module.Evaluator != null){
6460 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6464 undo.AddTypeContainer (current_container, tc);
6467 if (partial_token != null)
6468 current_container.AddPartial (tc);
6470 current_container.AddTypeContainer (tc);
6472 ++lexer.parsing_declaration;
6473 current_container = tc;
6477 TypeContainer pop_current_class ()
6479 var retval = current_container;
6481 current_container = current_container.Parent;
6482 current_type = current_type.Parent as TypeDefinition;
6487 [System.Diagnostics.Conditional ("FULL_AST")]
6488 void StoreModifierLocation (object token, Location loc)
6493 if (mod_locations == null)
6494 mod_locations = new List<Tuple<Modifiers, Location>> ();
6496 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6499 string CheckAttributeTarget (string a, Location l)
6502 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6506 report.Warning (658, 1, l,
6507 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6508 return string.Empty;
6511 static bool IsUnaryOperator (Operator.OpType op)
6515 case Operator.OpType.LogicalNot:
6516 case Operator.OpType.OnesComplement:
6517 case Operator.OpType.Increment:
6518 case Operator.OpType.Decrement:
6519 case Operator.OpType.True:
6520 case Operator.OpType.False:
6521 case Operator.OpType.UnaryPlus:
6522 case Operator.OpType.UnaryNegation:
6528 void syntax_error (Location l, string msg)
6530 report.Error (1003, l, "Syntax error, " + msg);
6535 public Tokenizer Lexer {
6541 static CSharpParser ()
6543 oob_stack = new Stack<object> ();
6546 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file)
6547 : this (reader, file, file.Compiler.Report)
6551 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report)
6554 current_container = current_namespace = file;
6556 this.module = file.Module;
6557 this.compiler = file.Compiler;
6558 this.settings = compiler.Settings;
6559 this.report = report;
6561 lang_version = settings.Version;
6562 yacc_verbose_flag = settings.VerboseParserFlag;
6563 doc_support = settings.DocumentationFile != null;
6565 lexer = new Tokenizer (reader, file);
6568 lbag = new LocationsBag ();
6573 use_global_stacks = true;
6576 public void parse ()
6578 eof_token = Token.EOF;
6579 Tokenizer.LocatedToken.Initialize ();
6582 if (yacc_verbose_flag > 1)
6583 yyparse (lexer, new yydebug.yyDebugSimple ());
6587 Tokenizer tokenizer = lexer as Tokenizer;
6588 tokenizer.cleanup ();
6589 } catch (Exception e){
6590 if (e is yyParser.yyUnexpectedEof) {
6591 Error_SyntaxError (yyToken);
6592 UnexpectedEOF = true;
6596 if (e is yyParser.yyException) {
6597 report.Error (-25, lexer.Location, "Parsing error");
6599 // Used by compiler-tester to test internal errors
6600 if (yacc_verbose_flag > 0 || e is FatalException)
6603 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
6608 void CheckToken (int error, int yyToken, string msg, Location loc)
6610 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6611 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6613 report.Error (error, loc, msg);
6616 string ConsumeStoredComment ()
6618 string s = tmpComment;
6620 Lexer.doc_state = XmlCommentState.Allowed;
6624 void FeatureIsNotAvailable (Location loc, string feature)
6626 report.FeatureIsNotAvailable (compiler, loc, feature);
6629 Location GetLocation (object obj)
6631 var lt = obj as Tokenizer.LocatedToken;
6635 var mn = obj as MemberName;
6639 var expr = obj as Expression;
6641 return expr.Location;
6643 return lexer.Location;
6646 public LocationsBag LocationsBag {
6652 void start_block (Location loc)
6654 if (current_block == null) {
6655 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6656 parsing_anonymous_method = false;
6657 } else if (parsing_anonymous_method) {
6658 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6659 parsing_anonymous_method = false;
6661 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6666 end_block (Location loc)
6668 Block retval = current_block.Explicit;
6669 retval.SetEndLocation (loc);
6670 current_block = retval.Parent;
6674 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
6676 oob_stack.Push (current_anonymous_method);
6677 oob_stack.Push (current_local_parameters);
6678 oob_stack.Push (current_variable);
6679 oob_stack.Push (async_block);
6681 current_local_parameters = parameters;
6683 if (lang_version <= LanguageVersion.ISO_2)
6684 FeatureIsNotAvailable (loc, "lambda expressions");
6686 current_anonymous_method = new LambdaExpression (loc);
6688 if (lang_version == LanguageVersion.ISO_1)
6689 FeatureIsNotAvailable (loc, "anonymous methods");
6691 current_anonymous_method = new AnonymousMethodExpression (loc);
6694 async_block = isAsync;
6695 // Force the next block to be created as a ToplevelBlock
6696 parsing_anonymous_method = true;
6700 * Completes the anonymous method processing, if lambda_expr is null, this
6701 * means that we have a Statement instead of an Expression embedded
6703 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6705 AnonymousMethodExpression retval;
6708 anon_block.IsAsync = true;
6710 current_anonymous_method.Block = anon_block;
6711 retval = current_anonymous_method;
6713 async_block = (bool) oob_stack.Pop ();
6714 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6715 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6716 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6721 void Error_SyntaxError (int token)
6723 Error_SyntaxError (0, token);
6726 void Error_SyntaxError (int error_code, int token)
6728 Error_SyntaxError (error_code, token, "Unexpected symbol");
6731 void Error_SyntaxError (int error_code, int token, string msg)
6733 Lexer.CompleteOnEOF = false;
6735 // An error message has been reported by tokenizer
6736 if (token == Token.ERROR)
6739 string symbol = GetSymbolName (token);
6740 string expecting = GetExpecting ();
6741 var loc = lexer.Location - symbol.Length;
6743 if (error_code == 0) {
6744 if (expecting == "`identifier'") {
6745 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6746 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6751 expecting = "identifier";
6752 } else if (expecting == "`)'") {
6759 if (string.IsNullOrEmpty (expecting))
6760 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6762 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6765 string GetExpecting ()
6767 int [] tokens = yyExpectingTokens (yyExpectingState);
6768 var names = new List<string> (tokens.Length);
6769 bool has_type = false;
6770 bool has_identifier = false;
6771 for (int i = 0; i < tokens.Length; i++){
6772 int token = tokens [i];
6773 has_identifier |= token == Token.IDENTIFIER;
6775 string name = GetTokenName (token);
6776 if (name == "<internal>")
6779 has_type |= name == "type";
6780 if (names.Contains (name))
6787 // Too many tokens to enumerate
6789 if (names.Count > 8)
6792 if (has_type && has_identifier)
6793 names.Remove ("identifier");
6795 if (names.Count == 1)
6796 return "`" + GetTokenName (tokens [0]) + "'";
6798 StringBuilder sb = new StringBuilder ();
6800 int count = names.Count;
6801 for (int i = 0; i < count; i++){
6802 bool last = i + 1 == count;
6806 sb.Append (names [i]);
6807 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6809 return sb.ToString ();
6813 string GetSymbolName (int token)
6817 return ((Constant)lexer.Value).GetValue ().ToString ();
6818 case Token.IDENTIFIER:
6819 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6861 case Token.BITWISE_AND:
6863 case Token.BITWISE_OR:
6877 case Token.OP_SHIFT_LEFT:
6879 case Token.OP_SHIFT_RIGHT:
6899 case Token.OP_COALESCING:
6901 case Token.OP_MULT_ASSIGN:
6903 case Token.OP_DIV_ASSIGN:
6905 case Token.OP_MOD_ASSIGN:
6907 case Token.OP_ADD_ASSIGN:
6909 case Token.OP_SUB_ASSIGN:
6911 case Token.OP_SHIFT_LEFT_ASSIGN:
6913 case Token.OP_SHIFT_RIGHT_ASSIGN:
6915 case Token.OP_AND_ASSIGN:
6917 case Token.OP_XOR_ASSIGN:
6919 case Token.OP_OR_ASSIGN:
6923 return GetTokenName (token);
6926 static string GetTokenName (int token)
6929 case Token.ABSTRACT:
6951 case Token.CONTINUE:
6955 case Token.DELEGATE:
6965 case Token.EXPLICIT:
6968 case Token.EXTERN_ALIAS:
6984 case Token.IMPLICIT:
6988 case Token.INTERFACE:
6990 case Token.INTERNAL:
6996 case Token.NAMESPACE:
7002 case Token.OPERATOR:
7006 case Token.OVERRIDE:
7012 case Token.PROTECTED:
7016 case Token.READONLY:
7028 case Token.STACKALLOC:
7029 return "stackalloc";
7046 case Token.UNCHECKED:
7054 case Token.VOLATILE:
7062 case Token.REFVALUE:
7063 return "__refvalue";
7073 case Token.FROM_FIRST:
7091 case Token.ASCENDING:
7093 case Token.DESCENDING:
7094 return "descending";
7101 case Token.OPEN_BRACE:
7103 case Token.CLOSE_BRACE:
7105 case Token.OPEN_BRACKET:
7106 case Token.OPEN_BRACKET_EXPR:
7108 case Token.CLOSE_BRACKET:
7110 case Token.OPEN_PARENS_CAST:
7111 case Token.OPEN_PARENS_LAMBDA:
7112 case Token.OPEN_PARENS:
7114 case Token.CLOSE_PARENS:
7120 case Token.DEFAULT_COLON:
7124 case Token.SEMICOLON:
7135 case Token.BITWISE_AND:
7136 case Token.BITWISE_OR:
7143 case Token.OP_SHIFT_LEFT:
7144 case Token.OP_SHIFT_RIGHT:
7152 case Token.OP_COALESCING:
7153 case Token.OP_MULT_ASSIGN:
7154 case Token.OP_DIV_ASSIGN:
7155 case Token.OP_MOD_ASSIGN:
7156 case Token.OP_ADD_ASSIGN:
7157 case Token.OP_SUB_ASSIGN:
7158 case Token.OP_SHIFT_LEFT_ASSIGN:
7159 case Token.OP_SHIFT_RIGHT_ASSIGN:
7160 case Token.OP_AND_ASSIGN:
7161 case Token.OP_XOR_ASSIGN:
7162 case Token.OP_OR_ASSIGN:
7163 return "<operator>";
7185 case Token.OP_GENERICS_LT:
7186 case Token.GENERIC_DIMENSION:
7188 case Token.OP_GENERICS_GT:
7191 case Token.INTERR_NULLABLE:
7193 case Token.DOUBLE_COLON:
7197 case Token.IDENTIFIER:
7199 return "identifier";
7202 return "end-of-file";
7204 // All of these are internal.
7207 case Token.FIRST_KEYWORD:
7208 case Token.EVAL_COMPILATION_UNIT_PARSER:
7209 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7210 case Token.EVAL_STATEMENT_PARSER:
7211 case Token.LAST_KEYWORD:
7212 case Token.GENERATE_COMPLETION:
7213 case Token.COMPLETE_COMPLETION:
7214 return "<internal>";
7216 // A bit more robust.
7218 return yyNames [token];