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);
1589 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1596 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1597 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1599 | PARAMS parameter_modifier
1601 Parameter.Modifier mod = (Parameter.Modifier)$2;
1602 if ((mod & Parameter.Modifier.This) != 0) {
1603 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1605 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1608 | PARAMS params_modifier
1610 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1617 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1618 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1622 property_declaration
1626 member_declaration_name
1629 tmpComment = Lexer.consume_doc_comment ();
1633 var type = (FullNamedExpression) $3;
1634 current_property = new Property (current_type, type, (Modifiers) $2,
1635 (MemberName) $4, (Attributes) $1);
1637 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1638 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1640 current_type.AddMember (current_property);
1641 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1643 lexer.PropertyParsing = true;
1645 accessor_declarations
1647 lexer.PropertyParsing = false;
1650 current_property.DocComment = ConsumeStoredComment ();
1654 lbag.AppendToMember (current_property, GetLocation ($10));
1655 current_property = null;
1661 : opt_attributes opt_modifiers
1662 member_type indexer_declaration_name OPEN_BRACKET
1664 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1666 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1668 valid_param_mod = 0;
1669 var type = (FullNamedExpression) $3;
1670 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1672 current_property = indexer;
1674 current_type.AddIndexer (indexer);
1675 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1677 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1678 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1680 if (indexer.ParameterInfo.IsEmpty) {
1681 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1685 tmpComment = Lexer.consume_doc_comment ();
1686 Lexer.doc_state = XmlCommentState.Allowed;
1689 lexer.PropertyParsing = true;
1691 accessor_declarations
1693 lexer.PropertyParsing = false;
1697 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1698 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1701 current_property.DocComment = ConsumeStoredComment ();
1703 lbag.AppendToMember (current_property, GetLocation ($12));
1704 current_property = null;
1709 accessor_declarations
1710 : get_accessor_declaration
1711 | get_accessor_declaration accessor_declarations
1712 | set_accessor_declaration
1713 | set_accessor_declaration accessor_declarations
1716 if (yyToken == Token.CLOSE_BRACE) {
1717 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1719 if (yyToken == Token.SEMICOLON)
1720 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1722 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1727 get_accessor_declaration
1728 : opt_attributes opt_modifiers GET
1730 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1731 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1734 if (current_property.Get != null) {
1735 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1738 if (current_property is Indexer) {
1739 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1740 (Attributes) $1, GetLocation ($3));
1742 current_property.Get = new Property.GetMethod (current_property,
1743 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1746 current_local_parameters = current_property.Get.ParameterInfo;
1747 lbag.AddMember (current_property.Get, mod_locations);
1748 lexer.PropertyParsing = false;
1753 current_property.Get.Block = (ToplevelBlock) $5;
1755 if (current_container.Kind == MemberKind.Interface) {
1756 report.Error (531, current_property.Get.Block.StartLocation,
1757 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1761 current_local_parameters = null;
1762 lexer.PropertyParsing = true;
1765 if (Lexer.doc_state == XmlCommentState.Error)
1766 Lexer.doc_state = XmlCommentState.NotAllowed;
1770 set_accessor_declaration
1771 : opt_attributes opt_modifiers SET
1773 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1774 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1777 if (current_property.Set != null) {
1778 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1781 if (current_property is Indexer) {
1782 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1783 ParametersCompiled.MergeGenerated (compiler,
1784 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1785 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1787 (Attributes) $1, GetLocation ($3));
1789 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1790 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1791 (Attributes) $1, GetLocation ($3));
1794 current_local_parameters = current_property.Set.ParameterInfo;
1795 lbag.AddMember (current_property.Set, mod_locations);
1796 lexer.PropertyParsing = false;
1801 current_property.Set.Block = (ToplevelBlock) $5;
1803 if (current_container.Kind == MemberKind.Interface) {
1804 report.Error (531, current_property.Set.Block.StartLocation,
1805 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1809 current_local_parameters = null;
1810 lexer.PropertyParsing = true;
1813 && Lexer.doc_state == XmlCommentState.Error)
1814 Lexer.doc_state = XmlCommentState.NotAllowed;
1827 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1832 interface_declaration
1838 lexer.ConstraintsParsing = true;
1840 type_declaration_name
1842 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1843 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1846 opt_type_parameter_constraints_clauses
1848 lexer.ConstraintsParsing = false;
1851 current_container.SetConstraints ((List<Constraints>) $9);
1854 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1855 Lexer.doc_state = XmlCommentState.Allowed;
1858 lexer.parsing_modifiers = true;
1860 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1862 --lexer.parsing_declaration;
1864 Lexer.doc_state = XmlCommentState.Allowed;
1868 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1869 $$ = pop_current_class ();
1871 | opt_attributes opt_modifiers opt_partial INTERFACE error
1873 Error_SyntaxError (yyToken);
1877 opt_interface_member_declarations
1879 | interface_member_declarations
1882 interface_member_declarations
1883 : interface_member_declaration
1885 lexer.parsing_modifiers = true;
1887 | interface_member_declarations interface_member_declaration
1889 lexer.parsing_modifiers = true;
1893 interface_member_declaration
1894 : constant_declaration
1896 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1900 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1902 | method_declaration
1903 | property_declaration
1905 | indexer_declaration
1906 | operator_declaration
1908 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1910 | constructor_declaration
1912 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1916 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1920 operator_declaration
1921 : opt_attributes opt_modifiers operator_declarator
1926 OperatorDeclaration decl = (OperatorDeclaration) $3;
1928 Operator op = new Operator (
1929 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
1930 current_local_parameters,
1931 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1933 if (op.Block == null)
1934 op.ParameterInfo.CheckParameters (op);
1937 op.DocComment = tmpComment;
1938 Lexer.doc_state = XmlCommentState.Allowed;
1941 // Note again, checking is done in semantic analysis
1942 current_type.AddOperator (op);
1944 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1947 current_local_parameters = null;
1953 | SEMICOLON { $$ = null; }
1957 : type_expression_or_array
1960 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
1961 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
1966 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1968 valid_param_mod = ParameterModifierType.DefaultValue;
1970 opt_formal_parameter_list CLOSE_PARENS
1972 valid_param_mod = 0;
1974 Location loc = GetLocation ($2);
1975 Operator.OpType op = (Operator.OpType) $3;
1976 current_local_parameters = (ParametersCompiled)$6;
1978 int p_count = current_local_parameters.Count;
1980 if (op == Operator.OpType.Addition)
1981 op = Operator.OpType.UnaryPlus;
1982 else if (op == Operator.OpType.Subtraction)
1983 op = Operator.OpType.UnaryNegation;
1986 if (IsUnaryOperator (op)) {
1988 report.Error (1020, loc, "Overloadable binary operator expected");
1989 } else if (p_count != 1) {
1990 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1991 Operator.GetName (op));
1995 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1996 Operator.GetName (op));
1997 } else if (p_count != 2) {
1998 report.Error (1019, loc, "Overloadable unary operator expected");
2003 tmpComment = Lexer.consume_doc_comment ();
2004 Lexer.doc_state = XmlCommentState.NotAllowed;
2007 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2008 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2010 | conversion_operator_declarator
2013 overloadable_operator
2015 : BANG { $$ = Operator.OpType.LogicalNot; }
2016 | TILDE { $$ = Operator.OpType.OnesComplement; }
2017 | OP_INC { $$ = Operator.OpType.Increment; }
2018 | OP_DEC { $$ = Operator.OpType.Decrement; }
2019 | TRUE { $$ = Operator.OpType.True; }
2020 | FALSE { $$ = Operator.OpType.False; }
2021 // Unary and binary:
2022 | PLUS { $$ = Operator.OpType.Addition; }
2023 | MINUS { $$ = Operator.OpType.Subtraction; }
2025 | STAR { $$ = Operator.OpType.Multiply; }
2026 | DIV { $$ = Operator.OpType.Division; }
2027 | PERCENT { $$ = Operator.OpType.Modulus; }
2028 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2029 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2030 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2031 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2032 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2033 | OP_EQ { $$ = Operator.OpType.Equality; }
2034 | OP_NE { $$ = Operator.OpType.Inequality; }
2035 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2036 | OP_LT { $$ = Operator.OpType.LessThan; }
2037 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2038 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2041 conversion_operator_declarator
2042 : IMPLICIT OPERATOR type OPEN_PARENS
2044 valid_param_mod = ParameterModifierType.DefaultValue;
2046 opt_formal_parameter_list CLOSE_PARENS
2048 valid_param_mod = 0;
2050 Location loc = GetLocation ($2);
2051 current_local_parameters = (ParametersCompiled)$6;
2054 tmpComment = Lexer.consume_doc_comment ();
2055 Lexer.doc_state = XmlCommentState.NotAllowed;
2058 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2059 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2061 | EXPLICIT OPERATOR type OPEN_PARENS
2063 valid_param_mod = ParameterModifierType.DefaultValue;
2065 opt_formal_parameter_list CLOSE_PARENS
2067 valid_param_mod = 0;
2069 Location loc = GetLocation ($2);
2070 current_local_parameters = (ParametersCompiled)$6;
2073 tmpComment = Lexer.consume_doc_comment ();
2074 Lexer.doc_state = XmlCommentState.NotAllowed;
2077 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2078 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2082 Error_SyntaxError (yyToken);
2083 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2084 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2088 Error_SyntaxError (yyToken);
2089 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2090 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2094 constructor_declaration
2095 : constructor_declarator
2098 Constructor c = (Constructor) $1;
2099 c.Block = (ToplevelBlock) $2;
2102 c.DocComment = ConsumeStoredComment ();
2104 current_local_parameters = null;
2106 Lexer.doc_state = XmlCommentState.Allowed;
2110 constructor_declarator
2116 tmpComment = Lexer.consume_doc_comment ();
2117 Lexer.doc_state = XmlCommentState.Allowed;
2120 valid_param_mod = ParameterModifierType.All;
2122 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2124 valid_param_mod = 0;
2125 current_local_parameters = (ParametersCompiled) $6;
2127 var lt = (Tokenizer.LocatedToken) $3;
2128 var mods = (Modifiers) $2;
2129 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2131 if (lt.Value != current_container.MemberName.Name) {
2132 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2133 } else if ((mods & Modifiers.STATIC) != 0) {
2134 if ((mods & Modifiers.AccessibilityMask) != 0){
2135 report.Error (515, c.Location,
2136 "`{0}': static constructor cannot have an access modifier",
2137 c.GetSignatureForError ());
2141 current_type.AddConstructor (c);
2142 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2146 // start block here, so possible anonymous methods inside
2147 // constructor initializer can get correct parent block
2149 start_block (lexer.Location);
2151 opt_constructor_initializer
2154 var c = (Constructor) $8;
2155 c.Initializer = (ConstructorInitializer) $9;
2158 report.Error (514, c.Location,
2159 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2160 c.GetSignatureForError ());
2170 | SEMICOLON { current_block = null; $$ = null; }
2173 opt_constructor_initializer
2175 | constructor_initializer
2178 constructor_initializer
2179 : COLON BASE OPEN_PARENS
2181 ++lexer.parsing_block;
2183 opt_argument_list CLOSE_PARENS
2185 --lexer.parsing_block;
2186 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2187 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2189 | COLON THIS OPEN_PARENS
2191 ++lexer.parsing_block;
2193 opt_argument_list CLOSE_PARENS
2195 --lexer.parsing_block;
2196 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2197 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2201 Error_SyntaxError (yyToken);
2202 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2203 lbag.AddLocation ($$, GetLocation ($1));
2207 Error_SyntaxError (yyToken);
2212 destructor_declaration
2213 : opt_attributes opt_modifiers TILDE
2216 tmpComment = Lexer.consume_doc_comment ();
2217 Lexer.doc_state = XmlCommentState.NotAllowed;
2220 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2222 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2224 var lt = (Tokenizer.LocatedToken) $5;
2225 if (lt.Value != current_container.MemberName.Name){
2226 report.Error (574, lt.Location, "Name of destructor must match name of class");
2227 } else if (current_container.Kind != MemberKind.Class){
2228 report.Error (575, lt.Location, "Only class types can contain destructor");
2231 Destructor d = new Destructor (current_type, (Modifiers) $2,
2232 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2234 d.DocComment = ConsumeStoredComment ();
2236 d.Block = (ToplevelBlock) $8;
2237 current_type.AddMember (d);
2238 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2240 current_local_parameters = null;
2247 EVENT type member_declaration_name
2249 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2250 current_type.AddMember (current_event_field);
2252 if (current_event_field.MemberName.ExplicitInterface != null) {
2253 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2254 current_event_field.GetSignatureForError ());
2257 $$ = current_event_field;
2259 opt_event_initializer
2260 opt_event_declarators
2264 current_event_field.DocComment = Lexer.consume_doc_comment ();
2265 Lexer.doc_state = XmlCommentState.Allowed;
2268 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2269 current_event_field = null;
2273 EVENT type member_declaration_name
2276 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2277 current_type.AddMember (current_event);
2278 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2280 lexer.EventParsing = true;
2282 event_accessor_declarations
2284 if (current_container.Kind == MemberKind.Interface)
2285 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2287 lexer.EventParsing = false;
2292 current_event.DocComment = Lexer.consume_doc_comment ();
2293 Lexer.doc_state = XmlCommentState.Allowed;
2296 lbag.AppendToMember (current_event, GetLocation ($9));
2297 current_event = null;
2298 current_local_parameters = null;
2302 opt_event_initializer
2306 ++lexer.parsing_block;
2308 event_variable_initializer
2310 --lexer.parsing_block;
2311 current_event_field.Initializer = (Expression) $3;
2315 opt_event_declarators
2323 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2325 | event_declarators event_declarator
2327 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2334 var lt = (Tokenizer.LocatedToken) $2;
2335 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2336 lbag.AddLocation ($$, GetLocation ($1));
2338 | COMMA IDENTIFIER ASSIGN
2340 ++lexer.parsing_block;
2342 event_variable_initializer
2344 --lexer.parsing_block;
2345 var lt = (Tokenizer.LocatedToken) $2;
2346 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2347 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2351 event_variable_initializer
2353 if (current_container.Kind == MemberKind.Interface) {
2354 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2355 current_event_field.GetSignatureForError ());
2358 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2359 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2360 current_event_field.GetSignatureForError ());
2363 variable_initializer
2369 event_accessor_declarations
2370 : add_accessor_declaration remove_accessor_declaration
2371 | remove_accessor_declaration add_accessor_declaration
2372 | add_accessor_declaration
2374 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2375 current_event.GetSignatureForError ());
2377 | remove_accessor_declaration
2379 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2380 current_event.GetSignatureForError ());
2384 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2389 add_accessor_declaration
2390 : opt_attributes opt_modifiers ADD
2392 if ($2 != ModifierNone) {
2393 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2396 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2397 current_local_parameters = current_event.Add.ParameterInfo;
2399 lbag.AddMember (current_event.Add, mod_locations);
2400 lexer.EventParsing = false;
2402 event_accessor_block
2404 lexer.EventParsing = true;
2406 current_event.Add.Block = (ToplevelBlock) $5;
2408 if (current_container.Kind == MemberKind.Interface) {
2409 report.Error (531, current_event.Add.Block.StartLocation,
2410 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2413 current_local_parameters = null;
2417 remove_accessor_declaration
2418 : opt_attributes opt_modifiers REMOVE
2420 if ($2 != ModifierNone) {
2421 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2424 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2425 current_local_parameters = current_event.Remove.ParameterInfo;
2427 lbag.AddMember (current_event.Remove, mod_locations);
2428 lexer.EventParsing = false;
2430 event_accessor_block
2432 lexer.EventParsing = true;
2434 current_event.Remove.Block = (ToplevelBlock) $5;
2436 if (current_container.Kind == MemberKind.Interface) {
2437 report.Error (531, current_event.Remove.Block.StartLocation,
2438 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2441 current_local_parameters = null;
2445 event_accessor_block
2448 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2454 attributes_without_members
2455 : attribute_sections CLOSE_BRACE
2457 current_type.UnattachedAttributes = (Attributes) $1;
2458 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2459 lexer.putback ('}');
2466 ENUM type_declaration_name
2470 enumTypeComment = Lexer.consume_doc_comment ();
2475 Lexer.doc_state = XmlCommentState.Allowed;
2477 MemberName name = (MemberName) $4;
2478 if (name.IsGeneric) {
2479 report.Error (1675, name.Location, "Enums cannot have type parameters");
2482 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2484 opt_enum_member_declarations
2486 // here will be evaluated after CLOSE_BLACE is consumed.
2488 Lexer.doc_state = XmlCommentState.Allowed;
2490 CLOSE_BRACE opt_semicolon
2493 current_container.DocComment = enumTypeComment;
2495 --lexer.parsing_declaration;
2498 // em.DocComment = ev.DocComment;
2500 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2501 $$ = pop_current_class ();
2509 var te = $2 as TypeExpression;
2510 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2511 Enum.Error_1008 (GetLocation ($2), report);
2517 Error_TypeExpected (GetLocation ($1));
2522 opt_enum_member_declarations
2524 | enum_member_declarations
2525 | enum_member_declarations COMMA
2527 lbag.AddLocation ($1, GetLocation ($2));
2531 enum_member_declarations
2532 : enum_member_declaration
2533 | enum_member_declarations COMMA enum_member_declaration
2535 lbag.AddLocation ($1, GetLocation ($2));
2540 enum_member_declaration
2541 : opt_attributes IDENTIFIER
2543 var lt = (Tokenizer.LocatedToken) $2;
2544 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2545 ((Enum) current_type).AddEnumMember (em);
2548 em.DocComment = Lexer.consume_doc_comment ();
2549 Lexer.doc_state = XmlCommentState.Allowed;
2554 | opt_attributes IDENTIFIER
2556 ++lexer.parsing_block;
2558 tmpComment = Lexer.consume_doc_comment ();
2559 Lexer.doc_state = XmlCommentState.NotAllowed;
2562 ASSIGN constant_expression
2564 --lexer.parsing_block;
2566 var lt = (Tokenizer.LocatedToken) $2;
2567 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2568 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2569 ((Enum) current_type).AddEnumMember (em);
2572 em.DocComment = ConsumeStoredComment ();
2576 | opt_attributes IDENTIFIER error
2578 Error_SyntaxError (yyToken);
2580 var lt = (Tokenizer.LocatedToken) $2;
2581 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2582 ((Enum) current_type).AddEnumMember (em);
2585 em.DocComment = Lexer.consume_doc_comment ();
2586 Lexer.doc_state = XmlCommentState.Allowed;
2591 | attributes_without_members
2594 delegate_declaration
2598 member_type type_declaration_name
2601 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2603 opt_formal_parameter_list CLOSE_PARENS
2605 valid_param_mod = 0;
2607 ParametersCompiled p = (ParametersCompiled) $8;
2609 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2611 p.CheckParameters (del);
2613 current_container.AddTypeContainer (del);
2615 current_delegate = del;
2616 lexer.ConstraintsParsing = true;
2618 opt_type_parameter_constraints_clauses
2620 lexer.ConstraintsParsing = false;
2625 current_delegate.DocComment = Lexer.consume_doc_comment ();
2626 Lexer.doc_state = XmlCommentState.Allowed;
2630 current_delegate.SetConstraints ((List<Constraints>) $11);
2631 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2633 $$ = current_delegate;
2635 current_delegate = null;
2643 if (lang_version < LanguageVersion.ISO_2)
2644 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2646 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2650 namespace_or_type_expr
2652 | qualified_alias_member IDENTIFIER opt_type_argument_list
2654 var lt1 = (Tokenizer.LocatedToken) $1;
2655 var lt2 = (Tokenizer.LocatedToken) $2;
2657 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2658 lbag.AddLocation ($$, GetLocation ($2));
2664 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2666 var lt = (Tokenizer.LocatedToken) $3;
2667 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2668 lbag.AddLocation ($$, GetLocation ($2));
2673 : IDENTIFIER opt_type_argument_list
2675 var lt = (Tokenizer.LocatedToken) $1;
2676 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2681 // Generics arguments (any type, without attributes)
2683 opt_type_argument_list
2685 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2687 if (lang_version < LanguageVersion.ISO_2)
2688 FeatureIsNotAvailable (GetLocation ($1), "generics");
2692 | OP_GENERICS_LT error
2694 Error_TypeExpected (lexer.Location);
2695 $$ = new TypeArguments ();
2702 TypeArguments type_args = new TypeArguments ();
2703 type_args.Add ((FullNamedExpression) $1);
2706 | type_arguments COMMA type
2708 TypeArguments type_args = (TypeArguments) $1;
2709 type_args.Add ((FullNamedExpression) $3);
2715 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2717 type_declaration_name
2720 lexer.parsing_generic_declaration = true;
2722 opt_type_parameter_list
2724 lexer.parsing_generic_declaration = false;
2725 var lt = (Tokenizer.LocatedToken) $1;
2726 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2730 member_declaration_name
2731 : method_declaration_name
2733 MemberName mn = (MemberName)$1;
2734 if (mn.TypeParameters != null)
2735 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2736 mn.GetSignatureForError ()));
2740 method_declaration_name
2741 : type_declaration_name
2742 | explicit_interface IDENTIFIER opt_type_parameter_list
2744 lexer.parsing_generic_declaration = false;
2745 var lt = (Tokenizer.LocatedToken) $2;
2746 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2750 indexer_declaration_name
2753 lexer.parsing_generic_declaration = false;
2754 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2756 | explicit_interface THIS
2758 lexer.parsing_generic_declaration = false;
2759 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2764 : IDENTIFIER opt_type_argument_list DOT
2766 var lt = (Tokenizer.LocatedToken) $1;
2767 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2768 lbag.AddLocation ($$, GetLocation ($3));
2770 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2772 var lt1 = (Tokenizer.LocatedToken) $1;
2773 var lt2 = (Tokenizer.LocatedToken) $2;
2775 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2776 lbag.AddLocation ($$, GetLocation ($4));
2778 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2780 var lt = (Tokenizer.LocatedToken) $2;
2781 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2782 lbag.AddLocation ($$, GetLocation ($4));
2786 opt_type_parameter_list
2788 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2790 if (lang_version < LanguageVersion.ISO_2)
2791 FeatureIsNotAvailable (GetLocation ($1), "generics");
2794 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2801 var tparams = new TypeParameters ();
2802 tparams.Add ((TypeParameter)$1);
2805 | type_parameters COMMA type_parameter
2807 var tparams = (TypeParameters) $1;
2808 tparams.Add ((TypeParameter)$3);
2810 lbag.AddLocation ($3, GetLocation ($3));
2815 : opt_attributes opt_type_parameter_variance IDENTIFIER
2817 var lt = (Tokenizer.LocatedToken)$3;
2818 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2822 if (GetTokenName (yyToken) == "type")
2823 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2825 Error_SyntaxError (yyToken);
2827 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2832 // All types where void is allowed
2835 : type_expression_or_array
2838 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2845 lexer.parsing_generic_declaration = true;
2850 // A type which does not allow `void' to be used
2853 : type_expression_or_array
2856 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2857 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2865 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2866 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2871 : type_expression_or_array
2874 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2875 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2879 type_expression_or_array
2881 | type_expression rank_specifiers
2883 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2888 : namespace_or_type_expr opt_nullable
2891 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2893 var sn = $1 as SimpleName;
2894 if (sn != null && sn.Name == "var")
2895 $$ = new VarExpr (sn.Location);
2900 | namespace_or_type_expr pointer_stars
2902 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2904 | builtin_types opt_nullable
2907 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2909 | builtin_types pointer_stars
2911 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2913 | VOID pointer_stars
2915 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2922 var types = new List<FullNamedExpression> (2);
2923 types.Add ((FullNamedExpression) $1);
2926 | type_list COMMA base_type_name
2928 var types = (List<FullNamedExpression>) $1;
2929 types.Add ((FullNamedExpression) $3);
2937 if ($1 is ComposedCast) {
2938 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2945 * replaces all the productions for isolating the various
2946 * simple types, but we need this to reuse it easily in variable_type
2949 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
2950 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
2951 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
2952 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
2953 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
2954 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
2959 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
2960 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
2961 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
2962 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
2963 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
2964 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
2965 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
2966 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
2967 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
2971 // Expressions, section 7.5
2976 : primary_expression_or_type
2978 | array_creation_expression
2979 | parenthesized_expression
2980 | default_value_expression
2981 | invocation_expression
2985 | post_increment_expression
2986 | post_decrement_expression
2987 | object_or_delegate_creation_expression
2988 | anonymous_type_expression
2991 | checked_expression
2992 | unchecked_expression
2993 | pointer_member_access
2994 | anonymous_method_expression
2995 | undocumented_expressions
2998 primary_expression_or_type
2999 : IDENTIFIER opt_type_argument_list
3001 var lt = (Tokenizer.LocatedToken) $1;
3002 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3004 | IDENTIFIER GENERATE_COMPLETION {
3005 var lt = (Tokenizer.LocatedToken) $1;
3006 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3014 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3018 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3019 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3024 // Here is the trick, tokenizer may think that parens is a special but
3025 // parser is interested in open parens only, so we merge them.
3026 // Consider: if (a)foo ();
3034 // Use this production to accept closing parenthesis or
3035 // performing completion
3039 | COMPLETE_COMPLETION
3043 parenthesized_expression
3044 : OPEN_PARENS expression CLOSE_PARENS
3046 $$ = new ParenthesizedExpression ((Expression) $2);
3047 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3049 | OPEN_PARENS expression COMPLETE_COMPLETION
3051 $$ = new ParenthesizedExpression ((Expression) $2);
3056 : primary_expression DOT IDENTIFIER opt_type_argument_list
3058 var lt = (Tokenizer.LocatedToken) $3;
3059 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3060 lbag.AddLocation ($$, GetLocation ($2));
3062 | builtin_types DOT IDENTIFIER opt_type_argument_list
3064 var lt = (Tokenizer.LocatedToken) $3;
3065 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3066 lbag.AddLocation ($$, GetLocation ($2));
3068 | BASE DOT IDENTIFIER opt_type_argument_list
3070 var lt = (Tokenizer.LocatedToken) $3;
3071 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3072 lbag.AddLocation ($$, GetLocation ($2));
3074 | qualified_alias_member IDENTIFIER opt_type_argument_list
3076 var lt1 = (Tokenizer.LocatedToken) $1;
3077 var lt2 = (Tokenizer.LocatedToken) $2;
3079 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3080 lbag.AddLocation ($$, GetLocation ($2));
3082 | primary_expression DOT GENERATE_COMPLETION {
3083 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3085 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3086 var lt = (Tokenizer.LocatedToken) $3;
3087 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3089 | builtin_types DOT GENERATE_COMPLETION
3091 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3093 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3094 var lt = (Tokenizer.LocatedToken) $3;
3095 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3099 invocation_expression
3100 : primary_expression open_parens_any opt_argument_list close_parens
3102 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3103 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3105 | primary_expression open_parens_any argument_list error
3107 Error_SyntaxError (yyToken);
3109 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3110 lbag.AddLocation ($$, GetLocation ($2));
3115 opt_object_or_collection_initializer
3116 : /* empty */ { $$ = null; }
3117 | object_or_collection_initializer
3120 object_or_collection_initializer
3121 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3124 $$ = CollectionOrObjectInitializers.Empty;
3127 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3128 lbag.AddLocation ($$, GetLocation ($3));
3131 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3133 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3134 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3138 opt_member_initializer_list
3139 : /* empty */ { $$ = null; }
3140 | member_initializer_list
3146 member_initializer_list
3147 : member_initializer
3149 var a = new List<Expression> ();
3150 a.Add ((Expression) $1);
3153 | member_initializer_list COMMA member_initializer
3155 var a = (List<Expression>)$1;
3156 a.Add ((Expression) $3);
3159 | member_initializer_list error {
3160 Error_SyntaxError (yyToken);
3166 : IDENTIFIER ASSIGN initializer_value
3168 var lt = (Tokenizer.LocatedToken) $1;
3169 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3170 lbag.AddLocation ($$, GetLocation ($2));
3172 | GENERATE_COMPLETION
3174 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3176 | non_assignment_expression opt_COMPLETE_COMPLETION {
3177 CompletionSimpleName csn = $1 as CompletionSimpleName;
3179 $$ = new CollectionElementInitializer ((Expression)$1);
3181 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3183 | OPEN_BRACE expression_list CLOSE_BRACE
3188 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3190 | OPEN_BRACE CLOSE_BRACE
3192 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3199 | object_or_collection_initializer
3203 : /* empty */ { $$ = null; }
3208 : argument_or_named_argument
3210 Arguments list = new Arguments (4);
3211 list.Add ((Argument) $1);
3214 | argument_list COMMA argument
3216 Arguments list = (Arguments) $1;
3217 if (list [list.Count - 1] is NamedArgument)
3218 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3220 list.Add ((Argument) $3);
3223 | argument_list COMMA named_argument
3225 Arguments list = (Arguments) $1;
3226 NamedArgument a = (NamedArgument) $3;
3227 for (int i = 0; i < list.Count; ++i) {
3228 NamedArgument na = list [i] as NamedArgument;
3229 if (na != null && na.Name == a.Name)
3230 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3237 | argument_list COMMA error
3239 lexer.putback (')'); // TODO: Wrong but what can I do
3240 Error_SyntaxError (yyToken);
3245 report.Error (839, GetLocation ($1), "An argument is missing");
3253 $$ = new Argument ((Expression) $1);
3255 | non_simple_argument
3258 argument_or_named_argument
3264 : REF variable_reference
3266 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3267 lbag.AddLocation ($$, GetLocation ($1));
3269 | OUT variable_reference
3271 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3272 lbag.AddLocation ($$, GetLocation ($1));
3274 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3276 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3277 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3279 | ARGLIST OPEN_PARENS CLOSE_PARENS
3281 $$ = new Argument (new Arglist (GetLocation ($1)));
3282 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3291 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3293 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3294 lbag.AddLocation ($$, GetLocation ($4));
3296 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3298 Error_SyntaxError (yyToken);
3299 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3301 | primary_expression OPEN_BRACKET_EXPR error
3303 Error_SyntaxError (yyToken);
3304 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3311 var list = new List<Expression> (4);
3312 list.Add ((Expression) $1);
3315 | expression_list COMMA expression
3317 var list = (List<Expression>) $1;
3318 list.Add ((Expression) $3);
3321 | expression_list error {
3322 Error_SyntaxError (yyToken);
3327 expression_list_arguments
3328 : expression_list_argument
3330 Arguments args = new Arguments (4);
3331 args.Add ((Argument) $1);
3334 | expression_list_arguments COMMA expression_list_argument
3336 Arguments args = (Arguments) $1;
3337 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3338 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3340 args.Add ((Argument) $3);
3345 expression_list_argument
3348 $$ = new Argument ((Expression) $1);
3356 $$ = new This (GetLocation ($1));
3361 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3363 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3364 lbag.AddLocation ($$, GetLocation ($4));
3366 | BASE OPEN_BRACKET error
3368 Error_SyntaxError (yyToken);
3369 $$ = new ElementAccess (null, null, GetLocation ($2));
3373 post_increment_expression
3374 : primary_expression OP_INC
3376 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3380 post_decrement_expression
3381 : primary_expression OP_DEC
3383 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3387 object_or_delegate_creation_expression
3388 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3391 if (lang_version <= LanguageVersion.ISO_2)
3392 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3394 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3396 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3399 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3401 | NEW new_expr_type object_or_collection_initializer
3403 if (lang_version <= LanguageVersion.ISO_2)
3404 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3406 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3410 array_creation_expression
3411 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3413 opt_array_initializer
3415 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3416 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3417 Next = (ComposedTypeSpecifier) $6
3418 }, (ArrayInitializer) $7, GetLocation ($1));
3419 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3421 | NEW new_expr_type rank_specifiers opt_array_initializer
3424 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3426 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3428 | NEW rank_specifier array_initializer
3430 if (lang_version <= LanguageVersion.ISO_2)
3431 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3433 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3435 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3437 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3438 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3440 | NEW new_expr_type error
3442 Error_SyntaxError (yyToken);
3443 // It can be any of new expression, create the most common one
3444 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3450 ++lexer.parsing_type;
3454 --lexer.parsing_type;
3459 anonymous_type_expression
3460 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3462 if (lang_version <= LanguageVersion.ISO_2)
3463 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3465 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3467 // TODO: lbag comma location
3468 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3472 anonymous_type_parameters_opt_comma
3473 : anonymous_type_parameters_opt
3474 | anonymous_type_parameters COMMA
3477 anonymous_type_parameters_opt
3479 | anonymous_type_parameters
3482 anonymous_type_parameters
3483 : anonymous_type_parameter
3485 var a = new List<AnonymousTypeParameter> (4);
3486 a.Add ((AnonymousTypeParameter) $1);
3489 | anonymous_type_parameters COMMA anonymous_type_parameter
3491 var a = (List<AnonymousTypeParameter>) $1;
3492 a.Add ((AnonymousTypeParameter) $3);
3497 anonymous_type_parameter
3498 : IDENTIFIER ASSIGN variable_initializer
3500 var lt = (Tokenizer.LocatedToken)$1;
3501 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3502 lbag.AddLocation ($$, GetLocation ($2));
3506 var lt = (Tokenizer.LocatedToken)$1;
3507 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3508 lt.Value, lt.Location);
3512 MemberAccess ma = (MemberAccess) $1;
3513 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3517 report.Error (746, lexer.Location,
3518 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3530 | rank_specifier rank_specifiers
3532 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3538 : OPEN_BRACKET CLOSE_BRACKET
3540 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3541 lbag.AddLocation ($$, GetLocation ($2));
3543 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3545 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3546 lbag.AddLocation ($$, GetLocation ($3));
3555 | dim_separators COMMA
3557 $$ = ((int) $1) + 1;
3561 opt_array_initializer
3573 : OPEN_BRACE CLOSE_BRACE
3575 var ai = new ArrayInitializer (0, GetLocation ($1));
3576 ai.VariableDeclaration = current_variable;
3577 lbag.AddLocation (ai, GetLocation ($2));
3580 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3582 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3583 ai.VariableDeclaration = current_variable;
3585 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3587 lbag.AddLocation (ai, GetLocation ($4));
3593 variable_initializer_list
3594 : variable_initializer
3596 var list = new List<Expression> (4);
3597 list.Add ((Expression) $1);
3600 | variable_initializer_list COMMA variable_initializer
3602 var list = (List<Expression>) $1;
3603 list.Add ((Expression) $3);
3611 lexer.TypeOfParsing = true;
3613 open_parens_any typeof_type_expression CLOSE_PARENS
3615 lexer.TypeOfParsing = false;
3616 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3617 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3621 typeof_type_expression
3626 Error_TypeExpected (lexer.Location);
3632 : identifier_inside_body generic_dimension
3634 var lt = (Tokenizer.LocatedToken) $1;
3636 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3638 | qualified_alias_member identifier_inside_body generic_dimension
3640 var lt1 = (Tokenizer.LocatedToken) $1;
3641 var lt2 = (Tokenizer.LocatedToken) $2;
3643 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3644 lbag.AddLocation ($$, GetLocation ($2));
3646 | unbound_type_name DOT identifier_inside_body
3648 var lt = (Tokenizer.LocatedToken) $3;
3650 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3652 | unbound_type_name DOT identifier_inside_body generic_dimension
3654 var lt = (Tokenizer.LocatedToken) $3;
3656 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3658 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3660 var tne = (ATypeNameExpression) $1;
3661 if (tne.HasTypeArguments)
3662 Error_TypeExpected (GetLocation ($4));
3664 var lt = (Tokenizer.LocatedToken) $3;
3665 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3672 if (lang_version < LanguageVersion.ISO_2)
3673 FeatureIsNotAvailable (GetLocation ($1), "generics");
3679 qualified_alias_member
3680 : IDENTIFIER DOUBLE_COLON
3682 var lt = (Tokenizer.LocatedToken) $1;
3683 if (lang_version == LanguageVersion.ISO_1)
3684 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3691 : SIZEOF open_parens_any type CLOSE_PARENS
3693 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3694 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3699 : CHECKED open_parens_any expression CLOSE_PARENS
3701 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3702 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3706 unchecked_expression
3707 : UNCHECKED open_parens_any expression CLOSE_PARENS
3709 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3710 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3714 pointer_member_access
3715 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3717 var lt = (Tokenizer.LocatedToken) $3;
3718 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3722 anonymous_method_expression
3723 : DELEGATE opt_anonymous_method_signature
3725 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3729 $$ = end_anonymous ((ParametersBlock) $4);
3731 | ASYNC DELEGATE opt_anonymous_method_signature
3733 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3737 $$ = end_anonymous ((ParametersBlock) $5);
3741 opt_anonymous_method_signature
3744 $$ = ParametersCompiled.Undefined;
3746 | anonymous_method_signature
3749 anonymous_method_signature
3752 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3754 opt_formal_parameter_list CLOSE_PARENS
3756 valid_param_mod = 0;
3761 default_value_expression
3762 : DEFAULT open_parens_any type CLOSE_PARENS
3764 if (lang_version < LanguageVersion.ISO_2)
3765 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3767 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3768 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3773 : primary_expression
3774 | BANG prefixed_unary_expression
3776 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3778 | TILDE prefixed_unary_expression
3780 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3782 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3784 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3785 lbag.AddLocation ($$, GetLocation ($3));
3787 | AWAIT prefixed_unary_expression
3790 if (current_anonymous_method is LambdaExpression) {
3791 report.Error (4034, GetLocation ($1),
3792 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3793 } else if (current_anonymous_method is AnonymousMethodExpression) {
3794 report.Error (4035, GetLocation ($1),
3795 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3797 report.Error (4033, GetLocation ($1),
3798 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3801 current_block.Explicit.RegisterAsyncAwait ();
3804 $$ = new Await ((Expression) $2, GetLocation ($1));
3809 // The idea to split this out is from Rhys' grammar
3810 // to solve the problem with casts.
3812 prefixed_unary_expression
3814 | PLUS prefixed_unary_expression
3816 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3818 | MINUS prefixed_unary_expression
3820 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3822 | OP_INC prefixed_unary_expression
3824 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3826 | OP_DEC prefixed_unary_expression
3828 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3830 | STAR prefixed_unary_expression
3832 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3834 | BITWISE_AND prefixed_unary_expression
3836 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3840 multiplicative_expression
3841 : prefixed_unary_expression
3842 | multiplicative_expression STAR prefixed_unary_expression
3844 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3845 lbag.AddLocation ($$, GetLocation ($2));
3847 | multiplicative_expression DIV prefixed_unary_expression
3849 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
3850 lbag.AddLocation ($$, GetLocation ($2));
3852 | multiplicative_expression PERCENT prefixed_unary_expression
3854 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3855 lbag.AddLocation ($$, GetLocation ($2));
3860 : multiplicative_expression
3861 | additive_expression PLUS multiplicative_expression
3863 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3864 lbag.AddLocation ($$, GetLocation ($2));
3866 | additive_expression MINUS multiplicative_expression
3868 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3869 lbag.AddLocation ($$, GetLocation ($2));
3871 | additive_expression AS type
3873 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3875 | additive_expression IS type
3877 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3882 : additive_expression
3883 | shift_expression OP_SHIFT_LEFT additive_expression
3885 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3886 lbag.AddLocation ($$, GetLocation ($2));
3888 | shift_expression OP_SHIFT_RIGHT additive_expression
3890 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3891 lbag.AddLocation ($$, GetLocation ($2));
3895 relational_expression
3897 | relational_expression OP_LT shift_expression
3899 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
3900 lbag.AddLocation ($$, GetLocation ($2));
3902 | relational_expression OP_GT shift_expression
3904 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
3905 lbag.AddLocation ($$, GetLocation ($2));
3907 | relational_expression OP_LE shift_expression
3909 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
3910 lbag.AddLocation ($$, GetLocation ($2));
3912 | relational_expression OP_GE shift_expression
3914 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
3915 lbag.AddLocation ($$, GetLocation ($2));
3920 : relational_expression
3921 | equality_expression OP_EQ relational_expression
3923 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
3924 lbag.AddLocation ($$, GetLocation ($2));
3926 | equality_expression OP_NE relational_expression
3928 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
3929 lbag.AddLocation ($$, GetLocation ($2));
3934 : equality_expression
3935 | and_expression BITWISE_AND equality_expression
3937 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3938 lbag.AddLocation ($$, GetLocation ($2));
3942 exclusive_or_expression
3944 | exclusive_or_expression CARRET and_expression
3946 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3947 lbag.AddLocation ($$, GetLocation ($2));
3951 inclusive_or_expression
3952 : exclusive_or_expression
3953 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3955 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3956 lbag.AddLocation ($$, GetLocation ($2));
3960 conditional_and_expression
3961 : inclusive_or_expression
3962 | conditional_and_expression OP_AND inclusive_or_expression
3964 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
3965 lbag.AddLocation ($$, GetLocation ($2));
3969 conditional_or_expression
3970 : conditional_and_expression
3971 | conditional_or_expression OP_OR conditional_and_expression
3973 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
3974 lbag.AddLocation ($$, GetLocation ($2));
3978 null_coalescing_expression
3979 : conditional_or_expression
3980 | conditional_or_expression OP_COALESCING null_coalescing_expression
3982 if (lang_version < LanguageVersion.ISO_2)
3983 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3985 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
3986 lbag.AddLocation ($$, GetLocation ($2));
3990 conditional_expression
3991 : null_coalescing_expression
3992 | null_coalescing_expression INTERR expression COLON expression_or_error
3994 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3995 lbag.AddLocation ($$, GetLocation ($4));
3997 | null_coalescing_expression INTERR expression error
3999 Error_SyntaxError (yyToken);
4000 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4004 assignment_expression
4005 : prefixed_unary_expression ASSIGN expression
4007 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4008 lbag.AddLocation ($$, GetLocation ($2));
4010 | prefixed_unary_expression OP_MULT_ASSIGN expression
4012 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4013 lbag.AddLocation ($$, GetLocation ($2));
4015 | prefixed_unary_expression OP_DIV_ASSIGN expression
4017 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4018 lbag.AddLocation ($$, GetLocation ($2));
4020 | prefixed_unary_expression OP_MOD_ASSIGN expression
4022 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4023 lbag.AddLocation ($$, GetLocation ($2));
4025 | prefixed_unary_expression OP_ADD_ASSIGN expression
4027 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4028 lbag.AddLocation ($$, GetLocation ($2));
4030 | prefixed_unary_expression OP_SUB_ASSIGN expression
4032 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4033 lbag.AddLocation ($$, GetLocation ($2));
4035 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4037 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4038 lbag.AddLocation ($$, GetLocation ($2));
4040 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4042 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4043 lbag.AddLocation ($$, GetLocation ($2));
4045 | prefixed_unary_expression OP_AND_ASSIGN expression
4047 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4048 lbag.AddLocation ($$, GetLocation ($2));
4050 | prefixed_unary_expression OP_OR_ASSIGN expression
4052 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4053 lbag.AddLocation ($$, GetLocation ($2));
4055 | prefixed_unary_expression OP_XOR_ASSIGN expression
4057 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4058 lbag.AddLocation ($$, GetLocation ($2));
4062 lambda_parameter_list
4065 var pars = new List<Parameter> (4);
4066 pars.Add ((Parameter) $1);
4070 | lambda_parameter_list COMMA lambda_parameter
4072 var pars = (List<Parameter>) $1;
4073 Parameter p = (Parameter)$3;
4074 if (pars[0].GetType () != p.GetType ()) {
4075 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4084 : parameter_modifier parameter_type identifier_inside_body
4086 var lt = (Tokenizer.LocatedToken) $3;
4088 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4090 | parameter_type identifier_inside_body
4092 var lt = (Tokenizer.LocatedToken) $2;
4094 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4098 var lt = (Tokenizer.LocatedToken) $1;
4099 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4103 opt_lambda_parameter_list
4104 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4105 | lambda_parameter_list {
4106 var pars_list = (List<Parameter>) $1;
4107 $$ = new ParametersCompiled (pars_list.ToArray ());
4111 lambda_expression_body
4112 : lambda_expression_body_simple
4116 lambda_expression_body_simple
4118 start_block (Location.Null);
4120 expression_or_error // Have to close block when error occurs
4122 Block b = end_block (Location.Null);
4123 b.IsCompilerGenerated = true;
4124 b.AddStatement (new ContextualReturn ((Expression) $2));
4133 Error_SyntaxError (yyToken);
4134 $$ = EmptyExpression.Null;
4141 var lt = (Tokenizer.LocatedToken) $1;
4142 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4143 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4145 lambda_expression_body
4147 $$ = end_anonymous ((ParametersBlock) $4);
4148 lbag.AddLocation ($$, GetLocation ($2));
4150 | ASYNC identifier_inside_body ARROW
4152 var lt = (Tokenizer.LocatedToken) $2;
4153 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4154 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4156 lambda_expression_body
4158 $$ = end_anonymous ((ParametersBlock) $5);
4159 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4161 | OPEN_PARENS_LAMBDA
4163 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4165 opt_lambda_parameter_list CLOSE_PARENS ARROW
4167 valid_param_mod = 0;
4168 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4170 lambda_expression_body
4172 $$ = end_anonymous ((ParametersBlock) $7);
4173 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4175 | ASYNC OPEN_PARENS_LAMBDA
4177 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4179 opt_lambda_parameter_list CLOSE_PARENS ARROW
4181 valid_param_mod = 0;
4182 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4184 lambda_expression_body
4186 $$ = end_anonymous ((ParametersBlock) $8);
4187 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4192 : assignment_expression
4193 | non_assignment_expression
4196 non_assignment_expression
4197 : conditional_expression
4202 $$ = new ArglistAccess (GetLocation ($1));
4206 undocumented_expressions
4207 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4209 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4210 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4212 | REFTYPE open_parens_any expression CLOSE_PARENS
4214 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4215 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4217 | MAKEREF open_parens_any expression CLOSE_PARENS
4219 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4220 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4231 $$ = new BooleanExpression ((Expression) $1);
4244 lexer.ConstraintsParsing = true;
4246 type_declaration_name
4248 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4249 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4250 FeatureIsNotAvailable (c.Location, "static classes");
4253 push_current_container (c, $3);
4256 opt_type_parameter_constraints_clauses
4258 lexer.ConstraintsParsing = false;
4261 current_container.SetConstraints ((List<Constraints>) $9);
4262 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4265 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4266 Lexer.doc_state = XmlCommentState.Allowed;
4269 lexer.parsing_modifiers = true;
4271 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4273 --lexer.parsing_declaration;
4275 Lexer.doc_state = XmlCommentState.Allowed;
4279 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4280 $$ = pop_current_class ();
4288 { $$ = $1; } // location
4294 mod_locations = null;
4296 lexer.parsing_modifiers = false;
4300 lexer.parsing_modifiers = false;
4306 | modifiers modifier
4308 var m1 = (Modifiers) $1;
4309 var m2 = (Modifiers) $2;
4311 if ((m1 & m2) != 0) {
4312 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4313 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4314 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4315 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4316 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4317 "More than one protection modifier specified");
4328 StoreModifierLocation ($$, GetLocation ($1));
4330 if (current_container.Kind == MemberKind.Namespace)
4331 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4335 $$ = Modifiers.PUBLIC;
4336 StoreModifierLocation ($$, GetLocation ($1));
4340 $$ = Modifiers.PROTECTED;
4341 StoreModifierLocation ($$, GetLocation ($1));
4345 $$ = Modifiers.INTERNAL;
4346 StoreModifierLocation ($$, GetLocation ($1));
4350 $$ = Modifiers.PRIVATE;
4351 StoreModifierLocation ($$, GetLocation ($1));
4355 $$ = Modifiers.ABSTRACT;
4356 StoreModifierLocation ($$, GetLocation ($1));
4360 $$ = Modifiers.SEALED;
4361 StoreModifierLocation ($$, GetLocation ($1));
4365 $$ = Modifiers.STATIC;
4366 StoreModifierLocation ($$, GetLocation ($1));
4370 $$ = Modifiers.READONLY;
4371 StoreModifierLocation ($$, GetLocation ($1));
4375 $$ = Modifiers.VIRTUAL;
4376 StoreModifierLocation ($$, GetLocation ($1));
4380 $$ = Modifiers.OVERRIDE;
4381 StoreModifierLocation ($$, GetLocation ($1));
4385 $$ = Modifiers.EXTERN;
4386 StoreModifierLocation ($$, GetLocation ($1));
4390 $$ = Modifiers.VOLATILE;
4391 StoreModifierLocation ($$, GetLocation ($1));
4395 $$ = Modifiers.UNSAFE;
4396 StoreModifierLocation ($$, GetLocation ($1));
4397 if (!settings.Unsafe)
4398 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4402 $$ = Modifiers.ASYNC;
4403 StoreModifierLocation ($$, GetLocation ($1));
4411 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4413 | COLON type_list error
4415 Error_SyntaxError (yyToken);
4417 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4421 opt_type_parameter_constraints_clauses
4423 | type_parameter_constraints_clauses
4429 type_parameter_constraints_clauses
4430 : type_parameter_constraints_clause
4432 var constraints = new List<Constraints> (1);
4433 constraints.Add ((Constraints) $1);
4436 | type_parameter_constraints_clauses type_parameter_constraints_clause
4438 var constraints = (List<Constraints>) $1;
4439 Constraints new_constraint = (Constraints)$2;
4441 foreach (Constraints c in constraints) {
4442 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4443 report.Error (409, new_constraint.Location,
4444 "A constraint clause has already been specified for type parameter `{0}'",
4445 new_constraint.TypeParameter.Value);
4449 constraints.Add (new_constraint);
4454 type_parameter_constraints_clause
4455 : WHERE IDENTIFIER COLON type_parameter_constraints
4457 var lt = (Tokenizer.LocatedToken) $2;
4458 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4459 lbag.AddLocation ($$, GetLocation ($3));
4461 | WHERE IDENTIFIER error
4463 Error_SyntaxError (yyToken);
4465 var lt = (Tokenizer.LocatedToken) $2;
4466 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4470 type_parameter_constraints
4471 : type_parameter_constraint
4473 var constraints = new List<FullNamedExpression> (1);
4474 constraints.Add ((FullNamedExpression) $1);
4477 | type_parameter_constraints COMMA type_parameter_constraint
4479 var constraints = (List<FullNamedExpression>) $1;
4480 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4481 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4482 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4485 prev = $3 as SpecialContraintExpr;
4487 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4488 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4490 prev = constraints [0] as SpecialContraintExpr;
4491 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4492 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4497 constraints.Add ((FullNamedExpression) $3);
4502 type_parameter_constraint
4505 if ($1 is ComposedCast)
4506 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4510 | NEW OPEN_PARENS CLOSE_PARENS
4512 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4513 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4517 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4521 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4525 opt_type_parameter_variance
4530 | type_parameter_variance
4532 if (lang_version <= LanguageVersion.V_3)
4533 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4539 type_parameter_variance
4542 $$ = Variance.Covariant;
4546 $$ = Variance.Contravariant;
4555 // A block is "contained" on the following places:
4557 // property_declaration as part of the accessor body (get/set)
4558 // operator_declaration
4559 // constructor_declaration
4560 // destructor_declaration
4561 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4566 ++lexer.parsing_block;
4567 start_block (GetLocation ($1));
4569 opt_statement_list block_end
4578 --lexer.parsing_block;
4579 $$ = end_block (GetLocation ($1));
4581 | COMPLETE_COMPLETION
4583 --lexer.parsing_block;
4584 $$ = end_block (lexer.Location);
4592 ++lexer.parsing_block;
4593 current_block.StartLocation = GetLocation ($1);
4595 opt_statement_list CLOSE_BRACE
4597 --lexer.parsing_block;
4598 $$ = end_block (GetLocation ($4));
4609 | statement_list statement
4613 : block_variable_declaration
4615 current_block.AddStatement ((Statement) $1);
4617 | valid_declaration_statement
4619 current_block.AddStatement ((Statement) $1);
4624 Error_SyntaxError (yyToken);
4630 // The interactive_statement and its derivatives are only
4631 // used to provide a special version of `expression_statement'
4632 // that has a side effect of assigning the expression to
4635 interactive_statement_list
4636 : interactive_statement
4637 | interactive_statement_list interactive_statement
4640 interactive_statement
4641 : block_variable_declaration
4643 current_block.AddStatement ((Statement) $1);
4645 | interactive_valid_declaration_statement
4647 current_block.AddStatement ((Statement) $1);
4652 valid_declaration_statement
4655 | expression_statement
4656 | selection_statement
4657 | iteration_statement
4661 | unchecked_statement
4668 interactive_valid_declaration_statement
4671 | interactive_expression_statement
4672 | selection_statement
4673 | iteration_statement
4677 | unchecked_statement
4685 : valid_declaration_statement
4686 | block_variable_declaration
4688 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4693 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4698 Error_SyntaxError (yyToken);
4699 $$ = new EmptyStatement (GetLocation ($1));
4706 // Uses lexer.Location because semicolon location is not kept in quick mode
4707 $$ = new EmptyStatement (lexer.Location);
4712 : identifier_inside_body COLON
4714 var lt = (Tokenizer.LocatedToken) $1;
4715 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4716 lbag.AddLocation (labeled, GetLocation ($2));
4717 current_block.AddLabel (labeled);
4718 current_block.AddStatement (labeled);
4724 : variable_type_simple
4725 | variable_type_simple rank_specifiers
4728 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4730 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4735 * The following is from Rhys' grammar:
4736 * > Types in local variable declarations must be recognized as
4737 * > expressions to prevent reduce/reduce errors in the grammar.
4738 * > The expressions are converted into types during semantic analysis.
4740 variable_type_simple
4741 : primary_expression_or_type opt_nullable
4743 // Ok, the above "primary_expression" is there to get rid of
4744 // both reduce/reduce and shift/reduces in the grammar, it should
4745 // really just be "type_name". If you use type_name, a reduce/reduce
4746 // creeps up. If you use namespace_or_type_name (which is all we need
4747 // really) two shift/reduces appear.
4750 // So the super-trick is that primary_expression
4751 // can only be either a SimpleName or a MemberAccess.
4752 // The MemberAccess case arises when you have a fully qualified type-name like :
4754 // SimpleName is when you have
4757 Expression expr = (Expression) $1;
4759 SimpleName sn = expr as SimpleName;
4760 if (sn != null && sn.Name == "var")
4761 $$ = new VarExpr (sn.Location);
4764 } else if (expr is ATypeNameExpression) {
4765 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4767 Error_ExpectingTypeName (expr);
4771 | primary_expression_or_type pointer_stars
4773 ATypeNameExpression expr = $1 as ATypeNameExpression;
4776 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4778 Error_ExpectingTypeName ((Expression)$1);
4782 | builtin_types opt_nullable
4787 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4789 | builtin_types pointer_stars
4791 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4793 | VOID pointer_stars
4795 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4799 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
4800 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
4806 | pointer_star pointer_stars
4808 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4816 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4820 identifier_inside_body
4825 report.Error (4003, GetLocation ($1), "`await' cannot be used as an identifier within an async method or lambda expression");
4826 $$ = new Tokenizer.LocatedToken ("await", GetLocation ($1));
4831 block_variable_declaration
4832 : variable_type identifier_inside_body
4834 var lt = (Tokenizer.LocatedToken) $2;
4835 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4836 current_block.AddLocalName (li);
4837 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4839 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4841 $$ = current_variable;
4842 current_variable = null;
4843 lbag.AddLocation ($$, GetLocation ($6));
4845 | CONST variable_type identifier_inside_body
4847 var lt = (Tokenizer.LocatedToken) $3;
4848 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4849 current_block.AddLocalName (li);
4850 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4852 const_variable_initializer opt_const_declarators SEMICOLON
4854 $$ = current_variable;
4855 current_variable = null;
4856 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4860 opt_local_variable_initializer
4862 | ASSIGN block_variable_initializer
4864 current_variable.Initializer = (Expression) $2;
4869 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4870 report.Error (650, lexer.Location,
4871 "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");
4873 Error_SyntaxError (yyToken);
4878 opt_variable_declarators
4880 | variable_declarators
4883 opt_using_or_fixed_variable_declarators
4885 | variable_declarators
4887 foreach (var d in current_variable.Declarators) {
4888 if (d.Initializer == null)
4889 Error_MissingInitializer (d.Variable.Location);
4894 variable_declarators
4895 : variable_declarator
4896 | variable_declarators variable_declarator
4900 : COMMA identifier_inside_body
4902 var lt = (Tokenizer.LocatedToken) $2;
4903 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4904 var d = new BlockVariableDeclaration.Declarator (li, null);
4905 current_variable.AddDeclarator (d);
4906 current_block.AddLocalName (li);
4907 lbag.AddLocation (d, GetLocation ($1));
4909 | COMMA identifier_inside_body ASSIGN block_variable_initializer
4911 var lt = (Tokenizer.LocatedToken) $2;
4912 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4913 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4914 current_variable.AddDeclarator (d);
4915 current_block.AddLocalName (li);
4916 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4920 const_variable_initializer
4923 report.Error (145, lexer.Location, "A const field requires a value to be provided");
4925 | ASSIGN constant_initializer_expr
4927 current_variable.Initializer = (Expression) $2;
4931 opt_const_declarators
4938 | const_declarators const_declarator
4942 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
4944 var lt = (Tokenizer.LocatedToken) $2;
4945 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4946 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4947 current_variable.AddDeclarator (d);
4948 current_block.AddLocalName (li);
4949 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4953 block_variable_initializer
4954 : variable_initializer
4955 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4957 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4958 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4960 | STACKALLOC simple_type
4962 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4963 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4967 expression_statement
4968 : statement_expression SEMICOLON
4971 lbag.AddStatement ($$, GetLocation ($2));
4973 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4974 | statement_expression CLOSE_BRACE
4977 report.Error (1002, GetLocation ($2), "; expected");
4978 lexer.putback ('}');
4982 interactive_expression_statement
4983 : interactive_statement_expression SEMICOLON { $$ = $1; }
4984 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4988 // We have to do the wrapping here and not in the case above,
4989 // because statement_expression is used for example in for_statement
4991 statement_expression
4994 ExpressionStatement s = $1 as ExpressionStatement;
4996 Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
4997 $$ = new StatementErrorExpression ($1 as Expression);
4999 $$ = new StatementExpression (s);
5004 interactive_statement_expression
5007 Expression expr = (Expression) $1;
5008 ExpressionStatement s;
5010 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
5011 $$ = new StatementExpression (s);
5015 Error_SyntaxError (yyToken);
5016 $$ = new EmptyStatement (GetLocation ($1));
5026 : IF open_parens_any boolean_expression CLOSE_PARENS
5029 if ($5 is EmptyStatement)
5030 Warning_EmptyStatement (GetLocation ($5));
5032 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5033 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5035 | IF open_parens_any boolean_expression CLOSE_PARENS
5036 embedded_statement ELSE embedded_statement
5038 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5039 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5041 if ($5 is EmptyStatement)
5042 Warning_EmptyStatement (GetLocation ($5));
5043 if ($7 is EmptyStatement)
5044 Warning_EmptyStatement (GetLocation ($7));
5046 | IF open_parens_any boolean_expression error
5048 Error_SyntaxError (yyToken);
5050 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5051 lbag.AddStatement ($$, GetLocation ($2));
5056 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5058 start_block (GetLocation ($5));
5060 opt_switch_sections CLOSE_BRACE
5062 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
5063 end_block (GetLocation ($8));
5064 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5066 | SWITCH open_parens_any expression error
5068 Error_SyntaxError (yyToken);
5070 $$ = new Switch ((Expression) $3, null, null, GetLocation ($1));
5071 lbag.AddStatement ($$, GetLocation ($2));
5078 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5079 $$ = new List<SwitchSection> ();
5087 var sections = new List<SwitchSection> (4);
5089 sections.Add ((SwitchSection) $1);
5092 | switch_sections switch_section
5094 var sections = (List<SwitchSection>) $1;
5096 sections.Add ((SwitchSection) $2);
5101 Error_SyntaxError (yyToken);
5102 $$ = new List<SwitchSection> ();
5109 current_block = current_block.CreateSwitchBlock (lexer.Location);
5113 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
5120 var labels = new List<SwitchLabel> (2);
5122 labels.Add ((SwitchLabel) $1);
5125 | switch_labels switch_label
5127 var labels = (List<SwitchLabel>) ($1);
5128 labels.Add ((SwitchLabel) $2);
5135 : CASE constant_expression COLON
5137 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5138 lbag.AddLocation ($$, GetLocation ($3));
5140 | CASE constant_expression error
5142 Error_SyntaxError (yyToken);
5143 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5147 $$ = new SwitchLabel (null, GetLocation ($1));
5159 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5161 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5162 Warning_EmptyStatement (GetLocation ($5));
5164 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5165 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5167 | WHILE open_parens_any boolean_expression error
5169 Error_SyntaxError (yyToken);
5171 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5172 lbag.AddStatement ($$, GetLocation ($2));
5177 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5179 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5180 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5182 | DO embedded_statement error
5184 Error_SyntaxError (yyToken);
5185 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5187 | DO embedded_statement WHILE open_parens_any boolean_expression error
5189 Error_SyntaxError (yyToken);
5191 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5192 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5197 : FOR open_parens_any
5199 start_block (GetLocation ($2));
5200 current_block.IsCompilerGenerated = true;
5201 For f = new For (GetLocation ($1));
5202 current_block.AddStatement (f);
5211 // Has to use be extra rule to recover started block
5213 : opt_for_initializer SEMICOLON
5215 ((For) $0).Initializer = (Statement) $1;
5217 // Pass the "For" object to the iterator_part4
5218 oob_stack.Push ($0);
5220 for_condition_and_iterator_part
5223 var locations = (Tuple<Location,Location>) $4;
5225 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5226 Warning_EmptyStatement (GetLocation ($5));
5229 f.Statement = (Statement) $5;
5230 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5232 $$ = end_block (GetLocation ($2));
5236 Error_SyntaxError (yyToken);
5237 $$ = end_block (current_block.StartLocation);
5241 for_condition_and_iterator_part
5242 : opt_for_condition SEMICOLON
5244 For f = (For) oob_stack.Peek ();
5245 f.Condition = (BooleanExpression) $1;
5248 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5251 // Handle errors in the case of opt_for_condition being followed by
5252 // a close parenthesis
5253 | opt_for_condition close_parens_close_brace {
5254 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5255 For f = (For) oob_stack.Peek ();
5256 f.Condition = (BooleanExpression) $1;
5257 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5262 : opt_for_iterator CLOSE_PARENS {
5263 For f = (For) oob_stack.Peek ();
5264 f.Iterator = (Statement) $1;
5265 $$ = GetLocation ($2);
5267 | opt_for_iterator CLOSE_BRACE {
5268 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5269 For f = (For) oob_stack.Peek ();
5270 f.Iterator = (Statement) $1;
5271 $$ = GetLocation ($2);
5275 close_parens_close_brace
5277 | CLOSE_BRACE { lexer.putback ('}'); }
5281 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5286 : variable_type identifier_inside_body
5288 var lt = (Tokenizer.LocatedToken) $2;
5289 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5290 current_block.AddLocalName (li);
5291 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5293 opt_local_variable_initializer opt_variable_declarators
5295 $$ = current_variable;
5296 current_variable = null;
5298 | statement_expression_list
5302 : /* empty */ { $$ = null; }
5303 | boolean_expression
5307 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5312 : statement_expression_list
5315 statement_expression_list
5316 : statement_expression
5317 | statement_expression_list COMMA statement_expression
5319 var sl = $1 as StatementList;
5321 sl = new StatementList ((Statement) $1, (Statement) $3);
5322 lbag.AddStatement (sl, GetLocation ($2));
5324 sl.Add ((Statement) $3);
5325 lbag.AppendTo (sl, GetLocation ($2));
5333 : FOREACH open_parens_any type error
5335 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5337 start_block (GetLocation ($2));
5338 current_block.IsCompilerGenerated = true;
5340 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5341 current_block.AddStatement (f);
5343 lbag.AddStatement (f, GetLocation ($2));
5344 $$ = end_block (GetLocation ($4));
5346 | FOREACH open_parens_any type identifier_inside_body error
5348 Error_SyntaxError (yyToken);
5350 start_block (GetLocation ($2));
5351 current_block.IsCompilerGenerated = true;
5353 var lt = (Tokenizer.LocatedToken) $4;
5354 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5355 current_block.AddLocalName (li);
5357 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5358 current_block.AddStatement (f);
5360 lbag.AddStatement (f, GetLocation ($2));
5361 $$ = end_block (GetLocation ($5));
5363 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5365 start_block (GetLocation ($2));
5366 current_block.IsCompilerGenerated = true;
5368 var lt = (Tokenizer.LocatedToken) $4;
5369 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5370 current_block.AddLocalName (li);
5375 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5376 Warning_EmptyStatement (GetLocation ($9));
5378 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5379 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5380 end_block (GetLocation ($7));
5388 | continue_statement
5398 $$ = new Break (GetLocation ($1));
5399 lbag.AddStatement ($$, GetLocation ($2));
5404 : CONTINUE SEMICOLON
5406 $$ = new Continue (GetLocation ($1));
5407 lbag.AddStatement ($$, GetLocation ($2));
5411 Error_SyntaxError (yyToken);
5412 $$ = new Continue (GetLocation ($1));
5417 : GOTO identifier_inside_body SEMICOLON
5419 var lt = (Tokenizer.LocatedToken) $2;
5420 $$ = new Goto (lt.Value, GetLocation ($1));
5421 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5423 | GOTO CASE constant_expression SEMICOLON
5425 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5426 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5428 | GOTO DEFAULT SEMICOLON
5430 $$ = new GotoDefault (GetLocation ($1));
5431 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5436 : RETURN opt_expression SEMICOLON
5438 $$ = new Return ((Expression) $2, GetLocation ($1));
5439 lbag.AddStatement ($$, GetLocation ($3));
5441 | RETURN expression error
5443 Error_SyntaxError (yyToken);
5444 $$ = new Return ((Expression) $2, GetLocation ($1));
5448 Error_SyntaxError (yyToken);
5449 $$ = new Return (null, GetLocation ($1));
5454 : THROW opt_expression SEMICOLON
5456 $$ = new Throw ((Expression) $2, GetLocation ($1));
5457 lbag.AddStatement ($$, GetLocation ($3));
5461 Error_SyntaxError (yyToken);
5462 $$ = new Throw (null, GetLocation ($1));
5467 : identifier_inside_body RETURN opt_expression SEMICOLON
5469 var lt = (Tokenizer.LocatedToken) $1;
5470 string s = lt.Value;
5472 report.Error (1003, lt.Location, "; expected");
5473 } else if ($3 == null) {
5474 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5475 } else if (lang_version == LanguageVersion.ISO_1){
5476 FeatureIsNotAvailable (lt.Location, "iterators");
5479 current_block.Explicit.RegisterIteratorYield ();
5480 $$ = new Yield ((Expression) $3, lt.Location);
5481 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5483 | identifier_inside_body RETURN expression error
5485 Error_SyntaxError (yyToken);
5487 var lt = (Tokenizer.LocatedToken) $1;
5488 string s = lt.Value;
5490 report.Error (1003, lt.Location, "; expected");
5491 } else if ($3 == null) {
5492 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5493 } else if (lang_version == LanguageVersion.ISO_1){
5494 FeatureIsNotAvailable (lt.Location, "iterators");
5497 current_block.Explicit.RegisterIteratorYield ();
5498 $$ = new Yield ((Expression) $3, lt.Location);
5499 lbag.AddStatement ($$, GetLocation ($2));
5501 | identifier_inside_body BREAK SEMICOLON
5503 var lt = (Tokenizer.LocatedToken) $1;
5504 string s = lt.Value;
5506 report.Error (1003, lt.Location, "; expected");
5507 } else if (lang_version == LanguageVersion.ISO_1){
5508 FeatureIsNotAvailable (lt.Location, "iterators");
5511 current_block.Explicit.RegisterIteratorYield ();
5512 $$ = new YieldBreak (lt.Location);
5513 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5523 : TRY block catch_clauses
5525 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5527 | TRY block FINALLY block
5529 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5530 lbag.AddStatement ($$, GetLocation ($3));
5532 | TRY block catch_clauses FINALLY block
5534 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5535 lbag.AddStatement ($$, GetLocation ($4));
5539 Error_SyntaxError (1524, yyToken);
5540 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5547 var l = new List<Catch> (2);
5552 | catch_clauses catch_clause
5554 var l = (List<Catch>) $1;
5556 Catch c = (Catch) $2;
5557 if (l [l.Count - 1].IsGeneral) {
5558 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5568 | identifier_inside_body
5574 $$ = new Catch ((Block) $2, GetLocation ($1));
5576 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5578 start_block (GetLocation ($2));
5579 var c = new Catch (current_block, GetLocation ($1));
5580 c.TypeExpression = (FullNamedExpression) $3;
5583 var lt = (Tokenizer.LocatedToken) $4;
5584 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5585 current_block.AddLocalName (c.Variable);
5588 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5595 | CATCH open_parens_any error
5597 if (yyToken == Token.CLOSE_PARENS) {
5598 report.Error (1015, lexer.Location,
5599 "A type that derives from `System.Exception', `object', or `string' expected");
5601 Error_SyntaxError (yyToken);
5604 $$ = new Catch (null, GetLocation ($1));
5611 $$ = new Checked ((Block) $2, GetLocation ($1));
5618 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5625 if (!settings.Unsafe)
5626 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5628 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5633 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5635 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5636 Warning_EmptyStatement (GetLocation ($5));
5638 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5639 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5641 | LOCK open_parens_any expression error
5643 Error_SyntaxError (yyToken);
5645 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
5646 lbag.AddStatement ($$, GetLocation ($2));
5651 : FIXED open_parens_any variable_type identifier_inside_body
5653 start_block (GetLocation ($2));
5655 current_block.IsCompilerGenerated = true;
5656 var lt = (Tokenizer.LocatedToken) $4;
5657 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5658 current_block.AddLocalName (li);
5659 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5661 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
5663 $$ = current_variable;
5664 current_variable = null;
5668 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5669 Warning_EmptyStatement (GetLocation ($10));
5671 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5672 current_block.AddStatement (f);
5673 $$ = end_block (GetLocation ($8));
5678 : USING open_parens_any variable_type identifier_inside_body
5680 start_block (GetLocation ($2));
5682 current_block.IsCompilerGenerated = true;
5683 var lt = (Tokenizer.LocatedToken) $4;
5684 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5685 current_block.AddLocalName (li);
5686 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5688 using_initialization CLOSE_PARENS
5690 $$ = current_variable;
5691 current_variable = null;
5695 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5696 Warning_EmptyStatement (GetLocation ($9));
5698 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
5699 current_block.AddStatement (u);
5700 $$ = end_block (GetLocation ($7));
5702 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5704 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5705 Warning_EmptyStatement (GetLocation ($5));
5707 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5708 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5710 | USING open_parens_any expression error
5712 Error_SyntaxError (yyToken);
5714 $$ = new Using ((Expression) $3, null, GetLocation ($1));
5715 lbag.AddStatement ($$, GetLocation ($2));
5719 using_initialization
5720 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
5723 // It has to be here for the parent to safely restore artificial block
5724 Error_SyntaxError (yyToken);
5728 using_or_fixed_variable_initializer
5731 Error_MissingInitializer (lexer.Location);
5733 | ASSIGN variable_initializer
5735 current_variable.Initializer = (Expression) $2;
5736 $$ = current_variable;
5744 : first_from_clause query_body
5746 lexer.query_parsing = false;
5748 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5750 from.Tail.Next = (Linq.AQueryClause)$2;
5753 current_block.SetEndLocation (lexer.Location);
5754 current_block = current_block.Parent;
5756 | nested_from_clause query_body
5758 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5760 from.Tail.Next = (Linq.AQueryClause)$2;
5763 current_block.SetEndLocation (lexer.Location);
5764 current_block = current_block.Parent;
5767 // Bubble up COMPLETE_COMPLETION productions
5768 | first_from_clause COMPLETE_COMPLETION {
5769 lexer.query_parsing = false;
5772 current_block.SetEndLocation (lexer.Location);
5773 current_block = current_block.Parent;
5775 | nested_from_clause COMPLETE_COMPLETION {
5777 current_block.SetEndLocation (lexer.Location);
5778 current_block = current_block.Parent;
5783 : FROM_FIRST identifier_inside_body IN expression
5785 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5787 var lt = (Tokenizer.LocatedToken) $2;
5788 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5789 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5791 | FROM_FIRST type identifier_inside_body IN expression
5793 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5795 var lt = (Tokenizer.LocatedToken) $3;
5796 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5797 $$ = new Linq.QueryExpression (
5798 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5799 IdentifierType = (FullNamedExpression)$2
5806 : FROM identifier_inside_body IN expression
5808 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5810 var lt = (Tokenizer.LocatedToken) $2;
5811 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5812 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5814 | FROM type identifier_inside_body IN expression
5816 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5818 var lt = (Tokenizer.LocatedToken) $3;
5819 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5820 $$ = new Linq.QueryExpression (
5821 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5822 IdentifierType = (FullNamedExpression)$2
5829 : FROM identifier_inside_body IN
5831 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5835 var lt = (Tokenizer.LocatedToken) $2;
5836 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5837 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5839 current_block.SetEndLocation (lexer.Location);
5840 current_block = current_block.Parent;
5842 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5844 | FROM type identifier_inside_body IN
5846 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5850 var lt = (Tokenizer.LocatedToken) $3;
5851 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5853 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5854 IdentifierType = (FullNamedExpression)$2
5857 current_block.SetEndLocation (lexer.Location);
5858 current_block = current_block.Parent;
5860 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5865 : query_body_clauses select_or_group_clause opt_query_continuation
5867 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5870 head.Next = (Linq.AQueryClause)$3;
5873 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5874 clause.Tail.Next = head;
5880 | select_or_group_clause opt_query_continuation
5882 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5885 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5886 clause.Tail.Next = head;
5892 | query_body_clauses COMPLETE_COMPLETION
5893 | query_body_clauses error
5895 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
5900 Error_SyntaxError (yyToken);
5905 select_or_group_clause
5908 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5912 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5914 current_block.SetEndLocation (lexer.Location);
5915 current_block = current_block.Parent;
5919 if (linq_clause_blocks == null)
5920 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5922 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5923 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5927 current_block.SetEndLocation (lexer.Location);
5928 current_block = current_block.Parent;
5930 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5932 BY expression_or_error
5934 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5935 lbag.AddLocation ($$, GetLocation ($5));
5937 current_block.SetEndLocation (lexer.Location);
5938 current_block = current_block.Parent;
5944 | query_body_clauses query_body_clause
5946 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5960 : LET identifier_inside_body ASSIGN
5962 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5966 var lt = (Tokenizer.LocatedToken) $2;
5967 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5968 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5969 lbag.AddLocation ($$, GetLocation ($3));
5971 current_block.SetEndLocation (lexer.Location);
5972 current_block = current_block.Parent;
5974 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5981 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5985 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5987 current_block.SetEndLocation (lexer.Location);
5988 current_block = current_block.Parent;
5993 : JOIN identifier_inside_body IN
5995 if (linq_clause_blocks == null)
5996 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5998 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5999 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6001 expression_or_error ON
6003 current_block.SetEndLocation (lexer.Location);
6004 current_block = current_block.Parent;
6006 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6007 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6009 expression_or_error EQUALS
6011 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6012 current_block.SetEndLocation (lexer.Location);
6013 current_block = current_block.Parent;
6015 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6017 expression_or_error opt_join_into
6019 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6020 current_block.SetEndLocation (lexer.Location);
6022 var outer_selector = linq_clause_blocks.Pop ();
6023 var block = linq_clause_blocks.Pop ();
6025 var lt = (Tokenizer.LocatedToken) $2;
6026 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6027 Linq.RangeVariable into;
6031 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6032 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6035 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6037 var parent = block.Parent;
6038 while (parent is Linq.QueryBlock) {
6039 parent = parent.Parent;
6041 current_block.Parent = parent;
6043 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6045 lt = (Tokenizer.LocatedToken) $12;
6046 into = new Linq.RangeVariable (lt.Value, lt.Location);
6048 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6049 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6052 current_block = block.Parent;
6053 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6055 | JOIN type identifier_inside_body IN
6057 if (linq_clause_blocks == null)
6058 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6060 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6061 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6063 expression_or_error ON
6065 current_block.SetEndLocation (lexer.Location);
6066 current_block = current_block.Parent;
6068 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6069 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6071 expression_or_error EQUALS
6073 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6074 current_block.SetEndLocation (lexer.Location);
6075 current_block = current_block.Parent;
6077 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6079 expression_or_error opt_join_into
6081 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6082 current_block.SetEndLocation (lexer.Location);
6084 var outer_selector = linq_clause_blocks.Pop ();
6085 var block = linq_clause_blocks.Pop ();
6087 var lt = (Tokenizer.LocatedToken) $3;
6088 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6089 Linq.RangeVariable into;
6093 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6094 IdentifierType = (FullNamedExpression)$2
6098 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6100 var parent = block.Parent;
6101 while (parent is Linq.QueryBlock) {
6102 parent = parent.Parent;
6104 current_block.Parent = parent;
6106 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6108 lt = (Tokenizer.LocatedToken) $13;
6109 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6111 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6112 IdentifierType = (FullNamedExpression)$2
6116 current_block = block.Parent;
6117 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6123 | INTO identifier_inside_body
6132 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6136 current_block.SetEndLocation (lexer.Location);
6137 current_block = current_block.Parent;
6147 current_block.SetEndLocation (lexer.Location);
6148 current_block = current_block.Parent;
6150 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6154 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6161 | orderings_then_by COMMA
6163 current_block.SetEndLocation (lexer.Location);
6164 current_block = current_block.Parent;
6166 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6170 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6178 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6180 | expression ASCENDING
6182 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6183 lbag.AddLocation ($$, GetLocation ($2));
6185 | expression DESCENDING
6187 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6188 lbag.AddLocation ($$, GetLocation ($2));
6195 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6197 | expression ASCENDING
6199 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6200 lbag.AddLocation ($$, GetLocation ($2));
6202 | expression DESCENDING
6204 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6205 lbag.AddLocation ($$, GetLocation ($2));
6210 opt_query_continuation
6212 | INTO identifier_inside_body
6214 // query continuation block is not linked with query block but with block
6215 // before. This means each query can use same range variable names for
6216 // different identifiers.
6218 current_block.SetEndLocation (GetLocation ($1));
6219 current_block = current_block.Parent;
6221 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6223 if (linq_clause_blocks == null)
6224 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6226 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6230 var current_block = linq_clause_blocks.Pop ();
6231 var lt = (Tokenizer.LocatedToken) $2;
6232 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6233 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6234 next = (Linq.AQueryClause)$4
6240 // Support for using the compiler as an interactive parser
6242 // The INTERACTIVE_PARSER token is first sent to parse our
6243 // productions; If the result is a Statement, the parsing
6244 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6245 // to setup the blocks in advance.
6247 // This setup is here so that in the future we can add
6248 // support for other constructs (type parsing, namespaces, etc)
6249 // that do not require a block to be setup in advance
6253 : EVAL_STATEMENT_PARSER EOF
6254 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6255 | EVAL_STATEMENT_PARSER
6257 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6259 // (ref object retval)
6260 Parameter [] mpar = new Parameter [1];
6261 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6263 ParametersCompiled pars = new ParametersCompiled (mpar);
6264 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6265 if (settings.Unsafe)
6266 mods |= Modifiers.UNSAFE;
6268 current_local_parameters = pars;
6269 Method method = new Method (
6271 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6273 new MemberName ("Host"),
6275 null /* attributes */);
6277 current_type.AddMember (method);
6279 oob_stack.Push (method);
6280 ++lexer.parsing_block;
6281 start_block (lexer.Location);
6283 interactive_statement_list opt_COMPLETE_COMPLETION
6285 --lexer.parsing_block;
6286 Method method = (Method) oob_stack.Pop ();
6288 method.Block = (ToplevelBlock) end_block(lexer.Location);
6290 InteractiveResult = (Class) pop_current_class ();
6291 current_local_parameters = null;
6293 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6296 interactive_compilation_unit
6297 : opt_extern_alias_directives opt_using_directives
6298 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6301 opt_COMPLETE_COMPLETION
6303 | COMPLETE_COMPLETION
6306 close_brace_or_complete_completion
6308 | COMPLETE_COMPLETION
6312 // XML documentation code references micro parser
6314 documentation_parsing
6317 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6322 : doc_type_declaration_name opt_doc_method_sig
6324 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6326 | builtin_types opt_doc_method_sig
6328 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6329 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6332 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6334 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6335 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6336 var lt = (Tokenizer.LocatedToken) $3;
6337 $$ = new MemberName (lt.Value);
6339 | doc_type_declaration_name DOT THIS
6341 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6343 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6345 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6347 opt_doc_parameters CLOSE_BRACKET
6349 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6350 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6352 | EXPLICIT OPERATOR type opt_doc_method_sig
6354 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6355 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6356 module.DocumentationBuilder.ParsedParameters = p;
6357 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6360 | IMPLICIT OPERATOR type opt_doc_method_sig
6362 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6363 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6364 module.DocumentationBuilder.ParsedParameters = p;
6365 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6368 | OPERATOR overloadable_operator opt_doc_method_sig
6370 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6371 module.DocumentationBuilder.ParsedParameters = p;
6372 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6377 doc_type_declaration_name
6378 : type_declaration_name
6379 | doc_type_declaration_name DOT type_declaration_name
6381 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6389 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6391 opt_doc_parameters CLOSE_PARENS
6400 $$ = new List<DocumentationParameter> (0);
6408 var parameters = new List<DocumentationParameter> ();
6409 parameters.Add ((DocumentationParameter) $1);
6412 | doc_parameters COMMA doc_parameter
6414 var parameters = $1 as List<DocumentationParameter>;
6415 parameters.Add ((DocumentationParameter) $3);
6421 : opt_parameter_modifier parameter_type
6424 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6426 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6433 // A class used to hold info about an operator declarator
6435 class OperatorDeclaration {
6436 public readonly Operator.OpType optype;
6437 public readonly FullNamedExpression ret_type;
6438 public readonly Location location;
6440 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6443 this.ret_type = ret_type;
6444 this.location = location;
6448 void Error_ExpectingTypeName (Expression expr)
6450 if (expr is Invocation){
6451 report.Error (1002, expr.Location, "Expecting `;'");
6453 Expression.Error_InvalidExpressionStatement (report, expr.Location);
6457 void Error_ParameterModifierNotValid (string modifier, Location loc)
6459 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6463 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6465 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6466 Parameter.GetModifierSignature (mod));
6469 void Error_TypeExpected (Location loc)
6471 report.Error (1031, loc, "Type expected");
6474 void Error_UnsafeCodeNotAllowed (Location loc)
6476 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6479 void Warning_EmptyStatement (Location loc)
6481 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6484 void Error_NamedArgumentExpected (NamedArgument a)
6486 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6489 void Error_MissingInitializer (Location loc)
6491 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6494 void push_current_container (TypeDefinition tc, object partial_token)
6496 if (module.Evaluator != null){
6497 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6501 undo.AddTypeContainer (current_container, tc);
6504 if (partial_token != null)
6505 current_container.AddPartial (tc);
6507 current_container.AddTypeContainer (tc);
6509 ++lexer.parsing_declaration;
6510 current_container = tc;
6514 TypeContainer pop_current_class ()
6516 var retval = current_container;
6518 current_container = current_container.Parent;
6519 current_type = current_type.Parent as TypeDefinition;
6524 [System.Diagnostics.Conditional ("FULL_AST")]
6525 void StoreModifierLocation (object token, Location loc)
6530 if (mod_locations == null)
6531 mod_locations = new List<Tuple<Modifiers, Location>> ();
6533 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6536 string CheckAttributeTarget (string a, Location l)
6539 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6543 report.Warning (658, 1, l,
6544 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6545 return string.Empty;
6548 static bool IsUnaryOperator (Operator.OpType op)
6552 case Operator.OpType.LogicalNot:
6553 case Operator.OpType.OnesComplement:
6554 case Operator.OpType.Increment:
6555 case Operator.OpType.Decrement:
6556 case Operator.OpType.True:
6557 case Operator.OpType.False:
6558 case Operator.OpType.UnaryPlus:
6559 case Operator.OpType.UnaryNegation:
6565 void syntax_error (Location l, string msg)
6567 report.Error (1003, l, "Syntax error, " + msg);
6572 public Tokenizer Lexer {
6578 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
6579 : this (reader, file, file.Compiler.Report, session)
6583 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
6586 current_container = current_namespace = file;
6588 this.module = file.Module;
6589 this.compiler = file.Compiler;
6590 this.settings = compiler.Settings;
6591 this.report = report;
6593 lang_version = settings.Version;
6594 yacc_verbose_flag = settings.VerboseParserFlag;
6595 doc_support = settings.DocumentationFile != null;
6596 lexer = new Tokenizer (reader, file, session);
6597 oob_stack = new Stack<object> ();
6598 lbag = session.LocationsBag;
6599 use_global_stacks = session.UseJayGlobalArrays;
6600 parameters_bucket = session.ParametersStack;
6603 public void parse ()
6605 eof_token = Token.EOF;
6608 if (yacc_verbose_flag > 1)
6609 yyparse (lexer, new yydebug.yyDebugSimple ());
6613 Tokenizer tokenizer = lexer as Tokenizer;
6614 tokenizer.cleanup ();
6615 } catch (Exception e){
6616 if (e is yyParser.yyUnexpectedEof) {
6617 Error_SyntaxError (yyToken);
6618 UnexpectedEOF = true;
6622 if (e is yyParser.yyException) {
6623 report.Error (-25, lexer.Location, "Parsing error");
6625 // Used by compiler-tester to test internal errors
6626 if (yacc_verbose_flag > 0 || e is FatalException)
6629 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
6634 void CheckToken (int error, int yyToken, string msg, Location loc)
6636 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6637 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6639 report.Error (error, loc, msg);
6642 string ConsumeStoredComment ()
6644 string s = tmpComment;
6646 Lexer.doc_state = XmlCommentState.Allowed;
6650 void FeatureIsNotAvailable (Location loc, string feature)
6652 report.FeatureIsNotAvailable (compiler, loc, feature);
6655 Location GetLocation (object obj)
6657 var lt = obj as Tokenizer.LocatedToken;
6661 var mn = obj as MemberName;
6665 var expr = obj as Expression;
6667 return expr.Location;
6669 return lexer.Location;
6672 void start_block (Location loc)
6674 if (current_block == null) {
6675 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6676 parsing_anonymous_method = false;
6677 } else if (parsing_anonymous_method) {
6678 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6679 parsing_anonymous_method = false;
6681 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6686 end_block (Location loc)
6688 Block retval = current_block.Explicit;
6689 retval.SetEndLocation (loc);
6690 current_block = retval.Parent;
6694 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
6696 oob_stack.Push (current_anonymous_method);
6697 oob_stack.Push (current_local_parameters);
6698 oob_stack.Push (current_variable);
6699 oob_stack.Push (async_block);
6701 current_local_parameters = parameters;
6703 if (lang_version <= LanguageVersion.ISO_2)
6704 FeatureIsNotAvailable (loc, "lambda expressions");
6706 current_anonymous_method = new LambdaExpression (loc);
6708 if (lang_version == LanguageVersion.ISO_1)
6709 FeatureIsNotAvailable (loc, "anonymous methods");
6711 current_anonymous_method = new AnonymousMethodExpression (loc);
6714 async_block = isAsync;
6715 // Force the next block to be created as a ToplevelBlock
6716 parsing_anonymous_method = true;
6720 * Completes the anonymous method processing, if lambda_expr is null, this
6721 * means that we have a Statement instead of an Expression embedded
6723 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6725 AnonymousMethodExpression retval;
6728 anon_block.IsAsync = true;
6730 current_anonymous_method.Block = anon_block;
6731 retval = current_anonymous_method;
6733 async_block = (bool) oob_stack.Pop ();
6734 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6735 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6736 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6741 void Error_SyntaxError (int token)
6743 Error_SyntaxError (0, token);
6746 void Error_SyntaxError (int error_code, int token)
6748 Error_SyntaxError (error_code, token, "Unexpected symbol");
6751 void Error_SyntaxError (int error_code, int token, string msg)
6753 Lexer.CompleteOnEOF = false;
6755 // An error message has been reported by tokenizer
6756 if (token == Token.ERROR)
6759 string symbol = GetSymbolName (token);
6760 string expecting = GetExpecting ();
6761 var loc = lexer.Location - symbol.Length;
6763 if (error_code == 0) {
6764 if (expecting == "`identifier'") {
6765 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6766 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6771 expecting = "identifier";
6772 } else if (expecting == "`)'") {
6779 if (string.IsNullOrEmpty (expecting))
6780 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6782 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6785 string GetExpecting ()
6787 int [] tokens = yyExpectingTokens (yyExpectingState);
6788 var names = new List<string> (tokens.Length);
6789 bool has_type = false;
6790 bool has_identifier = false;
6791 for (int i = 0; i < tokens.Length; i++){
6792 int token = tokens [i];
6793 has_identifier |= token == Token.IDENTIFIER;
6795 string name = GetTokenName (token);
6796 if (name == "<internal>")
6799 has_type |= name == "type";
6800 if (names.Contains (name))
6807 // Too many tokens to enumerate
6809 if (names.Count > 8)
6812 if (has_type && has_identifier)
6813 names.Remove ("identifier");
6815 if (names.Count == 1)
6816 return "`" + GetTokenName (tokens [0]) + "'";
6818 StringBuilder sb = new StringBuilder ();
6820 int count = names.Count;
6821 for (int i = 0; i < count; i++){
6822 bool last = i + 1 == count;
6826 sb.Append (names [i]);
6827 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6829 return sb.ToString ();
6833 string GetSymbolName (int token)
6837 return ((Constant)lexer.Value).GetValue ().ToString ();
6838 case Token.IDENTIFIER:
6839 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6881 case Token.BITWISE_AND:
6883 case Token.BITWISE_OR:
6897 case Token.OP_SHIFT_LEFT:
6899 case Token.OP_SHIFT_RIGHT:
6919 case Token.OP_COALESCING:
6921 case Token.OP_MULT_ASSIGN:
6923 case Token.OP_DIV_ASSIGN:
6925 case Token.OP_MOD_ASSIGN:
6927 case Token.OP_ADD_ASSIGN:
6929 case Token.OP_SUB_ASSIGN:
6931 case Token.OP_SHIFT_LEFT_ASSIGN:
6933 case Token.OP_SHIFT_RIGHT_ASSIGN:
6935 case Token.OP_AND_ASSIGN:
6937 case Token.OP_XOR_ASSIGN:
6939 case Token.OP_OR_ASSIGN:
6943 return GetTokenName (token);
6946 static string GetTokenName (int token)
6949 case Token.ABSTRACT:
6971 case Token.CONTINUE:
6975 case Token.DELEGATE:
6985 case Token.EXPLICIT:
6988 case Token.EXTERN_ALIAS:
7004 case Token.IMPLICIT:
7008 case Token.INTERFACE:
7010 case Token.INTERNAL:
7016 case Token.NAMESPACE:
7022 case Token.OPERATOR:
7026 case Token.OVERRIDE:
7032 case Token.PROTECTED:
7036 case Token.READONLY:
7048 case Token.STACKALLOC:
7049 return "stackalloc";
7066 case Token.UNCHECKED:
7074 case Token.VOLATILE:
7082 case Token.REFVALUE:
7083 return "__refvalue";
7093 case Token.FROM_FIRST:
7111 case Token.ASCENDING:
7113 case Token.DESCENDING:
7114 return "descending";
7121 case Token.OPEN_BRACE:
7123 case Token.CLOSE_BRACE:
7125 case Token.OPEN_BRACKET:
7126 case Token.OPEN_BRACKET_EXPR:
7128 case Token.CLOSE_BRACKET:
7130 case Token.OPEN_PARENS_CAST:
7131 case Token.OPEN_PARENS_LAMBDA:
7132 case Token.OPEN_PARENS:
7134 case Token.CLOSE_PARENS:
7140 case Token.DEFAULT_COLON:
7144 case Token.SEMICOLON:
7155 case Token.BITWISE_AND:
7156 case Token.BITWISE_OR:
7163 case Token.OP_SHIFT_LEFT:
7164 case Token.OP_SHIFT_RIGHT:
7172 case Token.OP_COALESCING:
7173 case Token.OP_MULT_ASSIGN:
7174 case Token.OP_DIV_ASSIGN:
7175 case Token.OP_MOD_ASSIGN:
7176 case Token.OP_ADD_ASSIGN:
7177 case Token.OP_SUB_ASSIGN:
7178 case Token.OP_SHIFT_LEFT_ASSIGN:
7179 case Token.OP_SHIFT_RIGHT_ASSIGN:
7180 case Token.OP_AND_ASSIGN:
7181 case Token.OP_XOR_ASSIGN:
7182 case Token.OP_OR_ASSIGN:
7183 return "<operator>";
7205 case Token.OP_GENERICS_LT:
7206 case Token.GENERIC_DIMENSION:
7208 case Token.OP_GENERICS_GT:
7211 case Token.INTERR_NULLABLE:
7213 case Token.DOUBLE_COLON:
7217 case Token.IDENTIFIER:
7219 return "identifier";
7222 return "end-of-file";
7224 // All of these are internal.
7227 case Token.FIRST_KEYWORD:
7228 case Token.EVAL_COMPILATION_UNIT_PARSER:
7229 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7230 case Token.EVAL_STATEMENT_PARSER:
7231 case Token.LAST_KEYWORD:
7232 case Token.GENERATE_COMPLETION:
7233 case Token.COMPLETE_COMPLETION:
7234 return "<internal>";
7236 // A bit more robust.
7238 return yyNames [token];