3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnu.org)
6 // Ravi Pratap (ravi@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004 Novell, Inc
15 // (1) Figure out why error productions dont work. `type-declaration' is a
16 // great spot to put an `error' because you can reproduce it with this input:
23 using System.Collections.Generic;
30 public class CSharpParser
33 enum ParameterModifierType
40 DefaultValue = 1 << 6,
42 All = Ref | Out | This | Params | Arglist | DefaultValue
45 static readonly object ModifierNone = 0;
47 NamespaceEntry current_namespace;
48 TypeContainer current_container;
49 DeclSpace current_class;
50 PropertyBase current_property;
51 EventProperty current_event;
52 EventField current_event_field;
53 FieldBase current_field;
56 /// Current block is used to add statements as we find
61 BlockVariableDeclaration current_variable;
63 Delegate current_delegate;
65 AnonymousMethodExpression current_anonymous_method;
68 /// This is used by the unary_expression code to resolve
69 /// a name against a parameter.
72 // FIXME: This is very ugly and it's very hard to reset it correctly
73 // on all places, especially when some parameters are autogenerated.
74 ParametersCompiled current_local_parameters;
76 bool parsing_anonymous_method;
79 /// An out-of-band stack.
81 static Stack<object> oob_stack;
84 /// Controls the verbosity of the errors produced by the parser
86 static public int yacc_verbose_flag;
89 /// Used by the interactive shell, flags whether EOF was reached
90 /// and an error was produced
92 public bool UnexpectedEOF;
97 readonly CompilationSourceFile file;
100 /// Temporary Xml documentation cache.
101 /// For enum types, we need one more temporary store.
104 string enumTypeComment;
106 /// Current attribute target
107 string current_attr_target;
109 /// assembly and module attribute definitions are enabled
110 bool global_attrs_enabled = true;
112 ParameterModifierType valid_param_mod;
114 bool default_parameter_used;
116 /// When using the interactive parser, this holds the
117 /// resulting expression
118 public Class InteractiveResult;
121 // Keeps track of global data changes to undo on parser error
125 Stack<Linq.QueryBlock> linq_clause_blocks;
127 ModuleContainer module;
129 readonly CompilerContext compiler;
130 readonly LanguageVersion lang_version;
131 readonly bool doc_support;
132 readonly CompilerSettings settings;
135 // Instead of allocating carrier array everytime we
136 // share the bucket for very common constructs which can never
139 static List<Parameter> parameters_bucket = new List<Parameter> (6);
142 // Full AST support members
145 List<Tuple<Modifiers, Location>> mod_locations;
149 %token NONE /* This token is never returned by our lexer */
150 %token ERROR // This is used not by the parser, but by the tokenizer.
154 *These are the C# keywords
253 %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
336 // This token is generated to trigger the completion engine at this point
338 %token GENERATE_COMPLETION
341 // This token is return repeatedly after the first GENERATE_COMPLETION
342 // token is produced and before the final EOF
344 %token COMPLETE_COMPLETION
346 /* Add precedence rules to solve dangling else s/r conflict */
350 /* Define the operator tokens and their precedences */
358 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
360 %left STAR DIV PERCENT
361 %right BANG CARRET UMINUS
362 %nonassoc OP_INC OP_DEC
364 %left OPEN_BRACKET OPEN_BRACE
367 %start compilation_unit
371 : outer_declarations opt_EOF
372 | outer_declarations global_attributes opt_EOF
373 | global_attributes opt_EOF
374 | opt_EOF /* allow empty files */
375 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
381 Lexer.check_incorrect_doc_comment ();
385 Lexer.check_incorrect_doc_comment ();
391 | outer_declarations outer_declaration
395 : extern_alias_directive
397 | namespace_member_declaration
400 extern_alias_directives
401 : extern_alias_directive
402 | extern_alias_directives extern_alias_directive
405 extern_alias_directive
406 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
408 var lt = (Tokenizer.LocatedToken) $2;
411 syntax_error (lt.Location, "`alias' expected");
412 } else if (lang_version == LanguageVersion.ISO_1) {
413 FeatureIsNotAvailable (lt.Location, "external alias");
415 lt = (Tokenizer.LocatedToken) $3;
416 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
421 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
427 | using_directives using_directive
431 : using_alias_directive
434 Lexer.doc_state = XmlCommentState.Allowed;
436 | using_namespace_directive
439 Lexer.doc_state = XmlCommentState.Allowed;
443 using_alias_directive
444 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
446 var lt = (Tokenizer.LocatedToken) $2;
447 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
448 Report.Warning (440, 2, lt.Location,
449 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
452 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
456 Error_SyntaxError (yyToken);
461 using_namespace_directive
462 : USING namespace_name SEMICOLON
464 current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
469 // Strictly speaking, namespaces don't have attributes but
470 // we parse global attributes along with namespace declarations and then
473 namespace_declaration
474 : opt_attributes NAMESPACE qualified_identifier
476 MemberName name = (MemberName) $3;
479 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
482 current_namespace = new NamespaceEntry (module,
483 current_namespace, file, name.GetName ());
484 current_class = current_namespace.SlaveDeclSpace;
485 current_container = current_class.PartialContainer;
487 namespace_body opt_semicolon
489 current_namespace = current_namespace.Parent;
490 current_class = current_namespace.SlaveDeclSpace;
491 current_container = current_class.PartialContainer;
498 var lt = (Tokenizer.LocatedToken) $1;
499 $$ = new MemberName (lt.Value, lt.Location);
501 | qualified_identifier DOT IDENTIFIER
503 var lt = (Tokenizer.LocatedToken) $3;
504 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
508 Error_SyntaxError (yyToken);
509 $$ = new MemberName ("<invalid>", lexer.Location);
524 : namespace_or_type_name
526 MemberName name = (MemberName) $1;
528 if (name.TypeArguments != null)
529 syntax_error (lexer.Location, "namespace name expected");
539 Lexer.doc_state = XmlCommentState.Allowed;
541 opt_extern_alias_directives
543 opt_namespace_member_declarations
552 opt_extern_alias_directives
554 | extern_alias_directives
557 opt_namespace_member_declarations
559 | namespace_member_declarations
562 namespace_member_declarations
563 : namespace_member_declaration
564 | namespace_member_declarations namespace_member_declaration
567 namespace_member_declaration
571 DeclSpace ds = (DeclSpace)$1;
573 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
574 Report.Error (1527, ds.Location,
575 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
578 current_namespace.DeclarationFound = true;
580 | namespace_declaration
582 current_namespace.DeclarationFound = true;
586 Error_SyntaxError (yyToken);
593 | interface_declaration
595 | delegate_declaration
597 // Enable this when we have handled all errors, because this acts as a generic fallback
600 // Console.WriteLine ("Token=" + yyToken);
601 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
613 Attributes attrs = (Attributes)$1;
614 if (global_attrs_enabled) {
615 module.AddAttributes (attrs.Attrs, current_namespace);
617 foreach (Attribute a in attrs.Attrs) {
618 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
629 global_attrs_enabled = false;
634 global_attrs_enabled = false;
643 if (current_attr_target != String.Empty) {
644 var sect = (List<Attribute>) $1;
646 if (global_attrs_enabled) {
647 if (!string.IsNullOrEmpty (current_attr_target)) {
648 module.AddAttributes (sect, current_namespace);
651 $$ = new Attributes (sect);
655 Lexer.check_incorrect_doc_comment ();
657 XmlCommentState.Allowed;
661 $$ = new Attributes (sect);
666 current_attr_target = null;
668 | attribute_sections attribute_section
670 if (current_attr_target != String.Empty) {
671 Attributes attrs = $1 as Attributes;
672 var sect = (List<Attribute>) $2;
674 if (global_attrs_enabled) {
675 if (!string.IsNullOrEmpty (current_attr_target)) {
676 module.AddAttributes (sect, current_namespace);
680 attrs = new Attributes (sect);
682 attrs.AddAttributes (sect);
686 attrs = new Attributes (sect);
688 attrs.AddAttributes (sect);
694 current_attr_target = null;
701 lexer.parsing_attribute_section = true;
703 attribute_section_cont
705 lexer.parsing_attribute_section = false;
710 attribute_section_cont
711 : attribute_target COLON
713 current_attr_target = (string)$1;
715 attribute_list opt_comma CLOSE_BRACKET
719 | attribute_list opt_comma CLOSE_BRACKET
728 var lt = (Tokenizer.LocatedToken) $1;
729 $$ = CheckAttributeTarget (lt.Value, lt.Location);
731 | EVENT { $$ = "event"; }
732 | RETURN { $$ = "return"; }
735 string name = GetTokenName (yyToken);
736 $$ = CheckAttributeTarget (name, GetLocation ($1));
743 $$ = new List<Attribute> (4) { (Attribute) $1 };
745 | attribute_list COMMA attribute
747 var attrs = (List<Attribute>) $1;
748 attrs.Add ((Attribute) $3);
757 ++lexer.parsing_block;
759 opt_attribute_arguments
761 --lexer.parsing_block;
762 MemberName mname = (MemberName) $1;
763 if (mname.IsGeneric) {
764 Report.Error (404, lexer.Location,
765 "'<' unexpected: attributes cannot be generic");
768 Arguments [] arguments = (Arguments []) $3;
769 ATypeNameExpression expr = mname.GetTypeExpression ();
771 if (current_attr_target == String.Empty)
773 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
774 // FIXME: supply "nameEscaped" parameter here.
775 $$ = new GlobalAttribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
777 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
782 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
785 opt_attribute_arguments
786 : /* empty */ { $$ = null; }
787 | OPEN_PARENS attribute_arguments CLOSE_PARENS
795 : /* empty */ { $$ = null; }
796 | positional_or_named_argument
798 Arguments a = new Arguments (4);
799 a.Add ((Argument) $1);
800 $$ = new Arguments [] { a, null };
802 | named_attribute_argument
804 Arguments a = new Arguments (4);
805 a.Add ((Argument) $1);
806 $$ = new Arguments [] { null, a };
808 | attribute_arguments COMMA positional_or_named_argument
810 Arguments[] o = (Arguments[]) $1;
812 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
813 o [0] = new Arguments (4);
816 Arguments args = ((Arguments) o [0]);
817 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
818 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
820 args.Add ((Argument) $3);
822 | attribute_arguments COMMA named_attribute_argument
824 Arguments[] o = (Arguments[]) $1;
826 o [1] = new Arguments (4);
829 ((Arguments) o [1]).Add ((Argument) $3);
833 positional_or_named_argument
836 $$ = new Argument ((Expression) $1);
841 named_attribute_argument
844 ++lexer.parsing_block;
848 --lexer.parsing_block;
849 var lt = (Tokenizer.LocatedToken) $1;
850 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
855 : IDENTIFIER COLON opt_named_modifier expression
857 if (lang_version <= LanguageVersion.V_3)
858 FeatureIsNotAvailable (GetLocation ($1), "named argument");
860 // Avoid boxing in common case (no modifier)
861 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
863 var lt = (Tokenizer.LocatedToken) $1;
864 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
869 : /* empty */ { $$ = null; }
872 $$ = Argument.AType.Ref;
876 $$ = Argument.AType.Out;
880 opt_class_member_declarations
882 | class_member_declarations
885 class_member_declarations
886 : class_member_declaration
887 | class_member_declarations
888 class_member_declaration
891 class_member_declaration
892 : constant_declaration // done
893 | field_declaration // done
894 | method_declaration // done
895 | property_declaration // done
896 | event_declaration // done
897 | indexer_declaration // done
898 | operator_declaration // done
899 | constructor_declaration // done
900 | destructor_declaration // done
904 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
905 GetSymbolName (yyToken));
907 lexer.parsing_generic_declaration = false;
917 lexer.ConstraintsParsing = true;
919 type_declaration_name
921 MemberName name = MakeName ((MemberName) $6);
922 push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
925 opt_type_parameter_constraints_clauses
927 lexer.ConstraintsParsing = false;
929 current_class.SetParameterInfo ((List<Constraints>) $9);
932 current_container.DocComment = Lexer.consume_doc_comment ();
934 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
938 --lexer.parsing_declaration;
940 Lexer.doc_state = XmlCommentState.Allowed;
944 lbag.AppendToMember (current_class, GetLocation ($13));
945 $$ = pop_current_class ();
947 | opt_attributes opt_modifiers opt_partial STRUCT error
949 Error_SyntaxError (yyToken);
957 Lexer.doc_state = XmlCommentState.Allowed;
959 opt_struct_member_declarations CLOSE_BRACE
961 lbag.AppendToMember (current_class, GetLocation ($1), GetLocation ($4));
965 opt_struct_member_declarations
967 | struct_member_declarations
970 struct_member_declarations
971 : struct_member_declaration
972 | struct_member_declarations struct_member_declaration
975 struct_member_declaration
976 : constant_declaration
979 | property_declaration
981 | indexer_declaration
982 | operator_declaration
983 | constructor_declaration
987 * This is only included so we can flag error 575:
988 * destructors only allowed on class types
990 | destructor_declaration
996 CONST type IDENTIFIER
998 var lt = (Tokenizer.LocatedToken) $5;
999 var mod = (Modifiers) $2;
1000 current_field = new Const (current_class, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1001 current_container.AddConstant ((Const) current_field);
1003 if ((mod & Modifiers.STATIC) != 0) {
1004 Report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1009 constant_initializer opt_constant_declarators SEMICOLON
1012 current_field.DocComment = Lexer.consume_doc_comment ();
1013 Lexer.doc_state = XmlCommentState.Allowed;
1016 current_field.Initializer = (ConstInitializer) $7;
1017 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1018 current_field = null;
1022 opt_constant_declarators
1024 | constant_declarators
1027 constant_declarators
1028 : constant_declarator
1030 current_field.AddDeclarator ((FieldDeclarator) $1);
1032 | constant_declarators constant_declarator
1034 current_field.AddDeclarator ((FieldDeclarator) $2);
1039 : COMMA IDENTIFIER constant_initializer
1041 var lt = (Tokenizer.LocatedToken) $2;
1042 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1043 lbag.AddLocation ($$, GetLocation ($1));
1047 constant_initializer
1050 ++lexer.parsing_block;
1052 constant_initializer_expr
1054 --lexer.parsing_block;
1055 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1059 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
1064 constant_initializer_expr
1065 : constant_expression
1072 member_type IDENTIFIER
1074 lexer.parsing_generic_declaration = false;
1076 FullNamedExpression type = (FullNamedExpression) $3;
1077 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1078 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1080 var lt = (Tokenizer.LocatedToken) $4;
1081 current_field = new Field (current_class, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1082 current_container.AddField (current_field);
1085 opt_field_initializer
1086 opt_field_declarators
1090 current_field.DocComment = Lexer.consume_doc_comment ();
1091 Lexer.doc_state = XmlCommentState.Allowed;
1094 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1096 current_field = null;
1100 FIXED simple_type IDENTIFIER
1102 if (lang_version < LanguageVersion.ISO_2)
1103 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1105 var lt = (Tokenizer.LocatedToken) $5;
1106 current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
1107 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1109 current_container.AddField (current_field);
1111 fixed_field_size opt_fixed_field_declarators SEMICOLON
1114 current_field.DocComment = Lexer.consume_doc_comment ();
1115 Lexer.doc_state = XmlCommentState.Allowed;
1118 current_field.Initializer = (ConstInitializer) $7;
1119 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1121 current_field = null;
1125 FIXED simple_type error
1128 Report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1132 opt_field_initializer
1136 ++lexer.parsing_block;
1137 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1138 start_block (GetLocation ($1));
1140 variable_initializer
1142 --lexer.parsing_block;
1143 current_field.Initializer = (Expression) $3;
1144 end_block (lexer.Location);
1145 current_local_parameters = null;
1149 opt_field_declarators
1157 current_field.AddDeclarator ((FieldDeclarator) $1);
1159 | field_declarators field_declarator
1161 current_field.AddDeclarator ((FieldDeclarator) $2);
1168 var lt = (Tokenizer.LocatedToken) $2;
1169 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1170 lbag.AddLocation ($$, GetLocation ($1));
1172 | COMMA IDENTIFIER ASSIGN
1174 ++lexer.parsing_block;
1176 variable_initializer
1178 --lexer.parsing_block;
1179 var lt = (Tokenizer.LocatedToken) $2;
1180 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1181 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1185 opt_fixed_field_declarators
1187 | fixed_field_declarators
1190 fixed_field_declarators
1191 : fixed_field_declarator
1193 current_field.AddDeclarator ((FieldDeclarator) $1);
1195 | fixed_field_declarators fixed_field_declarator
1197 current_field.AddDeclarator ((FieldDeclarator) $2);
1201 fixed_field_declarator
1202 : COMMA IDENTIFIER fixed_field_size
1204 var lt = (Tokenizer.LocatedToken) $2;
1205 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1206 lbag.AddLocation ($$, GetLocation ($1));
1213 ++lexer.parsing_block;
1215 expression CLOSE_BRACKET
1217 --lexer.parsing_block;
1218 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1219 lbag.AddLocation ($$, GetLocation ($4));
1221 | OPEN_BRACKET error
1223 Report.Error (443, lexer.Location, "Value or constant expected");
1228 variable_initializer
1233 // It has to be here for the parent to safely restore artificial block
1234 Error_SyntaxError (yyToken);
1243 Lexer.doc_state = XmlCommentState.NotAllowed;
1245 // Add it early in the case of body being eof for full aot
1246 current_container.AddMethod ((Method) $1);
1250 Method method = (Method) $1;
1251 method.Block = (ToplevelBlock) $3;
1253 if (current_container.Kind == MemberKind.Interface && method.Block != null) {
1254 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1257 current_local_parameters = null;
1260 Lexer.doc_state = XmlCommentState.Allowed;
1268 method_declaration_name OPEN_PARENS
1270 valid_param_mod = ParameterModifierType.All;
1272 opt_formal_parameter_list CLOSE_PARENS
1274 lexer.ConstraintsParsing = true;
1276 opt_type_parameter_constraints_clauses
1278 lexer.ConstraintsParsing = false;
1279 valid_param_mod = 0;
1280 MemberName name = (MemberName) $4;
1281 current_local_parameters = (ParametersCompiled) $7;
1283 GenericMethod generic = null;
1284 if (name.TypeArguments != null) {
1285 generic = new GenericMethod (current_namespace, current_class, name,
1286 (FullNamedExpression) $3, current_local_parameters);
1288 generic.SetParameterInfo ((List<Constraints>) $10);
1289 } else if ($10 != null) {
1290 Report.Error (80, GetLocation ($10),
1291 "Constraints are not allowed on non-generic declarations");
1294 Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
1295 name, current_local_parameters, (Attributes) $1);
1297 if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
1298 Report.Error (460, method.Location,
1299 "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
1300 method.GetSignatureForError ());
1304 method.DocComment = Lexer.consume_doc_comment ();
1306 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1312 VOID method_declaration_name
1315 valid_param_mod = ParameterModifierType.All;
1317 opt_formal_parameter_list CLOSE_PARENS
1319 lexer.ConstraintsParsing = true;
1321 opt_type_parameter_constraints_clauses
1323 lexer.ConstraintsParsing = false;
1324 valid_param_mod = 0;
1326 MemberName name = (MemberName) $5;
1327 current_local_parameters = (ParametersCompiled) $8;
1329 if ($10 != null && name.TypeArguments == null)
1330 Report.Error (80, lexer.Location,
1331 "Constraints are not allowed on non-generic declarations");
1334 GenericMethod generic = null;
1335 if (name.TypeArguments != null) {
1336 generic = new GenericMethod (current_namespace, current_class, name,
1337 new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($4)),
1338 current_local_parameters);
1340 generic.SetParameterInfo ((List<Constraints>) $11);
1343 var modifiers = (Modifiers) $2;
1346 const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
1347 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1349 if ((modifiers & invalid_partial_mod) != 0) {
1350 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1351 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1352 modifiers &= ~invalid_partial_mod;
1355 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1356 Report.Error (751, name.Location, "A partial method must be declared within a " +
1357 "partial class or partial struct");
1360 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1362 method = new Method (current_class, generic, new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($4)),
1363 modifiers, name, current_local_parameters, (Attributes) $1);
1366 method.DocComment = Lexer.consume_doc_comment ();
1368 // TODO: lbag, push void
1369 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1370 lbag.AddMember (method, mod_locations, GetLocation ($6), GetLocation ($9));
1376 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1378 MemberName name = (MemberName) $5;
1379 Report.Error (1585, name.Location,
1380 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1382 Method method = new Method (current_class, null, (FullNamedExpression) $3,
1383 0, name, (ParametersCompiled) $7, (Attributes) $1);
1385 current_local_parameters = (ParametersCompiled) $7;
1388 method.DocComment = Lexer.consume_doc_comment ();
1396 | SEMICOLON { $$ = null; }
1399 opt_formal_parameter_list
1400 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1401 | formal_parameter_list
1404 formal_parameter_list
1407 var pars_list = (List<Parameter>) $1;
1408 $$ = new ParametersCompiled (pars_list.ToArray ());
1410 | fixed_parameters COMMA parameter_array
1412 var pars_list = (List<Parameter>) $1;
1413 pars_list.Add ((Parameter) $3);
1415 $$ = new ParametersCompiled (pars_list.ToArray ());
1417 | fixed_parameters COMMA arglist_modifier
1419 var pars_list = (List<Parameter>) $1;
1420 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1421 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1423 | parameter_array COMMA error
1426 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1428 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1430 | fixed_parameters COMMA parameter_array COMMA error
1433 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1435 var pars_list = (List<Parameter>) $1;
1436 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1438 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1440 | arglist_modifier COMMA error
1442 Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1444 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1446 | fixed_parameters COMMA ARGLIST COMMA error
1448 Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1450 var pars_list = (List<Parameter>) $1;
1451 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1453 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1457 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1461 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1465 Error_SyntaxError (yyToken);
1466 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1473 parameters_bucket.Clear ();
1474 Parameter p = (Parameter) $1;
1475 parameters_bucket.Add (p);
1477 default_parameter_used = p.HasDefaultValue;
1478 $$ = parameters_bucket;
1480 | fixed_parameters COMMA fixed_parameter
1482 var pars = (List<Parameter>) $1;
1483 Parameter p = (Parameter) $3;
1485 if (p.HasExtensionMethodModifier)
1486 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1487 else if (!p.HasDefaultValue && default_parameter_used)
1488 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1490 default_parameter_used |= p.HasDefaultValue;
1493 lbag.AddLocation (p, GetLocation ($2));
1502 opt_parameter_modifier
1506 var lt = (Tokenizer.LocatedToken) $4;
1507 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1510 opt_parameter_modifier
1512 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1514 var lt = (Tokenizer.LocatedToken) $4;
1515 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1516 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1519 opt_parameter_modifier
1523 Error_SyntaxError (yyToken);
1524 Location l = GetLocation ($4);
1525 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1528 opt_parameter_modifier
1533 ++lexer.parsing_block;
1537 --lexer.parsing_block;
1538 if (lang_version <= LanguageVersion.V_3) {
1539 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1542 Parameter.Modifier mod = (Parameter.Modifier) $2;
1543 if (mod != Parameter.Modifier.NONE) {
1545 case Parameter.Modifier.REF:
1546 case Parameter.Modifier.OUT:
1547 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1548 Parameter.GetModifierSignature (mod));
1551 case Parameter.Modifier.This:
1552 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1553 Parameter.GetModifierSignature (mod));
1556 throw new NotImplementedException (mod.ToString ());
1559 mod = Parameter.Modifier.NONE;
1562 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1563 Report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1565 var lt = (Tokenizer.LocatedToken) $4;
1566 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1567 lbag.AddLocation ($$, GetLocation ($5));
1570 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1574 opt_parameter_modifier
1575 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1576 | parameter_modifiers
1580 : parameter_modifier
1584 | parameter_modifiers parameter_modifier
1586 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1587 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1588 if (((Parameter.Modifier)$1 & p2) == p2) {
1589 Error_DuplicateParameterModifier (lexer.Location, p2);
1591 switch (mod & ~Parameter.Modifier.This) {
1592 case Parameter.Modifier.REF:
1593 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1595 case Parameter.Modifier.OUT:
1596 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1599 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1610 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1611 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1613 $$ = Parameter.Modifier.REF;
1617 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1618 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1620 $$ = Parameter.Modifier.OUT;
1624 if ((valid_param_mod & ParameterModifierType.This) == 0)
1625 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1627 if (lang_version <= LanguageVersion.ISO_2)
1628 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1630 $$ = Parameter.Modifier.This;
1635 : opt_attributes params_modifier type IDENTIFIER
1637 var lt = (Tokenizer.LocatedToken) $4;
1638 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1640 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1642 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1644 var lt = (Tokenizer.LocatedToken) $4;
1645 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1647 | opt_attributes params_modifier type error
1649 Error_SyntaxError (yyToken);
1657 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1658 Report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1660 | PARAMS parameter_modifier
1662 Parameter.Modifier mod = (Parameter.Modifier)$2;
1663 if ((mod & Parameter.Modifier.This) != 0) {
1664 Report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1666 Report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1669 | PARAMS params_modifier
1671 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1678 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1679 Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1683 property_declaration
1687 member_declaration_name
1690 tmpComment = Lexer.consume_doc_comment ();
1694 var type = (FullNamedExpression) $3;
1695 current_property = new Property (current_class, type, (Modifiers) $2,
1696 (MemberName) $4, (Attributes) $1);
1698 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1699 Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1701 current_container.AddProperty ((Property)current_property);
1702 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1704 lexer.PropertyParsing = true;
1706 accessor_declarations
1708 lexer.PropertyParsing = false;
1711 current_property.DocComment = ConsumeStoredComment ();
1715 lbag.AppendToMember (current_property, GetLocation ($10));
1716 current_property = null;
1722 : opt_attributes opt_modifiers
1723 member_type indexer_declaration_name OPEN_BRACKET
1725 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1727 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1729 valid_param_mod = 0;
1730 var type = (FullNamedExpression) $3;
1731 Indexer indexer = new Indexer (current_class, type,
1732 (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1734 current_property = indexer;
1736 current_container.AddIndexer (indexer);
1737 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1739 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1740 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1742 if (indexer.Parameters.IsEmpty) {
1743 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1747 tmpComment = Lexer.consume_doc_comment ();
1748 Lexer.doc_state = XmlCommentState.Allowed;
1751 lexer.PropertyParsing = true;
1753 accessor_declarations
1755 lexer.PropertyParsing = false;
1760 current_property.DocComment = ConsumeStoredComment ();
1762 lbag.AppendToMember (current_property, GetLocation ($12));
1763 current_property = null;
1768 accessor_declarations
1769 : get_accessor_declaration
1770 | get_accessor_declaration accessor_declarations
1771 | set_accessor_declaration
1772 | set_accessor_declaration accessor_declarations
1775 if (yyToken == Token.CLOSE_BRACE) {
1776 Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1778 if (yyToken == Token.SEMICOLON)
1779 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1781 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1786 get_accessor_declaration
1787 : opt_attributes opt_modifiers GET
1789 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1790 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1793 if (current_property.Get != null) {
1794 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1797 if (current_property is Indexer) {
1798 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1799 (Attributes) $1, GetLocation ($3));
1801 current_property.Get = new Property.GetMethod (current_property,
1802 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1805 current_local_parameters = current_property.Get.ParameterInfo;
1806 lbag.AddMember (current_property.Get, mod_locations);
1807 lexer.PropertyParsing = false;
1812 current_property.Get.Block = (ToplevelBlock) $5;
1814 if (current_container.Kind == MemberKind.Interface) {
1815 Report.Error (531, current_property.Get.Block.StartLocation,
1816 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1820 current_local_parameters = null;
1821 lexer.PropertyParsing = true;
1824 if (Lexer.doc_state == XmlCommentState.Error)
1825 Lexer.doc_state = XmlCommentState.NotAllowed;
1829 set_accessor_declaration
1830 : opt_attributes opt_modifiers SET
1832 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1833 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1836 if (current_property.Set != null) {
1837 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1840 if (current_property is Indexer) {
1841 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1842 ParametersCompiled.MergeGenerated (compiler,
1843 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1844 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1846 (Attributes) $1, GetLocation ($3));
1848 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1849 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1850 (Attributes) $1, GetLocation ($3));
1853 current_local_parameters = current_property.Set.ParameterInfo;
1854 lbag.AddMember (current_property.Set, mod_locations);
1855 lexer.PropertyParsing = false;
1860 current_property.Set.Block = (ToplevelBlock) $5;
1862 if (current_container.Kind == MemberKind.Interface) {
1863 Report.Error (531, current_property.Set.Block.StartLocation,
1864 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1868 current_local_parameters = null;
1869 lexer.PropertyParsing = true;
1872 && Lexer.doc_state == XmlCommentState.Error)
1873 Lexer.doc_state = XmlCommentState.NotAllowed;
1886 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1891 interface_declaration
1897 lexer.ConstraintsParsing = true;
1899 type_declaration_name
1901 MemberName name = MakeName ((MemberName) $6);
1902 push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
1903 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
1906 opt_type_parameter_constraints_clauses
1908 lexer.ConstraintsParsing = false;
1910 current_class.SetParameterInfo ((List<Constraints>) $9);
1913 current_container.DocComment = Lexer.consume_doc_comment ();
1914 Lexer.doc_state = XmlCommentState.Allowed;
1917 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1919 --lexer.parsing_declaration;
1921 Lexer.doc_state = XmlCommentState.Allowed;
1925 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
1926 $$ = pop_current_class ();
1928 | opt_attributes opt_modifiers opt_partial INTERFACE error
1930 Error_SyntaxError (yyToken);
1934 opt_interface_member_declarations
1936 | interface_member_declarations
1939 interface_member_declarations
1940 : interface_member_declaration
1941 | interface_member_declarations interface_member_declaration
1944 interface_member_declaration
1945 : constant_declaration
1947 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1951 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1953 | method_declaration
1954 | property_declaration
1956 | indexer_declaration
1957 | operator_declaration
1959 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1961 | constructor_declaration
1963 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1967 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1971 operator_declaration
1972 : opt_attributes opt_modifiers operator_declarator
1977 OperatorDeclaration decl = (OperatorDeclaration) $3;
1979 Operator op = new Operator (
1980 current_class, decl.optype, decl.ret_type, (Modifiers) $2,
1981 current_local_parameters,
1982 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1985 op.DocComment = tmpComment;
1986 Lexer.doc_state = XmlCommentState.Allowed;
1989 // Note again, checking is done in semantic analysis
1990 current_container.AddOperator (op);
1992 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1995 current_local_parameters = null;
2001 | SEMICOLON { $$ = null; }
2005 : type_expression_or_array
2008 Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2009 $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
2014 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2016 valid_param_mod = ParameterModifierType.DefaultValue;
2018 opt_formal_parameter_list CLOSE_PARENS
2020 valid_param_mod = 0;
2022 Location loc = GetLocation ($2);
2023 Operator.OpType op = (Operator.OpType) $3;
2024 current_local_parameters = (ParametersCompiled)$6;
2026 int p_count = current_local_parameters.Count;
2028 if (op == Operator.OpType.Addition)
2029 op = Operator.OpType.UnaryPlus;
2030 else if (op == Operator.OpType.Subtraction)
2031 op = Operator.OpType.UnaryNegation;
2034 if (IsUnaryOperator (op)) {
2036 Report.Error (1020, loc, "Overloadable binary operator expected");
2037 } else if (p_count != 1) {
2038 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2039 Operator.GetName (op));
2043 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2044 Operator.GetName (op));
2045 } else if (p_count != 2) {
2046 Report.Error (1019, loc, "Overloadable unary operator expected");
2051 tmpComment = Lexer.consume_doc_comment ();
2052 Lexer.doc_state = XmlCommentState.NotAllowed;
2055 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2056 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2058 | conversion_operator_declarator
2061 overloadable_operator
2063 : BANG { $$ = Operator.OpType.LogicalNot; }
2064 | TILDE { $$ = Operator.OpType.OnesComplement; }
2065 | OP_INC { $$ = Operator.OpType.Increment; }
2066 | OP_DEC { $$ = Operator.OpType.Decrement; }
2067 | TRUE { $$ = Operator.OpType.True; }
2068 | FALSE { $$ = Operator.OpType.False; }
2069 // Unary and binary:
2070 | PLUS { $$ = Operator.OpType.Addition; }
2071 | MINUS { $$ = Operator.OpType.Subtraction; }
2073 | STAR { $$ = Operator.OpType.Multiply; }
2074 | DIV { $$ = Operator.OpType.Division; }
2075 | PERCENT { $$ = Operator.OpType.Modulus; }
2076 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2077 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2078 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2079 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2080 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2081 | OP_EQ { $$ = Operator.OpType.Equality; }
2082 | OP_NE { $$ = Operator.OpType.Inequality; }
2083 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2084 | OP_LT { $$ = Operator.OpType.LessThan; }
2085 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2086 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2089 conversion_operator_declarator
2090 : IMPLICIT OPERATOR type OPEN_PARENS
2092 valid_param_mod = ParameterModifierType.DefaultValue;
2094 opt_formal_parameter_list CLOSE_PARENS
2096 valid_param_mod = 0;
2098 Location loc = GetLocation ($2);
2099 current_local_parameters = (ParametersCompiled)$6;
2102 tmpComment = Lexer.consume_doc_comment ();
2103 Lexer.doc_state = XmlCommentState.NotAllowed;
2106 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2107 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2109 | EXPLICIT OPERATOR type OPEN_PARENS
2111 valid_param_mod = ParameterModifierType.DefaultValue;
2113 opt_formal_parameter_list CLOSE_PARENS
2115 valid_param_mod = 0;
2117 Location loc = GetLocation ($2);
2118 current_local_parameters = (ParametersCompiled)$6;
2121 tmpComment = Lexer.consume_doc_comment ();
2122 Lexer.doc_state = XmlCommentState.NotAllowed;
2125 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2126 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2130 Error_SyntaxError (yyToken);
2131 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2132 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2136 Error_SyntaxError (yyToken);
2137 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2138 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2142 constructor_declaration
2143 : constructor_declarator
2146 Constructor c = (Constructor) $1;
2147 c.Block = (ToplevelBlock) $2;
2150 c.DocComment = ConsumeStoredComment ();
2152 current_container.AddConstructor (c);
2154 current_local_parameters = null;
2156 Lexer.doc_state = XmlCommentState.Allowed;
2160 constructor_declarator
2166 tmpComment = Lexer.consume_doc_comment ();
2167 Lexer.doc_state = XmlCommentState.Allowed;
2170 valid_param_mod = ParameterModifierType.All;
2172 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2174 valid_param_mod = 0;
2175 current_local_parameters = (ParametersCompiled) $6;
2178 // start block here, so possible anonymous methods inside
2179 // constructor initializer can get correct parent block
2181 start_block (lexer.Location);
2183 opt_constructor_initializer
2185 var lt = (Tokenizer.LocatedToken) $3;
2186 var mods = (Modifiers) $2;
2187 ConstructorInitializer ci = (ConstructorInitializer) $9;
2189 Constructor c = new Constructor (current_class, lt.Value, mods,
2190 (Attributes) $1, current_local_parameters, ci, lt.Location);
2192 if (lt.Value != current_container.MemberName.Name) {
2193 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2194 } else if ((mods & Modifiers.STATIC) != 0) {
2195 if ((mods & Modifiers.AccessibilityMask) != 0){
2196 Report.Error (515, c.Location,
2197 "`{0}': static constructor cannot have an access modifier",
2198 c.GetSignatureForError ());
2201 Report.Error (514, c.Location,
2202 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2203 c.GetSignatureForError ());
2208 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2215 | SEMICOLON { current_block = null; $$ = null; }
2218 opt_constructor_initializer
2220 | constructor_initializer
2223 constructor_initializer
2224 : COLON BASE OPEN_PARENS
2226 ++lexer.parsing_block;
2228 opt_argument_list CLOSE_PARENS
2230 --lexer.parsing_block;
2231 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2232 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2234 | COLON THIS OPEN_PARENS
2236 ++lexer.parsing_block;
2238 opt_argument_list CLOSE_PARENS
2240 --lexer.parsing_block;
2241 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2242 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2246 Error_SyntaxError (yyToken);
2251 destructor_declaration
2252 : opt_attributes opt_modifiers TILDE
2255 tmpComment = Lexer.consume_doc_comment ();
2256 Lexer.doc_state = XmlCommentState.NotAllowed;
2259 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2261 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2263 var lt = (Tokenizer.LocatedToken) $5;
2264 if (lt.Value != current_container.MemberName.Name){
2265 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2266 } else if (current_container.Kind != MemberKind.Class){
2267 Report.Error (575, lt.Location, "Only class types can contain destructor");
2270 Destructor d = new Destructor (current_class, (Modifiers) $2,
2271 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2273 d.DocComment = ConsumeStoredComment ();
2275 d.Block = (ToplevelBlock) $8;
2276 current_container.AddMethod (d);
2277 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2279 current_local_parameters = null;
2286 EVENT type member_declaration_name
2288 current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2289 current_container.AddEvent (current_event_field);
2291 if (current_event_field.MemberName.Left != null) {
2292 Report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2293 current_event_field.GetSignatureForError ());
2296 $$ = current_event_field;
2298 opt_event_initializer
2299 opt_event_declarators
2303 current_event_field.DocComment = Lexer.consume_doc_comment ();
2304 Lexer.doc_state = XmlCommentState.Allowed;
2307 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2308 current_event_field = null;
2312 EVENT type member_declaration_name
2315 current_event = new EventProperty (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2316 current_container.AddEvent (current_event);
2317 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2319 lexer.EventParsing = true;
2321 event_accessor_declarations
2323 if (current_container.Kind == MemberKind.Interface)
2324 Report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2326 lexer.EventParsing = false;
2331 current_event.DocComment = Lexer.consume_doc_comment ();
2332 Lexer.doc_state = XmlCommentState.Allowed;
2335 lbag.AppendToMember (current_event, GetLocation ($9));
2336 current_event = null;
2337 current_local_parameters = null;
2341 opt_event_initializer
2345 ++lexer.parsing_block;
2347 event_variable_initializer
2349 --lexer.parsing_block;
2350 current_event_field.Initializer = (Expression) $3;
2354 opt_event_declarators
2362 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2364 | event_declarators event_declarator
2366 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2373 var lt = (Tokenizer.LocatedToken) $2;
2374 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2375 lbag.AddLocation ($$, GetLocation ($1));
2377 | COMMA IDENTIFIER ASSIGN
2379 ++lexer.parsing_block;
2381 event_variable_initializer
2383 --lexer.parsing_block;
2384 var lt = (Tokenizer.LocatedToken) $2;
2385 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2386 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2390 event_variable_initializer
2392 if (current_container.Kind == MemberKind.Interface) {
2393 Report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2394 current_event_field.GetSignatureForError ());
2397 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2398 Report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2399 current_event_field.GetSignatureForError ());
2402 variable_initializer
2408 event_accessor_declarations
2409 : add_accessor_declaration remove_accessor_declaration
2410 | remove_accessor_declaration add_accessor_declaration
2411 | add_accessor_declaration
2413 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2414 current_event.GetSignatureForError ());
2416 | remove_accessor_declaration
2418 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2419 current_event.GetSignatureForError ());
2423 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2428 add_accessor_declaration
2429 : opt_attributes opt_modifiers ADD
2431 if ($2 != ModifierNone) {
2432 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2435 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2436 current_local_parameters = current_event.Add.ParameterInfo;
2438 lbag.AddMember (current_event.Add, mod_locations);
2439 lexer.EventParsing = false;
2441 event_accessor_block
2443 lexer.EventParsing = true;
2445 current_event.Add.Block = (ToplevelBlock) $5;
2447 if (current_container.Kind == MemberKind.Interface) {
2448 Report.Error (531, current_event.Add.Block.StartLocation,
2449 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2452 current_local_parameters = null;
2456 remove_accessor_declaration
2457 : opt_attributes opt_modifiers REMOVE
2459 if ($2 != ModifierNone) {
2460 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2463 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2464 current_local_parameters = current_event.Remove.ParameterInfo;
2466 lbag.AddMember (current_event.Remove, mod_locations);
2467 lexer.EventParsing = false;
2469 event_accessor_block
2471 lexer.EventParsing = true;
2473 current_event.Remove.Block = (ToplevelBlock) $5;
2475 if (current_container.Kind == MemberKind.Interface) {
2476 Report.Error (531, current_event.Remove.Block.StartLocation,
2477 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2480 current_local_parameters = null;
2484 event_accessor_block
2487 Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2496 ENUM type_declaration_name
2500 enumTypeComment = Lexer.consume_doc_comment ();
2505 Lexer.doc_state = XmlCommentState.Allowed;
2507 MemberName name = (MemberName) $4;
2508 if (name.IsGeneric) {
2509 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2512 push_current_class (new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2, MakeName (name), (Attributes) $1), null);
2514 opt_enum_member_declarations
2516 // here will be evaluated after CLOSE_BLACE is consumed.
2518 Lexer.doc_state = XmlCommentState.Allowed;
2520 CLOSE_BRACE opt_semicolon
2523 current_class.DocComment = enumTypeComment;
2525 --lexer.parsing_declaration;
2528 // em.DocComment = ev.DocComment;
2530 lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2531 $$ = pop_current_class ();
2539 var te = $2 as TypeExpression;
2540 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2541 Enum.Error_1008 (GetLocation ($2), Report);
2549 Error_TypeExpected (GetLocation ($1));
2554 opt_enum_member_declarations
2556 | enum_member_declarations
2557 | enum_member_declarations COMMA
2559 lbag.AddLocation ($1, GetLocation ($2));
2563 enum_member_declarations
2564 : enum_member_declaration
2565 | enum_member_declarations COMMA enum_member_declaration
2567 lbag.AddLocation ($1, GetLocation ($2));
2572 enum_member_declaration
2573 : opt_attributes IDENTIFIER
2575 var lt = (Tokenizer.LocatedToken) $2;
2576 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2577 ((Enum) current_class).AddEnumMember (em);
2580 em.DocComment = Lexer.consume_doc_comment ();
2581 Lexer.doc_state = XmlCommentState.Allowed;
2586 | opt_attributes IDENTIFIER
2588 ++lexer.parsing_block;
2590 tmpComment = Lexer.consume_doc_comment ();
2591 Lexer.doc_state = XmlCommentState.NotAllowed;
2594 ASSIGN constant_expression
2596 --lexer.parsing_block;
2598 var lt = (Tokenizer.LocatedToken) $2;
2599 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2600 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2601 ((Enum) current_class).AddEnumMember (em);
2604 em.DocComment = ConsumeStoredComment ();
2610 delegate_declaration
2614 member_type type_declaration_name
2617 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2619 opt_formal_parameter_list CLOSE_PARENS
2621 valid_param_mod = 0;
2623 MemberName name = MakeName ((MemberName) $5);
2624 ParametersCompiled p = (ParametersCompiled) $8;
2626 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2627 (Modifiers) $2, name, p, (Attributes) $1);
2630 del.DocComment = Lexer.consume_doc_comment ();
2631 Lexer.doc_state = XmlCommentState.Allowed;
2634 current_container.AddDelegate (del);
2635 current_delegate = del;
2636 lexer.ConstraintsParsing = true;
2638 opt_type_parameter_constraints_clauses
2640 lexer.ConstraintsParsing = false;
2644 current_delegate.SetParameterInfo ((List<Constraints>) $11);
2645 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2647 $$ = current_delegate;
2649 current_delegate = null;
2657 if (lang_version < LanguageVersion.ISO_2)
2658 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2660 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2664 namespace_or_type_name
2666 | qualified_alias_member IDENTIFIER opt_type_argument_list
2668 var lt1 = (Tokenizer.LocatedToken) $1;
2669 var lt2 = (Tokenizer.LocatedToken) $2;
2671 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2677 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2679 var lt = (Tokenizer.LocatedToken) $3;
2680 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2681 lbag.AddLocation ($$, GetLocation ($2));
2686 : IDENTIFIER opt_type_argument_list
2688 var lt = (Tokenizer.LocatedToken) $1;
2689 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2694 // Generics arguments (any type, without attributes)
2696 opt_type_argument_list
2698 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2700 if (lang_version < LanguageVersion.ISO_2)
2701 FeatureIsNotAvailable (GetLocation ($1), "generics");
2705 | OP_GENERICS_LT error
2707 Error_TypeExpected (lexer.Location);
2708 $$ = new TypeArguments ();
2715 TypeArguments type_args = new TypeArguments ();
2716 type_args.Add ((FullNamedExpression) $1);
2719 | type_arguments COMMA type
2721 TypeArguments type_args = (TypeArguments) $1;
2722 type_args.Add ((FullNamedExpression) $3);
2728 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2730 type_declaration_name
2733 lexer.parsing_generic_declaration = true;
2735 opt_type_parameter_list
2737 lexer.parsing_generic_declaration = false;
2738 var lt = (Tokenizer.LocatedToken) $1;
2739 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2743 member_declaration_name
2744 : method_declaration_name
2746 MemberName mn = (MemberName)$1;
2747 if (mn.TypeArguments != null)
2748 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2749 mn.GetSignatureForError ()));
2753 method_declaration_name
2754 : type_declaration_name
2755 | explicit_interface IDENTIFIER opt_type_parameter_list
2757 lexer.parsing_generic_declaration = false;
2758 var lt = (Tokenizer.LocatedToken) $2;
2759 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2763 indexer_declaration_name
2766 lexer.parsing_generic_declaration = false;
2767 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2769 | explicit_interface THIS
2771 lexer.parsing_generic_declaration = false;
2772 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2777 : IDENTIFIER opt_type_argument_list DOT
2779 var lt = (Tokenizer.LocatedToken) $1;
2780 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2781 lbag.AddLocation ($$, GetLocation ($3));
2783 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2785 var lt1 = (Tokenizer.LocatedToken) $1;
2786 var lt2 = (Tokenizer.LocatedToken) $2;
2788 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2789 lbag.AddLocation ($$, GetLocation ($4));
2791 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2793 var lt = (Tokenizer.LocatedToken) $2;
2794 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2795 lbag.AddLocation ($$, GetLocation ($4));
2799 opt_type_parameter_list
2801 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2803 if (lang_version < LanguageVersion.ISO_2)
2804 FeatureIsNotAvailable (GetLocation ($1), "generics");
2807 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2814 TypeArguments type_args = new TypeArguments ();
2815 type_args.Add ((FullNamedExpression)$1);
2818 | type_parameters COMMA type_parameter
2820 TypeArguments type_args = (TypeArguments) $1;
2821 type_args.Add ((FullNamedExpression)$3);
2823 lbag.AddLocation ($3, GetLocation ($3));
2828 : opt_attributes opt_type_parameter_variance IDENTIFIER
2830 var lt = (Tokenizer.LocatedToken)$3;
2831 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2835 if (GetTokenName (yyToken) == "type")
2836 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2838 Error_SyntaxError (yyToken);
2840 $$ = new TypeParameterName ("", null, lexer.Location);
2845 // All types where void is allowed
2848 : type_expression_or_array
2851 $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
2858 lexer.parsing_generic_declaration = true;
2863 // A type which does not allow `void' to be used
2866 : type_expression_or_array
2869 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2870 $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
2878 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2879 $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
2884 : type_expression_or_array
2887 Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2888 $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
2892 type_expression_or_array
2894 | type_expression rank_specifiers
2896 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2901 : namespace_or_type_name opt_nullable
2903 MemberName name = (MemberName) $1;
2906 $$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
2908 if (name.Left == null && name.Name == "var")
2909 $$ = new VarExpr (name.Location);
2911 $$ = name.GetTypeExpression ();
2914 | namespace_or_type_name pointer_stars
2916 $$ = new ComposedCast (((MemberName) $1).GetTypeExpression (), (ComposedTypeSpecifier) $2);
2918 | builtin_types opt_nullable
2921 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2923 | builtin_types pointer_stars
2925 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2927 | VOID pointer_stars
2929 $$ = new ComposedCast (new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2936 var types = new List<FullNamedExpression> (2);
2937 types.Add ((FullNamedExpression) $1);
2940 | type_list COMMA base_type_name
2942 var types = (List<FullNamedExpression>) $1;
2943 types.Add ((FullNamedExpression) $3);
2951 if ($1 is ComposedCast) {
2952 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2958 Error_TypeExpected (lexer.Location);
2964 * replaces all the productions for isolating the various
2965 * simple types, but we need this to reuse it easily in variable_type
2968 : OBJECT { $$ = new TypeExpression (compiler.BuildinTypes.Object, GetLocation ($1)); }
2969 | STRING { $$ = new TypeExpression (compiler.BuildinTypes.String, GetLocation ($1)); }
2970 | BOOL { $$ = new TypeExpression (compiler.BuildinTypes.Bool, GetLocation ($1)); }
2971 | DECIMAL { $$ = new TypeExpression (compiler.BuildinTypes.Decimal, GetLocation ($1)); }
2972 | FLOAT { $$ = new TypeExpression (compiler.BuildinTypes.Float, GetLocation ($1)); }
2973 | DOUBLE { $$ = new TypeExpression (compiler.BuildinTypes.Double, GetLocation ($1)); }
2978 : SBYTE { $$ = new TypeExpression (compiler.BuildinTypes.SByte, GetLocation ($1)); }
2979 | BYTE { $$ = new TypeExpression (compiler.BuildinTypes.Byte, GetLocation ($1)); }
2980 | SHORT { $$ = new TypeExpression (compiler.BuildinTypes.Short, GetLocation ($1)); }
2981 | USHORT { $$ = new TypeExpression (compiler.BuildinTypes.UShort, GetLocation ($1)); }
2982 | INT { $$ = new TypeExpression (compiler.BuildinTypes.Int, GetLocation ($1)); }
2983 | UINT { $$ = new TypeExpression (compiler.BuildinTypes.UInt, GetLocation ($1)); }
2984 | LONG { $$ = new TypeExpression (compiler.BuildinTypes.Long, GetLocation ($1)); }
2985 | ULONG { $$ = new TypeExpression (compiler.BuildinTypes.ULong, GetLocation ($1)); }
2986 | CHAR { $$ = new TypeExpression (compiler.BuildinTypes.Char, GetLocation ($1)); }
2990 // Expressions, section 7.5
2995 : primary_expression_or_type
2997 | array_creation_expression
2998 | parenthesized_expression
2999 | default_value_expression
3000 | invocation_expression
3004 | post_increment_expression
3005 | post_decrement_expression
3006 | object_or_delegate_creation_expression
3007 | anonymous_type_expression
3010 | checked_expression
3011 | unchecked_expression
3012 | pointer_member_access
3013 | anonymous_method_expression
3016 primary_expression_or_type
3017 : IDENTIFIER opt_type_argument_list
3019 var lt = (Tokenizer.LocatedToken) $1;
3020 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3022 | IDENTIFIER GENERATE_COMPLETION {
3023 var lt = (Tokenizer.LocatedToken) $1;
3024 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3032 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3036 : TRUE { $$ = new BoolLiteral (compiler.BuildinTypes, true, GetLocation ($1)); }
3037 | FALSE { $$ = new BoolLiteral (compiler.BuildinTypes, false, GetLocation ($1)); }
3042 // Here is the trick, tokenizer may think that parens is a special but
3043 // parser is interested in open parens only, so we merge them.
3044 // Consider: if (a)foo ();
3052 // Use this production to accept closing parenthesis or
3053 // performing completion
3057 | COMPLETE_COMPLETION
3061 parenthesized_expression
3062 : OPEN_PARENS expression CLOSE_PARENS
3064 $$ = new ParenthesizedExpression ((Expression) $2);
3065 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3067 | OPEN_PARENS expression COMPLETE_COMPLETION
3069 $$ = new ParenthesizedExpression ((Expression) $2);
3074 : primary_expression DOT IDENTIFIER opt_type_argument_list
3076 var lt = (Tokenizer.LocatedToken) $3;
3077 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3078 lbag.AddLocation ($$, GetLocation ($2));
3080 | builtin_types DOT IDENTIFIER opt_type_argument_list
3082 var lt = (Tokenizer.LocatedToken) $3;
3083 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3084 lbag.AddLocation ($$, GetLocation ($2));
3086 | BASE DOT IDENTIFIER opt_type_argument_list
3088 var lt = (Tokenizer.LocatedToken) $3;
3089 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3090 lbag.AddLocation ($$, GetLocation ($2));
3092 | qualified_alias_member IDENTIFIER opt_type_argument_list
3094 var lt1 = (Tokenizer.LocatedToken) $1;
3095 var lt2 = (Tokenizer.LocatedToken) $2;
3097 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3099 | primary_expression DOT GENERATE_COMPLETION {
3100 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3102 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3103 var lt = (Tokenizer.LocatedToken) $3;
3104 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3106 | builtin_types DOT GENERATE_COMPLETION
3108 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3110 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3111 var lt = (Tokenizer.LocatedToken) $3;
3112 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3116 invocation_expression
3117 : primary_expression open_parens_any opt_argument_list close_parens
3119 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3120 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3124 opt_object_or_collection_initializer
3125 : /* empty */ { $$ = null; }
3126 | object_or_collection_initializer
3129 object_or_collection_initializer
3130 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3133 $$ = CollectionOrObjectInitializers.Empty;
3136 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3137 lbag.AddLocation ($$, GetLocation ($3));
3140 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3142 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3143 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3147 opt_member_initializer_list
3148 : /* empty */ { $$ = null; }
3149 | member_initializer_list
3155 member_initializer_list
3156 : member_initializer
3158 var a = new List<Expression> ();
3159 a.Add ((Expression) $1);
3162 | member_initializer_list COMMA member_initializer
3164 var a = (List<Expression>)$1;
3165 a.Add ((Expression) $3);
3168 | member_initializer_list error {
3169 Error_SyntaxError (yyToken);
3175 : IDENTIFIER ASSIGN initializer_value
3177 var lt = (Tokenizer.LocatedToken) $1;
3178 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3179 lbag.AddLocation ($$, GetLocation ($2));
3181 | GENERATE_COMPLETION
3183 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3185 | non_assignment_expression opt_COMPLETE_COMPLETION {
3186 CompletionSimpleName csn = $1 as CompletionSimpleName;
3188 $$ = new CollectionElementInitializer ((Expression)$1);
3190 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3192 | OPEN_BRACE expression_list CLOSE_BRACE
3197 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3199 | OPEN_BRACE CLOSE_BRACE
3201 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3208 | object_or_collection_initializer
3212 : /* empty */ { $$ = null; }
3217 : argument_or_named_argument
3219 Arguments list = new Arguments (4);
3220 list.Add ((Argument) $1);
3223 | argument_list COMMA argument
3225 Arguments list = (Arguments) $1;
3226 if (list [list.Count - 1] is NamedArgument)
3227 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3229 list.Add ((Argument) $3);
3232 | argument_list COMMA named_argument
3234 Arguments list = (Arguments) $1;
3235 NamedArgument a = (NamedArgument) $3;
3236 for (int i = 0; i < list.Count; ++i) {
3237 NamedArgument na = list [i] as NamedArgument;
3238 if (na != null && na.Name == a.Name)
3239 Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3246 | argument_list COMMA
3248 Report.Error (839, GetLocation ($2), "An argument is missing");
3253 Report.Error (839, GetLocation ($1), "An argument is missing");
3261 $$ = new Argument ((Expression) $1);
3263 | non_simple_argument
3266 argument_or_named_argument
3272 : REF variable_reference
3274 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3275 lbag.AddLocation ($$, GetLocation ($1));
3277 | OUT variable_reference
3279 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3280 lbag.AddLocation ($$, GetLocation ($1));
3282 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3284 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3285 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3287 | ARGLIST OPEN_PARENS CLOSE_PARENS
3289 $$ = new Argument (new Arglist (GetLocation ($1)));
3290 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3299 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3301 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3302 lbag.AddLocation ($$, GetLocation ($4));
3309 var list = new List<Expression> (4);
3310 list.Add ((Expression) $1);
3313 | expression_list COMMA expression
3315 var list = (List<Expression>) $1;
3316 list.Add ((Expression) $3);
3319 | expression_list error {
3320 Error_SyntaxError (yyToken);
3325 expression_list_arguments
3326 : expression_list_argument
3328 Arguments args = new Arguments (4);
3329 args.Add ((Argument) $1);
3332 | expression_list_arguments COMMA expression_list_argument
3334 Arguments args = (Arguments) $1;
3335 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3336 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3338 args.Add ((Argument) $3);
3343 expression_list_argument
3346 $$ = new Argument ((Expression) $1);
3354 $$ = new This (GetLocation ($1));
3359 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3361 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3362 lbag.AddLocation ($$, GetLocation ($4));
3364 | BASE OPEN_BRACKET error
3366 Error_SyntaxError (yyToken);
3367 $$ = new ElementAccess (null, null, GetLocation ($2));
3371 post_increment_expression
3372 : primary_expression OP_INC
3374 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3378 post_decrement_expression
3379 : primary_expression OP_DEC
3381 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3385 object_or_delegate_creation_expression
3386 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3389 if (lang_version <= LanguageVersion.ISO_2)
3390 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3392 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3394 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3397 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3399 | NEW new_expr_type object_or_collection_initializer
3401 if (lang_version <= LanguageVersion.ISO_2)
3402 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3404 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3408 array_creation_expression
3409 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3411 opt_array_initializer
3413 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3414 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3415 Next = (ComposedTypeSpecifier) $6
3416 }, (ArrayInitializer) $7, GetLocation ($1));
3417 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3419 | NEW new_expr_type rank_specifiers opt_array_initializer
3422 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3424 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3426 | NEW rank_specifier array_initializer
3428 if (lang_version <= LanguageVersion.ISO_2)
3429 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3431 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3433 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3435 Report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3436 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3438 | NEW new_expr_type error
3440 Error_SyntaxError (1526, yyToken, "Unexpected symbol");
3441 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3447 ++lexer.parsing_type;
3451 --lexer.parsing_type;
3456 anonymous_type_expression
3457 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3459 if (lang_version <= LanguageVersion.ISO_2)
3460 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3462 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3464 // TODO: lbag comma location
3465 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3469 anonymous_type_parameters_opt_comma
3470 : anonymous_type_parameters_opt
3471 | anonymous_type_parameters COMMA
3474 anonymous_type_parameters_opt
3476 | anonymous_type_parameters
3479 anonymous_type_parameters
3480 : anonymous_type_parameter
3482 var a = new List<AnonymousTypeParameter> (4);
3483 a.Add ((AnonymousTypeParameter) $1);
3486 | anonymous_type_parameters COMMA anonymous_type_parameter
3488 var a = (List<AnonymousTypeParameter>) $1;
3489 a.Add ((AnonymousTypeParameter) $3);
3494 anonymous_type_parameter
3495 : IDENTIFIER ASSIGN variable_initializer
3497 var lt = (Tokenizer.LocatedToken)$1;
3498 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3499 lbag.AddLocation ($$, GetLocation ($2));
3503 var lt = (Tokenizer.LocatedToken)$1;
3504 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3505 lt.Value, lt.Location);
3509 MemberAccess ma = (MemberAccess) $1;
3510 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3514 Report.Error (746, lexer.Location,
3515 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3527 | rank_specifier rank_specifiers
3529 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3535 : OPEN_BRACKET CLOSE_BRACKET
3537 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3538 lbag.AddLocation ($$, GetLocation ($2));
3540 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3542 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3543 lbag.AddLocation ($$, GetLocation ($3));
3552 | dim_separators COMMA
3554 $$ = ((int) $1) + 1;
3558 opt_array_initializer
3570 : OPEN_BRACE CLOSE_BRACE
3572 var ai = new ArrayInitializer (0, GetLocation ($1));
3573 ai.VariableDeclaration = current_variable;
3574 lbag.AddLocation (ai, GetLocation ($2));
3577 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3579 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3580 ai.VariableDeclaration = current_variable;
3582 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3584 lbag.AddLocation (ai, GetLocation ($4));
3590 variable_initializer_list
3591 : variable_initializer
3593 var list = new List<Expression> (4);
3594 list.Add ((Expression) $1);
3597 | variable_initializer_list COMMA variable_initializer
3599 var list = (List<Expression>) $1;
3600 list.Add ((Expression) $3);
3608 lexer.TypeOfParsing = true;
3610 open_parens_any typeof_type_expression CLOSE_PARENS
3612 lexer.TypeOfParsing = false;
3613 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3614 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3618 typeof_type_expression
3623 Error_TypeExpected (lexer.Location);
3629 : IDENTIFIER generic_dimension
3631 var lt = (Tokenizer.LocatedToken) $1;
3633 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3635 | qualified_alias_member IDENTIFIER generic_dimension
3637 var lt1 = (Tokenizer.LocatedToken) $1;
3638 var lt2 = (Tokenizer.LocatedToken) $2;
3640 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3642 | unbound_type_name DOT IDENTIFIER
3644 var lt = (Tokenizer.LocatedToken) $3;
3646 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3648 | unbound_type_name DOT IDENTIFIER generic_dimension
3650 var lt = (Tokenizer.LocatedToken) $3;
3652 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3654 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3656 var te = ((MemberName) $1).GetTypeExpression ();
3657 if (te.HasTypeArguments)
3658 Error_TypeExpected (GetLocation ($4));
3660 var lt = (Tokenizer.LocatedToken) $3;
3661 $$ = new MemberAccess (te, lt.Value, (int) $4, lt.Location);
3668 if (lang_version < LanguageVersion.ISO_2)
3669 FeatureIsNotAvailable (GetLocation ($1), "generics");
3675 qualified_alias_member
3676 : IDENTIFIER DOUBLE_COLON
3678 var lt = (Tokenizer.LocatedToken) $1;
3679 if (lang_version == LanguageVersion.ISO_1)
3680 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3687 : SIZEOF open_parens_any type CLOSE_PARENS
3689 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3690 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3695 : CHECKED open_parens_any expression CLOSE_PARENS
3697 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3698 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3702 unchecked_expression
3703 : UNCHECKED open_parens_any expression CLOSE_PARENS
3705 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3706 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3710 pointer_member_access
3711 : primary_expression OP_PTR IDENTIFIER
3713 var lt = (Tokenizer.LocatedToken) $3;
3714 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, lt.Location);
3718 anonymous_method_expression
3719 : DELEGATE opt_anonymous_method_signature
3721 start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1));
3725 $$ = end_anonymous ((ParametersBlock) $4);
3729 opt_anonymous_method_signature
3732 $$ = ParametersCompiled.Undefined;
3734 | anonymous_method_signature
3737 anonymous_method_signature
3740 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3742 opt_formal_parameter_list CLOSE_PARENS
3744 valid_param_mod = 0;
3749 default_value_expression
3750 : DEFAULT open_parens_any type CLOSE_PARENS
3752 if (lang_version < LanguageVersion.ISO_2)
3753 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3755 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3756 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3761 : primary_expression
3762 | BANG prefixed_unary_expression
3764 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3766 | TILDE prefixed_unary_expression
3768 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3774 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3776 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3777 lbag.AddLocation ($$, GetLocation ($3));
3782 // The idea to split this out is from Rhys' grammar
3783 // to solve the problem with casts.
3785 prefixed_unary_expression
3787 | PLUS prefixed_unary_expression
3789 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3791 | MINUS prefixed_unary_expression
3793 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3795 | OP_INC prefixed_unary_expression
3797 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3799 | OP_DEC prefixed_unary_expression
3801 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3803 | STAR prefixed_unary_expression
3805 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3807 | BITWISE_AND prefixed_unary_expression
3809 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3813 multiplicative_expression
3814 : prefixed_unary_expression
3815 | multiplicative_expression STAR prefixed_unary_expression
3817 $$ = new Binary (Binary.Operator.Multiply,
3818 (Expression) $1, (Expression) $3, GetLocation ($2));
3820 | multiplicative_expression DIV prefixed_unary_expression
3822 $$ = new Binary (Binary.Operator.Division,
3823 (Expression) $1, (Expression) $3, GetLocation ($2));
3825 | multiplicative_expression PERCENT prefixed_unary_expression
3827 $$ = new Binary (Binary.Operator.Modulus,
3828 (Expression) $1, (Expression) $3, GetLocation ($2));
3833 : multiplicative_expression
3834 | additive_expression PLUS multiplicative_expression
3836 $$ = new Binary (Binary.Operator.Addition,
3837 (Expression) $1, (Expression) $3, GetLocation ($2));
3839 | additive_expression MINUS multiplicative_expression
3841 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3843 | parenthesized_expression MINUS multiplicative_expression
3845 // Shift/Reduce conflict
3846 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3848 | additive_expression AS type
3850 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3852 | additive_expression IS type
3854 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3859 : additive_expression
3860 | shift_expression OP_SHIFT_LEFT additive_expression
3862 $$ = new Binary (Binary.Operator.LeftShift,
3863 (Expression) $1, (Expression) $3, GetLocation ($2));
3865 | shift_expression OP_SHIFT_RIGHT additive_expression
3867 $$ = new Binary (Binary.Operator.RightShift,
3868 (Expression) $1, (Expression) $3, GetLocation ($2));
3872 relational_expression
3874 | relational_expression OP_LT shift_expression
3876 $$ = new Binary (Binary.Operator.LessThan,
3877 (Expression) $1, (Expression) $3, GetLocation ($2));
3879 | relational_expression OP_GT shift_expression
3881 $$ = new Binary (Binary.Operator.GreaterThan,
3882 (Expression) $1, (Expression) $3, GetLocation ($2));
3884 | relational_expression OP_LE shift_expression
3886 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3887 (Expression) $1, (Expression) $3, GetLocation ($2));
3889 | relational_expression OP_GE shift_expression
3891 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3892 (Expression) $1, (Expression) $3, GetLocation ($2));
3897 : relational_expression
3898 | equality_expression OP_EQ relational_expression
3900 $$ = new Binary (Binary.Operator.Equality,
3901 (Expression) $1, (Expression) $3, GetLocation ($2));
3903 | equality_expression OP_NE relational_expression
3905 $$ = new Binary (Binary.Operator.Inequality,
3906 (Expression) $1, (Expression) $3, GetLocation ($2));
3911 : equality_expression
3912 | and_expression BITWISE_AND equality_expression
3914 $$ = new Binary (Binary.Operator.BitwiseAnd,
3915 (Expression) $1, (Expression) $3, GetLocation ($2));
3919 exclusive_or_expression
3921 | exclusive_or_expression CARRET and_expression
3923 $$ = new Binary (Binary.Operator.ExclusiveOr,
3924 (Expression) $1, (Expression) $3, GetLocation ($2));
3928 inclusive_or_expression
3929 : exclusive_or_expression
3930 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3932 $$ = new Binary (Binary.Operator.BitwiseOr,
3933 (Expression) $1, (Expression) $3, GetLocation ($2));
3937 conditional_and_expression
3938 : inclusive_or_expression
3939 | conditional_and_expression OP_AND inclusive_or_expression
3941 $$ = new Binary (Binary.Operator.LogicalAnd,
3942 (Expression) $1, (Expression) $3, GetLocation ($2));
3946 conditional_or_expression
3947 : conditional_and_expression
3948 | conditional_or_expression OP_OR conditional_and_expression
3950 $$ = new Binary (Binary.Operator.LogicalOr,
3951 (Expression) $1, (Expression) $3, GetLocation ($2));
3955 null_coalescing_expression
3956 : conditional_or_expression
3957 | conditional_or_expression OP_COALESCING null_coalescing_expression
3959 if (lang_version < LanguageVersion.ISO_2)
3960 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3962 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3966 conditional_expression
3967 : null_coalescing_expression
3968 | null_coalescing_expression INTERR expression COLON expression
3970 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3971 lbag.AddLocation ($$, GetLocation ($4));
3975 assignment_expression
3976 : prefixed_unary_expression ASSIGN expression
3978 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3980 | prefixed_unary_expression OP_MULT_ASSIGN expression
3982 $$ = new CompoundAssign (
3983 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
3985 | prefixed_unary_expression OP_DIV_ASSIGN expression
3987 $$ = new CompoundAssign (
3988 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
3990 | prefixed_unary_expression OP_MOD_ASSIGN expression
3992 $$ = new CompoundAssign (
3993 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
3995 | prefixed_unary_expression OP_ADD_ASSIGN expression
3997 $$ = new CompoundAssign (
3998 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
4000 | prefixed_unary_expression OP_SUB_ASSIGN expression
4002 $$ = new CompoundAssign (
4003 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4005 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4007 $$ = new CompoundAssign (
4008 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4010 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4012 $$ = new CompoundAssign (
4013 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4015 | prefixed_unary_expression OP_AND_ASSIGN expression
4017 $$ = new CompoundAssign (
4018 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4020 | prefixed_unary_expression OP_OR_ASSIGN expression
4022 $$ = new CompoundAssign (
4023 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4025 | prefixed_unary_expression OP_XOR_ASSIGN expression
4027 $$ = new CompoundAssign (
4028 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4032 lambda_parameter_list
4035 var pars = new List<Parameter> (4);
4036 pars.Add ((Parameter) $1);
4040 | lambda_parameter_list COMMA lambda_parameter
4042 var pars = (List<Parameter>) $1;
4043 Parameter p = (Parameter)$3;
4044 if (pars[0].GetType () != p.GetType ()) {
4045 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4054 : parameter_modifier parameter_type IDENTIFIER
4056 var lt = (Tokenizer.LocatedToken) $3;
4058 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4060 | parameter_type IDENTIFIER
4062 var lt = (Tokenizer.LocatedToken) $2;
4064 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4068 var lt = (Tokenizer.LocatedToken) $1;
4069 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4073 opt_lambda_parameter_list
4074 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4075 | lambda_parameter_list {
4076 var pars_list = (List<Parameter>) $1;
4077 $$ = new ParametersCompiled (pars_list.ToArray ());
4081 lambda_expression_body
4082 : lambda_expression_body_simple
4086 lambda_expression_body_simple
4088 start_block (lexer.Location);
4090 expression_or_error // Have to close block when error occurs
4092 Block b = end_block (lexer.Location);
4093 b.AddStatement (new ContextualReturn ((Expression) $2));
4102 Error_SyntaxError (yyToken);
4103 $$ = EmptyExpression.Null;
4110 var lt = (Tokenizer.LocatedToken) $1;
4111 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4112 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
4114 lambda_expression_body
4116 $$ = end_anonymous ((ParametersBlock) $4);
4117 lbag.AddLocation ($$, GetLocation ($2));
4119 | OPEN_PARENS_LAMBDA
4121 if (lang_version <= LanguageVersion.ISO_2)
4122 FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
4124 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4126 opt_lambda_parameter_list CLOSE_PARENS ARROW
4128 valid_param_mod = 0;
4129 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4131 lambda_expression_body
4133 $$ = end_anonymous ((ParametersBlock) $7);
4134 lbag.AddLocation ($$, GetLocation ($4), GetLocation ($5));
4139 : assignment_expression
4140 | non_assignment_expression
4143 non_assignment_expression
4144 : conditional_expression
4149 $$ = new ArglistAccess (GetLocation ($1));
4160 $$ = new BooleanExpression ((Expression) $1);
4173 lexer.ConstraintsParsing = true;
4175 type_declaration_name
4177 MemberName name = MakeName ((MemberName) $6);
4178 Class c = new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1);
4179 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4180 FeatureIsNotAvailable (c.Location, "static classes");
4183 push_current_class (c, $3);
4186 opt_type_parameter_constraints_clauses
4188 lexer.ConstraintsParsing = false;
4190 current_class.SetParameterInfo ((List<Constraints>) $9);
4191 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
4194 current_container.DocComment = Lexer.consume_doc_comment ();
4195 Lexer.doc_state = XmlCommentState.Allowed;
4198 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4200 --lexer.parsing_declaration;
4202 Lexer.doc_state = XmlCommentState.Allowed;
4206 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4207 $$ = pop_current_class ();
4215 { $$ = $1; } // location
4221 mod_locations = null;
4229 | modifiers modifier
4231 var m1 = (Modifiers) $1;
4232 var m2 = (Modifiers) $2;
4234 if ((m1 & m2) != 0) {
4235 Report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4236 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4237 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4238 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4239 Report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4240 "More than one protection modifier specified");
4251 StoreModifierLocation ($$, GetLocation ($1));
4253 if (current_container == RootContext.ToplevelTypes)
4254 Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4258 $$ = Modifiers.PUBLIC;
4259 StoreModifierLocation ($$, GetLocation ($1));
4263 $$ = Modifiers.PROTECTED;
4264 StoreModifierLocation ($$, GetLocation ($1));
4268 $$ = Modifiers.INTERNAL;
4269 StoreModifierLocation ($$, GetLocation ($1));
4273 $$ = Modifiers.PRIVATE;
4274 StoreModifierLocation ($$, GetLocation ($1));
4278 $$ = Modifiers.ABSTRACT;
4279 StoreModifierLocation ($$, GetLocation ($1));
4283 $$ = Modifiers.SEALED;
4284 StoreModifierLocation ($$, GetLocation ($1));
4288 $$ = Modifiers.STATIC;
4289 StoreModifierLocation ($$, GetLocation ($1));
4293 $$ = Modifiers.READONLY;
4294 StoreModifierLocation ($$, GetLocation ($1));
4298 $$ = Modifiers.VIRTUAL;
4299 StoreModifierLocation ($$, GetLocation ($1));
4303 $$ = Modifiers.OVERRIDE;
4304 StoreModifierLocation ($$, GetLocation ($1));
4308 $$ = Modifiers.EXTERN;
4309 StoreModifierLocation ($$, GetLocation ($1));
4313 $$ = Modifiers.VOLATILE;
4314 StoreModifierLocation ($$, GetLocation ($1));
4318 $$ = Modifiers.UNSAFE;
4319 StoreModifierLocation ($$, GetLocation ($1));
4320 if (!settings.Unsafe)
4321 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4325 $$ = Modifiers.ASYNC;
4326 StoreModifierLocation ($$, GetLocation ($1));
4334 current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
4338 opt_type_parameter_constraints_clauses
4340 | type_parameter_constraints_clauses
4346 Error_SyntaxError (yyToken);
4351 type_parameter_constraints_clauses
4352 : type_parameter_constraints_clause
4354 var constraints = new List<Constraints> (1);
4355 constraints.Add ((Constraints) $1);
4358 | type_parameter_constraints_clauses type_parameter_constraints_clause
4360 var constraints = (List<Constraints>) $1;
4361 Constraints new_constraint = (Constraints)$2;
4363 foreach (Constraints c in constraints) {
4364 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4365 Report.Error (409, new_constraint.Location,
4366 "A constraint clause has already been specified for type parameter `{0}'",
4367 new_constraint.TypeParameter.Value);
4371 constraints.Add (new_constraint);
4376 type_parameter_constraints_clause
4377 : WHERE IDENTIFIER COLON type_parameter_constraints
4379 var lt = (Tokenizer.LocatedToken) $2;
4380 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4384 type_parameter_constraints
4385 : type_parameter_constraint
4387 var constraints = new List<FullNamedExpression> (1);
4388 constraints.Add ((FullNamedExpression) $1);
4391 | type_parameter_constraints COMMA type_parameter_constraint
4393 var constraints = (List<FullNamedExpression>) $1;
4394 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4395 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4396 Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4399 prev = $3 as SpecialContraintExpr;
4401 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4402 Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4404 prev = constraints [0] as SpecialContraintExpr;
4405 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4406 Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4411 constraints.Add ((FullNamedExpression) $3);
4416 type_parameter_constraint
4419 if ($1 is ComposedCast)
4420 Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4424 | NEW OPEN_PARENS CLOSE_PARENS
4426 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4427 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4431 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4435 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4439 opt_type_parameter_variance
4444 | type_parameter_variance
4446 if (lang_version <= LanguageVersion.V_3)
4447 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4453 type_parameter_variance
4456 $$ = Variance.Covariant;
4460 $$ = Variance.Contravariant;
4469 // A block is "contained" on the following places:
4471 // property_declaration as part of the accessor body (get/set)
4472 // operator_declaration
4473 // constructor_declaration
4474 // destructor_declaration
4475 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4480 ++lexer.parsing_block;
4481 start_block (GetLocation ($1));
4483 opt_statement_list block_end
4492 --lexer.parsing_block;
4493 $$ = end_block (GetLocation ($1));
4495 | COMPLETE_COMPLETION
4497 --lexer.parsing_block;
4498 $$ = end_block (lexer.Location);
4506 ++lexer.parsing_block;
4507 current_block.StartLocation = GetLocation ($1);
4509 opt_statement_list CLOSE_BRACE
4511 --lexer.parsing_block;
4512 $$ = end_block (GetLocation ($4));
4523 | statement_list statement
4527 : block_variable_declaration
4529 current_block.AddStatement ((Statement) $1);
4531 | valid_declaration_statement
4533 current_block.AddStatement ((Statement) $1);
4538 Error_SyntaxError (yyToken);
4544 // The interactive_statement and its derivatives are only
4545 // used to provide a special version of `expression_statement'
4546 // that has a side effect of assigning the expression to
4549 interactive_statement_list
4550 : interactive_statement
4551 | interactive_statement_list interactive_statement
4554 interactive_statement
4555 : block_variable_declaration
4557 current_block.AddStatement ((Statement) $1);
4559 | interactive_valid_declaration_statement
4561 current_block.AddStatement ((Statement) $1);
4566 valid_declaration_statement
4569 | expression_statement
4570 | selection_statement
4571 | iteration_statement
4575 | unchecked_statement
4582 interactive_valid_declaration_statement
4585 | interactive_expression_statement
4586 | selection_statement
4587 | iteration_statement
4591 | unchecked_statement
4599 : valid_declaration_statement
4600 | block_variable_declaration
4602 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4607 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4612 Error_SyntaxError (yyToken);
4613 $$ = new EmptyStatement (GetLocation ($1));
4620 // Uses lexer.Location because semicolon location is not kept in quick mode
4621 $$ = new EmptyStatement (lexer.Location);
4628 var lt = (Tokenizer.LocatedToken) $1;
4629 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4631 current_block.AddLabel (labeled);
4632 current_block.AddStatement (labeled);
4638 : variable_type_simple
4639 | variable_type_simple rank_specifiers
4642 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4644 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4649 * The following is from Rhys' grammar:
4650 * > Types in local variable declarations must be recognized as
4651 * > expressions to prevent reduce/reduce errors in the grammar.
4652 * > The expressions are converted into types during semantic analysis.
4654 variable_type_simple
4655 : primary_expression_or_type opt_nullable
4657 // Ok, the above "primary_expression" is there to get rid of
4658 // both reduce/reduce and shift/reduces in the grammar, it should
4659 // really just be "type_name". If you use type_name, a reduce/reduce
4660 // creeps up. If you use namespace_or_type_name (which is all we need
4661 // really) two shift/reduces appear.
4664 // So the super-trick is that primary_expression
4665 // can only be either a SimpleName or a MemberAccess.
4666 // The MemberAccess case arises when you have a fully qualified type-name like :
4668 // SimpleName is when you have
4671 Expression expr = (Expression) $1;
4673 SimpleName sn = expr as SimpleName;
4674 if (sn != null && sn.Name == "var")
4675 $$ = new VarExpr (sn.Location);
4678 } else if (expr is ATypeNameExpression) {
4679 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4681 Error_ExpectingTypeName (expr);
4685 | primary_expression_or_type pointer_stars
4687 ATypeNameExpression expr = $1 as ATypeNameExpression;
4690 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4692 Error_ExpectingTypeName ((Expression)$1);
4696 | builtin_types opt_nullable
4701 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4703 | builtin_types pointer_stars
4705 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4707 | VOID pointer_stars
4709 $$ = new ComposedCast (new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4713 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
4714 $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
4720 | pointer_star pointer_stars
4722 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4730 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4734 block_variable_declaration
4735 : variable_type IDENTIFIER
4737 var lt = (Tokenizer.LocatedToken) $2;
4738 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4739 current_block.AddLocalName (li);
4740 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4742 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4744 $$ = current_variable;
4745 current_variable = null;
4746 lbag.AddLocation ($$, GetLocation ($6));
4748 | CONST variable_type IDENTIFIER
4750 var lt = (Tokenizer.LocatedToken) $3;
4751 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4752 current_block.AddLocalName (li);
4753 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4755 const_variable_initializer opt_const_declarators SEMICOLON
4757 $$ = current_variable;
4758 current_variable = null;
4759 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4763 opt_local_variable_initializer
4765 | ASSIGN block_variable_initializer
4767 current_variable.Initializer = (Expression) $2;
4772 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4773 Report.Error (650, lexer.Location,
4774 "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");
4776 Error_SyntaxError (yyToken);
4781 opt_variable_declarators
4783 | variable_declarators
4786 variable_declarators
4787 : variable_declarator
4788 | variable_declarators variable_declarator
4794 var lt = (Tokenizer.LocatedToken) $2;
4795 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4796 var d = new BlockVariableDeclaration.Declarator (li, null);
4797 current_variable.AddDeclarator (d);
4798 current_block.AddLocalName (li);
4799 lbag.AddLocation (d, GetLocation ($1));
4801 | COMMA IDENTIFIER ASSIGN block_variable_initializer
4803 var lt = (Tokenizer.LocatedToken) $2;
4804 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4805 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4806 current_variable.AddDeclarator (d);
4807 current_block.AddLocalName (li);
4808 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4812 const_variable_initializer
4815 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
4817 | ASSIGN constant_initializer_expr
4819 current_variable.Initializer = (Expression) $2;
4823 opt_const_declarators
4830 | const_declarators const_declarator
4834 : COMMA IDENTIFIER ASSIGN constant_initializer_expr
4836 var lt = (Tokenizer.LocatedToken) $2;
4837 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4838 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4839 current_variable.AddDeclarator (d);
4840 current_block.AddLocalName (li);
4841 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4845 block_variable_initializer
4846 : variable_initializer
4847 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4849 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4850 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4852 | STACKALLOC simple_type
4854 Report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4855 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4859 expression_statement
4860 : statement_expression SEMICOLON
4863 lbag.AddStatement ($$, GetLocation ($2));
4865 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4868 interactive_expression_statement
4869 : interactive_statement_expression SEMICOLON { $$ = $1; }
4870 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4874 // We have to do the wrapping here and not in the case above,
4875 // because statement_expression is used for example in for_statement
4877 statement_expression
4880 ExpressionStatement s = $1 as ExpressionStatement;
4882 Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
4883 s = EmptyExpressionStatement.Instance;
4886 $$ = new StatementExpression (s);
4890 interactive_statement_expression
4893 Expression expr = (Expression) $1;
4894 ExpressionStatement s;
4896 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4897 $$ = new StatementExpression (s);
4901 Error_SyntaxError (yyToken);
4902 $$ = new EmptyStatement (GetLocation ($1));
4912 : IF open_parens_any boolean_expression CLOSE_PARENS
4915 if ($5 is EmptyStatement)
4916 Warning_EmptyStatement (GetLocation ($5));
4918 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4919 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4921 | IF open_parens_any boolean_expression CLOSE_PARENS
4922 embedded_statement ELSE embedded_statement
4924 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
4925 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4927 if ($5 is EmptyStatement)
4928 Warning_EmptyStatement (GetLocation ($5));
4929 if ($7 is EmptyStatement)
4930 Warning_EmptyStatement (GetLocation ($7));
4935 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
4937 start_block (GetLocation ($5));
4939 opt_switch_sections CLOSE_BRACE
4941 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
4942 end_block (GetLocation ($8));
4943 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4950 Report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
4951 $$ = new List<SwitchSection> ();
4959 var sections = new List<SwitchSection> (4);
4961 sections.Add ((SwitchSection) $1);
4964 | switch_sections switch_section
4966 var sections = (List<SwitchSection>) $1;
4968 sections.Add ((SwitchSection) $2);
4973 Error_SyntaxError (yyToken);
4974 $$ = new List<SwitchSection> ();
4981 current_block = current_block.CreateSwitchBlock (lexer.Location);
4985 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
4992 var labels = new List<SwitchLabel> (2);
4994 labels.Add ((SwitchLabel) $1);
4997 | switch_labels switch_label
4999 var labels = (List<SwitchLabel>) ($1);
5000 labels.Add ((SwitchLabel) $2);
5007 : CASE constant_expression COLON
5009 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5010 lbag.AddLocation ($$, GetLocation ($3));
5014 $$ = new SwitchLabel (null, GetLocation ($1));
5026 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5028 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5029 Warning_EmptyStatement (GetLocation ($5));
5031 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5032 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5037 : DO embedded_statement
5038 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5040 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5041 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5046 : FOR open_parens_any
5048 start_block (GetLocation ($2));
5049 current_block.IsCompilerGenerated = true;
5057 // Has to use be extra rule to recover started block
5059 : opt_for_initializer SEMICOLON
5060 opt_for_condition SEMICOLON
5061 opt_for_iterator CLOSE_PARENS
5064 if ($7 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5065 Warning_EmptyStatement (GetLocation ($7));
5067 For f = new For ((Statement) $1, (BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($-2));
5068 current_block.AddStatement (f);
5070 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5072 $$ = end_block (GetLocation ($2));
5076 Error_SyntaxError (yyToken);
5077 $$ = end_block (current_block.StartLocation);
5082 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5087 : variable_type IDENTIFIER
5089 var lt = (Tokenizer.LocatedToken) $2;
5090 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5091 current_block.AddLocalName (li);
5092 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5094 opt_local_variable_initializer opt_variable_declarators
5096 $$ = current_variable;
5097 current_variable = null;
5099 | statement_expression_list
5103 : /* empty */ { $$ = null; }
5104 | boolean_expression
5108 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5113 : statement_expression_list
5116 statement_expression_list
5117 : statement_expression
5118 | statement_expression_list COMMA statement_expression
5120 var sl = $1 as StatementList;
5122 sl = new StatementList ((Statement) $1, (Statement) $3);
5123 lbag.AddStatement (sl, GetLocation ($2));
5125 sl.Add ((Statement) $3);
5126 lbag.AppendTo (sl, GetLocation ($2));
5134 : FOREACH open_parens_any type IN expression CLOSE_PARENS
5136 Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5139 | FOREACH open_parens_any type IDENTIFIER IN expression CLOSE_PARENS
5141 start_block (GetLocation ($2));
5142 current_block.IsCompilerGenerated = true;
5144 var lt = (Tokenizer.LocatedToken) $4;
5145 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5146 current_block.AddLocalName (li);
5151 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5152 Warning_EmptyStatement (GetLocation ($9));
5154 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, GetLocation ($1));
5155 current_block.AddStatement (f);
5157 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5158 $$ = end_block (GetLocation ($7));
5164 | continue_statement
5174 $$ = new Break (GetLocation ($1));
5175 lbag.AddStatement ($$, GetLocation ($2));
5180 : CONTINUE SEMICOLON
5182 $$ = new Continue (GetLocation ($1));
5183 lbag.AddStatement ($$, GetLocation ($2));
5188 : GOTO IDENTIFIER SEMICOLON
5190 var lt = (Tokenizer.LocatedToken) $2;
5191 $$ = new Goto (lt.Value, lt.Location);
5192 lbag.AddStatement ($$, GetLocation ($1), GetLocation ($3));
5194 | GOTO CASE constant_expression SEMICOLON
5196 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5197 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5199 | GOTO DEFAULT SEMICOLON
5201 $$ = new GotoDefault (GetLocation ($1));
5202 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5207 : RETURN opt_expression SEMICOLON
5209 $$ = new Return ((Expression) $2, GetLocation ($1));
5210 lbag.AddStatement ($$, GetLocation ($3));
5215 : THROW opt_expression SEMICOLON
5217 $$ = new Throw ((Expression) $2, GetLocation ($1));
5218 lbag.AddStatement ($$, GetLocation ($3));
5223 : IDENTIFIER RETURN opt_expression SEMICOLON
5225 var lt = (Tokenizer.LocatedToken) $1;
5226 string s = lt.Value;
5228 Report.Error (1003, lt.Location, "; expected");
5229 } else if ($3 == null) {
5230 Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5231 } else if (lang_version == LanguageVersion.ISO_1){
5232 FeatureIsNotAvailable (lt.Location, "iterators");
5235 current_block.ParametersBlock.TopBlock.IsIterator = true;
5236 $$ = new Yield ((Expression) $3, lt.Location);
5237 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5239 | IDENTIFIER BREAK SEMICOLON
5241 var lt = (Tokenizer.LocatedToken) $1;
5242 string s = lt.Value;
5244 Report.Error (1003, lt.Location, "; expected");
5245 } else if (lang_version == LanguageVersion.ISO_1){
5246 FeatureIsNotAvailable (lt.Location, "iterators");
5249 current_block.ParametersBlock.TopBlock.IsIterator = true;
5250 $$ = new YieldBreak (lt.Location);
5251 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5261 : TRY block catch_clauses
5263 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5265 | TRY block FINALLY block
5267 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5268 lbag.AddStatement ($$, GetLocation ($3));
5270 | TRY block catch_clauses FINALLY block
5272 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
5273 lbag.AddStatement ($$, GetLocation ($4));
5277 Report.Error (1524, GetLocation ($1), "Expected catch or finally");
5285 var l = new List<Catch> (2);
5290 | catch_clauses catch_clause
5292 var l = (List<Catch>) $1;
5294 Catch c = (Catch) $2;
5295 if (l [0].IsGeneral) {
5296 Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5316 $$ = new Catch ((Block) $2, GetLocation ($1));
5318 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5320 start_block (GetLocation ($2));
5321 var c = new Catch (current_block, GetLocation ($1));
5322 c.TypeExpression = (FullNamedExpression) $3;
5325 var lt = (Tokenizer.LocatedToken) $4;
5326 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5327 current_block.AddLocalName (c.Variable);
5330 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5337 | CATCH open_parens_any error
5339 if (yyToken == Token.CLOSE_PARENS) {
5340 Report.Error (1015, lexer.Location,
5341 "A type that derives from `System.Exception', `object', or `string' expected");
5343 Error_SyntaxError (yyToken);
5346 $$ = new Catch (null, GetLocation ($1));
5353 $$ = new Checked ((Block) $2, GetLocation ($1));
5360 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5367 if (!settings.Unsafe)
5368 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5370 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5375 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5377 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5378 Warning_EmptyStatement (GetLocation ($5));
5380 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5381 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5386 : FIXED open_parens_any variable_type IDENTIFIER
5388 start_block (GetLocation ($2));
5390 current_block.IsCompilerGenerated = true;
5391 var lt = (Tokenizer.LocatedToken) $4;
5392 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5393 current_block.AddLocalName (li);
5394 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5396 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5398 $$ = current_variable;
5399 current_variable = null;
5403 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5404 Warning_EmptyStatement (GetLocation ($10));
5406 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5407 current_block.AddStatement (f);
5408 $$ = end_block (GetLocation ($8));
5413 : USING open_parens_any variable_type IDENTIFIER
5415 start_block (GetLocation ($2));
5417 current_block.IsCompilerGenerated = true;
5418 var lt = (Tokenizer.LocatedToken) $4;
5419 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5420 current_block.AddLocalName (li);
5421 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5423 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5425 $$ = current_variable;
5426 current_variable = null;
5430 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5431 Warning_EmptyStatement (GetLocation ($10));
5433 Using u = new Using ((Using.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5434 current_block.AddStatement (u);
5435 $$ = end_block (GetLocation ($8));
5437 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5439 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5440 Warning_EmptyStatement (GetLocation ($5));
5442 Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5443 lbag.AddStatement (u, GetLocation ($2), GetLocation ($4));
5448 using_or_fixed_variable_initializer
5451 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
5453 | ASSIGN variable_initializer
5455 current_variable.Initializer = (Expression) $2;
5456 $$ = current_variable;
5464 : first_from_clause query_body
5466 lexer.query_parsing = false;
5468 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5470 from.Tail.Next = (Linq.AQueryClause)$2;
5473 current_block.SetEndLocation (lexer.Location);
5474 current_block = current_block.Parent;
5476 | nested_from_clause query_body
5478 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5480 from.Tail.Next = (Linq.AQueryClause)$2;
5483 current_block.SetEndLocation (lexer.Location);
5484 current_block = current_block.Parent;
5487 // Bubble up COMPLETE_COMPLETION productions
5488 | first_from_clause COMPLETE_COMPLETION {
5489 lexer.query_parsing = false;
5492 current_block.SetEndLocation (lexer.Location);
5493 current_block = current_block.Parent;
5495 | nested_from_clause COMPLETE_COMPLETION {
5497 current_block.SetEndLocation (lexer.Location);
5498 current_block = current_block.Parent;
5503 : FROM_FIRST IDENTIFIER IN expression
5505 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5507 var lt = (Tokenizer.LocatedToken) $2;
5508 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5509 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5511 | FROM_FIRST type IDENTIFIER IN expression
5513 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5515 var lt = (Tokenizer.LocatedToken) $3;
5516 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5517 $$ = new Linq.QueryExpression (
5518 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5519 IdentifierType = (FullNamedExpression)$2
5526 : FROM IDENTIFIER IN expression
5528 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5530 var lt = (Tokenizer.LocatedToken) $2;
5531 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5532 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5534 | FROM type IDENTIFIER IN expression
5536 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5538 var lt = (Tokenizer.LocatedToken) $3;
5539 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5540 $$ = new Linq.QueryExpression (
5541 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5542 IdentifierType = (FullNamedExpression)$2
5549 : FROM IDENTIFIER IN
5551 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5555 var lt = (Tokenizer.LocatedToken) $2;
5556 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5557 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5559 current_block.SetEndLocation (lexer.Location);
5560 current_block = current_block.Parent;
5562 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5564 | FROM type IDENTIFIER IN
5566 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5570 var lt = (Tokenizer.LocatedToken) $3;
5571 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5573 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5574 IdentifierType = (FullNamedExpression)$2
5577 current_block.SetEndLocation (lexer.Location);
5578 current_block = current_block.Parent;
5580 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5585 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5587 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5590 head.Next = (Linq.AQueryClause)$3;
5593 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5594 clause.Tail.Next = head;
5600 | opt_query_body_clauses COMPLETE_COMPLETION
5603 Error_SyntaxError (yyToken);
5608 select_or_group_clause
5611 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5615 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5617 current_block.SetEndLocation (lexer.Location);
5618 current_block = current_block.Parent;
5622 if (linq_clause_blocks == null)
5623 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5625 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5626 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5630 current_block.SetEndLocation (lexer.Location);
5631 current_block = current_block.Parent;
5633 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5637 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5639 current_block.SetEndLocation (lexer.Location);
5640 current_block = current_block.Parent;
5644 opt_query_body_clauses
5646 | query_body_clauses
5651 | query_body_clauses query_body_clause
5653 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5667 : LET IDENTIFIER ASSIGN
5669 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5673 var lt = (Tokenizer.LocatedToken) $2;
5674 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5675 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5677 current_block.SetEndLocation (lexer.Location);
5678 current_block = current_block.Parent;
5680 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5687 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5691 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5693 current_block.SetEndLocation (lexer.Location);
5694 current_block = current_block.Parent;
5699 : JOIN IDENTIFIER IN
5701 if (linq_clause_blocks == null)
5702 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5704 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5705 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5709 current_block.SetEndLocation (lexer.Location);
5710 current_block = current_block.Parent;
5712 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5713 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5717 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5718 current_block.SetEndLocation (lexer.Location);
5719 current_block = current_block.Parent;
5721 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5723 expression opt_join_into
5725 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5726 current_block.SetEndLocation (lexer.Location);
5728 var outer_selector = linq_clause_blocks.Pop ();
5729 var block = linq_clause_blocks.Pop ();
5731 var lt = (Tokenizer.LocatedToken) $2;
5732 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5733 Linq.RangeVariable into;
5737 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5740 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5742 var parent = block.Parent;
5743 while (parent is Linq.QueryBlock) {
5744 parent = parent.Parent;
5746 current_block.Parent = parent;
5748 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5750 lt = (Tokenizer.LocatedToken) $12;
5751 into = new Linq.RangeVariable (lt.Value, lt.Location);
5753 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
5756 current_block = block.Parent;
5757 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5759 | JOIN type IDENTIFIER IN
5761 if (linq_clause_blocks == null)
5762 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5764 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5765 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5769 current_block.SetEndLocation (lexer.Location);
5770 current_block = current_block.Parent;
5772 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5773 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5777 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5778 current_block.SetEndLocation (lexer.Location);
5779 current_block = current_block.Parent;
5781 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5783 expression opt_join_into
5785 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5786 current_block.SetEndLocation (lexer.Location);
5788 var outer_selector = linq_clause_blocks.Pop ();
5789 var block = linq_clause_blocks.Pop ();
5791 var lt = (Tokenizer.LocatedToken) $3;
5792 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5793 Linq.RangeVariable into;
5797 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
5798 IdentifierType = (FullNamedExpression)$2
5802 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5804 var parent = block.Parent;
5805 while (parent is Linq.QueryBlock) {
5806 parent = parent.Parent;
5808 current_block.Parent = parent;
5810 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5812 lt = (Tokenizer.LocatedToken) $13;
5813 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
5815 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
5816 IdentifierType = (FullNamedExpression)$2
5820 current_block = block.Parent;
5821 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5836 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5840 current_block.SetEndLocation (lexer.Location);
5841 current_block = current_block.Parent;
5851 current_block.SetEndLocation (lexer.Location);
5852 current_block = current_block.Parent;
5854 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5858 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5865 | orderings_then_by COMMA
5867 current_block.SetEndLocation (lexer.Location);
5868 current_block = current_block.Parent;
5870 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
5874 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
5882 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5884 | expression ASCENDING
5886 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5888 | expression DESCENDING
5890 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5897 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5899 | expression ASCENDING
5901 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5903 | expression DESCENDING
5905 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5910 opt_query_continuation
5914 // query continuation block is not linked with query block but with block
5915 // before. This means each query can use same range variable names for
5916 // different identifiers.
5918 current_block.SetEndLocation (GetLocation ($1));
5919 current_block = current_block.Parent;
5921 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5923 if (linq_clause_blocks == null)
5924 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5926 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5930 var current_block = linq_clause_blocks.Pop ();
5931 var lt = (Tokenizer.LocatedToken) $2;
5932 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5933 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
5934 next = (Linq.AQueryClause)$4
5940 // Support for using the compiler as an interactive parser
5942 // The INTERACTIVE_PARSER token is first sent to parse our
5943 // productions; If the result is a Statement, the parsing
5944 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5945 // to setup the blocks in advance.
5947 // This setup is here so that in the future we can add
5948 // support for other constructs (type parsing, namespaces, etc)
5949 // that do not require a block to be setup in advance
5953 : EVAL_STATEMENT_PARSER EOF
5954 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
5955 | EVAL_STATEMENT_PARSER
5957 current_container = new Class (current_namespace, current_class, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
5958 current_class = current_container;
5960 // (ref object retval)
5961 Parameter [] mpar = new Parameter [1];
5962 mpar [0] = new Parameter (new TypeExpression (compiler.BuildinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
5964 ParametersCompiled pars = new ParametersCompiled (mpar);
5965 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
5966 if (settings.Unsafe)
5967 mods |= Modifiers.UNSAFE;
5969 current_local_parameters = pars;
5970 Method method = new Method (
5973 new TypeExpression (compiler.BuildinTypes.Void, Location.Null),
5975 new MemberName ("Host"),
5977 null /* attributes */);
5979 current_container.AddMethod (method);
5981 oob_stack.Push (method);
5982 ++lexer.parsing_block;
5983 start_block (lexer.Location);
5985 interactive_statement_list opt_COMPLETE_COMPLETION
5987 --lexer.parsing_block;
5988 Method method = (Method) oob_stack.Pop ();
5990 method.Block = (ToplevelBlock) end_block(lexer.Location);
5992 InteractiveResult = (Class) pop_current_class ();
5993 current_local_parameters = null;
5995 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
5998 interactive_compilation_unit
5999 : outer_declarations
6000 | outer_declarations global_attributes
6005 opt_COMPLETE_COMPLETION
6007 | COMPLETE_COMPLETION
6010 close_brace_or_complete_completion
6012 | COMPLETE_COMPLETION
6017 // A class used to hold info about an operator declarator
6019 class OperatorDeclaration {
6020 public readonly Operator.OpType optype;
6021 public readonly FullNamedExpression ret_type;
6022 public readonly Location location;
6024 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6027 this.ret_type = ret_type;
6028 this.location = location;
6032 void Error_ExpectingTypeName (Expression expr)
6034 if (expr is Invocation){
6035 Report.Error (1002, expr.Location, "Expecting `;'");
6037 Expression.Error_InvalidExpressionStatement (Report, expr.Location);
6041 void Error_ParameterModifierNotValid (string modifier, Location loc)
6043 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6047 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6049 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6050 Parameter.GetModifierSignature (mod));
6053 void Error_TypeExpected (Location loc)
6055 Report.Error (1031, loc, "Type expected");
6058 void Error_UnsafeCodeNotAllowed (Location loc)
6060 Report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6063 void Warning_EmptyStatement (Location loc)
6065 Report.Warning (642, 3, loc, "Possible mistaken empty statement");
6068 void Error_NamedArgumentExpected (NamedArgument a)
6070 Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6073 void push_current_class (TypeContainer tc, object partial_token)
6075 if (module.Evaluator != null){
6076 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6079 undo.AddTypeContainer (current_container, tc);
6082 if (partial_token != null)
6083 current_container = current_container.AddPartial (tc);
6085 current_container = current_container.AddTypeContainer (tc);
6087 ++lexer.parsing_declaration;
6091 DeclSpace pop_current_class ()
6093 DeclSpace retval = current_class;
6095 current_class = current_class.Parent;
6096 current_container = current_class.PartialContainer;
6102 // Given the @class_name name, it creates a fully qualified name
6103 // based on the containing declaration space
6106 MakeName (MemberName class_name)
6108 Namespace ns = current_namespace.NS;
6110 if (current_container == RootContext.ToplevelTypes) {
6111 if (ns.Name.Length != 0)
6112 return new MemberName (ns.MemberName, class_name);
6116 return new MemberName (current_container.MemberName, class_name);
6120 [System.Diagnostics.Conditional ("FULL_AST")]
6121 void StoreModifierLocation (object token, Location loc)
6126 if (mod_locations == null)
6127 mod_locations = new List<Tuple<Modifiers, Location>> ();
6129 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6132 string CheckAttributeTarget (string a, Location l)
6135 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6139 Report.Warning (658, 1, l,
6140 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6141 return string.Empty;
6144 static bool IsUnaryOperator (Operator.OpType op)
6148 case Operator.OpType.LogicalNot:
6149 case Operator.OpType.OnesComplement:
6150 case Operator.OpType.Increment:
6151 case Operator.OpType.Decrement:
6152 case Operator.OpType.True:
6153 case Operator.OpType.False:
6154 case Operator.OpType.UnaryPlus:
6155 case Operator.OpType.UnaryNegation:
6161 void syntax_error (Location l, string msg)
6163 Report.Error (1003, l, "Syntax error, " + msg);
6168 public Tokenizer Lexer {
6174 static CSharpParser ()
6176 oob_stack = new Stack<object> ();
6179 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file)
6182 current_namespace = file.NamespaceContainer;
6184 this.module = current_namespace.Module;
6185 this.compiler = module.Compiler;
6186 this.settings = compiler.Settings;
6187 lang_version = settings.Version;
6188 doc_support = settings.Documentation != null;
6189 current_class = current_namespace.SlaveDeclSpace;
6190 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6192 lexer = new Tokenizer (reader, file, compiler);
6194 use_global_stacks = true;
6197 public void parse ()
6199 eof_token = Token.EOF;
6200 Tokenizer.LocatedToken.Initialize ();
6203 if (yacc_verbose_flag > 1)
6204 yyparse (lexer, new yydebug.yyDebugSimple ());
6208 Tokenizer tokenizer = lexer as Tokenizer;
6209 tokenizer.cleanup ();
6210 } catch (Exception e){
6211 if (e is yyParser.yyUnexpectedEof) {
6212 Error_SyntaxError (yyToken);
6213 UnexpectedEOF = true;
6217 if (e is yyParser.yyException) {
6218 Report.Error (-25, lexer.Location, "Parsing error");
6220 // Used by compiler-tester to test internal errors
6221 if (yacc_verbose_flag > 0)
6224 Report.Error (589, lexer.Location, "Internal compiler error during parsing");
6228 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6229 throw new InternalErrorException ("who set it?");
6232 void CheckToken (int error, int yyToken, string msg, Location loc)
6234 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6235 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6237 Report.Error (error, loc, msg);
6240 string ConsumeStoredComment ()
6242 string s = tmpComment;
6244 Lexer.doc_state = XmlCommentState.Allowed;
6248 void FeatureIsNotAvailable (Location loc, string feature)
6250 compiler.Report.FeatureIsNotAvailable (compiler, loc, feature);
6253 Location GetLocation (object obj)
6255 var lt = obj as Tokenizer.LocatedToken;
6259 var mn = obj as MemberName;
6263 var expr = obj as Expression;
6265 return expr.Location;
6267 return lexer.Location;
6271 get { return compiler.Report; }
6274 public LocationsBag LocationsBag {
6283 void start_block (Location loc)
6285 if (current_block == null) {
6286 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6287 parsing_anonymous_method = false;
6288 } else if (parsing_anonymous_method) {
6289 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6290 parsing_anonymous_method = false;
6292 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6297 end_block (Location loc)
6299 Block retval = current_block.Explicit;
6300 retval.SetEndLocation (loc);
6301 current_block = retval.Parent;
6305 void start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6307 if (lang_version == LanguageVersion.ISO_1){
6308 FeatureIsNotAvailable (loc, "anonymous methods");
6311 oob_stack.Push (current_anonymous_method);
6312 oob_stack.Push (current_local_parameters);
6313 oob_stack.Push (current_variable);
6315 current_local_parameters = parameters;
6317 current_anonymous_method = lambda
6318 ? new LambdaExpression (loc)
6319 : new AnonymousMethodExpression (loc);
6321 // Force the next block to be created as a ToplevelBlock
6322 parsing_anonymous_method = true;
6326 * Completes the anonymous method processing, if lambda_expr is null, this
6327 * means that we have a Statement instead of an Expression embedded
6329 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6331 AnonymousMethodExpression retval;
6333 current_anonymous_method.Block = anon_block;
6334 retval = current_anonymous_method;
6336 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6337 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6338 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6343 public NamespaceEntry CurrentNamespace {
6345 return current_namespace;
6349 void Error_SyntaxError (int token)
6351 Error_SyntaxError (0, token, "Unexpected symbol");
6354 void Error_SyntaxError (int error_code, int token, string msg)
6356 // An error message has been reported by tokenizer
6357 if (token == Token.ERROR)
6360 string symbol = GetSymbolName (token);
6361 string expecting = GetExpecting ();
6362 var loc = lexer.Location - symbol.Length;
6364 if (error_code == 0) {
6365 if (expecting == "`identifier'") {
6366 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6367 Report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6372 expecting = "identifier";
6373 } else if (expecting == "`)'") {
6380 if (string.IsNullOrEmpty (expecting))
6381 Report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6383 Report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6386 string GetExpecting ()
6388 int [] tokens = yyExpectingTokens (yyExpectingState);
6389 var names = new List<string> (tokens.Length);
6390 bool has_type = false;
6391 bool has_identifier = false;
6392 for (int i = 0; i < tokens.Length; i++){
6393 int token = tokens [i];
6394 has_identifier |= token == Token.IDENTIFIER;
6396 string name = GetTokenName (token);
6397 if (name == "<internal>")
6400 has_type |= name == "type";
6401 if (names.Contains (name))
6408 // Too many tokens to enumerate
6410 if (names.Count > 8)
6413 if (has_type && has_identifier)
6414 names.Remove ("identifier");
6416 if (names.Count == 1)
6417 return "`" + GetTokenName (tokens [0]) + "'";
6419 StringBuilder sb = new StringBuilder ();
6421 int count = names.Count;
6422 for (int i = 0; i < count; i++){
6423 bool last = i + 1 == count;
6427 sb.Append (names [i]);
6428 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6430 return sb.ToString ();
6434 string GetSymbolName (int token)
6438 return ((Constant)lexer.Value).GetValue ().ToString ();
6439 case Token.IDENTIFIER:
6440 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6482 case Token.BITWISE_AND:
6484 case Token.BITWISE_OR:
6498 case Token.OP_SHIFT_LEFT:
6500 case Token.OP_SHIFT_RIGHT:
6520 case Token.OP_COALESCING:
6522 case Token.OP_MULT_ASSIGN:
6524 case Token.OP_DIV_ASSIGN:
6526 case Token.OP_MOD_ASSIGN:
6528 case Token.OP_ADD_ASSIGN:
6530 case Token.OP_SUB_ASSIGN:
6532 case Token.OP_SHIFT_LEFT_ASSIGN:
6534 case Token.OP_SHIFT_RIGHT_ASSIGN:
6536 case Token.OP_AND_ASSIGN:
6538 case Token.OP_XOR_ASSIGN:
6540 case Token.OP_OR_ASSIGN:
6544 return GetTokenName (token);
6547 static string GetTokenName (int token)
6550 case Token.ABSTRACT:
6572 case Token.CONTINUE:
6576 case Token.DELEGATE:
6586 case Token.EXPLICIT:
6604 case Token.IMPLICIT:
6608 case Token.INTERFACE:
6610 case Token.INTERNAL:
6616 case Token.NAMESPACE:
6622 case Token.OPERATOR:
6626 case Token.OVERRIDE:
6632 case Token.PROTECTED:
6636 case Token.READONLY:
6648 case Token.STACKALLOC:
6649 return "stackalloc";
6666 case Token.UNCHECKED:
6674 case Token.VOLATILE:
6687 case Token.FROM_FIRST:
6705 case Token.ASCENDING:
6707 case Token.DESCENDING:
6708 return "descending";
6715 case Token.OPEN_BRACE:
6717 case Token.CLOSE_BRACE:
6719 case Token.OPEN_BRACKET:
6720 case Token.OPEN_BRACKET_EXPR:
6722 case Token.CLOSE_BRACKET:
6724 case Token.OPEN_PARENS_CAST:
6725 case Token.OPEN_PARENS_LAMBDA:
6726 case Token.OPEN_PARENS:
6728 case Token.CLOSE_PARENS:
6734 case Token.DEFAULT_COLON:
6738 case Token.SEMICOLON:
6749 case Token.BITWISE_AND:
6750 case Token.BITWISE_OR:
6757 case Token.OP_SHIFT_LEFT:
6758 case Token.OP_SHIFT_RIGHT:
6766 case Token.OP_COALESCING:
6767 case Token.OP_MULT_ASSIGN:
6768 case Token.OP_DIV_ASSIGN:
6769 case Token.OP_MOD_ASSIGN:
6770 case Token.OP_ADD_ASSIGN:
6771 case Token.OP_SUB_ASSIGN:
6772 case Token.OP_SHIFT_LEFT_ASSIGN:
6773 case Token.OP_SHIFT_RIGHT_ASSIGN:
6774 case Token.OP_AND_ASSIGN:
6775 case Token.OP_XOR_ASSIGN:
6776 case Token.OP_OR_ASSIGN:
6777 return "<operator>";
6799 case Token.OP_GENERICS_LT:
6800 case Token.GENERIC_DIMENSION:
6802 case Token.OP_GENERICS_GT:
6805 case Token.INTERR_NULLABLE:
6807 case Token.DOUBLE_COLON:
6811 case Token.IDENTIFIER:
6812 return "identifier";
6815 return "end-of-file";
6817 // All of these are internal.
6820 case Token.FIRST_KEYWORD:
6821 case Token.EVAL_COMPILATION_UNIT_PARSER:
6822 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6823 case Token.EVAL_STATEMENT_PARSER:
6824 case Token.LAST_KEYWORD:
6825 case Token.GENERATE_COMPLETION:
6826 case Token.COMPLETE_COMPLETION:
6827 return "<internal>";
6829 // A bit more robust.
6831 return yyNames [token];