3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnome.org)
6 // Ravi Pratap (ravi@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004-2011 Novell, Inc
13 // Copyright 2011-2012 Xamarin Inc.
19 using System.Collections.Generic;
26 public class CSharpParser
29 enum ParameterModifierType
36 DefaultValue = 1 << 6,
38 All = Ref | Out | This | Params | Arglist | DefaultValue
41 static readonly object ModifierNone = 0;
43 NamespaceContainer current_namespace;
44 TypeContainer current_container;
45 TypeDefinition current_type;
46 PropertyBase current_property;
47 EventProperty current_event;
48 EventField current_event_field;
49 FieldBase current_field;
52 /// Current block is used to add statements as we find
57 BlockVariableDeclaration current_variable;
59 Delegate current_delegate;
61 AnonymousMethodExpression current_anonymous_method;
64 /// This is used by the unary_expression code to resolve
65 /// a name against a parameter.
68 // FIXME: This is very ugly and it's very hard to reset it correctly
69 // on all places, especially when some parameters are autogenerated.
70 ParametersCompiled current_local_parameters;
72 bool parsing_anonymous_method;
77 /// An out-of-band stack.
79 Stack<object> oob_stack;
82 /// Controls the verbosity of the errors produced by the parser
84 int yacc_verbose_flag;
87 /// Used by the interactive shell, flags whether EOF was reached
88 /// and an error was produced
90 public bool UnexpectedEOF;
95 readonly CompilationSourceFile file;
98 /// Temporary Xml documentation cache.
99 /// For enum types, we need one more temporary store.
102 string enumTypeComment;
104 /// Current attribute target
105 string current_attr_target;
107 ParameterModifierType valid_param_mod;
109 bool default_parameter_used;
111 /// When using the interactive parser, this holds the
112 /// resulting expression
113 public Class InteractiveResult;
116 // Keeps track of global data changes to undo on parser error
120 Stack<Linq.QueryBlock> linq_clause_blocks;
122 ModuleContainer module;
124 readonly CompilerContext compiler;
125 readonly LanguageVersion lang_version;
126 readonly bool doc_support;
127 readonly CompilerSettings settings;
128 readonly Report report;
131 // Instead of allocating carrier array everytime we
132 // share the bucket for very common constructs which can never
135 List<Parameter> parameters_bucket;
138 // Full AST support members
141 List<Tuple<Modifiers, Location>> mod_locations;
145 %token NONE /* This token is never returned by our lexer */
146 %token ERROR // This is used not by the parser, but by the tokenizer.
150 *These are the C# keywords
249 %token INTERR_NULLABLE
257 /* C# keywords which are not really keywords */
263 /* C# single character operators/punctuation. */
291 /* C# multi-character operators. */
296 %token OP_SHIFT_RIGHT
303 %token OP_MULT_ASSIGN
308 %token OP_SHIFT_LEFT_ASSIGN
309 %token OP_SHIFT_RIGHT_ASSIGN
316 /* Generics <,> tokens */
317 %token OP_GENERICS_LT
318 %token OP_GENERICS_LT_DECL
319 %token OP_GENERICS_GT
324 %token OPEN_PARENS_LAMBDA
325 %token OPEN_PARENS_CAST
326 %token GENERIC_DIMENSION
328 %token OPEN_BRACKET_EXPR
330 // Make the parser go into eval mode parsing (statements and compilation units).
331 %token EVAL_STATEMENT_PARSER
332 %token EVAL_COMPILATION_UNIT_PARSER
333 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
338 // This token is generated to trigger the completion engine at this point
340 %token GENERATE_COMPLETION
343 // This token is return repeatedly after the first GENERATE_COMPLETION
344 // token is produced and before the final EOF
346 %token COMPLETE_COMPLETION
348 /* Add precedence rules to solve dangling else s/r conflict */
352 /* Define the operator tokens and their precedences */
360 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
362 %left STAR DIV PERCENT
363 %right BANG CARRET UMINUS
364 %nonassoc OP_INC OP_DEC
366 %left OPEN_BRACKET OPEN_BRACE
369 %start compilation_unit
373 : outer_declaration opt_EOF
375 Lexer.check_incorrect_doc_comment ();
377 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
378 | documentation_parsing
382 : opt_extern_alias_directives opt_using_directives
383 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
386 Attributes attrs = (Attributes) $4;
387 report.Error (1730, attrs.Attrs [0].Location,
388 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
390 current_namespace.UnattachedAttributes = attrs;
393 | opt_extern_alias_directives opt_using_directives attribute_sections
395 module.AddAttributes ((Attributes) $3, current_namespace);
399 if (yyToken == Token.EXTERN_ALIAS)
400 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
402 Error_SyntaxError (yyToken);
411 extern_alias_directives
412 : extern_alias_directive
413 | extern_alias_directives extern_alias_directive
416 extern_alias_directive
417 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
419 var lt = (Tokenizer.LocatedToken) $2;
422 syntax_error (lt.Location, "`alias' expected");
424 if (lang_version == LanguageVersion.ISO_1)
425 FeatureIsNotAvailable (lt.Location, "external alias");
427 lt = (Tokenizer.LocatedToken) $3;
428 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
429 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
432 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
433 current_namespace.AddUsing (na);
435 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
440 Error_SyntaxError (yyToken);
446 | using_directives using_directive
453 Lexer.doc_state = XmlCommentState.Allowed;
458 : USING namespace_or_type_expr SEMICOLON
460 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
461 current_namespace.AddUsing (un);
463 lbag.AddLocation (un, GetLocation ($3));
465 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
467 var lt = (Tokenizer.LocatedToken) $2;
468 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
469 report.Warning (440, 2, lt.Location,
470 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
473 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
474 current_namespace.AddUsing (un);
476 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
480 Error_SyntaxError (yyToken);
486 // Strictly speaking, namespaces don't have attributes but
487 // we parse global attributes along with namespace declarations and then
490 namespace_declaration
491 : opt_attributes NAMESPACE namespace_name
493 Attributes attrs = (Attributes) $1;
494 var name = (MemberName) $3;
496 bool valid_global_attrs = true;
497 if ((current_namespace.DeclarationFound || current_namespace != file)) {
498 valid_global_attrs = false;
500 foreach (var a in attrs.Attrs) {
501 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
504 valid_global_attrs = false;
509 if (!valid_global_attrs)
510 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
513 module.AddAttributes (attrs, current_namespace);
515 var ns = new NamespaceContainer (name, current_namespace);
516 current_namespace.AddTypeContainer (ns);
517 current_container = current_namespace = ns;
522 Lexer.doc_state = XmlCommentState.Allowed;
524 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon
527 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
529 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
531 current_container = current_namespace = current_namespace.Parent;
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 | opt_attributes IDENTIFIER error
2577 Error_SyntaxError (yyToken);
2579 var lt = (Tokenizer.LocatedToken) $2;
2580 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2581 ((Enum) current_type).AddEnumMember (em);
2584 em.DocComment = Lexer.consume_doc_comment ();
2585 Lexer.doc_state = XmlCommentState.Allowed;
2590 | attributes_without_members
2593 delegate_declaration
2597 member_type type_declaration_name
2600 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2602 opt_formal_parameter_list CLOSE_PARENS
2604 valid_param_mod = 0;
2606 ParametersCompiled p = (ParametersCompiled) $8;
2608 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2610 p.CheckParameters (del);
2612 current_container.AddTypeContainer (del);
2614 current_delegate = del;
2615 lexer.ConstraintsParsing = true;
2617 opt_type_parameter_constraints_clauses
2619 lexer.ConstraintsParsing = false;
2624 current_delegate.DocComment = Lexer.consume_doc_comment ();
2625 Lexer.doc_state = XmlCommentState.Allowed;
2629 current_delegate.SetConstraints ((List<Constraints>) $11);
2630 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2632 $$ = current_delegate;
2634 current_delegate = null;
2642 if (lang_version < LanguageVersion.ISO_2)
2643 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2645 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2649 namespace_or_type_expr
2651 | qualified_alias_member IDENTIFIER opt_type_argument_list
2653 var lt1 = (Tokenizer.LocatedToken) $1;
2654 var lt2 = (Tokenizer.LocatedToken) $2;
2656 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2657 lbag.AddLocation ($$, GetLocation ($2));
2663 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2665 var lt = (Tokenizer.LocatedToken) $3;
2666 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2667 lbag.AddLocation ($$, GetLocation ($2));
2672 : IDENTIFIER opt_type_argument_list
2674 var lt = (Tokenizer.LocatedToken) $1;
2675 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2680 // Generics arguments (any type, without attributes)
2682 opt_type_argument_list
2684 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2686 if (lang_version < LanguageVersion.ISO_2)
2687 FeatureIsNotAvailable (GetLocation ($1), "generics");
2691 | OP_GENERICS_LT error
2693 Error_TypeExpected (lexer.Location);
2694 $$ = new TypeArguments ();
2701 TypeArguments type_args = new TypeArguments ();
2702 type_args.Add ((FullNamedExpression) $1);
2705 | type_arguments COMMA type
2707 TypeArguments type_args = (TypeArguments) $1;
2708 type_args.Add ((FullNamedExpression) $3);
2714 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2716 type_declaration_name
2719 lexer.parsing_generic_declaration = true;
2721 opt_type_parameter_list
2723 lexer.parsing_generic_declaration = false;
2724 var lt = (Tokenizer.LocatedToken) $1;
2725 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2729 member_declaration_name
2730 : method_declaration_name
2732 MemberName mn = (MemberName)$1;
2733 if (mn.TypeParameters != null)
2734 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2735 mn.GetSignatureForError ()));
2739 method_declaration_name
2740 : type_declaration_name
2741 | explicit_interface IDENTIFIER opt_type_parameter_list
2743 lexer.parsing_generic_declaration = false;
2744 var lt = (Tokenizer.LocatedToken) $2;
2745 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2749 indexer_declaration_name
2752 lexer.parsing_generic_declaration = false;
2753 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2755 | explicit_interface THIS
2757 lexer.parsing_generic_declaration = false;
2758 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2763 : IDENTIFIER opt_type_argument_list DOT
2765 var lt = (Tokenizer.LocatedToken) $1;
2766 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2767 lbag.AddLocation ($$, GetLocation ($3));
2769 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2771 var lt1 = (Tokenizer.LocatedToken) $1;
2772 var lt2 = (Tokenizer.LocatedToken) $2;
2774 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2775 lbag.AddLocation ($$, GetLocation ($4));
2777 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2779 var lt = (Tokenizer.LocatedToken) $2;
2780 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2781 lbag.AddLocation ($$, GetLocation ($4));
2785 opt_type_parameter_list
2787 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2789 if (lang_version < LanguageVersion.ISO_2)
2790 FeatureIsNotAvailable (GetLocation ($1), "generics");
2793 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2800 var tparams = new TypeParameters ();
2801 tparams.Add ((TypeParameter)$1);
2804 | type_parameters COMMA type_parameter
2806 var tparams = (TypeParameters) $1;
2807 tparams.Add ((TypeParameter)$3);
2809 lbag.AddLocation ($3, GetLocation ($3));
2814 : opt_attributes opt_type_parameter_variance IDENTIFIER
2816 var lt = (Tokenizer.LocatedToken)$3;
2817 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2821 if (GetTokenName (yyToken) == "type")
2822 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2824 Error_SyntaxError (yyToken);
2826 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2831 // All types where void is allowed
2834 : type_expression_or_array
2837 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2844 lexer.parsing_generic_declaration = true;
2849 // A type which does not allow `void' to be used
2852 : type_expression_or_array
2855 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2856 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2864 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2865 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2870 : type_expression_or_array
2873 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2874 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2878 type_expression_or_array
2880 | type_expression rank_specifiers
2882 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2887 : namespace_or_type_expr opt_nullable
2890 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2892 var sn = $1 as SimpleName;
2893 if (sn != null && sn.Name == "var")
2894 $$ = new VarExpr (sn.Location);
2899 | namespace_or_type_expr pointer_stars
2901 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2903 | builtin_types opt_nullable
2906 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2908 | builtin_types pointer_stars
2910 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2912 | VOID pointer_stars
2914 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2921 var types = new List<FullNamedExpression> (2);
2922 types.Add ((FullNamedExpression) $1);
2925 | type_list COMMA base_type_name
2927 var types = (List<FullNamedExpression>) $1;
2928 types.Add ((FullNamedExpression) $3);
2936 if ($1 is ComposedCast) {
2937 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2944 * replaces all the productions for isolating the various
2945 * simple types, but we need this to reuse it easily in variable_type
2948 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
2949 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
2950 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
2951 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
2952 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
2953 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
2958 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
2959 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
2960 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
2961 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
2962 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
2963 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
2964 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
2965 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
2966 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
2970 // Expressions, section 7.5
2975 : primary_expression_or_type
2977 | array_creation_expression
2978 | parenthesized_expression
2979 | default_value_expression
2980 | invocation_expression
2984 | post_increment_expression
2985 | post_decrement_expression
2986 | object_or_delegate_creation_expression
2987 | anonymous_type_expression
2990 | checked_expression
2991 | unchecked_expression
2992 | pointer_member_access
2993 | anonymous_method_expression
2994 | undocumented_expressions
2997 primary_expression_or_type
2998 : IDENTIFIER opt_type_argument_list
3000 var lt = (Tokenizer.LocatedToken) $1;
3001 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3003 | IDENTIFIER GENERATE_COMPLETION {
3004 var lt = (Tokenizer.LocatedToken) $1;
3005 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3013 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3017 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3018 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3023 // Here is the trick, tokenizer may think that parens is a special but
3024 // parser is interested in open parens only, so we merge them.
3025 // Consider: if (a)foo ();
3033 // Use this production to accept closing parenthesis or
3034 // performing completion
3038 | COMPLETE_COMPLETION
3042 parenthesized_expression
3043 : OPEN_PARENS expression CLOSE_PARENS
3045 $$ = new ParenthesizedExpression ((Expression) $2);
3046 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3048 | OPEN_PARENS expression COMPLETE_COMPLETION
3050 $$ = new ParenthesizedExpression ((Expression) $2);
3055 : primary_expression DOT IDENTIFIER opt_type_argument_list
3057 var lt = (Tokenizer.LocatedToken) $3;
3058 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3059 lbag.AddLocation ($$, GetLocation ($2));
3061 | builtin_types DOT IDENTIFIER opt_type_argument_list
3063 var lt = (Tokenizer.LocatedToken) $3;
3064 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3065 lbag.AddLocation ($$, GetLocation ($2));
3067 | BASE DOT IDENTIFIER opt_type_argument_list
3069 var lt = (Tokenizer.LocatedToken) $3;
3070 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3071 lbag.AddLocation ($$, GetLocation ($2));
3073 | qualified_alias_member IDENTIFIER opt_type_argument_list
3075 var lt1 = (Tokenizer.LocatedToken) $1;
3076 var lt2 = (Tokenizer.LocatedToken) $2;
3078 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3079 lbag.AddLocation ($$, GetLocation ($2));
3081 | primary_expression DOT GENERATE_COMPLETION {
3082 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3084 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3085 var lt = (Tokenizer.LocatedToken) $3;
3086 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3088 | builtin_types DOT GENERATE_COMPLETION
3090 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3092 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3093 var lt = (Tokenizer.LocatedToken) $3;
3094 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3098 invocation_expression
3099 : primary_expression open_parens_any opt_argument_list close_parens
3101 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3102 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3104 | primary_expression open_parens_any argument_list error
3106 Error_SyntaxError (yyToken);
3108 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3109 lbag.AddLocation ($$, GetLocation ($2));
3114 opt_object_or_collection_initializer
3115 : /* empty */ { $$ = null; }
3116 | object_or_collection_initializer
3119 object_or_collection_initializer
3120 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3123 $$ = CollectionOrObjectInitializers.Empty;
3126 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3127 lbag.AddLocation ($$, GetLocation ($3));
3130 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3132 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3133 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3137 opt_member_initializer_list
3138 : /* empty */ { $$ = null; }
3139 | member_initializer_list
3145 member_initializer_list
3146 : member_initializer
3148 var a = new List<Expression> ();
3149 a.Add ((Expression) $1);
3152 | member_initializer_list COMMA member_initializer
3154 var a = (List<Expression>)$1;
3155 a.Add ((Expression) $3);
3158 | member_initializer_list error {
3159 Error_SyntaxError (yyToken);
3165 : IDENTIFIER ASSIGN initializer_value
3167 var lt = (Tokenizer.LocatedToken) $1;
3168 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3169 lbag.AddLocation ($$, GetLocation ($2));
3171 | GENERATE_COMPLETION
3173 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3175 | non_assignment_expression opt_COMPLETE_COMPLETION {
3176 CompletionSimpleName csn = $1 as CompletionSimpleName;
3178 $$ = new CollectionElementInitializer ((Expression)$1);
3180 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3182 | OPEN_BRACE expression_list CLOSE_BRACE
3187 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3189 | OPEN_BRACE CLOSE_BRACE
3191 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3198 | object_or_collection_initializer
3202 : /* empty */ { $$ = null; }
3207 : argument_or_named_argument
3209 Arguments list = new Arguments (4);
3210 list.Add ((Argument) $1);
3213 | argument_list COMMA argument
3215 Arguments list = (Arguments) $1;
3216 if (list [list.Count - 1] is NamedArgument)
3217 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3219 list.Add ((Argument) $3);
3222 | argument_list COMMA named_argument
3224 Arguments list = (Arguments) $1;
3225 NamedArgument a = (NamedArgument) $3;
3226 for (int i = 0; i < list.Count; ++i) {
3227 NamedArgument na = list [i] as NamedArgument;
3228 if (na != null && na.Name == a.Name)
3229 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3236 | argument_list COMMA error
3238 lexer.putback (')'); // TODO: Wrong but what can I do
3239 Error_SyntaxError (yyToken);
3244 report.Error (839, GetLocation ($1), "An argument is missing");
3252 $$ = new Argument ((Expression) $1);
3254 | non_simple_argument
3257 argument_or_named_argument
3263 : REF variable_reference
3265 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3266 lbag.AddLocation ($$, GetLocation ($1));
3268 | OUT variable_reference
3270 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3271 lbag.AddLocation ($$, GetLocation ($1));
3273 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3275 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3276 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3278 | ARGLIST OPEN_PARENS CLOSE_PARENS
3280 $$ = new Argument (new Arglist (GetLocation ($1)));
3281 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3290 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3292 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3293 lbag.AddLocation ($$, GetLocation ($4));
3295 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3297 Error_SyntaxError (yyToken);
3298 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3300 | primary_expression OPEN_BRACKET_EXPR error
3302 Error_SyntaxError (yyToken);
3303 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3310 var list = new List<Expression> (4);
3311 list.Add ((Expression) $1);
3314 | expression_list COMMA expression
3316 var list = (List<Expression>) $1;
3317 list.Add ((Expression) $3);
3320 | expression_list error {
3321 Error_SyntaxError (yyToken);
3326 expression_list_arguments
3327 : expression_list_argument
3329 Arguments args = new Arguments (4);
3330 args.Add ((Argument) $1);
3333 | expression_list_arguments COMMA expression_list_argument
3335 Arguments args = (Arguments) $1;
3336 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3337 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3339 args.Add ((Argument) $3);
3344 expression_list_argument
3347 $$ = new Argument ((Expression) $1);
3355 $$ = new This (GetLocation ($1));
3360 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3362 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3363 lbag.AddLocation ($$, GetLocation ($4));
3365 | BASE OPEN_BRACKET error
3367 Error_SyntaxError (yyToken);
3368 $$ = new ElementAccess (null, null, GetLocation ($2));
3372 post_increment_expression
3373 : primary_expression OP_INC
3375 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3379 post_decrement_expression
3380 : primary_expression OP_DEC
3382 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3386 object_or_delegate_creation_expression
3387 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3390 if (lang_version <= LanguageVersion.ISO_2)
3391 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3393 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3395 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3398 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3400 | NEW new_expr_type object_or_collection_initializer
3402 if (lang_version <= LanguageVersion.ISO_2)
3403 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3405 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3409 array_creation_expression
3410 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3412 opt_array_initializer
3414 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3415 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3416 Next = (ComposedTypeSpecifier) $6
3417 }, (ArrayInitializer) $7, GetLocation ($1));
3418 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3420 | NEW new_expr_type rank_specifiers opt_array_initializer
3423 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3425 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3427 | NEW rank_specifier array_initializer
3429 if (lang_version <= LanguageVersion.ISO_2)
3430 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3432 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3434 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3436 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3437 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3439 | NEW new_expr_type error
3441 Error_SyntaxError (yyToken);
3442 // It can be any of new expression, create the most common one
3443 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3449 ++lexer.parsing_type;
3453 --lexer.parsing_type;
3458 anonymous_type_expression
3459 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3461 if (lang_version <= LanguageVersion.ISO_2)
3462 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3464 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3466 // TODO: lbag comma location
3467 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3471 anonymous_type_parameters_opt_comma
3472 : anonymous_type_parameters_opt
3473 | anonymous_type_parameters COMMA
3476 anonymous_type_parameters_opt
3478 | anonymous_type_parameters
3481 anonymous_type_parameters
3482 : anonymous_type_parameter
3484 var a = new List<AnonymousTypeParameter> (4);
3485 a.Add ((AnonymousTypeParameter) $1);
3488 | anonymous_type_parameters COMMA anonymous_type_parameter
3490 var a = (List<AnonymousTypeParameter>) $1;
3491 a.Add ((AnonymousTypeParameter) $3);
3496 anonymous_type_parameter
3497 : IDENTIFIER ASSIGN variable_initializer
3499 var lt = (Tokenizer.LocatedToken)$1;
3500 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3501 lbag.AddLocation ($$, GetLocation ($2));
3505 var lt = (Tokenizer.LocatedToken)$1;
3506 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3507 lt.Value, lt.Location);
3511 MemberAccess ma = (MemberAccess) $1;
3512 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3516 report.Error (746, lexer.Location,
3517 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3529 | rank_specifier rank_specifiers
3531 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3537 : OPEN_BRACKET CLOSE_BRACKET
3539 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3540 lbag.AddLocation ($$, GetLocation ($2));
3542 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3544 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3545 lbag.AddLocation ($$, GetLocation ($3));
3554 | dim_separators COMMA
3556 $$ = ((int) $1) + 1;
3560 opt_array_initializer
3572 : OPEN_BRACE CLOSE_BRACE
3574 var ai = new ArrayInitializer (0, GetLocation ($1));
3575 ai.VariableDeclaration = current_variable;
3576 lbag.AddLocation (ai, GetLocation ($2));
3579 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3581 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3582 ai.VariableDeclaration = current_variable;
3584 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3586 lbag.AddLocation (ai, GetLocation ($4));
3592 variable_initializer_list
3593 : variable_initializer
3595 var list = new List<Expression> (4);
3596 list.Add ((Expression) $1);
3599 | variable_initializer_list COMMA variable_initializer
3601 var list = (List<Expression>) $1;
3602 list.Add ((Expression) $3);
3610 lexer.TypeOfParsing = true;
3612 open_parens_any typeof_type_expression CLOSE_PARENS
3614 lexer.TypeOfParsing = false;
3615 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3616 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3620 typeof_type_expression
3625 Error_TypeExpected (lexer.Location);
3631 : identifier_inside_body generic_dimension
3633 var lt = (Tokenizer.LocatedToken) $1;
3635 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3637 | qualified_alias_member identifier_inside_body generic_dimension
3639 var lt1 = (Tokenizer.LocatedToken) $1;
3640 var lt2 = (Tokenizer.LocatedToken) $2;
3642 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3643 lbag.AddLocation ($$, GetLocation ($2));
3645 | unbound_type_name DOT identifier_inside_body
3647 var lt = (Tokenizer.LocatedToken) $3;
3649 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3651 | unbound_type_name DOT identifier_inside_body generic_dimension
3653 var lt = (Tokenizer.LocatedToken) $3;
3655 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3657 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3659 var tne = (ATypeNameExpression) $1;
3660 if (tne.HasTypeArguments)
3661 Error_TypeExpected (GetLocation ($4));
3663 var lt = (Tokenizer.LocatedToken) $3;
3664 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3671 if (lang_version < LanguageVersion.ISO_2)
3672 FeatureIsNotAvailable (GetLocation ($1), "generics");
3678 qualified_alias_member
3679 : IDENTIFIER DOUBLE_COLON
3681 var lt = (Tokenizer.LocatedToken) $1;
3682 if (lang_version == LanguageVersion.ISO_1)
3683 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3690 : SIZEOF open_parens_any type CLOSE_PARENS
3692 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3693 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3698 : CHECKED open_parens_any expression CLOSE_PARENS
3700 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3701 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3705 unchecked_expression
3706 : UNCHECKED open_parens_any expression CLOSE_PARENS
3708 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3709 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3713 pointer_member_access
3714 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3716 var lt = (Tokenizer.LocatedToken) $3;
3717 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3721 anonymous_method_expression
3722 : DELEGATE opt_anonymous_method_signature
3724 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3728 $$ = end_anonymous ((ParametersBlock) $4);
3730 | ASYNC DELEGATE opt_anonymous_method_signature
3732 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3736 $$ = end_anonymous ((ParametersBlock) $5);
3740 opt_anonymous_method_signature
3743 $$ = ParametersCompiled.Undefined;
3745 | anonymous_method_signature
3748 anonymous_method_signature
3751 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3753 opt_formal_parameter_list CLOSE_PARENS
3755 valid_param_mod = 0;
3760 default_value_expression
3761 : DEFAULT open_parens_any type CLOSE_PARENS
3763 if (lang_version < LanguageVersion.ISO_2)
3764 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3766 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3767 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3772 : primary_expression
3773 | BANG prefixed_unary_expression
3775 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3777 | TILDE prefixed_unary_expression
3779 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3781 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3783 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3784 lbag.AddLocation ($$, GetLocation ($3));
3786 | AWAIT prefixed_unary_expression
3789 if (current_anonymous_method is LambdaExpression) {
3790 report.Error (4034, GetLocation ($1),
3791 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3792 } else if (current_anonymous_method is AnonymousMethodExpression) {
3793 report.Error (4035, GetLocation ($1),
3794 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3796 report.Error (4033, GetLocation ($1),
3797 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3800 current_block.Explicit.RegisterAsyncAwait ();
3803 $$ = new Await ((Expression) $2, GetLocation ($1));
3808 // The idea to split this out is from Rhys' grammar
3809 // to solve the problem with casts.
3811 prefixed_unary_expression
3813 | PLUS prefixed_unary_expression
3815 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3817 | MINUS prefixed_unary_expression
3819 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3821 | OP_INC prefixed_unary_expression
3823 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3825 | OP_DEC prefixed_unary_expression
3827 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3829 | STAR prefixed_unary_expression
3831 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3833 | BITWISE_AND prefixed_unary_expression
3835 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3839 multiplicative_expression
3840 : prefixed_unary_expression
3841 | multiplicative_expression STAR prefixed_unary_expression
3843 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3844 lbag.AddLocation ($$, GetLocation ($2));
3846 | multiplicative_expression DIV prefixed_unary_expression
3848 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
3849 lbag.AddLocation ($$, GetLocation ($2));
3851 | multiplicative_expression PERCENT prefixed_unary_expression
3853 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3854 lbag.AddLocation ($$, GetLocation ($2));
3859 : multiplicative_expression
3860 | additive_expression PLUS multiplicative_expression
3862 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3863 lbag.AddLocation ($$, GetLocation ($2));
3865 | additive_expression MINUS multiplicative_expression
3867 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3868 lbag.AddLocation ($$, GetLocation ($2));
3870 | additive_expression AS type
3872 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3874 | additive_expression IS type
3876 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3881 : additive_expression
3882 | shift_expression OP_SHIFT_LEFT additive_expression
3884 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3885 lbag.AddLocation ($$, GetLocation ($2));
3887 | shift_expression OP_SHIFT_RIGHT additive_expression
3889 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3890 lbag.AddLocation ($$, GetLocation ($2));
3894 relational_expression
3896 | relational_expression OP_LT shift_expression
3898 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
3899 lbag.AddLocation ($$, GetLocation ($2));
3901 | relational_expression OP_GT shift_expression
3903 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
3904 lbag.AddLocation ($$, GetLocation ($2));
3906 | relational_expression OP_LE shift_expression
3908 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
3909 lbag.AddLocation ($$, GetLocation ($2));
3911 | relational_expression OP_GE shift_expression
3913 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
3914 lbag.AddLocation ($$, GetLocation ($2));
3919 : relational_expression
3920 | equality_expression OP_EQ relational_expression
3922 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
3923 lbag.AddLocation ($$, GetLocation ($2));
3925 | equality_expression OP_NE relational_expression
3927 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
3928 lbag.AddLocation ($$, GetLocation ($2));
3933 : equality_expression
3934 | and_expression BITWISE_AND equality_expression
3936 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3937 lbag.AddLocation ($$, GetLocation ($2));
3941 exclusive_or_expression
3943 | exclusive_or_expression CARRET and_expression
3945 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3946 lbag.AddLocation ($$, GetLocation ($2));
3950 inclusive_or_expression
3951 : exclusive_or_expression
3952 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3954 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3955 lbag.AddLocation ($$, GetLocation ($2));
3959 conditional_and_expression
3960 : inclusive_or_expression
3961 | conditional_and_expression OP_AND inclusive_or_expression
3963 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
3964 lbag.AddLocation ($$, GetLocation ($2));
3968 conditional_or_expression
3969 : conditional_and_expression
3970 | conditional_or_expression OP_OR conditional_and_expression
3972 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
3973 lbag.AddLocation ($$, GetLocation ($2));
3977 null_coalescing_expression
3978 : conditional_or_expression
3979 | conditional_or_expression OP_COALESCING null_coalescing_expression
3981 if (lang_version < LanguageVersion.ISO_2)
3982 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3984 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
3985 lbag.AddLocation ($$, GetLocation ($2));
3989 conditional_expression
3990 : null_coalescing_expression
3991 | null_coalescing_expression INTERR expression COLON expression_or_error
3993 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3994 lbag.AddLocation ($$, GetLocation ($4));
3996 | null_coalescing_expression INTERR expression error
3998 Error_SyntaxError (yyToken);
3999 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4003 assignment_expression
4004 : prefixed_unary_expression ASSIGN expression
4006 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4007 lbag.AddLocation ($$, GetLocation ($2));
4009 | prefixed_unary_expression OP_MULT_ASSIGN expression
4011 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4012 lbag.AddLocation ($$, GetLocation ($2));
4014 | prefixed_unary_expression OP_DIV_ASSIGN expression
4016 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4017 lbag.AddLocation ($$, GetLocation ($2));
4019 | prefixed_unary_expression OP_MOD_ASSIGN expression
4021 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4022 lbag.AddLocation ($$, GetLocation ($2));
4024 | prefixed_unary_expression OP_ADD_ASSIGN expression
4026 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4027 lbag.AddLocation ($$, GetLocation ($2));
4029 | prefixed_unary_expression OP_SUB_ASSIGN expression
4031 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4032 lbag.AddLocation ($$, GetLocation ($2));
4034 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4036 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4037 lbag.AddLocation ($$, GetLocation ($2));
4039 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4041 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4042 lbag.AddLocation ($$, GetLocation ($2));
4044 | prefixed_unary_expression OP_AND_ASSIGN expression
4046 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4047 lbag.AddLocation ($$, GetLocation ($2));
4049 | prefixed_unary_expression OP_OR_ASSIGN expression
4051 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4052 lbag.AddLocation ($$, GetLocation ($2));
4054 | prefixed_unary_expression OP_XOR_ASSIGN expression
4056 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4057 lbag.AddLocation ($$, GetLocation ($2));
4061 lambda_parameter_list
4064 var pars = new List<Parameter> (4);
4065 pars.Add ((Parameter) $1);
4069 | lambda_parameter_list COMMA lambda_parameter
4071 var pars = (List<Parameter>) $1;
4072 Parameter p = (Parameter)$3;
4073 if (pars[0].GetType () != p.GetType ()) {
4074 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4083 : parameter_modifier parameter_type identifier_inside_body
4085 var lt = (Tokenizer.LocatedToken) $3;
4087 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4089 | parameter_type identifier_inside_body
4091 var lt = (Tokenizer.LocatedToken) $2;
4093 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4097 var lt = (Tokenizer.LocatedToken) $1;
4098 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4102 opt_lambda_parameter_list
4103 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4104 | lambda_parameter_list {
4105 var pars_list = (List<Parameter>) $1;
4106 $$ = new ParametersCompiled (pars_list.ToArray ());
4110 lambda_expression_body
4111 : lambda_expression_body_simple
4115 lambda_expression_body_simple
4117 start_block (Location.Null);
4119 expression_or_error // Have to close block when error occurs
4121 Block b = end_block (Location.Null);
4122 b.IsCompilerGenerated = true;
4123 b.AddStatement (new ContextualReturn ((Expression) $2));
4132 Error_SyntaxError (yyToken);
4133 $$ = EmptyExpression.Null;
4140 var lt = (Tokenizer.LocatedToken) $1;
4141 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4142 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4144 lambda_expression_body
4146 $$ = end_anonymous ((ParametersBlock) $4);
4147 lbag.AddLocation ($$, GetLocation ($2));
4149 | ASYNC identifier_inside_body ARROW
4151 var lt = (Tokenizer.LocatedToken) $2;
4152 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4153 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4155 lambda_expression_body
4157 $$ = end_anonymous ((ParametersBlock) $5);
4158 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4160 | OPEN_PARENS_LAMBDA
4162 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4164 opt_lambda_parameter_list CLOSE_PARENS ARROW
4166 valid_param_mod = 0;
4167 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4169 lambda_expression_body
4171 $$ = end_anonymous ((ParametersBlock) $7);
4172 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4174 | ASYNC OPEN_PARENS_LAMBDA
4176 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4178 opt_lambda_parameter_list CLOSE_PARENS ARROW
4180 valid_param_mod = 0;
4181 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4183 lambda_expression_body
4185 $$ = end_anonymous ((ParametersBlock) $8);
4186 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4191 : assignment_expression
4192 | non_assignment_expression
4195 non_assignment_expression
4196 : conditional_expression
4201 $$ = new ArglistAccess (GetLocation ($1));
4205 undocumented_expressions
4206 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4208 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4209 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4211 | REFTYPE open_parens_any expression CLOSE_PARENS
4213 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4214 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4216 | MAKEREF open_parens_any expression CLOSE_PARENS
4218 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4219 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4230 $$ = new BooleanExpression ((Expression) $1);
4243 lexer.ConstraintsParsing = true;
4245 type_declaration_name
4247 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4248 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4249 FeatureIsNotAvailable (c.Location, "static classes");
4252 push_current_container (c, $3);
4255 opt_type_parameter_constraints_clauses
4257 lexer.ConstraintsParsing = false;
4260 current_container.SetConstraints ((List<Constraints>) $9);
4261 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4264 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4265 Lexer.doc_state = XmlCommentState.Allowed;
4268 lexer.parsing_modifiers = true;
4270 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4272 --lexer.parsing_declaration;
4274 Lexer.doc_state = XmlCommentState.Allowed;
4278 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4279 $$ = pop_current_class ();
4287 { $$ = $1; } // location
4293 mod_locations = null;
4295 lexer.parsing_modifiers = false;
4299 lexer.parsing_modifiers = false;
4305 | modifiers modifier
4307 var m1 = (Modifiers) $1;
4308 var m2 = (Modifiers) $2;
4310 if ((m1 & m2) != 0) {
4311 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4312 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4313 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4314 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4315 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4316 "More than one protection modifier specified");
4327 StoreModifierLocation ($$, GetLocation ($1));
4329 if (current_container.Kind == MemberKind.Namespace)
4330 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4334 $$ = Modifiers.PUBLIC;
4335 StoreModifierLocation ($$, GetLocation ($1));
4339 $$ = Modifiers.PROTECTED;
4340 StoreModifierLocation ($$, GetLocation ($1));
4344 $$ = Modifiers.INTERNAL;
4345 StoreModifierLocation ($$, GetLocation ($1));
4349 $$ = Modifiers.PRIVATE;
4350 StoreModifierLocation ($$, GetLocation ($1));
4354 $$ = Modifiers.ABSTRACT;
4355 StoreModifierLocation ($$, GetLocation ($1));
4359 $$ = Modifiers.SEALED;
4360 StoreModifierLocation ($$, GetLocation ($1));
4364 $$ = Modifiers.STATIC;
4365 StoreModifierLocation ($$, GetLocation ($1));
4369 $$ = Modifiers.READONLY;
4370 StoreModifierLocation ($$, GetLocation ($1));
4374 $$ = Modifiers.VIRTUAL;
4375 StoreModifierLocation ($$, GetLocation ($1));
4379 $$ = Modifiers.OVERRIDE;
4380 StoreModifierLocation ($$, GetLocation ($1));
4384 $$ = Modifiers.EXTERN;
4385 StoreModifierLocation ($$, GetLocation ($1));
4389 $$ = Modifiers.VOLATILE;
4390 StoreModifierLocation ($$, GetLocation ($1));
4394 $$ = Modifiers.UNSAFE;
4395 StoreModifierLocation ($$, GetLocation ($1));
4396 if (!settings.Unsafe)
4397 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4401 $$ = Modifiers.ASYNC;
4402 StoreModifierLocation ($$, GetLocation ($1));
4410 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4412 | COLON type_list error
4414 Error_SyntaxError (yyToken);
4416 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4420 opt_type_parameter_constraints_clauses
4422 | type_parameter_constraints_clauses
4428 type_parameter_constraints_clauses
4429 : type_parameter_constraints_clause
4431 var constraints = new List<Constraints> (1);
4432 constraints.Add ((Constraints) $1);
4435 | type_parameter_constraints_clauses type_parameter_constraints_clause
4437 var constraints = (List<Constraints>) $1;
4438 Constraints new_constraint = (Constraints)$2;
4440 foreach (Constraints c in constraints) {
4441 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4442 report.Error (409, new_constraint.Location,
4443 "A constraint clause has already been specified for type parameter `{0}'",
4444 new_constraint.TypeParameter.Value);
4448 constraints.Add (new_constraint);
4453 type_parameter_constraints_clause
4454 : WHERE IDENTIFIER COLON type_parameter_constraints
4456 var lt = (Tokenizer.LocatedToken) $2;
4457 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4458 lbag.AddLocation ($$, GetLocation ($3));
4460 | WHERE IDENTIFIER error
4462 Error_SyntaxError (yyToken);
4464 var lt = (Tokenizer.LocatedToken) $2;
4465 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4469 type_parameter_constraints
4470 : type_parameter_constraint
4472 var constraints = new List<FullNamedExpression> (1);
4473 constraints.Add ((FullNamedExpression) $1);
4476 | type_parameter_constraints COMMA type_parameter_constraint
4478 var constraints = (List<FullNamedExpression>) $1;
4479 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4480 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4481 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4484 prev = $3 as SpecialContraintExpr;
4486 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4487 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4489 prev = constraints [0] as SpecialContraintExpr;
4490 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4491 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4496 constraints.Add ((FullNamedExpression) $3);
4501 type_parameter_constraint
4504 if ($1 is ComposedCast)
4505 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4509 | NEW OPEN_PARENS CLOSE_PARENS
4511 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4512 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4516 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4520 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4524 opt_type_parameter_variance
4529 | type_parameter_variance
4531 if (lang_version <= LanguageVersion.V_3)
4532 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4538 type_parameter_variance
4541 $$ = Variance.Covariant;
4545 $$ = Variance.Contravariant;
4554 // A block is "contained" on the following places:
4556 // property_declaration as part of the accessor body (get/set)
4557 // operator_declaration
4558 // constructor_declaration
4559 // destructor_declaration
4560 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4565 ++lexer.parsing_block;
4566 start_block (GetLocation ($1));
4568 opt_statement_list block_end
4577 --lexer.parsing_block;
4578 $$ = end_block (GetLocation ($1));
4580 | COMPLETE_COMPLETION
4582 --lexer.parsing_block;
4583 $$ = end_block (lexer.Location);
4591 ++lexer.parsing_block;
4592 current_block.StartLocation = GetLocation ($1);
4594 opt_statement_list CLOSE_BRACE
4596 --lexer.parsing_block;
4597 $$ = end_block (GetLocation ($4));
4608 | statement_list statement
4612 : block_variable_declaration
4614 current_block.AddStatement ((Statement) $1);
4616 | valid_declaration_statement
4618 current_block.AddStatement ((Statement) $1);
4623 Error_SyntaxError (yyToken);
4629 // The interactive_statement and its derivatives are only
4630 // used to provide a special version of `expression_statement'
4631 // that has a side effect of assigning the expression to
4634 interactive_statement_list
4635 : interactive_statement
4636 | interactive_statement_list interactive_statement
4639 interactive_statement
4640 : block_variable_declaration
4642 current_block.AddStatement ((Statement) $1);
4644 | interactive_valid_declaration_statement
4646 current_block.AddStatement ((Statement) $1);
4651 valid_declaration_statement
4654 | expression_statement
4655 | selection_statement
4656 | iteration_statement
4660 | unchecked_statement
4667 interactive_valid_declaration_statement
4670 | interactive_expression_statement
4671 | selection_statement
4672 | iteration_statement
4676 | unchecked_statement
4684 : valid_declaration_statement
4685 | block_variable_declaration
4687 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4692 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4697 Error_SyntaxError (yyToken);
4698 $$ = new EmptyStatement (GetLocation ($1));
4705 // Uses lexer.Location because semicolon location is not kept in quick mode
4706 $$ = new EmptyStatement (lexer.Location);
4711 : identifier_inside_body COLON
4713 var lt = (Tokenizer.LocatedToken) $1;
4714 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4715 lbag.AddLocation (labeled, GetLocation ($2));
4716 current_block.AddLabel (labeled);
4717 current_block.AddStatement (labeled);
4723 : variable_type_simple
4724 | variable_type_simple rank_specifiers
4727 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4729 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4734 * The following is from Rhys' grammar:
4735 * > Types in local variable declarations must be recognized as
4736 * > expressions to prevent reduce/reduce errors in the grammar.
4737 * > The expressions are converted into types during semantic analysis.
4739 variable_type_simple
4740 : primary_expression_or_type opt_nullable
4742 // Ok, the above "primary_expression" is there to get rid of
4743 // both reduce/reduce and shift/reduces in the grammar, it should
4744 // really just be "type_name". If you use type_name, a reduce/reduce
4745 // creeps up. If you use namespace_or_type_name (which is all we need
4746 // really) two shift/reduces appear.
4749 // So the super-trick is that primary_expression
4750 // can only be either a SimpleName or a MemberAccess.
4751 // The MemberAccess case arises when you have a fully qualified type-name like :
4753 // SimpleName is when you have
4756 Expression expr = (Expression) $1;
4758 SimpleName sn = expr as SimpleName;
4759 if (sn != null && sn.Name == "var")
4760 $$ = new VarExpr (sn.Location);
4763 } else if (expr is ATypeNameExpression) {
4764 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4766 Error_ExpectingTypeName (expr);
4770 | primary_expression_or_type pointer_stars
4772 ATypeNameExpression expr = $1 as ATypeNameExpression;
4775 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4777 Error_ExpectingTypeName ((Expression)$1);
4781 | builtin_types opt_nullable
4786 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4788 | builtin_types pointer_stars
4790 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4792 | VOID pointer_stars
4794 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4798 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
4799 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
4805 | pointer_star pointer_stars
4807 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4815 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4819 identifier_inside_body
4824 report.Error (4003, GetLocation ($1), "`await' cannot be used as an identifier within an async method or lambda expression");
4825 $$ = new Tokenizer.LocatedToken ("await", GetLocation ($1));
4830 block_variable_declaration
4831 : variable_type identifier_inside_body
4833 var lt = (Tokenizer.LocatedToken) $2;
4834 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4835 current_block.AddLocalName (li);
4836 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4838 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4840 $$ = current_variable;
4841 current_variable = null;
4842 lbag.AddLocation ($$, GetLocation ($6));
4844 | CONST variable_type identifier_inside_body
4846 var lt = (Tokenizer.LocatedToken) $3;
4847 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4848 current_block.AddLocalName (li);
4849 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4851 const_variable_initializer opt_const_declarators SEMICOLON
4853 $$ = current_variable;
4854 current_variable = null;
4855 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4859 opt_local_variable_initializer
4861 | ASSIGN block_variable_initializer
4863 current_variable.Initializer = (Expression) $2;
4868 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4869 report.Error (650, lexer.Location,
4870 "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");
4872 Error_SyntaxError (yyToken);
4877 opt_variable_declarators
4879 | variable_declarators
4882 opt_using_or_fixed_variable_declarators
4884 | variable_declarators
4886 foreach (var d in current_variable.Declarators) {
4887 if (d.Initializer == null)
4888 Error_MissingInitializer (d.Variable.Location);
4893 variable_declarators
4894 : variable_declarator
4895 | variable_declarators variable_declarator
4899 : COMMA identifier_inside_body
4901 var lt = (Tokenizer.LocatedToken) $2;
4902 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4903 var d = new BlockVariableDeclaration.Declarator (li, null);
4904 current_variable.AddDeclarator (d);
4905 current_block.AddLocalName (li);
4906 lbag.AddLocation (d, GetLocation ($1));
4908 | COMMA identifier_inside_body ASSIGN block_variable_initializer
4910 var lt = (Tokenizer.LocatedToken) $2;
4911 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4912 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4913 current_variable.AddDeclarator (d);
4914 current_block.AddLocalName (li);
4915 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4919 const_variable_initializer
4922 report.Error (145, lexer.Location, "A const field requires a value to be provided");
4924 | ASSIGN constant_initializer_expr
4926 current_variable.Initializer = (Expression) $2;
4930 opt_const_declarators
4937 | const_declarators const_declarator
4941 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
4943 var lt = (Tokenizer.LocatedToken) $2;
4944 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4945 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4946 current_variable.AddDeclarator (d);
4947 current_block.AddLocalName (li);
4948 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4952 block_variable_initializer
4953 : variable_initializer
4954 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4956 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4957 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4959 | STACKALLOC simple_type
4961 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4962 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4966 expression_statement
4967 : statement_expression SEMICOLON
4970 lbag.AddStatement ($$, GetLocation ($2));
4972 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4973 | statement_expression CLOSE_BRACE
4976 report.Error (1002, GetLocation ($2), "; expected");
4977 lexer.putback ('}');
4981 interactive_expression_statement
4982 : interactive_statement_expression SEMICOLON { $$ = $1; }
4983 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4987 // We have to do the wrapping here and not in the case above,
4988 // because statement_expression is used for example in for_statement
4990 statement_expression
4993 ExpressionStatement s = $1 as ExpressionStatement;
4995 Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
4996 $$ = new StatementErrorExpression ($1 as Expression);
4998 $$ = new StatementExpression (s);
5003 interactive_statement_expression
5006 Expression expr = (Expression) $1;
5007 ExpressionStatement s;
5009 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
5010 $$ = new StatementExpression (s);
5014 Error_SyntaxError (yyToken);
5015 $$ = new EmptyStatement (GetLocation ($1));
5025 : IF open_parens_any boolean_expression CLOSE_PARENS
5028 if ($5 is EmptyStatement)
5029 Warning_EmptyStatement (GetLocation ($5));
5031 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5032 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5034 | IF open_parens_any boolean_expression CLOSE_PARENS
5035 embedded_statement ELSE embedded_statement
5037 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5038 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5040 if ($5 is EmptyStatement)
5041 Warning_EmptyStatement (GetLocation ($5));
5042 if ($7 is EmptyStatement)
5043 Warning_EmptyStatement (GetLocation ($7));
5045 | IF open_parens_any boolean_expression error
5047 Error_SyntaxError (yyToken);
5049 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5050 lbag.AddStatement ($$, GetLocation ($2));
5055 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5057 start_block (GetLocation ($5));
5059 opt_switch_sections CLOSE_BRACE
5061 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
5062 end_block (GetLocation ($8));
5063 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5065 | SWITCH open_parens_any expression error
5067 Error_SyntaxError (yyToken);
5069 $$ = new Switch ((Expression) $3, null, null, GetLocation ($1));
5070 lbag.AddStatement ($$, GetLocation ($2));
5077 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5078 $$ = new List<SwitchSection> ();
5086 var sections = new List<SwitchSection> (4);
5088 sections.Add ((SwitchSection) $1);
5091 | switch_sections switch_section
5093 var sections = (List<SwitchSection>) $1;
5095 sections.Add ((SwitchSection) $2);
5100 Error_SyntaxError (yyToken);
5101 $$ = new List<SwitchSection> ();
5108 current_block = current_block.CreateSwitchBlock (lexer.Location);
5112 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
5119 var labels = new List<SwitchLabel> (2);
5121 labels.Add ((SwitchLabel) $1);
5124 | switch_labels switch_label
5126 var labels = (List<SwitchLabel>) ($1);
5127 labels.Add ((SwitchLabel) $2);
5134 : CASE constant_expression COLON
5136 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5137 lbag.AddLocation ($$, GetLocation ($3));
5139 | CASE constant_expression error
5141 Error_SyntaxError (yyToken);
5142 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5146 $$ = new SwitchLabel (null, GetLocation ($1));
5158 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5160 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5161 Warning_EmptyStatement (GetLocation ($5));
5163 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5164 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5166 | WHILE open_parens_any boolean_expression error
5168 Error_SyntaxError (yyToken);
5170 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5171 lbag.AddStatement ($$, GetLocation ($2));
5176 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5178 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5179 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5181 | DO embedded_statement error
5183 Error_SyntaxError (yyToken);
5184 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5186 | DO embedded_statement WHILE open_parens_any boolean_expression error
5188 Error_SyntaxError (yyToken);
5190 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5191 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5196 : FOR open_parens_any
5198 start_block (GetLocation ($2));
5199 current_block.IsCompilerGenerated = true;
5200 For f = new For (GetLocation ($1));
5201 current_block.AddStatement (f);
5210 // Has to use be extra rule to recover started block
5212 : opt_for_initializer SEMICOLON
5214 ((For) $0).Initializer = (Statement) $1;
5216 // Pass the "For" object to the iterator_part4
5217 oob_stack.Push ($0);
5219 for_condition_and_iterator_part
5222 var locations = (Tuple<Location,Location>) $4;
5224 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5225 Warning_EmptyStatement (GetLocation ($5));
5228 f.Statement = (Statement) $5;
5229 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5231 $$ = end_block (GetLocation ($2));
5235 Error_SyntaxError (yyToken);
5236 $$ = end_block (current_block.StartLocation);
5240 for_condition_and_iterator_part
5241 : opt_for_condition SEMICOLON
5243 For f = (For) oob_stack.Peek ();
5244 f.Condition = (BooleanExpression) $1;
5247 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5250 // Handle errors in the case of opt_for_condition being followed by
5251 // a close parenthesis
5252 | opt_for_condition close_parens_close_brace {
5253 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5254 For f = (For) oob_stack.Peek ();
5255 f.Condition = (BooleanExpression) $1;
5256 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5261 : opt_for_iterator CLOSE_PARENS {
5262 For f = (For) oob_stack.Peek ();
5263 f.Iterator = (Statement) $1;
5264 $$ = GetLocation ($2);
5266 | opt_for_iterator CLOSE_BRACE {
5267 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5268 For f = (For) oob_stack.Peek ();
5269 f.Iterator = (Statement) $1;
5270 $$ = GetLocation ($2);
5274 close_parens_close_brace
5276 | CLOSE_BRACE { lexer.putback ('}'); }
5280 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5285 : variable_type identifier_inside_body
5287 var lt = (Tokenizer.LocatedToken) $2;
5288 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5289 current_block.AddLocalName (li);
5290 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5292 opt_local_variable_initializer opt_variable_declarators
5294 $$ = current_variable;
5295 current_variable = null;
5297 | statement_expression_list
5301 : /* empty */ { $$ = null; }
5302 | boolean_expression
5306 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5311 : statement_expression_list
5314 statement_expression_list
5315 : statement_expression
5316 | statement_expression_list COMMA statement_expression
5318 var sl = $1 as StatementList;
5320 sl = new StatementList ((Statement) $1, (Statement) $3);
5321 lbag.AddStatement (sl, GetLocation ($2));
5323 sl.Add ((Statement) $3);
5324 lbag.AppendTo (sl, GetLocation ($2));
5332 : FOREACH open_parens_any type error
5334 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5336 start_block (GetLocation ($2));
5337 current_block.IsCompilerGenerated = true;
5339 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5340 current_block.AddStatement (f);
5342 lbag.AddStatement (f, GetLocation ($2));
5343 $$ = end_block (GetLocation ($4));
5345 | FOREACH open_parens_any type identifier_inside_body error
5347 Error_SyntaxError (yyToken);
5349 start_block (GetLocation ($2));
5350 current_block.IsCompilerGenerated = true;
5352 var lt = (Tokenizer.LocatedToken) $4;
5353 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5354 current_block.AddLocalName (li);
5356 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5357 current_block.AddStatement (f);
5359 lbag.AddStatement (f, GetLocation ($2));
5360 $$ = end_block (GetLocation ($5));
5362 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5364 start_block (GetLocation ($2));
5365 current_block.IsCompilerGenerated = true;
5367 var lt = (Tokenizer.LocatedToken) $4;
5368 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5369 current_block.AddLocalName (li);
5374 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5375 Warning_EmptyStatement (GetLocation ($9));
5377 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5378 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5379 end_block (GetLocation ($7));
5387 | continue_statement
5397 $$ = new Break (GetLocation ($1));
5398 lbag.AddStatement ($$, GetLocation ($2));
5403 : CONTINUE SEMICOLON
5405 $$ = new Continue (GetLocation ($1));
5406 lbag.AddStatement ($$, GetLocation ($2));
5410 Error_SyntaxError (yyToken);
5411 $$ = new Continue (GetLocation ($1));
5416 : GOTO identifier_inside_body SEMICOLON
5418 var lt = (Tokenizer.LocatedToken) $2;
5419 $$ = new Goto (lt.Value, GetLocation ($1));
5420 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5422 | GOTO CASE constant_expression SEMICOLON
5424 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5425 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5427 | GOTO DEFAULT SEMICOLON
5429 $$ = new GotoDefault (GetLocation ($1));
5430 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5435 : RETURN opt_expression SEMICOLON
5437 $$ = new Return ((Expression) $2, GetLocation ($1));
5438 lbag.AddStatement ($$, GetLocation ($3));
5440 | RETURN expression error
5442 Error_SyntaxError (yyToken);
5443 $$ = new Return ((Expression) $2, GetLocation ($1));
5447 Error_SyntaxError (yyToken);
5448 $$ = new Return (null, GetLocation ($1));
5453 : THROW opt_expression SEMICOLON
5455 $$ = new Throw ((Expression) $2, GetLocation ($1));
5456 lbag.AddStatement ($$, GetLocation ($3));
5460 Error_SyntaxError (yyToken);
5461 $$ = new Throw (null, GetLocation ($1));
5466 : identifier_inside_body RETURN opt_expression SEMICOLON
5468 var lt = (Tokenizer.LocatedToken) $1;
5469 string s = lt.Value;
5471 report.Error (1003, lt.Location, "; expected");
5472 } else if ($3 == null) {
5473 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5474 } else if (lang_version == LanguageVersion.ISO_1){
5475 FeatureIsNotAvailable (lt.Location, "iterators");
5478 current_block.Explicit.RegisterIteratorYield ();
5479 $$ = new Yield ((Expression) $3, lt.Location);
5480 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5482 | identifier_inside_body RETURN expression error
5484 Error_SyntaxError (yyToken);
5486 var lt = (Tokenizer.LocatedToken) $1;
5487 string s = lt.Value;
5489 report.Error (1003, lt.Location, "; expected");
5490 } else if ($3 == null) {
5491 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5492 } else if (lang_version == LanguageVersion.ISO_1){
5493 FeatureIsNotAvailable (lt.Location, "iterators");
5496 current_block.Explicit.RegisterIteratorYield ();
5497 $$ = new Yield ((Expression) $3, lt.Location);
5498 lbag.AddStatement ($$, GetLocation ($2));
5500 | identifier_inside_body BREAK SEMICOLON
5502 var lt = (Tokenizer.LocatedToken) $1;
5503 string s = lt.Value;
5505 report.Error (1003, lt.Location, "; expected");
5506 } else if (lang_version == LanguageVersion.ISO_1){
5507 FeatureIsNotAvailable (lt.Location, "iterators");
5510 current_block.Explicit.RegisterIteratorYield ();
5511 $$ = new YieldBreak (lt.Location);
5512 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5522 : TRY block catch_clauses
5524 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5526 | TRY block FINALLY block
5528 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5529 lbag.AddStatement ($$, GetLocation ($3));
5531 | TRY block catch_clauses FINALLY block
5533 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5534 lbag.AddStatement ($$, GetLocation ($4));
5538 Error_SyntaxError (1524, yyToken);
5539 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5546 var l = new List<Catch> (2);
5551 | catch_clauses catch_clause
5553 var l = (List<Catch>) $1;
5555 Catch c = (Catch) $2;
5556 if (l [l.Count - 1].IsGeneral) {
5557 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5567 | identifier_inside_body
5573 $$ = new Catch ((Block) $2, GetLocation ($1));
5575 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5577 start_block (GetLocation ($2));
5578 var c = new Catch (current_block, GetLocation ($1));
5579 c.TypeExpression = (FullNamedExpression) $3;
5582 var lt = (Tokenizer.LocatedToken) $4;
5583 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5584 current_block.AddLocalName (c.Variable);
5587 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5594 | CATCH open_parens_any error
5596 if (yyToken == Token.CLOSE_PARENS) {
5597 report.Error (1015, lexer.Location,
5598 "A type that derives from `System.Exception', `object', or `string' expected");
5600 Error_SyntaxError (yyToken);
5603 $$ = new Catch (null, GetLocation ($1));
5610 $$ = new Checked ((Block) $2, GetLocation ($1));
5617 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5624 if (!settings.Unsafe)
5625 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5627 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5632 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5634 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5635 Warning_EmptyStatement (GetLocation ($5));
5637 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5638 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5640 | LOCK open_parens_any expression error
5642 Error_SyntaxError (yyToken);
5644 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
5645 lbag.AddStatement ($$, GetLocation ($2));
5650 : FIXED open_parens_any variable_type identifier_inside_body
5652 start_block (GetLocation ($2));
5654 current_block.IsCompilerGenerated = true;
5655 var lt = (Tokenizer.LocatedToken) $4;
5656 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5657 current_block.AddLocalName (li);
5658 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5660 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
5662 $$ = current_variable;
5663 current_variable = null;
5667 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5668 Warning_EmptyStatement (GetLocation ($10));
5670 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5671 current_block.AddStatement (f);
5672 $$ = end_block (GetLocation ($8));
5677 : USING open_parens_any variable_type identifier_inside_body
5679 start_block (GetLocation ($2));
5681 current_block.IsCompilerGenerated = true;
5682 var lt = (Tokenizer.LocatedToken) $4;
5683 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5684 current_block.AddLocalName (li);
5685 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5687 using_initialization CLOSE_PARENS
5689 $$ = current_variable;
5690 current_variable = null;
5694 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5695 Warning_EmptyStatement (GetLocation ($9));
5697 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
5698 current_block.AddStatement (u);
5699 $$ = end_block (GetLocation ($7));
5701 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5703 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5704 Warning_EmptyStatement (GetLocation ($5));
5706 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5707 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5709 | USING open_parens_any expression error
5711 Error_SyntaxError (yyToken);
5713 $$ = new Using ((Expression) $3, null, GetLocation ($1));
5714 lbag.AddStatement ($$, GetLocation ($2));
5718 using_initialization
5719 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
5722 // It has to be here for the parent to safely restore artificial block
5723 Error_SyntaxError (yyToken);
5727 using_or_fixed_variable_initializer
5730 Error_MissingInitializer (lexer.Location);
5732 | ASSIGN variable_initializer
5734 current_variable.Initializer = (Expression) $2;
5735 $$ = current_variable;
5743 : first_from_clause query_body
5745 lexer.query_parsing = false;
5747 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5749 from.Tail.Next = (Linq.AQueryClause)$2;
5752 current_block.SetEndLocation (lexer.Location);
5753 current_block = current_block.Parent;
5755 | nested_from_clause query_body
5757 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5759 from.Tail.Next = (Linq.AQueryClause)$2;
5762 current_block.SetEndLocation (lexer.Location);
5763 current_block = current_block.Parent;
5766 // Bubble up COMPLETE_COMPLETION productions
5767 | first_from_clause COMPLETE_COMPLETION {
5768 lexer.query_parsing = false;
5771 current_block.SetEndLocation (lexer.Location);
5772 current_block = current_block.Parent;
5774 | nested_from_clause COMPLETE_COMPLETION {
5776 current_block.SetEndLocation (lexer.Location);
5777 current_block = current_block.Parent;
5782 : FROM_FIRST identifier_inside_body IN expression
5784 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5786 var lt = (Tokenizer.LocatedToken) $2;
5787 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5788 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5790 | FROM_FIRST type identifier_inside_body IN expression
5792 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5794 var lt = (Tokenizer.LocatedToken) $3;
5795 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5796 $$ = new Linq.QueryExpression (
5797 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5798 IdentifierType = (FullNamedExpression)$2
5805 : FROM identifier_inside_body IN expression
5807 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5809 var lt = (Tokenizer.LocatedToken) $2;
5810 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5811 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5813 | FROM type identifier_inside_body IN expression
5815 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5817 var lt = (Tokenizer.LocatedToken) $3;
5818 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5819 $$ = new Linq.QueryExpression (
5820 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5821 IdentifierType = (FullNamedExpression)$2
5828 : FROM identifier_inside_body IN
5830 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5834 var lt = (Tokenizer.LocatedToken) $2;
5835 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5836 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5838 current_block.SetEndLocation (lexer.Location);
5839 current_block = current_block.Parent;
5841 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5843 | FROM type identifier_inside_body IN
5845 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5849 var lt = (Tokenizer.LocatedToken) $3;
5850 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5852 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5853 IdentifierType = (FullNamedExpression)$2
5856 current_block.SetEndLocation (lexer.Location);
5857 current_block = current_block.Parent;
5859 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5864 : query_body_clauses select_or_group_clause opt_query_continuation
5866 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5869 head.Next = (Linq.AQueryClause)$3;
5872 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5873 clause.Tail.Next = head;
5879 | select_or_group_clause opt_query_continuation
5881 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5884 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5885 clause.Tail.Next = head;
5891 | query_body_clauses COMPLETE_COMPLETION
5892 | query_body_clauses error
5894 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
5899 Error_SyntaxError (yyToken);
5904 select_or_group_clause
5907 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5911 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5913 current_block.SetEndLocation (lexer.Location);
5914 current_block = current_block.Parent;
5918 if (linq_clause_blocks == null)
5919 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5921 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5922 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5926 current_block.SetEndLocation (lexer.Location);
5927 current_block = current_block.Parent;
5929 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5931 BY expression_or_error
5933 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5934 lbag.AddLocation ($$, GetLocation ($5));
5936 current_block.SetEndLocation (lexer.Location);
5937 current_block = current_block.Parent;
5943 | query_body_clauses query_body_clause
5945 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5959 : LET identifier_inside_body ASSIGN
5961 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5965 var lt = (Tokenizer.LocatedToken) $2;
5966 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5967 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5968 lbag.AddLocation ($$, GetLocation ($3));
5970 current_block.SetEndLocation (lexer.Location);
5971 current_block = current_block.Parent;
5973 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5980 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5984 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5986 current_block.SetEndLocation (lexer.Location);
5987 current_block = current_block.Parent;
5992 : JOIN identifier_inside_body IN
5994 if (linq_clause_blocks == null)
5995 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5997 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5998 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6000 expression_or_error ON
6002 current_block.SetEndLocation (lexer.Location);
6003 current_block = current_block.Parent;
6005 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6006 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6008 expression_or_error EQUALS
6010 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6011 current_block.SetEndLocation (lexer.Location);
6012 current_block = current_block.Parent;
6014 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6016 expression_or_error opt_join_into
6018 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6019 current_block.SetEndLocation (lexer.Location);
6021 var outer_selector = linq_clause_blocks.Pop ();
6022 var block = linq_clause_blocks.Pop ();
6024 var lt = (Tokenizer.LocatedToken) $2;
6025 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6026 Linq.RangeVariable into;
6030 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6031 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6034 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6036 var parent = block.Parent;
6037 while (parent is Linq.QueryBlock) {
6038 parent = parent.Parent;
6040 current_block.Parent = parent;
6042 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6044 lt = (Tokenizer.LocatedToken) $12;
6045 into = new Linq.RangeVariable (lt.Value, lt.Location);
6047 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6048 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6051 current_block = block.Parent;
6052 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6054 | JOIN type identifier_inside_body IN
6056 if (linq_clause_blocks == null)
6057 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6059 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6060 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6062 expression_or_error ON
6064 current_block.SetEndLocation (lexer.Location);
6065 current_block = current_block.Parent;
6067 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6068 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6070 expression_or_error EQUALS
6072 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6073 current_block.SetEndLocation (lexer.Location);
6074 current_block = current_block.Parent;
6076 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6078 expression_or_error opt_join_into
6080 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6081 current_block.SetEndLocation (lexer.Location);
6083 var outer_selector = linq_clause_blocks.Pop ();
6084 var block = linq_clause_blocks.Pop ();
6086 var lt = (Tokenizer.LocatedToken) $3;
6087 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6088 Linq.RangeVariable into;
6092 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6093 IdentifierType = (FullNamedExpression)$2
6097 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6099 var parent = block.Parent;
6100 while (parent is Linq.QueryBlock) {
6101 parent = parent.Parent;
6103 current_block.Parent = parent;
6105 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6107 lt = (Tokenizer.LocatedToken) $13;
6108 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6110 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6111 IdentifierType = (FullNamedExpression)$2
6115 current_block = block.Parent;
6116 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6122 | INTO identifier_inside_body
6131 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6135 current_block.SetEndLocation (lexer.Location);
6136 current_block = current_block.Parent;
6146 current_block.SetEndLocation (lexer.Location);
6147 current_block = current_block.Parent;
6149 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6153 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6160 | orderings_then_by COMMA
6162 current_block.SetEndLocation (lexer.Location);
6163 current_block = current_block.Parent;
6165 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6169 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6177 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6179 | expression ASCENDING
6181 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6182 lbag.AddLocation ($$, GetLocation ($2));
6184 | expression DESCENDING
6186 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6187 lbag.AddLocation ($$, GetLocation ($2));
6194 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6196 | expression ASCENDING
6198 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6199 lbag.AddLocation ($$, GetLocation ($2));
6201 | expression DESCENDING
6203 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6204 lbag.AddLocation ($$, GetLocation ($2));
6209 opt_query_continuation
6211 | INTO identifier_inside_body
6213 // query continuation block is not linked with query block but with block
6214 // before. This means each query can use same range variable names for
6215 // different identifiers.
6217 current_block.SetEndLocation (GetLocation ($1));
6218 current_block = current_block.Parent;
6220 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6222 if (linq_clause_blocks == null)
6223 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6225 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6229 var current_block = linq_clause_blocks.Pop ();
6230 var lt = (Tokenizer.LocatedToken) $2;
6231 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6232 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6233 next = (Linq.AQueryClause)$4
6239 // Support for using the compiler as an interactive parser
6241 // The INTERACTIVE_PARSER token is first sent to parse our
6242 // productions; If the result is a Statement, the parsing
6243 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6244 // to setup the blocks in advance.
6246 // This setup is here so that in the future we can add
6247 // support for other constructs (type parsing, namespaces, etc)
6248 // that do not require a block to be setup in advance
6252 : EVAL_STATEMENT_PARSER EOF
6253 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6254 | EVAL_STATEMENT_PARSER
6256 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6258 // (ref object retval)
6259 Parameter [] mpar = new Parameter [1];
6260 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6262 ParametersCompiled pars = new ParametersCompiled (mpar);
6263 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6264 if (settings.Unsafe)
6265 mods |= Modifiers.UNSAFE;
6267 current_local_parameters = pars;
6268 Method method = new Method (
6270 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6272 new MemberName ("Host"),
6274 null /* attributes */);
6276 current_type.AddMember (method);
6278 oob_stack.Push (method);
6279 ++lexer.parsing_block;
6280 start_block (lexer.Location);
6282 interactive_statement_list opt_COMPLETE_COMPLETION
6284 --lexer.parsing_block;
6285 Method method = (Method) oob_stack.Pop ();
6287 method.Block = (ToplevelBlock) end_block(lexer.Location);
6289 InteractiveResult = (Class) pop_current_class ();
6290 current_local_parameters = null;
6292 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6295 interactive_compilation_unit
6296 : opt_extern_alias_directives opt_using_directives
6297 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6300 opt_COMPLETE_COMPLETION
6302 | COMPLETE_COMPLETION
6305 close_brace_or_complete_completion
6307 | COMPLETE_COMPLETION
6311 // XML documentation code references micro parser
6313 documentation_parsing
6316 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6321 : doc_type_declaration_name opt_doc_method_sig
6323 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6325 | builtin_types opt_doc_method_sig
6327 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6328 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6331 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6333 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6334 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6335 var lt = (Tokenizer.LocatedToken) $3;
6336 $$ = new MemberName (lt.Value);
6338 | doc_type_declaration_name DOT THIS
6340 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6342 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6344 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6346 opt_doc_parameters CLOSE_BRACKET
6348 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6349 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6351 | EXPLICIT OPERATOR type opt_doc_method_sig
6353 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6354 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6355 module.DocumentationBuilder.ParsedParameters = p;
6356 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6359 | IMPLICIT OPERATOR type opt_doc_method_sig
6361 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6362 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6363 module.DocumentationBuilder.ParsedParameters = p;
6364 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6367 | OPERATOR overloadable_operator opt_doc_method_sig
6369 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6370 module.DocumentationBuilder.ParsedParameters = p;
6371 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6376 doc_type_declaration_name
6377 : type_declaration_name
6378 | doc_type_declaration_name DOT type_declaration_name
6380 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6388 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6390 opt_doc_parameters CLOSE_PARENS
6399 $$ = new List<DocumentationParameter> (0);
6407 var parameters = new List<DocumentationParameter> ();
6408 parameters.Add ((DocumentationParameter) $1);
6411 | doc_parameters COMMA doc_parameter
6413 var parameters = $1 as List<DocumentationParameter>;
6414 parameters.Add ((DocumentationParameter) $3);
6420 : opt_parameter_modifier parameter_type
6423 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6425 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6432 // A class used to hold info about an operator declarator
6434 class OperatorDeclaration {
6435 public readonly Operator.OpType optype;
6436 public readonly FullNamedExpression ret_type;
6437 public readonly Location location;
6439 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6442 this.ret_type = ret_type;
6443 this.location = location;
6447 void Error_ExpectingTypeName (Expression expr)
6449 if (expr is Invocation){
6450 report.Error (1002, expr.Location, "Expecting `;'");
6452 Expression.Error_InvalidExpressionStatement (report, expr.Location);
6456 void Error_ParameterModifierNotValid (string modifier, Location loc)
6458 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6462 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6464 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6465 Parameter.GetModifierSignature (mod));
6468 void Error_TypeExpected (Location loc)
6470 report.Error (1031, loc, "Type expected");
6473 void Error_UnsafeCodeNotAllowed (Location loc)
6475 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6478 void Warning_EmptyStatement (Location loc)
6480 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6483 void Error_NamedArgumentExpected (NamedArgument a)
6485 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6488 void Error_MissingInitializer (Location loc)
6490 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6493 void push_current_container (TypeDefinition tc, object partial_token)
6495 if (module.Evaluator != null){
6496 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6500 undo.AddTypeContainer (current_container, tc);
6503 if (partial_token != null)
6504 current_container.AddPartial (tc);
6506 current_container.AddTypeContainer (tc);
6508 ++lexer.parsing_declaration;
6509 current_container = tc;
6513 TypeContainer pop_current_class ()
6515 var retval = current_container;
6517 current_container = current_container.Parent;
6518 current_type = current_type.Parent as TypeDefinition;
6523 [System.Diagnostics.Conditional ("FULL_AST")]
6524 void StoreModifierLocation (object token, Location loc)
6529 if (mod_locations == null)
6530 mod_locations = new List<Tuple<Modifiers, Location>> ();
6532 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6535 string CheckAttributeTarget (string a, Location l)
6538 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6542 report.Warning (658, 1, l,
6543 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6544 return string.Empty;
6547 static bool IsUnaryOperator (Operator.OpType op)
6551 case Operator.OpType.LogicalNot:
6552 case Operator.OpType.OnesComplement:
6553 case Operator.OpType.Increment:
6554 case Operator.OpType.Decrement:
6555 case Operator.OpType.True:
6556 case Operator.OpType.False:
6557 case Operator.OpType.UnaryPlus:
6558 case Operator.OpType.UnaryNegation:
6564 void syntax_error (Location l, string msg)
6566 report.Error (1003, l, "Syntax error, " + msg);
6571 public Tokenizer Lexer {
6577 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
6578 : this (reader, file, file.Compiler.Report, session)
6582 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
6585 current_container = current_namespace = file;
6587 this.module = file.Module;
6588 this.compiler = file.Compiler;
6589 this.settings = compiler.Settings;
6590 this.report = report;
6592 lang_version = settings.Version;
6593 yacc_verbose_flag = settings.VerboseParserFlag;
6594 doc_support = settings.DocumentationFile != null;
6595 lexer = new Tokenizer (reader, file, session);
6596 oob_stack = new Stack<object> ();
6597 lbag = session.LocationsBag;
6598 use_global_stacks = session.UseJayGlobalArrays;
6599 parameters_bucket = session.ParametersStack;
6602 public void parse ()
6604 eof_token = Token.EOF;
6607 if (yacc_verbose_flag > 1)
6608 yyparse (lexer, new yydebug.yyDebugSimple ());
6612 Tokenizer tokenizer = lexer as Tokenizer;
6613 tokenizer.cleanup ();
6614 } catch (Exception e){
6615 if (e is yyParser.yyUnexpectedEof) {
6616 Error_SyntaxError (yyToken);
6617 UnexpectedEOF = true;
6621 if (e is yyParser.yyException) {
6622 report.Error (-25, lexer.Location, "Parsing error");
6624 // Used by compiler-tester to test internal errors
6625 if (yacc_verbose_flag > 0 || e is FatalException)
6628 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
6633 void CheckToken (int error, int yyToken, string msg, Location loc)
6635 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6636 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6638 report.Error (error, loc, msg);
6641 string ConsumeStoredComment ()
6643 string s = tmpComment;
6645 Lexer.doc_state = XmlCommentState.Allowed;
6649 void FeatureIsNotAvailable (Location loc, string feature)
6651 report.FeatureIsNotAvailable (compiler, loc, feature);
6654 Location GetLocation (object obj)
6656 var lt = obj as Tokenizer.LocatedToken;
6660 var mn = obj as MemberName;
6664 var expr = obj as Expression;
6666 return expr.Location;
6668 return lexer.Location;
6671 void start_block (Location loc)
6673 if (current_block == null) {
6674 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6675 parsing_anonymous_method = false;
6676 } else if (parsing_anonymous_method) {
6677 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6678 parsing_anonymous_method = false;
6680 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6685 end_block (Location loc)
6687 Block retval = current_block.Explicit;
6688 retval.SetEndLocation (loc);
6689 current_block = retval.Parent;
6693 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
6695 oob_stack.Push (current_anonymous_method);
6696 oob_stack.Push (current_local_parameters);
6697 oob_stack.Push (current_variable);
6698 oob_stack.Push (async_block);
6700 current_local_parameters = parameters;
6702 if (lang_version <= LanguageVersion.ISO_2)
6703 FeatureIsNotAvailable (loc, "lambda expressions");
6705 current_anonymous_method = new LambdaExpression (loc);
6707 if (lang_version == LanguageVersion.ISO_1)
6708 FeatureIsNotAvailable (loc, "anonymous methods");
6710 current_anonymous_method = new AnonymousMethodExpression (loc);
6713 async_block = isAsync;
6714 // Force the next block to be created as a ToplevelBlock
6715 parsing_anonymous_method = true;
6719 * Completes the anonymous method processing, if lambda_expr is null, this
6720 * means that we have a Statement instead of an Expression embedded
6722 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6724 AnonymousMethodExpression retval;
6727 anon_block.IsAsync = true;
6729 current_anonymous_method.Block = anon_block;
6730 retval = current_anonymous_method;
6732 async_block = (bool) oob_stack.Pop ();
6733 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6734 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6735 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6740 void Error_SyntaxError (int token)
6742 Error_SyntaxError (0, token);
6745 void Error_SyntaxError (int error_code, int token)
6747 Error_SyntaxError (error_code, token, "Unexpected symbol");
6750 void Error_SyntaxError (int error_code, int token, string msg)
6752 Lexer.CompleteOnEOF = false;
6754 // An error message has been reported by tokenizer
6755 if (token == Token.ERROR)
6758 string symbol = GetSymbolName (token);
6759 string expecting = GetExpecting ();
6760 var loc = lexer.Location - symbol.Length;
6762 if (error_code == 0) {
6763 if (expecting == "`identifier'") {
6764 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6765 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6770 expecting = "identifier";
6771 } else if (expecting == "`)'") {
6778 if (string.IsNullOrEmpty (expecting))
6779 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6781 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6784 string GetExpecting ()
6786 int [] tokens = yyExpectingTokens (yyExpectingState);
6787 var names = new List<string> (tokens.Length);
6788 bool has_type = false;
6789 bool has_identifier = false;
6790 for (int i = 0; i < tokens.Length; i++){
6791 int token = tokens [i];
6792 has_identifier |= token == Token.IDENTIFIER;
6794 string name = GetTokenName (token);
6795 if (name == "<internal>")
6798 has_type |= name == "type";
6799 if (names.Contains (name))
6806 // Too many tokens to enumerate
6808 if (names.Count > 8)
6811 if (has_type && has_identifier)
6812 names.Remove ("identifier");
6814 if (names.Count == 1)
6815 return "`" + GetTokenName (tokens [0]) + "'";
6817 StringBuilder sb = new StringBuilder ();
6819 int count = names.Count;
6820 for (int i = 0; i < count; i++){
6821 bool last = i + 1 == count;
6825 sb.Append (names [i]);
6826 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6828 return sb.ToString ();
6832 string GetSymbolName (int token)
6836 return ((Constant)lexer.Value).GetValue ().ToString ();
6837 case Token.IDENTIFIER:
6838 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6880 case Token.BITWISE_AND:
6882 case Token.BITWISE_OR:
6896 case Token.OP_SHIFT_LEFT:
6898 case Token.OP_SHIFT_RIGHT:
6918 case Token.OP_COALESCING:
6920 case Token.OP_MULT_ASSIGN:
6922 case Token.OP_DIV_ASSIGN:
6924 case Token.OP_MOD_ASSIGN:
6926 case Token.OP_ADD_ASSIGN:
6928 case Token.OP_SUB_ASSIGN:
6930 case Token.OP_SHIFT_LEFT_ASSIGN:
6932 case Token.OP_SHIFT_RIGHT_ASSIGN:
6934 case Token.OP_AND_ASSIGN:
6936 case Token.OP_XOR_ASSIGN:
6938 case Token.OP_OR_ASSIGN:
6942 return GetTokenName (token);
6945 static string GetTokenName (int token)
6948 case Token.ABSTRACT:
6970 case Token.CONTINUE:
6974 case Token.DELEGATE:
6984 case Token.EXPLICIT:
6987 case Token.EXTERN_ALIAS:
7003 case Token.IMPLICIT:
7007 case Token.INTERFACE:
7009 case Token.INTERNAL:
7015 case Token.NAMESPACE:
7021 case Token.OPERATOR:
7025 case Token.OVERRIDE:
7031 case Token.PROTECTED:
7035 case Token.READONLY:
7047 case Token.STACKALLOC:
7048 return "stackalloc";
7065 case Token.UNCHECKED:
7073 case Token.VOLATILE:
7081 case Token.REFVALUE:
7082 return "__refvalue";
7092 case Token.FROM_FIRST:
7110 case Token.ASCENDING:
7112 case Token.DESCENDING:
7113 return "descending";
7120 case Token.OPEN_BRACE:
7122 case Token.CLOSE_BRACE:
7124 case Token.OPEN_BRACKET:
7125 case Token.OPEN_BRACKET_EXPR:
7127 case Token.CLOSE_BRACKET:
7129 case Token.OPEN_PARENS_CAST:
7130 case Token.OPEN_PARENS_LAMBDA:
7131 case Token.OPEN_PARENS:
7133 case Token.CLOSE_PARENS:
7139 case Token.DEFAULT_COLON:
7143 case Token.SEMICOLON:
7154 case Token.BITWISE_AND:
7155 case Token.BITWISE_OR:
7162 case Token.OP_SHIFT_LEFT:
7163 case Token.OP_SHIFT_RIGHT:
7171 case Token.OP_COALESCING:
7172 case Token.OP_MULT_ASSIGN:
7173 case Token.OP_DIV_ASSIGN:
7174 case Token.OP_MOD_ASSIGN:
7175 case Token.OP_ADD_ASSIGN:
7176 case Token.OP_SUB_ASSIGN:
7177 case Token.OP_SHIFT_LEFT_ASSIGN:
7178 case Token.OP_SHIFT_RIGHT_ASSIGN:
7179 case Token.OP_AND_ASSIGN:
7180 case Token.OP_XOR_ASSIGN:
7181 case Token.OP_OR_ASSIGN:
7182 return "<operator>";
7204 case Token.OP_GENERICS_LT:
7205 case Token.GENERIC_DIMENSION:
7207 case Token.OP_GENERICS_GT:
7210 case Token.INTERR_NULLABLE:
7212 case Token.DOUBLE_COLON:
7216 case Token.IDENTIFIER:
7218 return "identifier";
7221 return "end-of-file";
7223 // All of these are internal.
7226 case Token.FIRST_KEYWORD:
7227 case Token.EVAL_COMPILATION_UNIT_PARSER:
7228 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7229 case Token.EVAL_STATEMENT_PARSER:
7230 case Token.LAST_KEYWORD:
7231 case Token.GENERATE_COMPLETION:
7232 case Token.COMPLETE_COMPLETION:
7233 return "<internal>";
7235 // A bit more robust.
7237 return yyNames [token];