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;
86 Stack<Block> switch_stack;
89 /// Controls the verbosity of the errors produced by the parser
91 static public int yacc_verbose_flag;
94 /// Used by the interactive shell, flags whether EOF was reached
95 /// and an error was produced
97 public bool UnexpectedEOF;
100 /// The current file.
102 CompilationUnit file;
105 /// Temporary Xml documentation cache.
106 /// For enum types, we need one more temporary store.
109 string enumTypeComment;
111 /// Current attribute target
112 string current_attr_target;
114 /// assembly and module attribute definitions are enabled
115 bool global_attrs_enabled = true;
117 ParameterModifierType valid_param_mod;
119 bool default_parameter_used;
121 /// When using the interactive parser, this holds the
122 /// resulting expression
123 public object InteractiveResult;
126 // Keeps track of global data changes to undo on parser error
130 Stack<Linq.QueryBlock> linq_clause_blocks;
132 // A counter to create new class names in interactive mode
133 static int class_count;
135 CompilerContext compiler;
138 // Instead of allocating carrier array everytime we
139 // share the bucket for very common constructs which can never
142 static List<Parameter> parameters_bucket = new List<Parameter> (6);
145 // Full AST support members
148 List<Tuple<Modifiers, Location>> mod_locations;
152 %token NONE /* This token is never returned by our lexer */
153 %token ERROR // This is used not by the parser, but by the tokenizer.
157 *These are the C# keywords
256 %token INTERR_NULLABLE
259 /* Generics <,> tokens */
260 %token OP_GENERICS_LT
261 %token OP_GENERICS_LT_DECL
262 %token OP_GENERICS_GT
264 /* C# keywords which are not really keywords */
270 /* C# single character operators/punctuation. */
298 /* C# multi-character operators. */
303 %token OP_SHIFT_RIGHT
310 %token OP_MULT_ASSIGN
315 %token OP_SHIFT_LEFT_ASSIGN
316 %token OP_SHIFT_RIGHT_ASSIGN
326 %token OPEN_PARENS_LAMBDA
327 %token OPEN_PARENS_CAST
328 %token GENERIC_DIMENSION
330 %token OPEN_BRACKET_EXPR
332 // Make the parser go into eval mode parsing (statements and compilation units).
333 %token EVAL_STATEMENT_PARSER
334 %token EVAL_COMPILATION_UNIT_PARSER
335 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
338 // This token is generated to trigger the completion engine at this point
340 %token GENERATE_COMPLETION
343 // This token is return repeatedly after the first GENERATE_COMPLETION
344 // token is produced and before the final EOF
346 %token COMPLETE_COMPLETION
348 /* Add precedence rules to solve dangling else s/r conflict */
352 /* Define the operator tokens and their precedences */
360 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
362 %left STAR DIV PERCENT
363 %right BANG CARRET UMINUS
364 %nonassoc OP_INC OP_DEC
366 %left OPEN_BRACKET OPEN_BRACE
369 %start compilation_unit
373 : outer_declarations opt_EOF
374 | outer_declarations global_attributes opt_EOF
375 | global_attributes opt_EOF
376 | opt_EOF /* allow empty files */
377 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
383 Lexer.check_incorrect_doc_comment ();
387 Lexer.check_incorrect_doc_comment ();
393 | outer_declarations outer_declaration
397 : extern_alias_directive
399 | namespace_member_declaration
402 extern_alias_directives
403 : extern_alias_directive
404 | extern_alias_directives extern_alias_directive
407 extern_alias_directive
408 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
410 var lt = (Tokenizer.LocatedToken) $2;
413 syntax_error (lt.Location, "`alias' expected");
414 } else if (RootContext.Version == LanguageVersion.ISO_1) {
415 Report.FeatureIsNotAvailable (lt.Location, "external alias");
417 lt = (Tokenizer.LocatedToken) $3;
418 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
423 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
429 | using_directives using_directive
433 : using_alias_directive
435 if (RootContext.Documentation != null)
436 Lexer.doc_state = XmlCommentState.Allowed;
438 | using_namespace_directive
440 if (RootContext.Documentation != null)
441 Lexer.doc_state = XmlCommentState.Allowed;
445 using_alias_directive
446 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
448 var lt = (Tokenizer.LocatedToken) $2;
449 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
452 CheckIdentifierToken (yyToken, GetLocation ($2));
457 using_namespace_directive
458 : USING namespace_name SEMICOLON
460 current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
465 // Strictly speaking, namespaces don't have attributes but
466 // we parse global attributes along with namespace declarations and then
469 namespace_declaration
470 : opt_attributes NAMESPACE qualified_identifier
472 MemberName name = (MemberName) $3;
475 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
478 current_namespace = new NamespaceEntry (
479 current_namespace, file, name.GetName ());
480 current_class = current_namespace.SlaveDeclSpace;
481 current_container = current_class.PartialContainer;
483 namespace_body opt_semicolon
485 current_namespace = current_namespace.Parent;
486 current_class = current_namespace.SlaveDeclSpace;
487 current_container = current_class.PartialContainer;
494 var lt = (Tokenizer.LocatedToken) $1;
495 $$ = new MemberName (lt.Value, lt.Location);
497 | qualified_identifier DOT IDENTIFIER
499 var lt = (Tokenizer.LocatedToken) $3;
500 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
504 syntax_error (lexer.Location, "`.' expected");
505 $$ = new MemberName ("<invalid>", lexer.Location);
520 : namespace_or_type_name
522 MemberName name = (MemberName) $1;
524 if (name.TypeArguments != null)
525 syntax_error (lexer.Location, "namespace name expected");
534 if (RootContext.Documentation != null)
535 Lexer.doc_state = XmlCommentState.Allowed;
541 : opt_extern_alias_directives
543 opt_namespace_member_declarations
547 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
550 | opt_extern_alias_directives
552 opt_namespace_member_declarations
555 Report.Error (1513, lexer.Location, "Expected `}'");
564 opt_extern_alias_directives
566 | extern_alias_directives
569 opt_namespace_member_declarations
571 | namespace_member_declarations
574 namespace_member_declarations
575 : namespace_member_declaration
576 | namespace_member_declarations namespace_member_declaration
579 namespace_member_declaration
583 DeclSpace ds = (DeclSpace)$1;
585 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
586 Report.Error (1527, ds.Location,
587 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
590 current_namespace.DeclarationFound = true;
592 | namespace_declaration {
593 current_namespace.DeclarationFound = true;
596 | field_declaration {
597 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
599 | method_declaration {
600 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
607 | interface_declaration
609 | delegate_declaration
611 // Enable this when we have handled all errors, because this acts as a generic fallback
614 // Console.WriteLine ("Token=" + yyToken);
615 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
627 Attributes attrs = (Attributes)$1;
628 if (global_attrs_enabled) {
629 CodeGen.Assembly.AddAttributes (attrs.Attrs, current_namespace);
631 foreach (Attribute a in attrs.Attrs) {
632 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
643 global_attrs_enabled = false;
648 global_attrs_enabled = false;
657 if (current_attr_target != String.Empty) {
658 var sect = (List<Attribute>) $1;
660 if (global_attrs_enabled) {
661 if (current_attr_target == "module") {
662 current_container.Module.Compiled.AddAttributes (sect);
664 } else if (current_attr_target != null && current_attr_target.Length > 0) {
665 CodeGen.Assembly.AddAttributes (sect, current_namespace);
668 $$ = new Attributes (sect);
671 if (RootContext.Documentation != null) {
672 Lexer.check_incorrect_doc_comment ();
674 XmlCommentState.Allowed;
678 $$ = new Attributes (sect);
683 current_attr_target = null;
685 | attribute_sections attribute_section
687 if (current_attr_target != String.Empty) {
688 Attributes attrs = $1 as Attributes;
689 var sect = (List<Attribute>) $2;
691 if (global_attrs_enabled) {
692 if (current_attr_target == "module") {
693 current_container.Module.Compiled.AddAttributes (sect);
695 } else if (current_attr_target == "assembly") {
696 CodeGen.Assembly.AddAttributes (sect, current_namespace);
700 attrs = new Attributes (sect);
702 attrs.AddAttributes (sect);
706 attrs = new Attributes (sect);
708 attrs.AddAttributes (sect);
714 current_attr_target = null;
719 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
723 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
729 attribute_target_specifier
730 : attribute_target COLON
732 current_attr_target = (string)$1;
740 var lt = (Tokenizer.LocatedToken) $1;
741 $$ = CheckAttributeTarget (lt.Value, lt.Location);
743 | EVENT { $$ = "event"; }
744 | RETURN { $$ = "return"; }
747 string name = GetTokenName (yyToken);
748 $$ = CheckAttributeTarget (name, GetLocation ($1));
755 $$ = new List<Attribute> (4) { (Attribute) $1 };
757 | attribute_list COMMA attribute
759 var attrs = (List<Attribute>) $1;
760 attrs.Add ((Attribute) $3);
769 ++lexer.parsing_block;
771 opt_attribute_arguments
773 --lexer.parsing_block;
774 MemberName mname = (MemberName) $1;
775 if (mname.IsGeneric) {
776 Report.Error (404, lexer.Location,
777 "'<' unexpected: attributes cannot be generic");
780 Arguments [] arguments = (Arguments []) $3;
781 ATypeNameExpression expr = mname.GetTypeExpression ();
783 if (current_attr_target == String.Empty)
785 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
786 // FIXME: supply "nameEscaped" parameter here.
787 $$ = new GlobalAttribute (current_namespace, current_attr_target,
788 expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
790 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
795 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
798 opt_attribute_arguments
799 : /* empty */ { $$ = null; }
800 | OPEN_PARENS attribute_arguments CLOSE_PARENS
808 : /* empty */ { $$ = null; }
809 | positional_or_named_argument
811 Arguments a = new Arguments (4);
812 a.Add ((Argument) $1);
813 $$ = new Arguments [] { a, null };
815 | named_attribute_argument
817 Arguments a = new Arguments (4);
818 a.Add ((Argument) $1);
819 $$ = new Arguments [] { null, a };
821 | attribute_arguments COMMA positional_or_named_argument
823 Arguments[] o = (Arguments[]) $1;
825 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
826 o [0] = new Arguments (4);
829 Arguments args = ((Arguments) o [0]);
830 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
831 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
833 args.Add ((Argument) $3);
835 | attribute_arguments COMMA named_attribute_argument
837 Arguments[] o = (Arguments[]) $1;
839 o [1] = new Arguments (4);
842 ((Arguments) o [1]).Add ((Argument) $3);
846 positional_or_named_argument
849 $$ = new Argument ((Expression) $1);
854 named_attribute_argument
857 ++lexer.parsing_block;
861 --lexer.parsing_block;
862 var lt = (Tokenizer.LocatedToken) $1;
863 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
868 : IDENTIFIER COLON opt_named_modifier expression
870 if (RootContext.Version <= LanguageVersion.V_3)
871 Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
873 // Avoid boxing in common case (no modifier)
874 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
876 var lt = (Tokenizer.LocatedToken) $1;
877 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
882 : /* empty */ { $$ = null; }
885 $$ = Argument.AType.Ref;
889 $$ = Argument.AType.Out;
893 opt_class_member_declarations
895 | class_member_declarations
898 class_member_declarations
899 : class_member_declaration
900 | class_member_declarations
901 class_member_declaration
904 class_member_declaration
905 : constant_declaration // done
906 | field_declaration // done
907 | method_declaration // done
908 | property_declaration // done
909 | event_declaration // done
910 | indexer_declaration // done
911 | operator_declaration // done
912 | constructor_declaration // done
913 | destructor_declaration // done
917 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
918 GetSymbolName (yyToken));
920 lexer.parsing_generic_declaration = false;
930 lexer.ConstraintsParsing = true;
932 type_declaration_name
934 MemberName name = MakeName ((MemberName) $6);
935 push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
938 opt_type_parameter_constraints_clauses
940 lexer.ConstraintsParsing = false;
942 current_class.SetParameterInfo ((List<Constraints>) $9);
944 if (RootContext.Documentation != null)
945 current_container.DocComment = Lexer.consume_doc_comment ();
947 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
951 --lexer.parsing_declaration;
952 if (RootContext.Documentation != null)
953 Lexer.doc_state = XmlCommentState.Allowed;
957 lbag.AppendToMember (current_class, GetLocation ($13));
958 $$ = pop_current_class ();
960 | opt_attributes opt_modifiers opt_partial STRUCT error {
961 CheckIdentifierToken (yyToken, GetLocation ($5));
968 if (RootContext.Documentation != null)
969 Lexer.doc_state = XmlCommentState.Allowed;
971 opt_struct_member_declarations CLOSE_BRACE
973 lbag.AppendToMember (current_class, GetLocation ($1), GetLocation ($4));
977 opt_struct_member_declarations
979 | struct_member_declarations
982 struct_member_declarations
983 : struct_member_declaration
984 | struct_member_declarations struct_member_declaration
987 struct_member_declaration
988 : constant_declaration
991 | property_declaration
993 | indexer_declaration
994 | operator_declaration
995 | constructor_declaration
999 * This is only included so we can flag error 575:
1000 * destructors only allowed on class types
1002 | destructor_declaration
1005 constant_declaration
1008 CONST type IDENTIFIER
1010 var lt = (Tokenizer.LocatedToken) $5;
1011 var mod = (Modifiers) $2;
1012 current_field = new Const (current_class, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1013 current_container.AddConstant ((Const) current_field);
1015 if ((mod & Modifiers.STATIC) != 0) {
1016 Report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1021 constant_initializer opt_constant_declarators SEMICOLON
1023 if (RootContext.Documentation != null) {
1024 current_field.DocComment = Lexer.consume_doc_comment ();
1025 Lexer.doc_state = XmlCommentState.Allowed;
1028 current_field.Initializer = (ConstInitializer) $7;
1029 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1030 current_field = null;
1034 opt_constant_declarators
1036 | constant_declarators
1039 constant_declarators
1040 : constant_declarator
1042 current_field.AddDeclarator ((FieldDeclarator) $1);
1044 | constant_declarators constant_declarator
1046 current_field.AddDeclarator ((FieldDeclarator) $2);
1051 : COMMA IDENTIFIER constant_initializer
1053 var lt = (Tokenizer.LocatedToken) $2;
1054 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1055 lbag.AddLocation ($$, GetLocation ($1));
1059 constant_initializer
1062 ++lexer.parsing_block;
1064 constant_initializer_expr
1066 --lexer.parsing_block;
1067 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1071 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
1076 constant_initializer_expr
1077 : constant_expression
1084 member_type IDENTIFIER
1086 lexer.parsing_generic_declaration = false;
1088 FullNamedExpression type = (FullNamedExpression) $3;
1089 if (type.Type == TypeManager.void_type)
1090 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1092 var lt = (Tokenizer.LocatedToken) $4;
1093 current_field = new Field (current_class, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1094 current_container.AddField (current_field);
1097 opt_field_initializer
1098 opt_field_declarators
1101 if (RootContext.Documentation != null) {
1102 current_field.DocComment = Lexer.consume_doc_comment ();
1103 Lexer.doc_state = XmlCommentState.Allowed;
1106 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1108 current_field = null;
1112 FIXED simple_type IDENTIFIER
1114 if (RootContext.Version < LanguageVersion.ISO_2)
1115 Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1117 var lt = (Tokenizer.LocatedToken) $5;
1118 current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
1119 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1121 current_container.AddField (current_field);
1123 fixed_field_size opt_fixed_field_declarators SEMICOLON
1125 if (RootContext.Documentation != null) {
1126 current_field.DocComment = Lexer.consume_doc_comment ();
1127 Lexer.doc_state = XmlCommentState.Allowed;
1130 current_field.Initializer = (ConstInitializer) $7;
1131 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1133 current_field = null;
1137 FIXED simple_type error
1140 Report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1144 opt_field_initializer
1148 ++lexer.parsing_block;
1149 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1150 start_block (GetLocation ($1));
1152 variable_initializer
1154 --lexer.parsing_block;
1155 current_field.Initializer = (Expression) $3;
1156 end_block (lexer.Location);
1157 current_local_parameters = null;
1161 opt_field_declarators
1169 current_field.AddDeclarator ((FieldDeclarator) $1);
1171 | field_declarators field_declarator
1173 current_field.AddDeclarator ((FieldDeclarator) $2);
1180 var lt = (Tokenizer.LocatedToken) $2;
1181 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1182 lbag.AddLocation ($$, GetLocation ($1));
1184 | COMMA IDENTIFIER ASSIGN
1186 ++lexer.parsing_block;
1188 variable_initializer
1190 --lexer.parsing_block;
1191 var lt = (Tokenizer.LocatedToken) $2;
1192 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1193 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1197 opt_fixed_field_declarators
1199 | fixed_field_declarators
1202 fixed_field_declarators
1203 : fixed_field_declarator
1205 current_field.AddDeclarator ((FieldDeclarator) $1);
1207 | fixed_field_declarators fixed_field_declarator
1209 current_field.AddDeclarator ((FieldDeclarator) $2);
1213 fixed_field_declarator
1214 : COMMA IDENTIFIER fixed_field_size
1216 var lt = (Tokenizer.LocatedToken) $2;
1217 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1218 lbag.AddLocation ($$, GetLocation ($1));
1225 ++lexer.parsing_block;
1227 expression CLOSE_BRACKET
1229 --lexer.parsing_block;
1230 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1231 lbag.AddLocation ($$, GetLocation ($4));
1233 | OPEN_BRACKET error
1235 Report.Error (443, lexer.Location, "Value or constant expected");
1240 variable_initializer
1247 if (RootContext.Documentation != null)
1248 Lexer.doc_state = XmlCommentState.NotAllowed;
1252 Method method = (Method) $1;
1253 method.Block = (ToplevelBlock) $3;
1254 current_container.AddMethod (method);
1256 if (current_container.Kind == MemberKind.Interface && method.Block != null) {
1257 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1260 current_local_parameters = null;
1262 if (RootContext.Documentation != null)
1263 Lexer.doc_state = XmlCommentState.Allowed;
1271 method_declaration_name OPEN_PARENS
1273 valid_param_mod = ParameterModifierType.All;
1275 opt_formal_parameter_list CLOSE_PARENS
1277 lexer.ConstraintsParsing = true;
1279 opt_type_parameter_constraints_clauses
1281 lexer.ConstraintsParsing = false;
1282 valid_param_mod = 0;
1283 MemberName name = (MemberName) $4;
1284 current_local_parameters = (ParametersCompiled) $7;
1286 GenericMethod generic = null;
1287 if (name.TypeArguments != null) {
1288 generic = new GenericMethod (current_namespace, current_class, name,
1289 (FullNamedExpression) $3, current_local_parameters);
1291 generic.SetParameterInfo ((List<Constraints>) $10);
1292 } else if ($10 != null) {
1293 Report.Error (80, GetLocation ($10),
1294 "Constraints are not allowed on non-generic declarations");
1297 Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
1298 name, current_local_parameters, (Attributes) $1);
1300 if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
1301 Report.Error (460, method.Location,
1302 "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
1303 method.GetSignatureForError ());
1306 if (RootContext.Documentation != null)
1307 method.DocComment = Lexer.consume_doc_comment ();
1309 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1315 VOID method_declaration_name
1318 valid_param_mod = ParameterModifierType.All;
1320 opt_formal_parameter_list CLOSE_PARENS
1322 lexer.ConstraintsParsing = true;
1324 opt_type_parameter_constraints_clauses
1326 lexer.ConstraintsParsing = false;
1327 valid_param_mod = 0;
1329 MemberName name = (MemberName) $5;
1330 current_local_parameters = (ParametersCompiled) $8;
1332 if ($10 != null && name.TypeArguments == null)
1333 Report.Error (80, lexer.Location,
1334 "Constraints are not allowed on non-generic declarations");
1337 GenericMethod generic = null;
1338 if (name.TypeArguments != null) {
1339 generic = new GenericMethod (current_namespace, current_class, name,
1340 new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1341 current_local_parameters);
1343 generic.SetParameterInfo ((List<Constraints>) $11);
1346 var modifiers = (Modifiers) $2;
1349 const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
1350 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1352 if ((modifiers & invalid_partial_mod) != 0) {
1353 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1354 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1355 modifiers &= ~invalid_partial_mod;
1358 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1359 Report.Error (751, name.Location, "A partial method must be declared within a " +
1360 "partial class or partial struct");
1363 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1365 method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1366 modifiers, name, current_local_parameters, (Attributes) $1);
1368 if (RootContext.Documentation != null)
1369 method.DocComment = Lexer.consume_doc_comment ();
1371 // TODO: lbag, push void
1372 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1373 lbag.AddMember (method, mod_locations, GetLocation ($6), GetLocation ($9));
1379 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1381 MemberName name = (MemberName) $5;
1382 Report.Error (1585, name.Location,
1383 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1385 Method method = new Method (current_class, null, (FullNamedExpression) $3,
1386 0, name, (ParametersCompiled) $7, (Attributes) $1);
1388 current_local_parameters = (ParametersCompiled) $7;
1390 if (RootContext.Documentation != null)
1391 method.DocComment = Lexer.consume_doc_comment ();
1399 | SEMICOLON { $$ = null; }
1402 opt_formal_parameter_list
1403 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1404 | formal_parameter_list
1407 formal_parameter_list
1410 var pars_list = (List<Parameter>) $1;
1411 $$ = new ParametersCompiled (pars_list.ToArray ());
1413 | fixed_parameters COMMA parameter_array
1415 var pars_list = (List<Parameter>) $1;
1416 pars_list.Add ((Parameter) $3);
1418 $$ = new ParametersCompiled (pars_list.ToArray ());
1420 | fixed_parameters COMMA arglist_modifier
1422 var pars_list = (List<Parameter>) $1;
1423 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1424 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1426 | parameter_array COMMA error
1429 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1431 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1433 | fixed_parameters COMMA parameter_array COMMA error
1436 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1438 var pars_list = (List<Parameter>) $1;
1439 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1441 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1443 | arglist_modifier COMMA error
1445 Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1447 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1449 | fixed_parameters COMMA ARGLIST COMMA error
1451 Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1453 var pars_list = (List<Parameter>) $1;
1454 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1456 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1460 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1464 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1471 parameters_bucket.Clear ();
1472 Parameter p = (Parameter) $1;
1473 parameters_bucket.Add (p);
1475 default_parameter_used = p.HasDefaultValue;
1476 $$ = parameters_bucket;
1478 | fixed_parameters COMMA fixed_parameter
1480 var pars = (List<Parameter>) $1;
1481 Parameter p = (Parameter) $3;
1483 if (p.HasExtensionMethodModifier)
1484 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1485 else if (!p.HasDefaultValue && default_parameter_used)
1486 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1488 default_parameter_used |= p.HasDefaultValue;
1491 lbag.AddLocation (p, GetLocation ($2));
1500 opt_parameter_modifier
1504 var lt = (Tokenizer.LocatedToken) $4;
1505 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1508 opt_parameter_modifier
1510 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1512 var lt = (Tokenizer.LocatedToken) $4;
1513 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1514 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1517 opt_parameter_modifier
1521 Location l = GetLocation ($4);
1522 CheckIdentifierToken (yyToken, l);
1523 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1526 opt_parameter_modifier
1531 ++lexer.parsing_block;
1535 --lexer.parsing_block;
1536 if (RootContext.Version <= LanguageVersion.V_3) {
1537 Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1540 Parameter.Modifier mod = (Parameter.Modifier) $2;
1541 if (mod != Parameter.Modifier.NONE) {
1543 case Parameter.Modifier.REF:
1544 case Parameter.Modifier.OUT:
1545 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1546 Parameter.GetModifierSignature (mod));
1549 case Parameter.Modifier.This:
1550 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1551 Parameter.GetModifierSignature (mod));
1554 throw new NotImplementedException (mod.ToString ());
1557 mod = Parameter.Modifier.NONE;
1560 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1561 Report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1563 var lt = (Tokenizer.LocatedToken) $4;
1564 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1565 lbag.AddLocation ($$, GetLocation ($5));
1568 ((Parameter) $$).DefaultValue = (Expression) $7;
1572 opt_parameter_modifier
1573 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1574 | parameter_modifiers
1578 : parameter_modifier
1582 | parameter_modifiers parameter_modifier
1584 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1585 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1586 if (((Parameter.Modifier)$1 & p2) == p2) {
1587 Error_DuplicateParameterModifier (lexer.Location, p2);
1589 switch (mod & ~Parameter.Modifier.This) {
1590 case Parameter.Modifier.REF:
1591 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1593 case Parameter.Modifier.OUT:
1594 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1597 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1608 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1609 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1611 $$ = Parameter.Modifier.REF;
1615 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1616 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1618 $$ = Parameter.Modifier.OUT;
1622 if ((valid_param_mod & ParameterModifierType.This) == 0)
1623 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1625 if (RootContext.Version <= LanguageVersion.ISO_2)
1626 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1628 $$ = Parameter.Modifier.This;
1633 : opt_attributes params_modifier type IDENTIFIER
1635 var lt = (Tokenizer.LocatedToken) $4;
1636 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1638 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1640 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1642 var lt = (Tokenizer.LocatedToken) $4;
1643 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1645 | opt_attributes params_modifier type error
1647 CheckIdentifierToken (yyToken, GetLocation ($4));
1655 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1656 Report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1658 | PARAMS parameter_modifier
1660 Parameter.Modifier mod = (Parameter.Modifier)$2;
1661 if ((mod & Parameter.Modifier.This) != 0) {
1662 Report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1664 Report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1667 | PARAMS params_modifier
1669 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1676 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1677 Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1681 property_declaration
1685 member_declaration_name
1687 if (RootContext.Documentation != null)
1688 tmpComment = Lexer.consume_doc_comment ();
1692 current_property = new Property (current_class, (FullNamedExpression) $3, (Modifiers) $2,
1693 (MemberName) $4, (Attributes) $1);
1695 if (current_property.TypeExpression.Type == TypeManager.void_type)
1696 Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1698 current_container.AddProperty ((Property)current_property);
1699 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1701 lexer.PropertyParsing = true;
1703 accessor_declarations
1705 lexer.PropertyParsing = false;
1707 if (RootContext.Documentation != null)
1708 current_property.DocComment = ConsumeStoredComment ();
1712 lbag.AppendToMember (current_property, GetLocation ($10));
1713 current_property = null;
1719 : opt_attributes opt_modifiers
1720 member_type indexer_declaration_name OPEN_BRACKET
1722 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1724 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1726 valid_param_mod = 0;
1728 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
1729 (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1731 current_property = indexer;
1733 current_container.AddIndexer (indexer);
1734 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1736 if (indexer.TypeExpression.Type == TypeManager.void_type)
1737 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1739 if (indexer.Parameters.IsEmpty) {
1740 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1743 if (RootContext.Documentation != null) {
1744 tmpComment = Lexer.consume_doc_comment ();
1745 Lexer.doc_state = XmlCommentState.Allowed;
1748 lexer.PropertyParsing = true;
1750 accessor_declarations
1752 lexer.PropertyParsing = false;
1756 if (RootContext.Documentation != null)
1757 current_property.DocComment = ConsumeStoredComment ();
1759 lbag.AppendToMember (current_property, GetLocation ($12));
1760 current_property = null;
1765 accessor_declarations
1766 : get_accessor_declaration
1767 | get_accessor_declaration accessor_declarations
1768 | set_accessor_declaration
1769 | set_accessor_declaration accessor_declarations
1772 if (yyToken == Token.CLOSE_BRACE) {
1773 Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1775 if (yyToken == Token.SEMICOLON)
1776 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1778 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1783 get_accessor_declaration
1784 : opt_attributes opt_modifiers GET
1786 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1787 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1790 if (current_property.Get != null) {
1791 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1794 if (current_property is Indexer) {
1795 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1796 (Attributes) $1, GetLocation ($3));
1798 current_property.Get = new Property.GetMethod (current_property,
1799 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1802 current_local_parameters = current_property.Get.ParameterInfo;
1803 lbag.AddMember (current_property.Get, mod_locations);
1804 lexer.PropertyParsing = false;
1809 current_property.Get.Block = (ToplevelBlock) $5;
1811 if (current_container.Kind == MemberKind.Interface) {
1812 Report.Error (531, current_property.Get.Block.StartLocation,
1813 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1817 current_local_parameters = null;
1818 lexer.PropertyParsing = true;
1820 if (RootContext.Documentation != null)
1821 if (Lexer.doc_state == XmlCommentState.Error)
1822 Lexer.doc_state = XmlCommentState.NotAllowed;
1826 set_accessor_declaration
1827 : opt_attributes opt_modifiers SET
1829 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1830 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1833 if (current_property.Set != null) {
1834 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1837 if (current_property is Indexer) {
1838 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1839 ParametersCompiled.MergeGenerated (compiler,
1840 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1841 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1843 (Attributes) $1, GetLocation ($3));
1845 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1846 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1847 (Attributes) $1, GetLocation ($3));
1850 current_local_parameters = current_property.Set.ParameterInfo;
1851 lbag.AddMember (current_property.Set, mod_locations);
1852 lexer.PropertyParsing = false;
1857 current_property.Set.Block = (ToplevelBlock) $5;
1859 if (current_container.Kind == MemberKind.Interface) {
1860 Report.Error (531, current_property.Set.Block.StartLocation,
1861 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1865 current_local_parameters = null;
1866 lexer.PropertyParsing = true;
1868 if (RootContext.Documentation != null
1869 && Lexer.doc_state == XmlCommentState.Error)
1870 Lexer.doc_state = XmlCommentState.NotAllowed;
1883 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1888 interface_declaration
1894 lexer.ConstraintsParsing = true;
1896 type_declaration_name
1898 MemberName name = MakeName ((MemberName) $6);
1899 push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
1900 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
1903 opt_type_parameter_constraints_clauses
1905 lexer.ConstraintsParsing = false;
1907 current_class.SetParameterInfo ((List<Constraints>) $9);
1909 if (RootContext.Documentation != null) {
1910 current_container.DocComment = Lexer.consume_doc_comment ();
1911 Lexer.doc_state = XmlCommentState.Allowed;
1914 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1916 --lexer.parsing_declaration;
1917 if (RootContext.Documentation != null)
1918 Lexer.doc_state = XmlCommentState.Allowed;
1922 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
1923 $$ = pop_current_class ();
1925 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1926 CheckIdentifierToken (yyToken, GetLocation ($5));
1930 opt_interface_member_declarations
1932 | interface_member_declarations
1935 interface_member_declarations
1936 : interface_member_declaration
1937 | interface_member_declarations interface_member_declaration
1940 interface_member_declaration
1941 : constant_declaration
1943 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1947 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1949 | method_declaration
1950 | property_declaration
1952 | indexer_declaration
1953 | operator_declaration
1955 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1957 | constructor_declaration
1959 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1963 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1967 operator_declaration
1968 : opt_attributes opt_modifiers operator_declarator
1973 OperatorDeclaration decl = (OperatorDeclaration) $3;
1975 Operator op = new Operator (
1976 current_class, decl.optype, decl.ret_type, (Modifiers) $2,
1977 current_local_parameters,
1978 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1980 if (RootContext.Documentation != null) {
1981 op.DocComment = tmpComment;
1982 Lexer.doc_state = XmlCommentState.Allowed;
1985 // Note again, checking is done in semantic analysis
1986 current_container.AddOperator (op);
1988 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1991 current_local_parameters = null;
1997 | SEMICOLON { $$ = null; }
2001 : type_expression_or_array
2004 Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2005 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2010 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2012 valid_param_mod = ParameterModifierType.DefaultValue;
2014 opt_formal_parameter_list CLOSE_PARENS
2016 valid_param_mod = 0;
2018 Location loc = GetLocation ($2);
2019 Operator.OpType op = (Operator.OpType) $3;
2020 current_local_parameters = (ParametersCompiled)$6;
2022 int p_count = current_local_parameters.Count;
2024 if (op == Operator.OpType.Addition)
2025 op = Operator.OpType.UnaryPlus;
2026 else if (op == Operator.OpType.Subtraction)
2027 op = Operator.OpType.UnaryNegation;
2030 if (IsUnaryOperator (op)) {
2032 Report.Error (1020, loc, "Overloadable binary operator expected");
2033 } else if (p_count != 1) {
2034 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2035 Operator.GetName (op));
2039 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2040 Operator.GetName (op));
2041 } else if (p_count != 2) {
2042 Report.Error (1019, loc, "Overloadable unary operator expected");
2046 if (RootContext.Documentation != null) {
2047 tmpComment = Lexer.consume_doc_comment ();
2048 Lexer.doc_state = XmlCommentState.NotAllowed;
2051 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2052 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2054 | conversion_operator_declarator
2057 overloadable_operator
2059 : BANG { $$ = Operator.OpType.LogicalNot; }
2060 | TILDE { $$ = Operator.OpType.OnesComplement; }
2061 | OP_INC { $$ = Operator.OpType.Increment; }
2062 | OP_DEC { $$ = Operator.OpType.Decrement; }
2063 | TRUE { $$ = Operator.OpType.True; }
2064 | FALSE { $$ = Operator.OpType.False; }
2065 // Unary and binary:
2066 | PLUS { $$ = Operator.OpType.Addition; }
2067 | MINUS { $$ = Operator.OpType.Subtraction; }
2069 | STAR { $$ = Operator.OpType.Multiply; }
2070 | DIV { $$ = Operator.OpType.Division; }
2071 | PERCENT { $$ = Operator.OpType.Modulus; }
2072 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2073 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2074 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2075 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2076 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2077 | OP_EQ { $$ = Operator.OpType.Equality; }
2078 | OP_NE { $$ = Operator.OpType.Inequality; }
2079 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2080 | OP_LT { $$ = Operator.OpType.LessThan; }
2081 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2082 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2085 conversion_operator_declarator
2086 : IMPLICIT OPERATOR type OPEN_PARENS
2088 valid_param_mod = ParameterModifierType.DefaultValue;
2090 opt_formal_parameter_list CLOSE_PARENS
2092 valid_param_mod = 0;
2094 Location loc = GetLocation ($2);
2095 current_local_parameters = (ParametersCompiled)$6;
2097 if (RootContext.Documentation != null) {
2098 tmpComment = Lexer.consume_doc_comment ();
2099 Lexer.doc_state = XmlCommentState.NotAllowed;
2102 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2103 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2105 | EXPLICIT OPERATOR type OPEN_PARENS
2107 valid_param_mod = ParameterModifierType.DefaultValue;
2109 opt_formal_parameter_list CLOSE_PARENS
2111 valid_param_mod = 0;
2113 Location loc = GetLocation ($2);
2114 current_local_parameters = (ParametersCompiled)$6;
2116 if (RootContext.Documentation != null) {
2117 tmpComment = Lexer.consume_doc_comment ();
2118 Lexer.doc_state = XmlCommentState.NotAllowed;
2121 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2122 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2126 Error_SyntaxError (yyToken);
2127 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2128 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2132 Error_SyntaxError (yyToken);
2133 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2134 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2138 constructor_declaration
2139 : constructor_declarator
2142 Constructor c = (Constructor) $1;
2143 c.Block = (ToplevelBlock) $2;
2145 if (RootContext.Documentation != null)
2146 c.DocComment = ConsumeStoredComment ();
2148 current_container.AddConstructor (c);
2150 current_local_parameters = null;
2151 if (RootContext.Documentation != null)
2152 Lexer.doc_state = XmlCommentState.Allowed;
2156 constructor_declarator
2161 if (RootContext.Documentation != null) {
2162 tmpComment = Lexer.consume_doc_comment ();
2163 Lexer.doc_state = XmlCommentState.Allowed;
2166 valid_param_mod = ParameterModifierType.All;
2168 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2170 valid_param_mod = 0;
2171 current_local_parameters = (ParametersCompiled) $6;
2174 // start block here, so possible anonymous methods inside
2175 // constructor initializer can get correct parent block
2177 start_block (lexer.Location);
2179 opt_constructor_initializer
2181 var lt = (Tokenizer.LocatedToken) $3;
2182 var mods = (Modifiers) $2;
2183 ConstructorInitializer ci = (ConstructorInitializer) $9;
2185 Constructor c = new Constructor (current_class, lt.Value, mods,
2186 (Attributes) $1, current_local_parameters, ci, lt.Location);
2188 if (lt.Value != current_container.MemberName.Name) {
2189 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2190 } else if ((mods & Modifiers.STATIC) != 0) {
2191 if ((mods & Modifiers.AccessibilityMask) != 0){
2192 Report.Error (515, c.Location,
2193 "`{0}': static constructor cannot have an access modifier",
2194 c.GetSignatureForError ());
2197 Report.Error (514, c.Location,
2198 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2199 c.GetSignatureForError ());
2204 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2211 | SEMICOLON { current_block = null; $$ = null; }
2214 opt_constructor_initializer
2216 | constructor_initializer
2219 constructor_initializer
2220 : COLON BASE OPEN_PARENS
2222 ++lexer.parsing_block;
2224 opt_argument_list CLOSE_PARENS
2226 --lexer.parsing_block;
2227 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2228 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2230 | COLON THIS OPEN_PARENS
2232 ++lexer.parsing_block;
2234 opt_argument_list CLOSE_PARENS
2236 --lexer.parsing_block;
2237 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2238 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2241 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2246 destructor_declaration
2247 : opt_attributes opt_modifiers TILDE
2249 if (RootContext.Documentation != null) {
2250 tmpComment = Lexer.consume_doc_comment ();
2251 Lexer.doc_state = XmlCommentState.NotAllowed;
2254 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2256 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2258 var lt = (Tokenizer.LocatedToken) $5;
2259 if (lt.Value != current_container.MemberName.Name){
2260 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2261 } else if (current_container.Kind != MemberKind.Class){
2262 Report.Error (575, lt.Location, "Only class types can contain destructor");
2265 Destructor d = new Destructor (current_class, (Modifiers) $2,
2266 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2267 if (RootContext.Documentation != null)
2268 d.DocComment = ConsumeStoredComment ();
2270 d.Block = (ToplevelBlock) $8;
2271 current_container.AddMethod (d);
2272 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2274 current_local_parameters = null;
2281 EVENT type member_declaration_name
2283 current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2284 current_container.AddEvent (current_event_field);
2286 if (current_event_field.MemberName.Left != null) {
2287 Report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2288 current_event_field.GetSignatureForError ());
2291 $$ = current_event_field;
2293 opt_event_initializer
2294 opt_event_declarators
2297 if (RootContext.Documentation != null) {
2298 current_event_field.DocComment = Lexer.consume_doc_comment ();
2299 Lexer.doc_state = XmlCommentState.Allowed;
2302 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2303 current_event_field = null;
2307 EVENT type member_declaration_name
2310 current_event = new EventProperty (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2311 current_container.AddEvent (current_event);
2312 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2314 lexer.EventParsing = true;
2316 event_accessor_declarations
2318 if (current_container.Kind == MemberKind.Interface)
2319 Report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2321 lexer.EventParsing = false;
2325 if (RootContext.Documentation != null) {
2326 current_event.DocComment = Lexer.consume_doc_comment ();
2327 Lexer.doc_state = XmlCommentState.Allowed;
2330 lbag.AppendToMember (current_event, GetLocation ($9));
2331 current_event = null;
2332 current_local_parameters = null;
2336 opt_event_initializer
2340 ++lexer.parsing_block;
2342 event_variable_initializer
2344 --lexer.parsing_block;
2345 current_event_field.Initializer = (Expression) $3;
2349 opt_event_declarators
2357 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2359 | event_declarators event_declarator
2361 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2368 var lt = (Tokenizer.LocatedToken) $2;
2369 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2370 lbag.AddLocation ($$, GetLocation ($1));
2372 | COMMA IDENTIFIER ASSIGN
2374 ++lexer.parsing_block;
2376 event_variable_initializer
2378 --lexer.parsing_block;
2379 var lt = (Tokenizer.LocatedToken) $2;
2380 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2381 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2385 event_variable_initializer
2387 if (current_container.Kind == MemberKind.Interface) {
2388 Report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2389 current_event_field.GetSignatureForError ());
2392 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2393 Report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2394 current_event_field.GetSignatureForError ());
2397 variable_initializer
2403 event_accessor_declarations
2404 : add_accessor_declaration remove_accessor_declaration
2405 | remove_accessor_declaration add_accessor_declaration
2406 | add_accessor_declaration
2408 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2409 current_event.GetSignatureForError ());
2411 | remove_accessor_declaration
2413 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2414 current_event.GetSignatureForError ());
2418 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2423 add_accessor_declaration
2424 : opt_attributes opt_modifiers ADD
2426 if ($2 != ModifierNone) {
2427 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2430 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2431 current_local_parameters = current_event.Add.ParameterInfo;
2433 lbag.AddMember (current_event.Add, mod_locations);
2434 lexer.EventParsing = false;
2436 event_accessor_block
2438 lexer.EventParsing = true;
2440 current_event.Add.Block = (ToplevelBlock) $5;
2442 if (current_container.Kind == MemberKind.Interface) {
2443 Report.Error (531, current_event.Add.Block.StartLocation,
2444 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2447 current_local_parameters = null;
2451 remove_accessor_declaration
2452 : opt_attributes opt_modifiers REMOVE
2454 if ($2 != ModifierNone) {
2455 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2458 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2459 current_local_parameters = current_event.Remove.ParameterInfo;
2461 lbag.AddMember (current_event.Remove, mod_locations);
2462 lexer.EventParsing = false;
2464 event_accessor_block
2466 lexer.EventParsing = true;
2468 current_event.Remove.Block = (ToplevelBlock) $5;
2470 if (current_container.Kind == MemberKind.Interface) {
2471 Report.Error (531, current_event.Remove.Block.StartLocation,
2472 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2475 current_local_parameters = null;
2479 event_accessor_block
2482 Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2491 ENUM type_declaration_name
2494 if (RootContext.Documentation != null)
2495 enumTypeComment = Lexer.consume_doc_comment ();
2499 if (RootContext.Documentation != null)
2500 Lexer.doc_state = XmlCommentState.Allowed;
2502 MemberName name = (MemberName) $4;
2503 if (name.IsGeneric) {
2504 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2507 push_current_class (new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2, MakeName (name), (Attributes) $1), null);
2509 opt_enum_member_declarations
2511 // here will be evaluated after CLOSE_BLACE is consumed.
2512 if (RootContext.Documentation != null)
2513 Lexer.doc_state = XmlCommentState.Allowed;
2515 CLOSE_BRACE opt_semicolon
2517 if (RootContext.Documentation != null)
2518 current_class.DocComment = enumTypeComment;
2520 --lexer.parsing_declaration;
2522 // if (RootContext.Documentation != null)
2523 // em.DocComment = ev.DocComment;
2525 lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2526 $$ = pop_current_class ();
2534 var te = $2 as TypeExpression;
2536 (te.Type != TypeManager.int32_type && te.Type != TypeManager.uint32_type &&
2537 te.Type != TypeManager.int64_type && te.Type != TypeManager.uint64_type &&
2538 te.Type != TypeManager.short_type && te.Type != TypeManager.ushort_type &&
2539 te.Type != TypeManager.byte_type && te.Type != TypeManager.sbyte_type)) {
2540 Enum.Error_1008 (GetLocation ($2), Report);
2548 Error_TypeExpected (GetLocation ($1));
2553 opt_enum_member_declarations
2555 | enum_member_declarations
2556 | enum_member_declarations COMMA
2558 lbag.AddLocation ($1, GetLocation ($2));
2562 enum_member_declarations
2563 : enum_member_declaration
2564 | enum_member_declarations COMMA enum_member_declaration
2566 lbag.AddLocation ($1, GetLocation ($2));
2571 enum_member_declaration
2572 : opt_attributes IDENTIFIER
2574 var lt = (Tokenizer.LocatedToken) $2;
2575 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2576 ((Enum) current_class).AddEnumMember (em);
2578 if (RootContext.Documentation != null) {
2579 em.DocComment = Lexer.consume_doc_comment ();
2580 Lexer.doc_state = XmlCommentState.Allowed;
2585 | opt_attributes IDENTIFIER
2587 ++lexer.parsing_block;
2588 if (RootContext.Documentation != null) {
2589 tmpComment = Lexer.consume_doc_comment ();
2590 Lexer.doc_state = XmlCommentState.NotAllowed;
2593 ASSIGN constant_expression
2595 --lexer.parsing_block;
2597 var lt = (Tokenizer.LocatedToken) $2;
2598 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2599 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2600 ((Enum) current_class).AddEnumMember (em);
2602 if (RootContext.Documentation != null)
2603 em.DocComment = ConsumeStoredComment ();
2609 delegate_declaration
2613 member_type type_declaration_name
2616 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2618 opt_formal_parameter_list CLOSE_PARENS
2620 valid_param_mod = 0;
2622 MemberName name = MakeName ((MemberName) $5);
2623 ParametersCompiled p = (ParametersCompiled) $8;
2625 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2626 (Modifiers) $2, name, p, (Attributes) $1);
2628 if (RootContext.Documentation != null) {
2629 del.DocComment = Lexer.consume_doc_comment ();
2630 Lexer.doc_state = XmlCommentState.Allowed;
2633 current_container.AddDelegate (del);
2634 current_delegate = del;
2635 lexer.ConstraintsParsing = true;
2637 opt_type_parameter_constraints_clauses
2639 lexer.ConstraintsParsing = false;
2643 current_delegate.SetParameterInfo ((List<Constraints>) $11);
2644 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2646 $$ = current_delegate;
2648 current_delegate = null;
2656 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2657 Report.FeatureIsNotSupported (GetLocation ($1), "nullable types");
2658 else if (RootContext.Version < LanguageVersion.ISO_2)
2659 Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2661 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2665 namespace_or_type_name
2667 | qualified_alias_member IDENTIFIER opt_type_argument_list
2669 var lt1 = (Tokenizer.LocatedToken) $1;
2670 var lt2 = (Tokenizer.LocatedToken) $2;
2672 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2678 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2680 var lt = (Tokenizer.LocatedToken) $3;
2681 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2682 lbag.AddLocation ($$, GetLocation ($2));
2687 : IDENTIFIER opt_type_argument_list
2689 var lt = (Tokenizer.LocatedToken) $1;
2690 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2695 // Generics arguments (any type, without attributes)
2697 opt_type_argument_list
2699 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2701 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2702 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
2703 else if (RootContext.Version < LanguageVersion.ISO_2)
2704 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2708 | OP_GENERICS_LT error
2710 Error_TypeExpected (lexer.Location);
2711 $$ = new TypeArguments ();
2718 TypeArguments type_args = new TypeArguments ();
2719 type_args.Add ((FullNamedExpression) $1);
2722 | type_arguments COMMA type
2724 TypeArguments type_args = (TypeArguments) $1;
2725 type_args.Add ((FullNamedExpression) $3);
2731 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2733 type_declaration_name
2736 lexer.parsing_generic_declaration = true;
2738 opt_type_parameter_list
2740 lexer.parsing_generic_declaration = false;
2741 var lt = (Tokenizer.LocatedToken) $1;
2742 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2746 member_declaration_name
2747 : method_declaration_name
2749 MemberName mn = (MemberName)$1;
2750 if (mn.TypeArguments != null)
2751 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2752 mn.GetSignatureForError ()));
2756 method_declaration_name
2757 : type_declaration_name
2758 | explicit_interface IDENTIFIER opt_type_parameter_list
2760 lexer.parsing_generic_declaration = false;
2761 var lt = (Tokenizer.LocatedToken) $2;
2762 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2766 indexer_declaration_name
2769 lexer.parsing_generic_declaration = false;
2770 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2772 | explicit_interface THIS
2774 lexer.parsing_generic_declaration = false;
2775 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2780 : IDENTIFIER opt_type_argument_list DOT
2782 var lt = (Tokenizer.LocatedToken) $1;
2783 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2784 lbag.AddLocation ($$, GetLocation ($3));
2786 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2788 var lt1 = (Tokenizer.LocatedToken) $1;
2789 var lt2 = (Tokenizer.LocatedToken) $2;
2791 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2792 lbag.AddLocation ($$, GetLocation ($4));
2794 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2796 var lt = (Tokenizer.LocatedToken) $2;
2797 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2798 lbag.AddLocation ($$, GetLocation ($4));
2802 opt_type_parameter_list
2804 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2806 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2807 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
2808 else if (RootContext.Version < LanguageVersion.ISO_2)
2809 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2812 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2819 TypeArguments type_args = new TypeArguments ();
2820 type_args.Add ((FullNamedExpression)$1);
2823 | type_parameters COMMA type_parameter
2825 TypeArguments type_args = (TypeArguments) $1;
2826 type_args.Add ((FullNamedExpression)$3);
2828 lbag.AddLocation ($3, GetLocation ($3));
2833 : opt_attributes opt_type_parameter_variance IDENTIFIER
2835 var lt = (Tokenizer.LocatedToken)$3;
2836 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2840 if (GetTokenName (yyToken) == "type")
2841 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2843 Error_SyntaxError (yyToken);
2845 $$ = new TypeParameterName ("", null, lexer.Location);
2850 // All types where void is allowed
2853 : type_expression_or_array
2856 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2863 lexer.parsing_generic_declaration = true;
2868 // A type which does not allow `void' to be used
2871 : type_expression_or_array
2874 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2875 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2883 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2884 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2889 : type_expression_or_array
2892 Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2893 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2897 type_expression_or_array
2899 | type_expression rank_specifiers
2901 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2906 : namespace_or_type_name opt_nullable
2908 MemberName name = (MemberName) $1;
2911 $$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
2913 if (name.Left == null && name.Name == "var")
2914 $$ = new VarExpr (name.Location);
2916 $$ = name.GetTypeExpression ();
2919 | namespace_or_type_name pointer_stars
2921 $$ = new ComposedCast (((MemberName) $1).GetTypeExpression (), (ComposedTypeSpecifier) $2);
2923 | builtin_types opt_nullable
2926 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2928 | builtin_types pointer_stars
2930 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2932 | VOID pointer_stars
2934 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2941 var types = new List<FullNamedExpression> (2);
2942 types.Add ((FullNamedExpression) $1);
2945 | type_list COMMA base_type_name
2947 var types = (List<FullNamedExpression>) $1;
2948 types.Add ((FullNamedExpression) $3);
2956 if ($1 is ComposedCast) {
2957 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2963 Error_TypeExpected (lexer.Location);
2969 * replaces all the productions for isolating the various
2970 * simple types, but we need this to reuse it easily in variable_type
2973 : OBJECT { $$ = new TypeExpression (TypeManager.object_type, GetLocation ($1)); }
2974 | STRING { $$ = new TypeExpression (TypeManager.string_type, GetLocation ($1)); }
2975 | BOOL { $$ = new TypeExpression (TypeManager.bool_type, GetLocation ($1)); }
2976 | DECIMAL { $$ = new TypeExpression (TypeManager.decimal_type, GetLocation ($1)); }
2977 | FLOAT { $$ = new TypeExpression (TypeManager.float_type, GetLocation ($1)); }
2978 | DOUBLE { $$ = new TypeExpression (TypeManager.double_type, GetLocation ($1)); }
2983 : SBYTE { $$ = new TypeExpression (TypeManager.sbyte_type, GetLocation ($1)); }
2984 | BYTE { $$ = new TypeExpression (TypeManager.byte_type, GetLocation ($1)); }
2985 | SHORT { $$ = new TypeExpression (TypeManager.short_type, GetLocation ($1)); }
2986 | USHORT { $$ = new TypeExpression (TypeManager.ushort_type, GetLocation ($1)); }
2987 | INT { $$ = new TypeExpression (TypeManager.int32_type, GetLocation ($1)); }
2988 | UINT { $$ = new TypeExpression (TypeManager.uint32_type, GetLocation ($1)); }
2989 | LONG { $$ = new TypeExpression (TypeManager.int64_type, GetLocation ($1)); }
2990 | ULONG { $$ = new TypeExpression (TypeManager.uint64_type, GetLocation ($1)); }
2991 | CHAR { $$ = new TypeExpression (TypeManager.char_type, GetLocation ($1)); }
2995 // Expressions, section 7.5
3000 : primary_expression_or_type
3002 | array_creation_expression
3003 | parenthesized_expression
3004 | default_value_expression
3005 | invocation_expression
3009 | post_increment_expression
3010 | post_decrement_expression
3011 | object_or_delegate_creation_expression
3012 | anonymous_type_expression
3015 | checked_expression
3016 | unchecked_expression
3017 | pointer_member_access
3018 | anonymous_method_expression
3021 primary_expression_or_type
3022 : IDENTIFIER opt_type_argument_list
3024 var lt = (Tokenizer.LocatedToken) $1;
3025 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3027 | IDENTIFIER GENERATE_COMPLETION {
3028 var lt = (Tokenizer.LocatedToken) $1;
3029 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3037 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3041 : TRUE { $$ = new BoolLiteral (true, GetLocation ($1)); }
3042 | FALSE { $$ = new BoolLiteral (false, GetLocation ($1)); }
3047 // Here is the trick, tokenizer may think that parens is a special but
3048 // parser is interested in open parens only, so we merge them.
3049 // Consider: if (a)foo ();
3057 // Use this production to accept closing parenthesis or
3058 // performing completion
3062 | COMPLETE_COMPLETION
3066 parenthesized_expression
3067 : OPEN_PARENS expression CLOSE_PARENS
3069 $$ = new ParenthesizedExpression ((Expression) $2);
3070 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3072 | OPEN_PARENS expression COMPLETE_COMPLETION
3074 $$ = new ParenthesizedExpression ((Expression) $2);
3079 : primary_expression DOT IDENTIFIER opt_type_argument_list
3081 var lt = (Tokenizer.LocatedToken) $3;
3082 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3083 lbag.AddLocation ($$, GetLocation ($2));
3085 | builtin_types DOT IDENTIFIER opt_type_argument_list
3087 var lt = (Tokenizer.LocatedToken) $3;
3088 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3089 lbag.AddLocation ($$, GetLocation ($2));
3091 | BASE DOT IDENTIFIER opt_type_argument_list
3093 var lt = (Tokenizer.LocatedToken) $3;
3094 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3095 lbag.AddLocation ($$, GetLocation ($2));
3097 | qualified_alias_member IDENTIFIER opt_type_argument_list
3099 var lt1 = (Tokenizer.LocatedToken) $1;
3100 var lt2 = (Tokenizer.LocatedToken) $2;
3102 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3104 | primary_expression DOT GENERATE_COMPLETION {
3105 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3107 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3108 var lt = (Tokenizer.LocatedToken) $3;
3109 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3111 | builtin_types DOT GENERATE_COMPLETION
3113 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3115 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3116 var lt = (Tokenizer.LocatedToken) $3;
3117 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3121 invocation_expression
3122 : primary_expression open_parens_any opt_argument_list close_parens
3124 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3125 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3129 opt_object_or_collection_initializer
3130 : /* empty */ { $$ = null; }
3131 | object_or_collection_initializer
3134 object_or_collection_initializer
3135 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3138 $$ = CollectionOrObjectInitializers.Empty;
3141 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3142 lbag.AddLocation ($$, GetLocation ($3));
3145 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3147 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3148 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3152 opt_member_initializer_list
3153 : /* empty */ { $$ = null; }
3154 | member_initializer_list
3160 member_initializer_list
3161 : member_initializer
3163 var a = new List<Expression> ();
3164 a.Add ((Expression) $1);
3167 | member_initializer_list COMMA member_initializer
3169 var a = (List<Expression>)$1;
3170 a.Add ((Expression) $3);
3173 | member_initializer_list error {
3174 Error_SyntaxError (yyToken);
3180 : IDENTIFIER ASSIGN initializer_value
3182 var lt = (Tokenizer.LocatedToken) $1;
3183 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3184 lbag.AddLocation ($$, GetLocation ($2));
3186 | GENERATE_COMPLETION
3188 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3190 | non_assignment_expression opt_COMPLETE_COMPLETION {
3191 CompletionSimpleName csn = $1 as CompletionSimpleName;
3193 $$ = new CollectionElementInitializer ((Expression)$1);
3195 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3197 | OPEN_BRACE expression_list CLOSE_BRACE
3202 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3204 | OPEN_BRACE CLOSE_BRACE
3206 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3213 | object_or_collection_initializer
3217 : /* empty */ { $$ = null; }
3222 : argument_or_named_argument
3224 Arguments list = new Arguments (4);
3225 list.Add ((Argument) $1);
3228 | argument_list COMMA argument
3230 Arguments list = (Arguments) $1;
3231 if (list [list.Count - 1] is NamedArgument)
3232 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3234 list.Add ((Argument) $3);
3237 | argument_list COMMA named_argument
3239 Arguments list = (Arguments) $1;
3240 NamedArgument a = (NamedArgument) $3;
3241 for (int i = 0; i < list.Count; ++i) {
3242 NamedArgument na = list [i] as NamedArgument;
3243 if (na != null && na.Name == a.Name)
3244 Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3251 | argument_list COMMA
3253 Report.Error (839, GetLocation ($2), "An argument is missing");
3258 Report.Error (839, GetLocation ($1), "An argument is missing");
3266 $$ = new Argument ((Expression) $1);
3268 | non_simple_argument
3271 argument_or_named_argument
3277 : REF variable_reference
3279 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3280 lbag.AddLocation ($$, GetLocation ($1));
3282 | OUT variable_reference
3284 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3285 lbag.AddLocation ($$, GetLocation ($1));
3287 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3289 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3290 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3292 | ARGLIST OPEN_PARENS CLOSE_PARENS
3294 $$ = new Argument (new Arglist (GetLocation ($1)));
3295 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3299 $$ = new Argument (new ArglistAccess (GetLocation ($1)));
3308 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3310 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3311 lbag.AddLocation ($$, GetLocation ($4));
3318 var list = new List<Expression> (4);
3319 list.Add ((Expression) $1);
3322 | expression_list COMMA expression
3324 var list = (List<Expression>) $1;
3325 list.Add ((Expression) $3);
3328 | expression_list error {
3329 Error_SyntaxError (yyToken);
3334 expression_list_arguments
3335 : expression_list_argument
3337 Arguments args = new Arguments (4);
3338 args.Add ((Argument) $1);
3341 | expression_list_arguments COMMA expression_list_argument
3343 Arguments args = (Arguments) $1;
3344 args.Add ((Argument) $3);
3349 expression_list_argument
3352 $$ = new Argument ((Expression) $1);
3360 $$ = new This (GetLocation ($1));
3365 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3367 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3368 lbag.AddLocation ($$, GetLocation ($4));
3370 | BASE OPEN_BRACKET error
3372 Error_SyntaxError (yyToken);
3373 $$ = new ElementAccess (null, null, GetLocation ($2));
3377 post_increment_expression
3378 : primary_expression OP_INC
3380 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3384 post_decrement_expression
3385 : primary_expression OP_DEC
3387 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3391 object_or_delegate_creation_expression
3392 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3395 if (RootContext.Version <= LanguageVersion.ISO_2)
3396 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3398 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3400 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3403 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3405 | NEW new_expr_type object_or_collection_initializer
3407 if (RootContext.Version <= LanguageVersion.ISO_2)
3408 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3410 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3414 array_creation_expression
3415 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3417 opt_array_initializer
3419 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3420 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3421 Next = (ComposedTypeSpecifier) $6
3422 }, (ArrayInitializer) $7, GetLocation ($1));
3423 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3425 | NEW new_expr_type rank_specifiers opt_array_initializer
3428 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3430 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3432 | NEW rank_specifiers array_initializer
3434 if (RootContext.Version <= LanguageVersion.ISO_2)
3435 Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3437 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3439 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3441 Report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3442 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3444 | NEW new_expr_type error
3446 Error_SyntaxError (1526, yyToken, "Unexpected symbol");
3447 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3453 ++lexer.parsing_type;
3457 --lexer.parsing_type;
3462 anonymous_type_expression
3463 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3465 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3466 Report.FeatureIsNotSupported (GetLocation ($1), "anonymous types");
3467 else if (RootContext.Version <= LanguageVersion.ISO_2)
3468 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3470 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3472 // TODO: lbag comma location
3473 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3477 anonymous_type_parameters_opt_comma
3478 : anonymous_type_parameters_opt
3479 | anonymous_type_parameters COMMA
3482 anonymous_type_parameters_opt
3484 | anonymous_type_parameters
3487 anonymous_type_parameters
3488 : anonymous_type_parameter
3490 var a = new List<AnonymousTypeParameter> (4);
3491 a.Add ((AnonymousTypeParameter) $1);
3494 | anonymous_type_parameters COMMA anonymous_type_parameter
3496 var a = (List<AnonymousTypeParameter>) $1;
3497 a.Add ((AnonymousTypeParameter) $3);
3502 anonymous_type_parameter
3503 : IDENTIFIER ASSIGN variable_initializer
3505 var lt = (Tokenizer.LocatedToken)$1;
3506 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3507 lbag.AddLocation ($$, GetLocation ($2));
3511 var lt = (Tokenizer.LocatedToken)$1;
3512 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3513 lt.Value, lt.Location);
3517 MemberAccess ma = (MemberAccess) $1;
3518 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3522 Report.Error (746, lexer.Location,
3523 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3535 | rank_specifier rank_specifiers
3537 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3543 : OPEN_BRACKET CLOSE_BRACKET
3545 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3547 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3549 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3558 | dim_separators COMMA
3560 $$ = ((int) $1) + 1;
3564 opt_array_initializer
3576 : OPEN_BRACE CLOSE_BRACE
3578 var ai = new ArrayInitializer (0, GetLocation ($1));
3579 ai.VariableDeclaration = current_variable;
3580 lbag.AddLocation (ai, GetLocation ($2));
3583 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3585 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3586 ai.VariableDeclaration = current_variable;
3587 lbag.AddLocation (ai, GetLocation ($3));
3592 variable_initializer_list
3593 : variable_initializer
3595 var list = new List<Expression> (4);
3596 list.Add ((Expression) $1);
3599 | variable_initializer_list COMMA variable_initializer
3601 var list = (List<Expression>) $1;
3602 list.Add ((Expression) $3);
3607 Error_SyntaxError (yyToken);
3608 $$ = new List<Expression> ();
3615 lexer.TypeOfParsing = true;
3617 open_parens_any typeof_type_expression CLOSE_PARENS
3619 lexer.TypeOfParsing = false;
3620 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3621 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3625 typeof_type_expression
3630 Error_TypeExpected (lexer.Location);
3636 : IDENTIFIER generic_dimension
3638 var lt = (Tokenizer.LocatedToken) $1;
3640 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3642 | qualified_alias_member IDENTIFIER generic_dimension
3644 var lt1 = (Tokenizer.LocatedToken) $1;
3645 var lt2 = (Tokenizer.LocatedToken) $2;
3647 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3649 | unbound_type_name DOT IDENTIFIER
3651 var lt = (Tokenizer.LocatedToken) $3;
3653 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3655 | unbound_type_name DOT IDENTIFIER generic_dimension
3657 var lt = (Tokenizer.LocatedToken) $3;
3659 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3661 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3663 var te = ((MemberName) $1).GetTypeExpression ();
3664 if (te.HasTypeArguments)
3665 Error_TypeExpected (GetLocation ($4));
3667 var lt = (Tokenizer.LocatedToken) $3;
3668 $$ = new MemberAccess (te, lt.Value, (int) $4, lt.Location);
3675 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3676 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
3677 else if (RootContext.Version < LanguageVersion.ISO_2)
3678 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
3684 qualified_alias_member
3685 : IDENTIFIER DOUBLE_COLON
3687 var lt = (Tokenizer.LocatedToken) $1;
3688 if (RootContext.Version == LanguageVersion.ISO_1)
3689 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3696 : SIZEOF open_parens_any type CLOSE_PARENS
3698 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3699 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3704 : CHECKED open_parens_any expression CLOSE_PARENS
3706 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3707 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3711 unchecked_expression
3712 : UNCHECKED open_parens_any expression CLOSE_PARENS
3714 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3715 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3719 pointer_member_access
3720 : primary_expression OP_PTR IDENTIFIER
3722 var lt = (Tokenizer.LocatedToken) $3;
3723 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, lt.Location);
3727 anonymous_method_expression
3728 : DELEGATE opt_anonymous_method_signature
3730 start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1));
3734 $$ = end_anonymous ((ParametersBlock) $4);
3738 opt_anonymous_method_signature
3741 $$ = ParametersCompiled.Undefined;
3743 | anonymous_method_signature
3746 anonymous_method_signature
3749 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3751 opt_formal_parameter_list CLOSE_PARENS
3753 valid_param_mod = 0;
3758 default_value_expression
3759 : DEFAULT open_parens_any type CLOSE_PARENS
3761 if (RootContext.Version < LanguageVersion.ISO_2)
3762 Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3764 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3765 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3770 : primary_expression
3771 | BANG prefixed_unary_expression
3773 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3775 | TILDE prefixed_unary_expression
3777 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3783 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3785 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3786 lbag.AddLocation ($$, GetLocation ($3));
3788 | OPEN_PARENS builtin_types CLOSE_PARENS prefixed_unary_expression
3790 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3791 lbag.AddLocation ($$, GetLocation ($3));
3796 // The idea to split this out is from Rhys' grammar
3797 // to solve the problem with casts.
3799 prefixed_unary_expression
3801 | PLUS prefixed_unary_expression
3803 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3805 | MINUS prefixed_unary_expression
3807 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3809 | OP_INC prefixed_unary_expression
3811 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3813 | OP_DEC prefixed_unary_expression
3815 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3817 | STAR prefixed_unary_expression
3819 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3821 | BITWISE_AND prefixed_unary_expression
3823 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3827 multiplicative_expression
3828 : prefixed_unary_expression
3829 | multiplicative_expression STAR prefixed_unary_expression
3831 $$ = new Binary (Binary.Operator.Multiply,
3832 (Expression) $1, (Expression) $3, GetLocation ($2));
3834 | multiplicative_expression DIV prefixed_unary_expression
3836 $$ = new Binary (Binary.Operator.Division,
3837 (Expression) $1, (Expression) $3, GetLocation ($2));
3839 | multiplicative_expression PERCENT prefixed_unary_expression
3841 $$ = new Binary (Binary.Operator.Modulus,
3842 (Expression) $1, (Expression) $3, GetLocation ($2));
3847 : multiplicative_expression
3848 | additive_expression PLUS multiplicative_expression
3850 $$ = new Binary (Binary.Operator.Addition,
3851 (Expression) $1, (Expression) $3, GetLocation ($2));
3853 | additive_expression MINUS multiplicative_expression
3855 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3857 | parenthesized_expression MINUS multiplicative_expression
3859 // Shift/Reduce conflict
3860 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3862 | additive_expression AS type
3864 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3866 | additive_expression IS type
3868 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3873 : additive_expression
3874 | shift_expression OP_SHIFT_LEFT additive_expression
3876 $$ = new Binary (Binary.Operator.LeftShift,
3877 (Expression) $1, (Expression) $3, GetLocation ($2));
3879 | shift_expression OP_SHIFT_RIGHT additive_expression
3881 $$ = new Binary (Binary.Operator.RightShift,
3882 (Expression) $1, (Expression) $3, GetLocation ($2));
3886 relational_expression
3888 | relational_expression OP_LT shift_expression
3890 $$ = new Binary (Binary.Operator.LessThan,
3891 (Expression) $1, (Expression) $3, GetLocation ($2));
3893 | relational_expression OP_GT shift_expression
3895 $$ = new Binary (Binary.Operator.GreaterThan,
3896 (Expression) $1, (Expression) $3, GetLocation ($2));
3898 | relational_expression OP_LE shift_expression
3900 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3901 (Expression) $1, (Expression) $3, GetLocation ($2));
3903 | relational_expression OP_GE shift_expression
3905 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3906 (Expression) $1, (Expression) $3, GetLocation ($2));
3911 : relational_expression
3912 | equality_expression OP_EQ relational_expression
3914 $$ = new Binary (Binary.Operator.Equality,
3915 (Expression) $1, (Expression) $3, GetLocation ($2));
3917 | equality_expression OP_NE relational_expression
3919 $$ = new Binary (Binary.Operator.Inequality,
3920 (Expression) $1, (Expression) $3, GetLocation ($2));
3925 : equality_expression
3926 | and_expression BITWISE_AND equality_expression
3928 $$ = new Binary (Binary.Operator.BitwiseAnd,
3929 (Expression) $1, (Expression) $3, GetLocation ($2));
3933 exclusive_or_expression
3935 | exclusive_or_expression CARRET and_expression
3937 $$ = new Binary (Binary.Operator.ExclusiveOr,
3938 (Expression) $1, (Expression) $3, GetLocation ($2));
3942 inclusive_or_expression
3943 : exclusive_or_expression
3944 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3946 $$ = new Binary (Binary.Operator.BitwiseOr,
3947 (Expression) $1, (Expression) $3, GetLocation ($2));
3951 conditional_and_expression
3952 : inclusive_or_expression
3953 | conditional_and_expression OP_AND inclusive_or_expression
3955 $$ = new Binary (Binary.Operator.LogicalAnd,
3956 (Expression) $1, (Expression) $3, GetLocation ($2));
3960 conditional_or_expression
3961 : conditional_and_expression
3962 | conditional_or_expression OP_OR conditional_and_expression
3964 $$ = new Binary (Binary.Operator.LogicalOr,
3965 (Expression) $1, (Expression) $3, GetLocation ($2));
3969 null_coalescing_expression
3970 : conditional_or_expression
3971 | conditional_or_expression OP_COALESCING null_coalescing_expression
3973 if (RootContext.Version < LanguageVersion.ISO_2)
3974 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3976 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3980 conditional_expression
3981 : null_coalescing_expression
3982 | null_coalescing_expression INTERR expression COLON expression
3984 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3985 lbag.AddLocation ($$, GetLocation ($4));
3989 assignment_expression
3990 : prefixed_unary_expression ASSIGN expression
3992 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3994 | prefixed_unary_expression OP_MULT_ASSIGN expression
3996 $$ = new CompoundAssign (
3997 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
3999 | prefixed_unary_expression OP_DIV_ASSIGN expression
4001 $$ = new CompoundAssign (
4002 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
4004 | prefixed_unary_expression OP_MOD_ASSIGN expression
4006 $$ = new CompoundAssign (
4007 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
4009 | prefixed_unary_expression OP_ADD_ASSIGN expression
4011 $$ = new CompoundAssign (
4012 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
4014 | prefixed_unary_expression OP_SUB_ASSIGN expression
4016 $$ = new CompoundAssign (
4017 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4019 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4021 $$ = new CompoundAssign (
4022 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4024 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4026 $$ = new CompoundAssign (
4027 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4029 | prefixed_unary_expression OP_AND_ASSIGN expression
4031 $$ = new CompoundAssign (
4032 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4034 | prefixed_unary_expression OP_OR_ASSIGN expression
4036 $$ = new CompoundAssign (
4037 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4039 | prefixed_unary_expression OP_XOR_ASSIGN expression
4041 $$ = new CompoundAssign (
4042 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4046 lambda_parameter_list
4049 var pars = new List<Parameter> (4);
4050 pars.Add ((Parameter) $1);
4054 | lambda_parameter_list COMMA lambda_parameter
4056 var pars = (List<Parameter>) $1;
4057 Parameter p = (Parameter)$3;
4058 if (pars[0].GetType () != p.GetType ()) {
4059 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4068 : parameter_modifier parameter_type IDENTIFIER
4070 var lt = (Tokenizer.LocatedToken) $3;
4072 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4074 | parameter_type IDENTIFIER
4076 var lt = (Tokenizer.LocatedToken) $2;
4078 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4082 var lt = (Tokenizer.LocatedToken) $1;
4083 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4087 opt_lambda_parameter_list
4088 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4089 | lambda_parameter_list {
4090 var pars_list = (List<Parameter>) $1;
4091 $$ = new ParametersCompiled (pars_list.ToArray ());
4095 lambda_expression_body
4097 start_block (lexer.Location);
4101 Block b = end_block (lexer.Location);
4102 b.AddStatement (new ContextualReturn ((Expression) $2));
4114 var lt = (Tokenizer.LocatedToken) $1;
4115 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4116 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
4118 lambda_expression_body
4120 $$ = end_anonymous ((ParametersBlock) $4);
4121 lbag.AddLocation ($$, GetLocation ($2));
4123 | OPEN_PARENS_LAMBDA
4125 if (RootContext.Version <= LanguageVersion.ISO_2)
4126 Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
4128 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4130 opt_lambda_parameter_list CLOSE_PARENS ARROW
4132 valid_param_mod = 0;
4133 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4135 lambda_expression_body
4137 $$ = end_anonymous ((ParametersBlock) $7);
4138 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
4143 : assignment_expression
4144 | non_assignment_expression
4147 non_assignment_expression
4148 : conditional_expression
4160 $$ = new BooleanExpression ((Expression) $1);
4173 lexer.ConstraintsParsing = true;
4175 type_declaration_name
4177 MemberName name = MakeName ((MemberName) $6);
4178 push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
4181 opt_type_parameter_constraints_clauses
4183 lexer.ConstraintsParsing = false;
4185 current_class.SetParameterInfo ((List<Constraints>) $9);
4186 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
4188 if (RootContext.Documentation != null) {
4189 current_container.DocComment = Lexer.consume_doc_comment ();
4190 Lexer.doc_state = XmlCommentState.Allowed;
4193 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4195 --lexer.parsing_declaration;
4196 if (RootContext.Documentation != null)
4197 Lexer.doc_state = XmlCommentState.Allowed;
4201 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4202 $$ = pop_current_class ();
4210 { $$ = $1; } // location
4216 mod_locations = null;
4224 | modifiers modifier
4226 var m1 = (Modifiers) $1;
4227 var m2 = (Modifiers) $2;
4229 if ((m1 & m2) != 0) {
4230 Report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4231 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4232 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4233 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4234 Report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4235 "More than one protection modifier specified");
4246 StoreModifierLocation ($$, GetLocation ($1));
4248 if (current_container == RootContext.ToplevelTypes)
4249 Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4253 $$ = Modifiers.PUBLIC;
4254 StoreModifierLocation ($$, GetLocation ($1));
4258 $$ = Modifiers.PROTECTED;
4259 StoreModifierLocation ($$, GetLocation ($1));
4263 $$ = Modifiers.INTERNAL;
4264 StoreModifierLocation ($$, GetLocation ($1));
4268 $$ = Modifiers.PRIVATE;
4269 StoreModifierLocation ($$, GetLocation ($1));
4273 $$ = Modifiers.ABSTRACT;
4274 StoreModifierLocation ($$, GetLocation ($1));
4278 $$ = Modifiers.SEALED;
4279 StoreModifierLocation ($$, GetLocation ($1));
4283 $$ = Modifiers.STATIC;
4284 StoreModifierLocation ($$, GetLocation ($1));
4288 $$ = Modifiers.READONLY;
4289 StoreModifierLocation ($$, GetLocation ($1));
4293 $$ = Modifiers.VIRTUAL;
4294 StoreModifierLocation ($$, GetLocation ($1));
4298 $$ = Modifiers.OVERRIDE;
4299 StoreModifierLocation ($$, GetLocation ($1));
4303 $$ = Modifiers.EXTERN;
4304 StoreModifierLocation ($$, GetLocation ($1));
4308 $$ = Modifiers.VOLATILE;
4309 StoreModifierLocation ($$, GetLocation ($1));
4313 $$ = Modifiers.UNSAFE;
4314 StoreModifierLocation ($$, GetLocation ($1));
4315 if (!RootContext.Unsafe)
4316 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4324 current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
4328 opt_type_parameter_constraints_clauses
4330 | type_parameter_constraints_clauses
4336 type_parameter_constraints_clauses
4337 : type_parameter_constraints_clause
4339 var constraints = new List<Constraints> (1);
4340 constraints.Add ((Constraints) $1);
4343 | type_parameter_constraints_clauses type_parameter_constraints_clause
4345 var constraints = (List<Constraints>) $1;
4346 Constraints new_constraint = (Constraints)$2;
4348 foreach (Constraints c in constraints) {
4349 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4350 Report.Error (409, new_constraint.Location,
4351 "A constraint clause has already been specified for type parameter `{0}'",
4352 new_constraint.TypeParameter.Value);
4356 constraints.Add (new_constraint);
4361 type_parameter_constraints_clause
4362 : WHERE IDENTIFIER COLON type_parameter_constraints
4364 var lt = (Tokenizer.LocatedToken) $2;
4365 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4369 type_parameter_constraints
4370 : type_parameter_constraint
4372 var constraints = new List<FullNamedExpression> (1);
4373 constraints.Add ((FullNamedExpression) $1);
4376 | type_parameter_constraints COMMA type_parameter_constraint
4378 var constraints = (List<FullNamedExpression>) $1;
4379 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4380 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4381 Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4384 prev = $3 as SpecialContraintExpr;
4386 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4387 Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4389 prev = constraints [0] as SpecialContraintExpr;
4390 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4391 Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4396 constraints.Add ((FullNamedExpression) $3);
4401 type_parameter_constraint
4404 if ($1 is ComposedCast)
4405 Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4409 | NEW OPEN_PARENS CLOSE_PARENS
4411 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4412 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4416 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4420 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4424 opt_type_parameter_variance
4429 | type_parameter_variance
4431 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
4432 Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
4433 else if (RootContext.Version <= LanguageVersion.V_3)
4434 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4440 type_parameter_variance
4443 $$ = Variance.Covariant;
4447 $$ = Variance.Contravariant;
4456 // A block is "contained" on the following places:
4458 // property_declaration as part of the accessor body (get/set)
4459 // operator_declaration
4460 // constructor_declaration
4461 // destructor_declaration
4462 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4467 ++lexer.parsing_block;
4468 start_block (GetLocation ($1));
4470 opt_statement_list block_end
4479 --lexer.parsing_block;
4480 $$ = end_block (GetLocation ($1));
4482 | COMPLETE_COMPLETION
4484 --lexer.parsing_block;
4485 $$ = end_block (lexer.Location);
4493 ++lexer.parsing_block;
4494 current_block.StartLocation = GetLocation ($1);
4496 opt_statement_list CLOSE_BRACE
4498 --lexer.parsing_block;
4499 $$ = end_block (GetLocation ($4));
4510 | statement_list statement
4514 : block_variable_declaration
4516 current_block.AddStatement ((Statement) $1);
4518 | valid_declaration_statement
4520 current_block.AddStatement ((Statement) $1);
4526 // The interactive_statement and its derivatives are only
4527 // used to provide a special version of `expression_statement'
4528 // that has a side effect of assigning the expression to
4531 interactive_statement_list
4532 : interactive_statement
4533 | interactive_statement_list interactive_statement
4536 interactive_statement
4537 : block_variable_declaration
4539 current_block.AddStatement ((Statement) $1);
4541 | interactive_valid_declaration_statement
4543 current_block.AddStatement ((Statement) $1);
4548 valid_declaration_statement
4551 | expression_statement
4552 | selection_statement
4553 | iteration_statement
4557 | unchecked_statement
4564 interactive_valid_declaration_statement
4567 | interactive_expression_statement
4568 | selection_statement
4569 | iteration_statement
4573 | unchecked_statement
4581 : valid_declaration_statement
4582 | block_variable_declaration
4584 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4589 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4597 $$ = new EmptyStatement (GetLocation ($1));
4604 var lt = (Tokenizer.LocatedToken) $1;
4605 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4607 if (current_block.AddLabel (labeled))
4608 current_block.AddStatement (labeled);
4614 : variable_type_simple
4615 | variable_type_simple rank_specifiers
4618 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4620 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4625 * The following is from Rhys' grammar:
4626 * > Types in local variable declarations must be recognized as
4627 * > expressions to prevent reduce/reduce errors in the grammar.
4628 * > The expressions are converted into types during semantic analysis.
4630 variable_type_simple
4631 : primary_expression_or_type opt_nullable
4633 // Ok, the above "primary_expression" is there to get rid of
4634 // both reduce/reduce and shift/reduces in the grammar, it should
4635 // really just be "type_name". If you use type_name, a reduce/reduce
4636 // creeps up. If you use namespace_or_type_name (which is all we need
4637 // really) two shift/reduces appear.
4640 // So the super-trick is that primary_expression
4641 // can only be either a SimpleName or a MemberAccess.
4642 // The MemberAccess case arises when you have a fully qualified type-name like :
4644 // SimpleName is when you have
4647 Expression expr = (Expression) $1;
4649 SimpleName sn = expr as SimpleName;
4650 if (sn != null && sn.Name == "var")
4651 $$ = new VarExpr (sn.Location);
4654 } else if (expr is ATypeNameExpression) {
4655 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4657 Error_ExpectingTypeName (expr);
4661 | primary_expression_or_type pointer_stars
4663 ATypeNameExpression expr = $1 as ATypeNameExpression;
4666 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4668 Error_ExpectingTypeName ((Expression)$1);
4672 | builtin_types opt_nullable
4677 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4679 | builtin_types pointer_stars
4681 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4683 | VOID pointer_stars
4685 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4689 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
4690 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
4696 | pointer_star pointer_stars
4698 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4706 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4710 block_variable_declaration
4711 : variable_type IDENTIFIER
4713 var lt = (Tokenizer.LocatedToken) $2;
4714 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4715 current_block.AddLocalName (li);
4716 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4718 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4720 $$ = current_variable;
4721 current_variable = null;
4722 lbag.AddLocation ($$, GetLocation ($6));
4724 | CONST variable_type IDENTIFIER
4726 var lt = (Tokenizer.LocatedToken) $3;
4727 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4728 current_block.AddLocalName (li);
4729 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4731 const_variable_initializer opt_const_declarators SEMICOLON
4733 $$ = current_variable;
4734 current_variable = null;
4735 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4739 opt_local_variable_initializer
4741 | ASSIGN block_variable_initializer
4743 current_variable.Initializer = (Expression) $2;
4748 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4749 Report.Error (650, lexer.Location,
4750 "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");
4752 Error_SyntaxError (yyToken);
4757 opt_variable_declarators
4759 | variable_declarators
4762 variable_declarators
4763 : variable_declarator
4764 | variable_declarators variable_declarator
4770 var lt = (Tokenizer.LocatedToken) $2;
4771 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4772 var d = new BlockVariableDeclaration.Declarator (li, null);
4773 current_variable.AddDeclarator (d);
4774 current_block.AddLocalName (li);
4775 lbag.AddLocation (d, GetLocation ($1));
4777 | COMMA IDENTIFIER ASSIGN block_variable_initializer
4779 var lt = (Tokenizer.LocatedToken) $2;
4780 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4781 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4782 current_variable.AddDeclarator (d);
4783 current_block.AddLocalName (li);
4784 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4788 const_variable_initializer
4791 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
4793 | ASSIGN constant_initializer_expr
4795 current_variable.Initializer = (Expression) $2;
4799 opt_const_declarators
4806 | const_declarators const_declarator
4810 : COMMA IDENTIFIER ASSIGN constant_initializer_expr
4812 var lt = (Tokenizer.LocatedToken) $2;
4813 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4814 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4815 current_variable.AddDeclarator (d);
4816 current_block.AddLocalName (li);
4817 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4821 block_variable_initializer
4822 : variable_initializer
4823 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4825 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4826 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4830 $$ = new ArglistAccess (GetLocation ($1));
4832 | STACKALLOC simple_type
4834 Report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4835 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4839 expression_statement
4840 : statement_expression SEMICOLON
4843 lbag.AddStatement ($$, GetLocation ($2));
4845 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4848 interactive_expression_statement
4849 : interactive_statement_expression SEMICOLON { $$ = $1; }
4850 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4854 // We have to do the wrapping here and not in the case above,
4855 // because statement_expression is used for example in for_statement
4857 statement_expression
4860 ExpressionStatement s = $1 as ExpressionStatement;
4862 Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
4863 s = EmptyExpressionStatement.Instance;
4866 $$ = new StatementExpression (s);
4870 Error_SyntaxError (yyToken);
4875 interactive_statement_expression
4878 Expression expr = (Expression) $1;
4879 ExpressionStatement s;
4881 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4882 $$ = new StatementExpression (s);
4886 Error_SyntaxError (yyToken);
4887 $$ = new EmptyStatement (GetLocation ($1));
4897 : IF open_parens_any boolean_expression CLOSE_PARENS
4900 if ($5 is EmptyStatement)
4901 Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
4903 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4904 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4906 | IF open_parens_any boolean_expression CLOSE_PARENS
4907 embedded_statement ELSE embedded_statement
4909 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
4910 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4912 if ($5 is EmptyStatement)
4913 Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
4914 if ($7 is EmptyStatement)
4915 Report.Warning (642, 3, GetLocation ($7), "Possible mistaken empty statement");
4920 : SWITCH open_parens_any
4922 if (switch_stack == null)
4923 switch_stack = new Stack<Block> (2);
4924 switch_stack.Push (current_block);
4926 expression CLOSE_PARENS
4927 OPEN_BRACE opt_switch_sections CLOSE_BRACE
4929 $$ = new Switch ((Expression) $4, (List<SwitchSection>) $7, GetLocation ($1));
4930 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6), GetLocation ($8));
4932 current_block = (Block) switch_stack.Pop ();
4939 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4940 $$ = new List<SwitchSection> ();
4948 var sections = new List<SwitchSection> (4);
4950 sections.Add ((SwitchSection) $1);
4953 | switch_sections switch_section
4955 var sections = (List<SwitchSection>) $1;
4957 sections.Add ((SwitchSection) $2);
4965 current_block = current_block.CreateSwitchBlock (lexer.Location);
4969 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block.Explicit);
4976 var labels = new List<SwitchLabel> (4);
4978 labels.Add ((SwitchLabel) $1);
4981 | switch_labels switch_label
4983 var labels = (List<SwitchLabel>) ($1);
4984 labels.Add ((SwitchLabel) $2);
4991 : CASE constant_expression COLON
4993 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
4994 lbag.AddLocation ($$, GetLocation ($3));
4998 $$ = new SwitchLabel (null, GetLocation ($1));
5010 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5012 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5013 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5018 : DO embedded_statement
5019 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5021 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5022 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5027 : FOR open_parens_any
5029 start_block (GetLocation ($2));
5030 current_block.IsCompilerGenerated = true;
5032 opt_for_initializer SEMICOLON
5033 opt_for_condition SEMICOLON
5034 opt_for_iterator CLOSE_PARENS
5037 For f = new For ((Statement) $4, (BooleanExpression) $6, (Statement) $8, (Statement) $10, GetLocation ($1));
5038 current_block.AddStatement (f);
5040 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7), GetLocation ($9));
5042 $$ = end_block (GetLocation ($5));
5047 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5052 : variable_type IDENTIFIER
5054 var lt = (Tokenizer.LocatedToken) $2;
5055 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5056 current_block.AddLocalName (li);
5057 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5059 opt_local_variable_initializer opt_variable_declarators
5061 $$ = current_variable;
5062 current_variable = null;
5064 | statement_expression_list
5068 : /* empty */ { $$ = null; }
5069 | boolean_expression
5073 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5078 : statement_expression_list
5081 statement_expression_list
5082 : statement_expression
5083 | statement_expression_list COMMA statement_expression
5085 var sl = $1 as StatementList;
5087 sl = new StatementList ((Statement) $1, (Statement) $3);
5089 sl.Add ((Statement) $3);
5091 lbag.AddStatement (sl, GetLocation ($2));
5097 : FOREACH open_parens_any type IN expression CLOSE_PARENS
5099 Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5102 | FOREACH open_parens_any type IDENTIFIER IN expression CLOSE_PARENS
5104 start_block (GetLocation ($2));
5105 current_block.IsCompilerGenerated = true;
5107 var lt = (Tokenizer.LocatedToken) $4;
5108 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5109 current_block.AddLocalName (li);
5114 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, GetLocation ($1));
5115 current_block.AddStatement (f);
5117 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5118 $$ = end_block (GetLocation ($7));
5124 | continue_statement
5134 $$ = new Break (GetLocation ($1));
5135 lbag.AddStatement ($$, GetLocation ($2));
5140 : CONTINUE SEMICOLON
5142 $$ = new Continue (GetLocation ($1));
5143 lbag.AddStatement ($$, GetLocation ($2));
5148 : GOTO IDENTIFIER SEMICOLON
5150 var lt = (Tokenizer.LocatedToken) $2;
5151 $$ = new Goto (lt.Value, lt.Location);
5152 lbag.AddStatement ($$, GetLocation ($1), GetLocation ($3));
5154 | GOTO CASE constant_expression SEMICOLON
5156 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5157 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5159 | GOTO DEFAULT SEMICOLON
5161 $$ = new GotoDefault (GetLocation ($1));
5162 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5167 : RETURN opt_expression SEMICOLON
5169 $$ = new Return ((Expression) $2, GetLocation ($1));
5170 lbag.AddStatement ($$, GetLocation ($3));
5175 : THROW opt_expression SEMICOLON
5177 $$ = new Throw ((Expression) $2, GetLocation ($1));
5178 lbag.AddStatement ($$, GetLocation ($3));
5183 : IDENTIFIER RETURN opt_expression SEMICOLON
5185 var lt = (Tokenizer.LocatedToken) $1;
5186 string s = lt.Value;
5188 Report.Error (1003, lt.Location, "; expected");
5189 } else if ($3 == null) {
5190 Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5191 } else if (RootContext.Version == LanguageVersion.ISO_1){
5192 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5195 current_block.ParametersBlock.TopBlock.IsIterator = true;
5196 $$ = new Yield ((Expression) $3, lt.Location);
5197 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5199 | IDENTIFIER BREAK SEMICOLON
5201 var lt = (Tokenizer.LocatedToken) $1;
5202 string s = lt.Value;
5204 Report.Error (1003, lt.Location, "; expected");
5205 } else if (RootContext.Version == LanguageVersion.ISO_1){
5206 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5209 current_block.ParametersBlock.TopBlock.IsIterator = true;
5210 $$ = new YieldBreak (lt.Location);
5211 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5221 : TRY block catch_clauses
5223 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5225 | TRY block FINALLY block
5227 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5228 lbag.AddStatement ($$, GetLocation ($3));
5230 | TRY block catch_clauses FINALLY block
5232 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
5233 lbag.AddStatement ($$, GetLocation ($4));
5237 Report.Error (1524, GetLocation ($1), "Expected catch or finally");
5245 var l = new List<Catch> (2);
5250 | catch_clauses catch_clause
5252 var l = (List<Catch>) $1;
5254 Catch c = (Catch) $2;
5255 if (l [0].IsGeneral) {
5256 Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5276 $$ = new Catch ((Block) $2, GetLocation ($1));
5278 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5280 start_block (GetLocation ($2));
5281 var c = new Catch (current_block, GetLocation ($1));
5282 c.TypeExpression = (FullNamedExpression) $3;
5285 var lt = (Tokenizer.LocatedToken) $4;
5286 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5287 current_block.AddLocalName (c.Variable);
5290 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5297 | CATCH open_parens_any error
5299 if (yyToken == Token.CLOSE_PARENS) {
5300 Report.Error (1015, lexer.Location,
5301 "A type that derives from `System.Exception', `object', or `string' expected");
5303 Error_SyntaxError (yyToken);
5306 $$ = new Catch (null, GetLocation ($1));
5313 $$ = new Checked ((Block) $2, GetLocation ($1));
5320 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5327 if (!RootContext.Unsafe)
5328 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5330 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5335 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5337 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5338 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5343 : FIXED open_parens_any variable_type IDENTIFIER
5345 start_block (GetLocation ($2));
5347 var lt = (Tokenizer.LocatedToken) $4;
5348 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5349 current_block.AddLocalName (li);
5350 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5352 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5354 $$ = current_variable;
5355 current_variable = null;
5359 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5360 current_block.AddStatement (f);
5361 $$ = end_block (GetLocation ($8));
5366 : USING open_parens_any variable_type IDENTIFIER
5368 start_block (GetLocation ($2));
5370 var lt = (Tokenizer.LocatedToken) $4;
5371 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5372 current_block.AddLocalName (li);
5373 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5375 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5377 $$ = current_variable;
5378 current_variable = null;
5382 Using u = new Using ((Using.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5383 current_block.AddStatement (u);
5384 $$ = end_block (GetLocation ($8));
5386 | USING open_parens_any expression CLOSE_PARENS
5388 start_block (lexer.Location);
5392 UsingTemporary usingTemporary = new UsingTemporary ((Expression) $3, (Statement) $6, GetLocation ($1));
5393 lbag.AddStatement (usingTemporary, GetLocation ($2), GetLocation ($4));
5394 current_block.AddStatement (usingTemporary);
5395 $$ = end_block (lexer.Location);
5399 using_or_fixed_variable_initializer
5402 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
5404 | ASSIGN variable_initializer
5406 current_variable.Initializer = (Expression) $2;
5407 $$ = current_variable;
5415 : first_from_clause query_body
5417 lexer.query_parsing = false;
5419 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5421 from.Tail.Next = (Linq.AQueryClause)$2;
5424 current_block.SetEndLocation (lexer.Location);
5425 current_block = current_block.Parent;
5427 | nested_from_clause query_body
5429 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5431 from.Tail.Next = (Linq.AQueryClause)$2;
5434 current_block.SetEndLocation (lexer.Location);
5435 current_block = current_block.Parent;
5438 // Bubble up COMPLETE_COMPLETION productions
5439 | first_from_clause COMPLETE_COMPLETION {
5440 lexer.query_parsing = false;
5443 current_block.SetEndLocation (lexer.Location);
5444 current_block = current_block.Parent;
5446 | nested_from_clause COMPLETE_COMPLETION {
5448 current_block.SetEndLocation (lexer.Location);
5449 current_block = current_block.Parent;
5454 : FROM_FIRST IDENTIFIER IN expression
5456 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5458 var lt = (Tokenizer.LocatedToken) $2;
5459 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5460 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5462 | FROM_FIRST type IDENTIFIER IN expression
5464 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5466 var lt = (Tokenizer.LocatedToken) $3;
5467 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5468 $$ = new Linq.QueryExpression (
5469 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5470 IdentifierType = (FullNamedExpression)$2
5477 : FROM IDENTIFIER IN expression
5479 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5481 var lt = (Tokenizer.LocatedToken) $2;
5482 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5483 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5485 | FROM type IDENTIFIER IN expression
5487 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5489 var lt = (Tokenizer.LocatedToken) $3;
5490 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5491 $$ = new Linq.QueryExpression (
5492 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5493 IdentifierType = (FullNamedExpression)$2
5500 : FROM IDENTIFIER IN
5502 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5506 var lt = (Tokenizer.LocatedToken) $2;
5507 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5508 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5510 current_block.SetEndLocation (lexer.Location);
5511 current_block = current_block.Parent;
5513 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5515 | FROM type IDENTIFIER IN
5517 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5521 var lt = (Tokenizer.LocatedToken) $3;
5522 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5524 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5525 IdentifierType = (FullNamedExpression)$2
5528 current_block.SetEndLocation (lexer.Location);
5529 current_block = current_block.Parent;
5531 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5536 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5538 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5541 head.Next = (Linq.AQueryClause)$3;
5544 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5545 clause.Tail.Next = head;
5551 | opt_query_body_clauses COMPLETE_COMPLETION
5554 select_or_group_clause
5557 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5561 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5563 current_block.SetEndLocation (lexer.Location);
5564 current_block = current_block.Parent;
5568 if (linq_clause_blocks == null)
5569 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5571 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5572 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5576 current_block.SetEndLocation (lexer.Location);
5577 current_block = current_block.Parent;
5579 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5583 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5585 current_block.SetEndLocation (lexer.Location);
5586 current_block = current_block.Parent;
5590 opt_query_body_clauses
5592 | query_body_clauses
5597 | query_body_clauses query_body_clause
5599 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5613 : LET IDENTIFIER ASSIGN
5615 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5619 var lt = (Tokenizer.LocatedToken) $2;
5620 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5621 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5623 current_block.SetEndLocation (lexer.Location);
5624 current_block = current_block.Parent;
5626 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5633 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5637 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
5639 current_block.SetEndLocation (lexer.Location);
5640 current_block = current_block.Parent;
5645 : JOIN IDENTIFIER IN
5647 if (linq_clause_blocks == null)
5648 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5650 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5651 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5655 current_block.SetEndLocation (lexer.Location);
5656 current_block = current_block.Parent;
5658 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5659 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5663 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5664 current_block.SetEndLocation (lexer.Location);
5665 current_block = current_block.Parent;
5667 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5669 expression opt_join_into
5671 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5672 current_block.SetEndLocation (lexer.Location);
5674 var outer_selector = linq_clause_blocks.Pop ();
5675 var block = linq_clause_blocks.Pop ();
5677 var lt = (Tokenizer.LocatedToken) $2;
5678 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5679 Linq.RangeVariable into;
5683 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5686 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5688 var parent = block.Parent;
5689 while (parent is Linq.QueryBlock) {
5690 parent = parent.Parent;
5692 current_block.Parent = parent;
5694 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5696 lt = (Tokenizer.LocatedToken) $12;
5697 into = new Linq.RangeVariable (lt.Value, lt.Location);
5699 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
5702 current_block = block.Parent;
5703 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5705 | JOIN type IDENTIFIER IN
5707 if (linq_clause_blocks == null)
5708 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5710 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5711 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5715 current_block.SetEndLocation (lexer.Location);
5716 current_block = current_block.Parent;
5718 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5719 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5723 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5724 current_block.SetEndLocation (lexer.Location);
5725 current_block = current_block.Parent;
5727 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5729 expression opt_join_into
5731 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5732 current_block.SetEndLocation (lexer.Location);
5734 var outer_selector = linq_clause_blocks.Pop ();
5735 var block = linq_clause_blocks.Pop ();
5737 var lt = (Tokenizer.LocatedToken) $3;
5738 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5739 Linq.RangeVariable into;
5743 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
5744 IdentifierType = (FullNamedExpression)$2
5748 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5750 var parent = block.Parent;
5751 while (parent is Linq.QueryBlock) {
5752 parent = parent.Parent;
5754 current_block.Parent = parent;
5756 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5758 lt = (Tokenizer.LocatedToken) $13;
5759 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
5761 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
5762 IdentifierType = (FullNamedExpression)$2
5766 current_block = block.Parent;
5767 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5782 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5786 current_block.SetEndLocation (lexer.Location);
5787 current_block = current_block.Parent;
5797 current_block.SetEndLocation (lexer.Location);
5798 current_block = current_block.Parent;
5800 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5804 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5811 | orderings_then_by COMMA
5813 current_block.SetEndLocation (lexer.Location);
5814 current_block = current_block.Parent;
5816 current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);
5820 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
5828 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5830 | expression ASCENDING
5832 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5834 | expression DESCENDING
5836 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5843 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5845 | expression ASCENDING
5847 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5849 | expression DESCENDING
5851 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5856 opt_query_continuation
5860 // query continuation block is not linked with query block but with block
5861 // before. This means each query can use same range variable names for
5862 // different identifiers.
5864 current_block.SetEndLocation (GetLocation ($1));
5865 current_block = current_block.Parent;
5867 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5869 if (linq_clause_blocks == null)
5870 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5872 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5876 var current_block = linq_clause_blocks.Pop ();
5877 var lt = (Tokenizer.LocatedToken) $2;
5878 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5879 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
5880 next = (Linq.AQueryClause)$4
5886 // Support for using the compiler as an interactive parser
5888 // The INTERACTIVE_PARSER token is first sent to parse our
5889 // productions; If the result is a Statement, the parsing
5890 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5891 // to setup the blocks in advance.
5893 // This setup is here so that in the future we can add
5894 // support for other constructs (type parsing, namespaces, etc)
5895 // that do not require a block to be setup in advance
5899 : EVAL_STATEMENT_PARSER EOF
5900 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5901 | EVAL_STATEMENT_PARSER {
5902 Evaluator.LoadAliases (current_namespace);
5904 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5905 Modifiers.PUBLIC, null), null);
5907 var baseclass_list = new List<FullNamedExpression> ();
5908 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5909 current_container.AddBasesForPart (current_class, baseclass_list);
5911 // (ref object retval)
5912 Parameter [] mpar = new Parameter [1];
5913 mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
5915 ParametersCompiled pars = new ParametersCompiled (mpar);
5916 current_local_parameters = pars;
5917 Method method = new Method (
5920 new TypeExpression (TypeManager.void_type, Location.Null),
5921 Modifiers.PUBLIC | Modifiers.STATIC,
5922 new MemberName ("Host"),
5924 null /* attributes */);
5926 oob_stack.Push (method);
5927 ++lexer.parsing_block;
5928 start_block (lexer.Location);
5930 interactive_statement_list opt_COMPLETE_COMPLETION
5932 --lexer.parsing_block;
5933 Method method = (Method) oob_stack.Pop ();
5935 method.Block = (ToplevelBlock) end_block(lexer.Location);
5936 current_container.AddMethod (method);
5938 --lexer.parsing_declaration;
5939 InteractiveResult = pop_current_class ();
5940 current_local_parameters = null;
5942 | EVAL_COMPILATION_UNIT_PARSER {
5943 Evaluator.LoadAliases (current_namespace);
5945 interactive_compilation_unit
5948 interactive_compilation_unit
5949 : outer_declarations
5950 | outer_declarations global_attributes
5955 opt_COMPLETE_COMPLETION
5957 | COMPLETE_COMPLETION
5960 close_brace_or_complete_completion
5962 | COMPLETE_COMPLETION
5967 // A class used to hold info about an operator declarator
5969 class OperatorDeclaration {
5970 public readonly Operator.OpType optype;
5971 public readonly FullNamedExpression ret_type;
5972 public readonly Location location;
5974 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5977 this.ret_type = ret_type;
5978 this.location = location;
5982 void Error_ExpectingTypeName (Expression expr)
5984 if (expr is Invocation){
5985 Report.Error (1002, expr.Location, "Expecting `;'");
5987 Expression.Error_InvalidExpressionStatement (Report, expr.Location);
5991 void Error_ParameterModifierNotValid (string modifier, Location loc)
5993 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5997 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5999 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6000 Parameter.GetModifierSignature (mod));
6003 void Error_TypeExpected (Location loc)
6005 Report.Error (1031, loc, "Type expected");
6008 void Error_UnsafeCodeNotAllowed (Location loc)
6010 Report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6013 void Error_NamedArgumentExpected (NamedArgument a)
6015 Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6018 void push_current_class (TypeContainer tc, object partial_token)
6020 if (RootContext.EvalMode){
6021 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
6022 undo.AddTypeContainer (current_container, tc);
6025 if (partial_token != null)
6026 current_container = current_container.AddPartial (tc);
6028 current_container = current_container.AddTypeContainer (tc);
6030 ++lexer.parsing_declaration;
6034 DeclSpace pop_current_class ()
6036 DeclSpace retval = current_class;
6038 current_class = current_class.Parent;
6039 current_container = current_class.PartialContainer;
6045 // Given the @class_name name, it creates a fully qualified name
6046 // based on the containing declaration space
6049 MakeName (MemberName class_name)
6051 Namespace ns = current_namespace.NS;
6053 if (current_container == RootContext.ToplevelTypes) {
6054 if (ns.Name.Length != 0)
6055 return new MemberName (ns.MemberName, class_name);
6059 return new MemberName (current_container.MemberName, class_name);
6063 [System.Diagnostics.Conditional ("FULL_AST")]
6064 void StoreModifierLocation (object token, Location loc)
6069 if (mod_locations == null)
6070 mod_locations = new List<Tuple<Modifiers, Location>> ();
6072 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6075 string CheckAttributeTarget (string a, Location l)
6078 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6082 Report.Warning (658, 1, l,
6083 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6084 return string.Empty;
6087 static bool IsUnaryOperator (Operator.OpType op)
6091 case Operator.OpType.LogicalNot:
6092 case Operator.OpType.OnesComplement:
6093 case Operator.OpType.Increment:
6094 case Operator.OpType.Decrement:
6095 case Operator.OpType.True:
6096 case Operator.OpType.False:
6097 case Operator.OpType.UnaryPlus:
6098 case Operator.OpType.UnaryNegation:
6104 void syntax_error (Location l, string msg)
6106 Report.Error (1003, l, "Syntax error, " + msg);
6111 public Tokenizer Lexer {
6117 static CSharpParser ()
6119 oob_stack = new Stack<object> ();
6122 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
6124 if (RootContext.EvalMode)
6128 this.compiler = ctx;
6129 current_namespace = new NamespaceEntry (null, file, null);
6130 current_class = current_namespace.SlaveDeclSpace;
6131 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6133 lexer = new Tokenizer (reader, file, ctx);
6135 use_global_stacks = true;
6138 public void parse ()
6140 eof_token = Token.EOF;
6141 Tokenizer.LocatedToken.Initialize ();
6144 if (yacc_verbose_flag > 1)
6145 yyparse (lexer, new yydebug.yyDebugSimple ());
6149 Tokenizer tokenizer = lexer as Tokenizer;
6150 tokenizer.cleanup ();
6151 } catch (Exception e){
6152 if (e is yyParser.yyUnexpectedEof)
6153 UnexpectedEOF = true;
6155 if (e is yyParser.yyException)
6156 Report.Error (-25, lexer.Location, "Parsing error");
6157 else if (yacc_verbose_flag > 0)
6158 throw; // Used by compiler-tester to test internal errors
6160 Report.Error (589, lexer.Location, "Internal compiler error during parsing");
6163 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6164 throw new InternalErrorException ("who set it?");
6167 void CheckToken (int error, int yyToken, string msg, Location loc)
6169 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6170 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6172 Report.Error (error, loc, msg);
6175 void CheckIdentifierToken (int yyToken, Location loc)
6177 CheckToken (1041, yyToken, "Identifier expected", loc);
6180 string ConsumeStoredComment ()
6182 string s = tmpComment;
6184 Lexer.doc_state = XmlCommentState.Allowed;
6188 Location GetLocation (object obj)
6190 if (obj is Tokenizer.LocatedToken)
6191 return ((Tokenizer.LocatedToken) obj).Location;
6192 if (obj is MemberName)
6193 return ((MemberName) obj).Location;
6195 if (obj is Expression)
6196 return ((Expression) obj).Location;
6198 return lexer.Location;
6202 get { return compiler.Report; }
6205 public LocationsBag LocationsBag {
6214 void start_block (Location loc)
6216 if (current_block == null) {
6217 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6218 } else if (parsing_anonymous_method) {
6219 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6220 parsing_anonymous_method = false;
6222 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6227 end_block (Location loc)
6229 Block retval = current_block.Explicit;
6230 retval.SetEndLocation (loc);
6231 current_block = retval.Parent;
6235 void start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6237 if (RootContext.Version == LanguageVersion.ISO_1){
6238 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6241 oob_stack.Push (current_anonymous_method);
6242 oob_stack.Push (current_local_parameters);
6243 oob_stack.Push (current_variable);
6245 current_local_parameters = parameters;
6247 current_anonymous_method = lambda
6248 ? new LambdaExpression (loc)
6249 : new AnonymousMethodExpression (loc);
6251 // Force the next block to be created as a ToplevelBlock
6252 parsing_anonymous_method = true;
6256 * Completes the anonymous method processing, if lambda_expr is null, this
6257 * means that we have a Statement instead of an Expression embedded
6259 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6261 AnonymousMethodExpression retval;
6263 current_anonymous_method.Block = anon_block;
6264 retval = current_anonymous_method;
6266 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6267 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6268 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6273 public NamespaceEntry CurrentNamespace {
6275 return current_namespace;
6280 void Error_SyntaxError (int token)
6282 Error_SyntaxError (0, token, "Unexpected symbol");
6285 void Error_SyntaxError (int error_code, int token, string msg)
6287 string symbol = GetSymbolName (token);
6288 string expecting = GetExpecting ();
6290 if (error_code == 0) {
6291 if (expecting == "`)'")
6297 if (string.IsNullOrEmpty (expecting))
6298 Report.Error (error_code, lexer.Location, "{1} `{0}'", symbol, msg);
6300 Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6303 string GetExpecting ()
6305 int [] tokens = yyExpectingTokens (yyExpectingState);
6306 var names = new List<string> (tokens.Length);
6307 bool has_type = false;
6308 bool has_identifier = false;
6309 for (int i = 0; i < tokens.Length; i++){
6310 int token = tokens [i];
6311 has_identifier |= token == Token.IDENTIFIER;
6313 string name = GetTokenName (token);
6314 if (name == "<internal>")
6317 has_type |= name == "type";
6318 if (names.Contains (name))
6325 // Too many tokens to enumerate
6327 if (names.Count > 8)
6330 if (has_type && has_identifier)
6331 names.Remove ("identifier");
6333 if (names.Count == 1)
6334 return "`" + GetTokenName (tokens [0]) + "'";
6336 StringBuilder sb = new StringBuilder ();
6338 int count = names.Count;
6339 for (int i = 0; i < count; i++){
6340 bool last = i + 1 == count;
6344 sb.Append (names [i]);
6345 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6347 return sb.ToString ();
6351 string GetSymbolName (int token)
6355 return ((Constant)lexer.Value).GetValue ().ToString ();
6356 case Token.IDENTIFIER:
6357 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6399 case Token.BITWISE_AND:
6401 case Token.BITWISE_OR:
6415 case Token.OP_SHIFT_LEFT:
6417 case Token.OP_SHIFT_RIGHT:
6437 case Token.OP_COALESCING:
6439 case Token.OP_MULT_ASSIGN:
6441 case Token.OP_DIV_ASSIGN:
6443 case Token.OP_MOD_ASSIGN:
6445 case Token.OP_ADD_ASSIGN:
6447 case Token.OP_SUB_ASSIGN:
6449 case Token.OP_SHIFT_LEFT_ASSIGN:
6451 case Token.OP_SHIFT_RIGHT_ASSIGN:
6453 case Token.OP_AND_ASSIGN:
6455 case Token.OP_XOR_ASSIGN:
6457 case Token.OP_OR_ASSIGN:
6461 return GetTokenName (token);
6464 static string GetTokenName (int token)
6467 case Token.ABSTRACT:
6487 case Token.CONTINUE:
6491 case Token.DELEGATE:
6501 case Token.EXPLICIT:
6519 case Token.IMPLICIT:
6523 case Token.INTERFACE:
6525 case Token.INTERNAL:
6531 case Token.NAMESPACE:
6537 case Token.OPERATOR:
6541 case Token.OVERRIDE:
6547 case Token.PROTECTED:
6551 case Token.READONLY:
6563 case Token.STACKALLOC:
6564 return "stackalloc";
6581 case Token.UNCHECKED:
6589 case Token.VOLATILE:
6602 case Token.FROM_FIRST:
6620 case Token.ASCENDING:
6622 case Token.DESCENDING:
6623 return "descending";
6630 case Token.OPEN_BRACE:
6632 case Token.CLOSE_BRACE:
6634 case Token.OPEN_BRACKET:
6635 case Token.OPEN_BRACKET_EXPR:
6637 case Token.CLOSE_BRACKET:
6639 case Token.OPEN_PARENS_CAST:
6640 case Token.OPEN_PARENS_LAMBDA:
6641 case Token.OPEN_PARENS:
6643 case Token.CLOSE_PARENS:
6649 case Token.DEFAULT_COLON:
6653 case Token.SEMICOLON:
6664 case Token.BITWISE_AND:
6665 case Token.BITWISE_OR:
6672 case Token.OP_SHIFT_LEFT:
6673 case Token.OP_SHIFT_RIGHT:
6681 case Token.OP_COALESCING:
6682 case Token.OP_MULT_ASSIGN:
6683 case Token.OP_DIV_ASSIGN:
6684 case Token.OP_MOD_ASSIGN:
6685 case Token.OP_ADD_ASSIGN:
6686 case Token.OP_SUB_ASSIGN:
6687 case Token.OP_SHIFT_LEFT_ASSIGN:
6688 case Token.OP_SHIFT_RIGHT_ASSIGN:
6689 case Token.OP_AND_ASSIGN:
6690 case Token.OP_XOR_ASSIGN:
6691 case Token.OP_OR_ASSIGN:
6692 return "<operator>";
6714 case Token.OP_GENERICS_LT:
6715 case Token.GENERIC_DIMENSION:
6717 case Token.OP_GENERICS_GT:
6720 case Token.INTERR_NULLABLE:
6722 case Token.DOUBLE_COLON:
6726 case Token.IDENTIFIER:
6727 return "identifier";
6729 // All of these are internal.
6732 case Token.FIRST_KEYWORD:
6734 case Token.EVAL_COMPILATION_UNIT_PARSER:
6735 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6736 case Token.EVAL_STATEMENT_PARSER:
6737 case Token.LAST_KEYWORD:
6738 case Token.GENERATE_COMPLETION:
6739 case Token.COMPLETE_COMPLETION:
6740 return "<internal>";
6742 // A bit more robust.
6744 return yyNames [token];