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:
19 // Possible optimization:
20 // Run memory profiler with parsing only, and consider dropping
21 // arraylists where not needed. Some pieces can use linked lists.
30 using System.Collections;
35 public class CSharpParser
38 enum ParameterModifierType
45 DefaultValue = 1 << 6,
47 All = Ref | Out | This | Params | Arglist | DefaultValue
50 NamespaceEntry current_namespace;
51 TypeContainer current_container;
52 DeclSpace current_class;
55 /// Current block is used to add statements as we find
60 Delegate current_delegate;
62 GenericMethod current_generic_method;
63 AnonymousMethodExpression current_anonymous_method;
66 /// This is used by the unary_expression code to resolve
67 /// a name against a parameter.
70 // FIXME: This is very ugly and it's very hard to reset it correctly
71 // on all places, especially when some parameters are autogenerated.
72 ParametersCompiled current_local_parameters;
75 /// Using during property parsing to describe the implicit
76 /// value parameter that is passed to the "set" and "get"accesor
77 /// methods (properties and indexers).
79 FullNamedExpression implicit_value_parameter_type;
80 ParametersCompiled indexer_parameters;
83 /// Hack to help create non-typed array initializer
85 public static FullNamedExpression current_array_type;
86 FullNamedExpression pushed_current_array_type;
89 /// Used to determine if we are parsing the get/set pair
90 /// of an indexer or a property
94 bool parsing_anonymous_method;
97 /// An out-of-band stack.
99 static Stack oob_stack;
107 /// Controls the verbosity of the errors produced by the parser
109 static public int yacc_verbose_flag;
112 /// Used by the interactive shell, flags whether EOF was reached
113 /// and an error was produced
115 public bool UnexpectedEOF;
118 /// The current file.
120 CompilationUnit file;
123 /// Temporary Xml documentation cache.
124 /// For enum types, we need one more temporary store.
127 string enumTypeComment;
129 /// Current attribute target
130 string current_attr_target;
132 /// assembly and module attribute definitions are enabled
133 bool global_attrs_enabled = true;
134 bool has_get, has_set;
136 ParameterModifierType valid_param_mod;
138 bool default_parameter_used;
140 /// When using the interactive parser, this holds the
141 /// resulting expression
142 public object InteractiveResult;
145 // Keeps track of global data changes to undo on parser error
149 // Stack<ToplevelBlock>
150 Stack linq_clause_blocks;
152 // A counter to create new class names in interactive mode
153 static int class_count;
157 %token NONE /* This token is never returned by our lexer */
158 %token ERROR // This is used not by the parser, but by the tokenizer.
162 *These are the C# keywords
261 %token INTERR_NULLABLE
264 /* Generics <,> tokens */
265 %token OP_GENERICS_LT
266 %token OP_GENERICS_LT_DECL
267 %token OP_GENERICS_GT
269 /* C# keywords which are not really keywords */
275 /* C# single character operators/punctuation. */
303 /* C# multi-character operators. */
308 %token OP_SHIFT_RIGHT
315 %token OP_MULT_ASSIGN
320 %token OP_SHIFT_LEFT_ASSIGN
321 %token OP_SHIFT_RIGHT_ASSIGN
329 %token LITERAL_INTEGER
331 %token LITERAL_DOUBLE
332 %token LITERAL_DECIMAL
333 %token LITERAL_CHARACTER
334 %token LITERAL_STRING
337 %token OPEN_PARENS_LAMBDA
338 %token OPEN_PARENS_CAST
339 %token GENERIC_DIMENSION
342 // Make the parser go into eval mode parsing (statements and compilation units).
343 %token EVAL_STATEMENT_PARSER
344 %token EVAL_COMPILATION_UNIT_PARSER
345 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
348 // This token is generated to trigger the completion engine at this point
350 %token GENERATE_COMPLETION
353 // This token is return repeatedly after the first GENERATE_COMPLETION
354 // token is produced and before the final EOF
356 %token COMPLETE_COMPLETION
358 /* Add precedence rules to solve dangling else s/r conflict */
362 /* Define the operator tokens and their precedences */
370 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
372 %left STAR DIV PERCENT
373 %right BANG CARRET UMINUS
374 %nonassoc OP_INC OP_DEC
376 %left OPEN_BRACKET OPEN_BRACE
379 %start compilation_unit
383 : outer_declarations opt_EOF
384 | outer_declarations global_attributes opt_EOF
385 | global_attributes opt_EOF
386 | opt_EOF /* allow empty files */
387 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
393 Lexer.check_incorrect_doc_comment ();
397 Lexer.check_incorrect_doc_comment ();
403 | outer_declarations outer_declaration
407 : extern_alias_directive
409 | namespace_member_declaration
412 extern_alias_directives
413 : extern_alias_directive
414 | extern_alias_directives extern_alias_directive
417 extern_alias_directive
418 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
420 LocatedToken lt = (LocatedToken) $2;
423 syntax_error (lt.Location, "`alias' expected");
424 } else if (RootContext.Version == LanguageVersion.ISO_1) {
425 Report.FeatureIsNotAvailable (lt.Location, "external alias");
427 lt = (LocatedToken) $3;
428 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
433 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
439 | using_directives using_directive
443 : using_alias_directive
445 if (RootContext.Documentation != null)
446 Lexer.doc_state = XmlCommentState.Allowed;
448 | using_namespace_directive
450 if (RootContext.Documentation != null)
451 Lexer.doc_state = XmlCommentState.Allowed;
455 using_alias_directive
456 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
458 LocatedToken lt = (LocatedToken) $2;
459 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
462 CheckIdentifierToken (yyToken, GetLocation ($2));
467 using_namespace_directive
468 : USING namespace_name SEMICOLON
470 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
475 // Strictly speaking, namespaces don't have attributes but
476 // we parse global attributes along with namespace declarations and then
479 namespace_declaration
480 : opt_attributes NAMESPACE qualified_identifier
482 MemberName name = (MemberName) $3;
485 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
488 current_namespace = new NamespaceEntry (
489 current_namespace, file, name.GetName ());
490 current_class = current_namespace.SlaveDeclSpace;
491 current_container = current_class.PartialContainer;
493 namespace_body opt_semicolon
495 current_namespace = current_namespace.Parent;
496 current_class = current_namespace.SlaveDeclSpace;
497 current_container = current_class.PartialContainer;
504 LocatedToken lt = (LocatedToken) $1;
505 $$ = new MemberName (lt.Value, lt.Location);
507 | qualified_identifier DOT IDENTIFIER
509 LocatedToken lt = (LocatedToken) $3;
510 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
514 syntax_error (lexer.Location, "`.' expected");
529 : namespace_or_type_name
531 MemberName name = (MemberName) $1;
533 if (name.TypeArguments != null)
534 syntax_error (lexer.Location, "namespace name expected");
543 if (RootContext.Documentation != null)
544 Lexer.doc_state = XmlCommentState.Allowed;
550 : opt_extern_alias_directives
552 opt_namespace_member_declarations
556 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
559 | opt_extern_alias_directives
561 opt_namespace_member_declarations
564 Report.Error (1513, lexer.Location, "Expected `}'");
573 opt_extern_alias_directives
575 | extern_alias_directives
578 opt_namespace_member_declarations
580 | namespace_member_declarations
583 namespace_member_declarations
584 : namespace_member_declaration
585 | namespace_member_declarations namespace_member_declaration
588 namespace_member_declaration
592 DeclSpace ds = (DeclSpace)$1;
594 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
595 Report.Error (1527, ds.Location,
596 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
599 current_namespace.DeclarationFound = true;
601 | namespace_declaration {
602 current_namespace.DeclarationFound = true;
605 | field_declaration {
606 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
608 | method_declaration {
609 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
616 | interface_declaration
618 | delegate_declaration
620 // Enable this when we have handled all errors, because this acts as a generic fallback
623 // Console.WriteLine ("Token=" + yyToken);
624 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
636 Attributes attrs = (Attributes)$1;
637 if (global_attrs_enabled) {
638 CodeGen.Assembly.AddAttributes (attrs.Attrs, current_namespace);
640 foreach (Attribute a in attrs.Attrs) {
641 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
652 global_attrs_enabled = false;
657 global_attrs_enabled = false;
666 if (current_attr_target != String.Empty) {
667 ArrayList sect = (ArrayList) $1;
669 if (global_attrs_enabled) {
670 if (current_attr_target == "module") {
671 current_container.Module.AddAttributes (sect);
673 } else if (current_attr_target != null && current_attr_target.Length > 0) {
674 CodeGen.Assembly.AddAttributes (sect, current_namespace);
677 $$ = new Attributes (sect);
680 if (RootContext.Documentation != null) {
681 Lexer.check_incorrect_doc_comment ();
683 XmlCommentState.Allowed;
687 $$ = new Attributes (sect);
692 current_attr_target = null;
694 | attribute_sections attribute_section
696 if (current_attr_target != String.Empty) {
697 Attributes attrs = $1 as Attributes;
698 ArrayList sect = (ArrayList) $2;
700 if (global_attrs_enabled) {
701 if (current_attr_target == "module") {
702 current_container.Module.AddAttributes (sect);
704 } else if (current_attr_target == "assembly") {
705 CodeGen.Assembly.AddAttributes (sect, current_namespace);
709 attrs = new Attributes (sect);
711 attrs.AddAttributes (sect);
715 attrs = new Attributes (sect);
717 attrs.AddAttributes (sect);
723 current_attr_target = null;
728 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
732 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
738 attribute_target_specifier
739 : attribute_target COLON
741 current_attr_target = (string)$1;
749 LocatedToken lt = (LocatedToken) $1;
750 $$ = CheckAttributeTarget (lt.Value, lt.Location);
752 | EVENT { $$ = "event"; }
753 | RETURN { $$ = "return"; }
756 string name = GetTokenName (yyToken);
757 $$ = CheckAttributeTarget (name, GetLocation ($1));
764 ArrayList attrs = new ArrayList (4);
770 | attribute_list COMMA attribute
772 ArrayList attrs = (ArrayList) $1;
782 ++lexer.parsing_block;
784 opt_attribute_arguments
786 --lexer.parsing_block;
787 MemberName mname = (MemberName) $1;
788 if (mname.IsGeneric) {
789 Report.Error (404, lexer.Location,
790 "'<' unexpected: attributes cannot be generic");
793 Arguments [] arguments = (Arguments []) $3;
794 ATypeNameExpression expr = mname.GetTypeExpression ();
796 if (current_attr_target == String.Empty)
798 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
799 // FIXME: supply "nameEscaped" parameter here.
800 $$ = new GlobalAttribute (current_namespace, current_attr_target,
801 expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
803 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
808 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
811 opt_attribute_arguments
812 : /* empty */ { $$ = null; }
813 | OPEN_PARENS attribute_arguments CLOSE_PARENS
821 : /* empty */ { $$ = null; }
822 | positional_or_named_argument
824 Arguments a = new Arguments (4);
825 a.Add ((Argument) $1);
826 $$ = new Arguments [] { a, null };
828 | named_attribute_argument
830 Arguments a = new Arguments (4);
831 a.Add ((Argument) $1);
832 $$ = new Arguments [] { null, a };
834 | attribute_arguments COMMA positional_or_named_argument
836 Arguments[] o = (Arguments[]) $1;
838 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
839 o [0] = new Arguments (4);
842 Arguments args = ((Arguments) o [0]);
843 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
844 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
846 args.Add ((Argument) $3);
848 | attribute_arguments COMMA named_attribute_argument
850 Arguments[] o = (Arguments[]) $1;
852 o [1] = new Arguments (4);
855 ((Arguments) o [1]).Add ((Argument) $3);
859 positional_or_named_argument
862 $$ = new Argument ((Expression) $1);
867 named_attribute_argument
868 : IDENTIFIER ASSIGN expression
870 $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);
875 : IDENTIFIER COLON expression
877 if (RootContext.Version <= LanguageVersion.V_3)
878 Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
880 $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);
886 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
889 opt_class_member_declarations
891 | class_member_declarations
894 class_member_declarations
895 : class_member_declaration
896 | class_member_declarations
897 class_member_declaration
900 class_member_declaration
901 : constant_declaration // done
902 | field_declaration // done
903 | method_declaration // done
904 | property_declaration // done
905 | event_declaration // done
906 | indexer_declaration // done
907 | operator_declaration // done
908 | constructor_declaration // done
909 | destructor_declaration // done
913 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
914 GetSymbolName (yyToken));
916 lexer.parsing_generic_declaration = false;
926 lexer.ConstraintsParsing = true;
928 type_declaration_name
930 MemberName name = MakeName ((MemberName) $6);
931 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
934 opt_type_parameter_constraints_clauses
936 lexer.ConstraintsParsing = false;
938 current_class.SetParameterInfo ((ArrayList) $9);
940 if (RootContext.Documentation != null)
941 current_container.DocComment = Lexer.consume_doc_comment ();
945 --lexer.parsing_declaration;
946 if (RootContext.Documentation != null)
947 Lexer.doc_state = XmlCommentState.Allowed;
951 $$ = pop_current_class ();
953 | opt_attributes opt_modifiers opt_partial STRUCT error {
954 CheckIdentifierToken (yyToken, GetLocation ($5));
961 if (RootContext.Documentation != null)
962 Lexer.doc_state = XmlCommentState.Allowed;
964 opt_struct_member_declarations CLOSE_BRACE
967 opt_struct_member_declarations
969 | struct_member_declarations
972 struct_member_declarations
973 : struct_member_declaration
974 | struct_member_declarations struct_member_declaration
977 struct_member_declaration
978 : constant_declaration
981 | property_declaration
983 | indexer_declaration
984 | operator_declaration
985 | constructor_declaration
989 * This is only included so we can flag error 575:
990 * destructors only allowed on class types
992 | destructor_declaration
1000 constant_declarators
1003 int modflags = (int) $2;
1004 foreach (VariableDeclaration constant in (ArrayList) $5){
1005 Location l = constant.Location;
1006 if ((modflags & Modifiers.STATIC) != 0) {
1007 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
1011 Const c = new Const (
1012 current_class, (FullNamedExpression) $4, (string) constant.identifier,
1013 (Expression) constant.expression_or_array_initializer, modflags,
1014 (Attributes) $1, l);
1016 if (RootContext.Documentation != null) {
1017 c.DocComment = Lexer.consume_doc_comment ();
1018 Lexer.doc_state = XmlCommentState.Allowed;
1020 current_container.AddConstant (c);
1025 constant_declarators
1026 : constant_declarator
1028 ArrayList constants = new ArrayList (4);
1033 | constant_declarators COMMA constant_declarator
1036 ArrayList constants = (ArrayList) $1;
1045 ++lexer.parsing_block;
1047 constant_initializer
1049 --lexer.parsing_block;
1050 $$ = new VariableDeclaration ((LocatedToken) $1, $4);
1054 // A const field requires a value to be provided
1055 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1060 constant_initializer
1061 : constant_expression
1069 variable_declarators
1072 FullNamedExpression type = (FullNamedExpression) $3;
1073 if (type == TypeManager.system_void_expr)
1074 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1078 current_array_type = null;
1080 foreach (VariableMemberDeclaration var in (ArrayList) $4){
1081 Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1083 field.Initializer = var.expression_or_array_initializer;
1085 if (RootContext.Documentation != null) {
1086 field.DocComment = Lexer.consume_doc_comment ();
1087 Lexer.doc_state = XmlCommentState.Allowed;
1089 current_container.AddField (field);
1090 $$ = field; // FIXME: might be better if it points to the top item
1097 fixed_variable_declarators
1100 FullNamedExpression type = (FullNamedExpression) $4;
1104 current_array_type = null;
1106 foreach (VariableDeclaration var in (ArrayList) $5) {
1107 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1108 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1110 if (RootContext.Documentation != null) {
1111 field.DocComment = Lexer.consume_doc_comment ();
1112 Lexer.doc_state = XmlCommentState.Allowed;
1114 current_container.AddField (field);
1115 $$ = field; // FIXME: might be better if it points to the top item
1124 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1128 fixed_variable_declarators
1129 : fixed_variable_declarator
1131 ArrayList decl = new ArrayList (2);
1135 | fixed_variable_declarators COMMA fixed_variable_declarator
1137 ArrayList decls = (ArrayList) $1;
1143 fixed_variable_declarator
1144 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1146 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1148 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1150 Report.Error (443, lexer.Location, "Value or constant expected");
1151 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1156 local_variable_declarators
1157 : local_variable_declarator
1159 ArrayList decl = new ArrayList (4);
1164 | local_variable_declarators COMMA local_variable_declarator
1166 ArrayList decls = (ArrayList) $1;
1172 local_variable_declarator
1173 : IDENTIFIER ASSIGN local_variable_initializer
1175 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1179 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1181 | IDENTIFIER variable_bad_array
1187 local_variable_initializer
1190 | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
1192 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1196 $$ = new ArglistAccess ((Location) $1);
1198 | STACKALLOC simple_type
1200 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1201 $$ = new StackAlloc ((Expression) $2, null, (Location) $1);
1205 variable_declarators
1206 : variable_declarator
1208 ArrayList decl = new ArrayList (4);
1213 | variable_declarators COMMA variable_declarator
1215 ArrayList decls = (ArrayList) $1;
1222 : member_declaration_name ASSIGN
1224 ++lexer.parsing_block;
1225 lexer.parsing_generic_declaration = false;
1227 variable_initializer
1229 --lexer.parsing_block;
1230 $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
1232 | member_declaration_name
1234 lexer.parsing_generic_declaration = false;
1235 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1237 | member_declaration_name variable_bad_array
1239 lexer.parsing_generic_declaration = false;
1245 : OPEN_BRACKET opt_expression CLOSE_BRACKET
1247 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1248 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1252 variable_initializer
1259 if (RootContext.Documentation != null)
1260 Lexer.doc_state = XmlCommentState.NotAllowed;
1264 Method method = (Method) $1;
1265 method.Block = (ToplevelBlock) $3;
1266 current_container.AddMethod (method);
1268 if (current_container.Kind == Kind.Interface && method.Block != null) {
1269 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1272 current_generic_method = null;
1273 current_local_parameters = null;
1275 if (RootContext.Documentation != null)
1276 Lexer.doc_state = XmlCommentState.Allowed;
1284 method_declaration_name OPEN_PARENS
1286 valid_param_mod = ParameterModifierType.All;
1288 opt_formal_parameter_list CLOSE_PARENS
1290 lexer.ConstraintsParsing = true;
1292 opt_type_parameter_constraints_clauses
1294 lexer.ConstraintsParsing = false;
1295 valid_param_mod = 0;
1296 MemberName name = (MemberName) $4;
1297 current_local_parameters = (ParametersCompiled) $7;
1299 if ($10 != null && name.TypeArguments == null)
1300 Report.Error (80, lexer.Location,
1301 "Constraints are not allowed on non-generic declarations");
1305 GenericMethod generic = null;
1306 if (name.TypeArguments != null) {
1307 generic = new GenericMethod (current_namespace, current_class, name,
1308 (FullNamedExpression) $3, current_local_parameters);
1310 generic.SetParameterInfo ((ArrayList) $10);
1313 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1314 name, current_local_parameters, (Attributes) $1);
1316 current_generic_method = generic;
1318 if (RootContext.Documentation != null)
1319 method.DocComment = Lexer.consume_doc_comment ();
1326 VOID method_declaration_name
1329 valid_param_mod = ParameterModifierType.All;
1331 opt_formal_parameter_list CLOSE_PARENS
1333 lexer.ConstraintsParsing = true;
1335 opt_type_parameter_constraints_clauses
1337 lexer.ConstraintsParsing = false;
1338 valid_param_mod = 0;
1340 MemberName name = (MemberName) $5;
1341 current_local_parameters = (ParametersCompiled) $8;
1343 if ($10 != null && name.TypeArguments == null)
1344 Report.Error (80, lexer.Location,
1345 "Constraints are not allowed on non-generic declarations");
1348 GenericMethod generic = null;
1349 if (name.TypeArguments != null) {
1350 generic = new GenericMethod (current_namespace, current_class, name,
1351 TypeManager.system_void_expr, current_local_parameters);
1353 generic.SetParameterInfo ((ArrayList) $11);
1356 int modifiers = (int) $2;
1359 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1360 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1362 if ((modifiers & invalid_partial_mod) != 0) {
1363 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1364 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1365 modifiers &= ~invalid_partial_mod;
1368 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1369 Report.Error (751, name.Location, "A partial method must be declared within a " +
1370 "partial class or partial struct");
1373 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1375 method = new Method (current_class, generic, TypeManager.system_void_expr,
1376 modifiers, name, current_local_parameters, (Attributes) $1);
1378 current_generic_method = generic;
1380 if (RootContext.Documentation != null)
1381 method.DocComment = Lexer.consume_doc_comment ();
1388 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1390 MemberName name = (MemberName) $5;
1391 Report.Error (1585, name.Location,
1392 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1394 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1395 0, name, (ParametersCompiled) $7, (Attributes) $1);
1397 current_local_parameters = (ParametersCompiled) $7;
1399 if (RootContext.Documentation != null)
1400 method.DocComment = Lexer.consume_doc_comment ();
1408 | SEMICOLON { $$ = null; }
1411 opt_formal_parameter_list
1412 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1413 | formal_parameter_list
1416 formal_parameter_list
1419 ArrayList pars_list = (ArrayList) $1;
1421 Parameter [] pars = new Parameter [pars_list.Count];
1422 pars_list.CopyTo (pars);
1424 $$ = new ParametersCompiled (pars);
1426 | fixed_parameters COMMA parameter_array
1428 ArrayList pars_list = (ArrayList) $1;
1431 Parameter [] pars = new Parameter [pars_list.Count];
1432 pars_list.CopyTo (pars);
1434 $$ = new ParametersCompiled (pars);
1436 | fixed_parameters COMMA arglist_modifier
1438 ArrayList pars_list = (ArrayList) $1;
1439 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1441 Parameter [] pars = new Parameter [pars_list.Count];
1442 pars_list.CopyTo (pars);
1444 $$ = new ParametersCompiled (pars, true);
1446 | parameter_array COMMA error
1449 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1452 | fixed_parameters COMMA parameter_array COMMA error
1455 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1458 | arglist_modifier COMMA error
1460 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1463 | fixed_parameters COMMA ARGLIST COMMA error
1465 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1470 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1474 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1481 ArrayList pars = new ArrayList (4);
1482 Parameter p = (Parameter) $1;
1485 default_parameter_used = p.HasDefaultValue;
1488 | fixed_parameters COMMA fixed_parameter
1490 ArrayList pars = (ArrayList) $1;
1491 Parameter p = (Parameter) $3;
1493 if (p.HasExtensionMethodModifier)
1494 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1495 else if (!p.HasDefaultValue && default_parameter_used)
1496 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1498 default_parameter_used |= p.HasDefaultValue;
1507 opt_parameter_modifier
1511 LocatedToken lt = (LocatedToken) $4;
1512 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1515 opt_parameter_modifier
1517 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1519 LocatedToken lt = (LocatedToken) $4;
1520 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1524 opt_parameter_modifier
1528 Location l = GetLocation ($4);
1529 CheckIdentifierToken (yyToken, l);
1530 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1533 opt_parameter_modifier
1539 if (RootContext.Version <= LanguageVersion.V_3) {
1540 Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1543 Parameter.Modifier mod = (Parameter.Modifier) $2;
1544 if (mod != Parameter.Modifier.NONE) {
1546 case Parameter.Modifier.REF:
1547 case Parameter.Modifier.OUT:
1548 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1549 Parameter.GetModifierSignature (mod));
1552 case Parameter.Modifier.This:
1553 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1554 Parameter.GetModifierSignature (mod));
1557 throw new NotImplementedException (mod.ToString ());
1560 mod = Parameter.Modifier.NONE;
1563 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1564 Report.Error (1065, GetLocation ($6), "Optional parameter is not valid in this context");
1566 LocatedToken lt = (LocatedToken) $4;
1567 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1569 ((Parameter) $$).DefaultValue = (Expression) $6;
1573 opt_parameter_modifier
1574 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1575 | parameter_modifiers
1579 : parameter_modifier
1583 | parameter_modifiers parameter_modifier
1585 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1586 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1587 if (((Parameter.Modifier)$1 & p2) == p2) {
1588 Error_DuplicateParameterModifier (lexer.Location, p2);
1590 switch (mod & ~Parameter.Modifier.This) {
1591 case Parameter.Modifier.REF:
1592 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1594 case Parameter.Modifier.OUT:
1595 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1598 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1609 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1610 Error_ParameterModifierNotValid ("ref", (Location)$1);
1612 $$ = Parameter.Modifier.REF;
1616 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1617 Error_ParameterModifierNotValid ("out", (Location)$1);
1619 $$ = Parameter.Modifier.OUT;
1623 if ((valid_param_mod & ParameterModifierType.This) == 0)
1624 Error_ParameterModifierNotValid ("this", (Location)$1);
1626 if (RootContext.Version <= LanguageVersion.ISO_2)
1627 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1629 $$ = Parameter.Modifier.This;
1634 : opt_attributes params_modifier type IDENTIFIER
1636 LocatedToken lt = (LocatedToken) $4;
1637 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1639 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1641 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1643 LocatedToken lt = (LocatedToken) $4;
1644 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1646 | opt_attributes params_modifier type error {
1647 CheckIdentifierToken (yyToken, GetLocation ($4));
1655 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1656 Report.Error (1670, ((Location) $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, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1664 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1667 | PARAMS params_modifier
1669 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1676 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1677 Report.Error (1669, (Location) $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 implicit_value_parameter_type = (FullNamedExpression) $3;
1693 lexer.PropertyParsing = true;
1695 accessor_declarations
1697 lexer.PropertyParsing = false;
1698 has_get = has_set = false;
1703 Accessors accessors = (Accessors) $8;
1704 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1705 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1706 bool order = accessors != null ? accessors.declared_in_reverse : false;
1708 MemberName name = (MemberName) $4;
1709 FullNamedExpression ptype = (FullNamedExpression) $3;
1711 prop = new Property (current_class, ptype, (int) $2,
1712 name, (Attributes) $1, get_block, set_block, order, current_block);
1714 if (ptype == TypeManager.system_void_expr)
1715 Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
1717 if (accessors == null)
1718 Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1720 if (current_container.Kind == Kind.Interface) {
1721 if (prop.Get.Block != null)
1722 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1724 if (prop.Set.Block != null)
1725 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1728 current_container.AddProperty (prop);
1729 implicit_value_parameter_type = null;
1731 if (RootContext.Documentation != null)
1732 prop.DocComment = ConsumeStoredComment ();
1737 accessor_declarations
1738 : get_accessor_declaration
1740 $$ = new Accessors ((Accessor) $1, null);
1742 | get_accessor_declaration accessor_declarations
1744 Accessors accessors = (Accessors) $2;
1745 accessors.get_or_add = (Accessor) $1;
1748 | set_accessor_declaration
1750 $$ = new Accessors (null, (Accessor) $1);
1752 | set_accessor_declaration accessor_declarations
1754 Accessors accessors = (Accessors) $2;
1755 accessors.set_or_remove = (Accessor) $1;
1756 accessors.declared_in_reverse = true;
1761 if (yyToken == Token.CLOSE_BRACE) {
1764 if (yyToken == Token.SEMICOLON)
1765 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1767 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1769 $$ = new Accessors (null, null);
1774 get_accessor_declaration
1775 : opt_attributes opt_modifiers GET
1777 // If this is not the case, then current_local_parameters has already
1778 // been set in indexer_declaration
1779 if (parsing_indexer == false)
1780 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1782 current_local_parameters = indexer_parameters;
1783 lexer.PropertyParsing = false;
1788 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1791 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1793 current_local_parameters = null;
1794 lexer.PropertyParsing = true;
1796 if (RootContext.Documentation != null)
1797 if (Lexer.doc_state == XmlCommentState.Error)
1798 Lexer.doc_state = XmlCommentState.NotAllowed;
1804 set_accessor_declaration
1805 : opt_attributes opt_modifiers SET
1807 Parameter implicit_value_parameter = new Parameter (
1808 implicit_value_parameter_type, "value",
1809 Parameter.Modifier.NONE, null, (Location) $3);
1811 if (!parsing_indexer) {
1812 current_local_parameters = new ParametersCompiled (new Parameter [] { implicit_value_parameter });
1814 current_local_parameters = ParametersCompiled.MergeGenerated (
1815 indexer_parameters, true, implicit_value_parameter, null);
1818 lexer.PropertyParsing = false;
1823 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1826 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1828 current_local_parameters = null;
1829 lexer.PropertyParsing = true;
1831 if (RootContext.Documentation != null
1832 && Lexer.doc_state == XmlCommentState.Error)
1833 Lexer.doc_state = XmlCommentState.NotAllowed;
1847 Error_SyntaxError (1043, yyToken);
1852 interface_declaration
1858 lexer.ConstraintsParsing = true;
1860 type_declaration_name
1862 MemberName name = MakeName ((MemberName) $6);
1863 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1866 opt_type_parameter_constraints_clauses
1868 lexer.ConstraintsParsing = false;
1870 current_class.SetParameterInfo ((ArrayList) $9);
1872 if (RootContext.Documentation != null) {
1873 current_container.DocComment = Lexer.consume_doc_comment ();
1874 Lexer.doc_state = XmlCommentState.Allowed;
1879 --lexer.parsing_declaration;
1880 if (RootContext.Documentation != null)
1881 Lexer.doc_state = XmlCommentState.Allowed;
1885 $$ = pop_current_class ();
1887 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1888 CheckIdentifierToken (yyToken, GetLocation ($5));
1894 opt_interface_member_declarations
1898 opt_interface_member_declarations
1900 | interface_member_declarations
1903 interface_member_declarations
1904 : interface_member_declaration
1905 | interface_member_declarations interface_member_declaration
1908 interface_member_declaration
1909 : constant_declaration
1911 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1915 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1917 | method_declaration
1918 | property_declaration
1920 | indexer_declaration
1921 | operator_declaration
1923 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1925 | constructor_declaration
1927 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1931 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1935 operator_declaration
1936 : opt_attributes opt_modifiers operator_declarator
1944 OperatorDeclaration decl = (OperatorDeclaration) $3;
1945 Operator op = new Operator (
1946 current_class, decl.optype, decl.ret_type, (int) $2,
1947 current_local_parameters,
1948 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1950 if (RootContext.Documentation != null) {
1951 op.DocComment = tmpComment;
1952 Lexer.doc_state = XmlCommentState.Allowed;
1955 // Note again, checking is done in semantic analysis
1956 current_container.AddOperator (op);
1958 current_local_parameters = null;
1964 | SEMICOLON { $$ = null; }
1968 : type_expression_or_array
1971 Report.Error (590, lexer.Location, "User-defined operators cannot return void");
1972 $$ = TypeManager.system_void_expr;
1977 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1979 valid_param_mod = ParameterModifierType.DefaultValue;
1981 opt_formal_parameter_list CLOSE_PARENS
1983 valid_param_mod = 0;
1985 Location loc = (Location) $2;
1986 Operator.OpType op = (Operator.OpType) $3;
1987 current_local_parameters = (ParametersCompiled)$6;
1989 int p_count = current_local_parameters.Count;
1991 if (op == Operator.OpType.Addition)
1992 op = Operator.OpType.UnaryPlus;
1993 else if (op == Operator.OpType.Subtraction)
1994 op = Operator.OpType.UnaryNegation;
1997 if (IsUnaryOperator (op)) {
1999 Report.Error (1020, loc, "Overloadable binary operator expected");
2000 } else if (p_count != 1) {
2001 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2002 Operator.GetName (op));
2006 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2007 Operator.GetName (op));
2008 } else if (p_count != 2) {
2009 Report.Error (1019, loc, "Overloadable unary operator expected");
2013 if (RootContext.Documentation != null) {
2014 tmpComment = Lexer.consume_doc_comment ();
2015 Lexer.doc_state = XmlCommentState.NotAllowed;
2018 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2020 | conversion_operator_declarator
2023 overloadable_operator
2025 : BANG { $$ = Operator.OpType.LogicalNot; }
2026 | TILDE { $$ = Operator.OpType.OnesComplement; }
2027 | OP_INC { $$ = Operator.OpType.Increment; }
2028 | OP_DEC { $$ = Operator.OpType.Decrement; }
2029 | TRUE { $$ = Operator.OpType.True; }
2030 | FALSE { $$ = Operator.OpType.False; }
2031 // Unary and binary:
2032 | PLUS { $$ = Operator.OpType.Addition; }
2033 | MINUS { $$ = Operator.OpType.Subtraction; }
2035 | STAR { $$ = Operator.OpType.Multiply; }
2036 | DIV { $$ = Operator.OpType.Division; }
2037 | PERCENT { $$ = Operator.OpType.Modulus; }
2038 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2039 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2040 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2041 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2042 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2043 | OP_EQ { $$ = Operator.OpType.Equality; }
2044 | OP_NE { $$ = Operator.OpType.Inequality; }
2045 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2046 | OP_LT { $$ = Operator.OpType.LessThan; }
2047 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2048 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2051 conversion_operator_declarator
2052 : IMPLICIT OPERATOR type OPEN_PARENS
2054 valid_param_mod = ParameterModifierType.DefaultValue;
2056 opt_formal_parameter_list CLOSE_PARENS
2058 valid_param_mod = 0;
2060 Location loc = (Location) $2;
2061 current_local_parameters = (ParametersCompiled)$6;
2063 if (RootContext.Documentation != null) {
2064 tmpComment = Lexer.consume_doc_comment ();
2065 Lexer.doc_state = XmlCommentState.NotAllowed;
2068 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2070 | EXPLICIT OPERATOR type OPEN_PARENS
2072 valid_param_mod = ParameterModifierType.DefaultValue;
2074 opt_formal_parameter_list CLOSE_PARENS
2076 valid_param_mod = 0;
2078 Location loc = (Location) $2;
2079 current_local_parameters = (ParametersCompiled)$6;
2081 if (RootContext.Documentation != null) {
2082 tmpComment = Lexer.consume_doc_comment ();
2083 Lexer.doc_state = XmlCommentState.NotAllowed;
2086 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2090 Error_SyntaxError (yyToken);
2091 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2095 Error_SyntaxError (yyToken);
2096 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2100 constructor_declaration
2101 : constructor_declarator
2104 Constructor c = (Constructor) $1;
2105 c.Block = (ToplevelBlock) $2;
2107 if (RootContext.Documentation != null)
2108 c.DocComment = ConsumeStoredComment ();
2110 current_container.AddConstructor (c);
2112 current_local_parameters = null;
2113 if (RootContext.Documentation != null)
2114 Lexer.doc_state = XmlCommentState.Allowed;
2118 constructor_declarator
2123 if (RootContext.Documentation != null) {
2124 tmpComment = Lexer.consume_doc_comment ();
2125 Lexer.doc_state = XmlCommentState.Allowed;
2128 valid_param_mod = ParameterModifierType.All;
2130 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2132 valid_param_mod = 0;
2133 current_local_parameters = (ParametersCompiled) $6;
2136 // start block here, so possible anonymous methods inside
2137 // constructor initializer can get correct parent block
2139 start_block (lexer.Location);
2141 opt_constructor_initializer
2143 LocatedToken lt = (LocatedToken) $3;
2144 int mods = (int) $2;
2145 ConstructorInitializer ci = (ConstructorInitializer) $9;
2147 Constructor c = new Constructor (current_class, lt.Value, mods,
2148 (Attributes) $1, current_local_parameters, ci, lt.Location);
2150 if (lt.Value != current_container.MemberName.Name) {
2151 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2152 } else if ((mods & Modifiers.STATIC) != 0) {
2153 if ((mods & Modifiers.Accessibility) != 0){
2154 Report.Error (515, c.Location,
2155 "`{0}': static constructor cannot have an access modifier",
2156 c.GetSignatureForError ());
2159 Report.Error (514, c.Location,
2160 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2161 c.GetSignatureForError ());
2172 | SEMICOLON { current_block = null; $$ = null; }
2175 opt_constructor_initializer
2177 | constructor_initializer
2180 constructor_initializer
2181 : COLON BASE OPEN_PARENS
2183 ++lexer.parsing_block;
2185 opt_argument_list CLOSE_PARENS
2187 --lexer.parsing_block;
2188 $$ = new ConstructorBaseInitializer ((Arguments) $5, (Location) $2);
2190 | COLON THIS OPEN_PARENS
2192 ++lexer.parsing_block;
2194 opt_argument_list CLOSE_PARENS
2196 --lexer.parsing_block;
2197 $$ = new ConstructorThisInitializer ((Arguments) $5, (Location) $2);
2200 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2205 destructor_declaration
2206 : opt_attributes opt_modifiers TILDE
2208 if (RootContext.Documentation != null) {
2209 tmpComment = Lexer.consume_doc_comment ();
2210 Lexer.doc_state = XmlCommentState.NotAllowed;
2213 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2215 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2217 LocatedToken lt = (LocatedToken) $5;
2218 if (lt.Value != current_container.MemberName.Name){
2219 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2220 } else if (current_container.Kind != Kind.Class){
2221 Report.Error (575, lt.Location, "Only class types can contain destructor");
2223 Destructor d = new Destructor (current_class, (int) $2,
2224 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2225 if (RootContext.Documentation != null)
2226 d.DocComment = ConsumeStoredComment ();
2228 d.Block = (ToplevelBlock) $8;
2229 current_container.AddMethod (d);
2232 current_local_parameters = null;
2239 EVENT type variable_declarators SEMICOLON
2241 current_array_type = null;
2242 foreach (VariableMemberDeclaration var in (ArrayList) $5) {
2244 EventField e = new EventField (
2245 current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
2247 if (var.expression_or_array_initializer != null) {
2248 if (current_container.Kind == Kind.Interface) {
2249 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2252 e.Initializer = var.expression_or_array_initializer;
2255 if (var.MemberName.Left != null) {
2256 Report.Error (71, e.Location,
2257 "`{0}': An explicit interface implementation of an event must use property syntax",
2258 e.GetSignatureForError ());
2261 current_container.AddEvent (e);
2263 if (RootContext.Documentation != null) {
2264 e.DocComment = Lexer.consume_doc_comment ();
2265 Lexer.doc_state = XmlCommentState.Allowed;
2271 EVENT type member_declaration_name
2274 implicit_value_parameter_type = (FullNamedExpression) $4;
2275 current_local_parameters = new ParametersCompiled (
2276 new Parameter (implicit_value_parameter_type, "value",
2277 Parameter.Modifier.NONE, null, GetLocation ($3)));
2279 lexer.EventParsing = true;
2281 event_accessor_declarations
2283 lexer.EventParsing = false;
2287 MemberName name = (MemberName) $5;
2289 if (current_container.Kind == Kind.Interface) {
2290 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2291 $8 = new Accessors (null, null);
2292 } else if ($8 == null) {
2293 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2294 current_container.GetSignatureForError (), name.GetSignatureForError ());
2295 $8 = new Accessors (null, null);
2298 Accessors accessors = (Accessors) $8;
2300 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2301 // CS0073 is already reported, so no CS0065 here.
2304 Event e = new EventProperty (
2305 current_class, (FullNamedExpression) $4, (int) $2, name,
2306 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2307 if (RootContext.Documentation != null) {
2308 e.DocComment = Lexer.consume_doc_comment ();
2309 Lexer.doc_state = XmlCommentState.Allowed;
2312 current_container.AddEvent (e);
2313 implicit_value_parameter_type = null;
2315 current_local_parameters = null;
2317 | opt_attributes opt_modifiers EVENT type member_declaration_name error
2319 MemberName mn = (MemberName) $5;
2320 if (mn.Left != null)
2321 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2323 if (RootContext.Documentation != null)
2324 Lexer.doc_state = XmlCommentState.Allowed;
2326 Error_SyntaxError (yyToken);
2331 event_accessor_declarations
2332 : add_accessor_declaration remove_accessor_declaration
2334 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2336 | remove_accessor_declaration add_accessor_declaration
2338 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2339 accessors.declared_in_reverse = true;
2342 | add_accessor_declaration { $$ = null; }
2343 | remove_accessor_declaration { $$ = null; }
2346 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2352 add_accessor_declaration
2353 : opt_attributes ADD
2355 lexer.EventParsing = false;
2359 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2360 lexer.EventParsing = true;
2363 | opt_attributes ADD error {
2364 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2367 | opt_attributes modifiers ADD {
2368 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2373 remove_accessor_declaration
2374 : opt_attributes REMOVE
2376 lexer.EventParsing = false;
2380 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2381 lexer.EventParsing = true;
2383 | opt_attributes REMOVE error {
2384 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2387 | opt_attributes modifiers REMOVE {
2388 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2394 : opt_attributes opt_modifiers
2395 member_type indexer_declaration_name OPEN_BRACKET
2397 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2399 opt_formal_parameter_list CLOSE_BRACKET
2402 valid_param_mod = 0;
2403 implicit_value_parameter_type = (FullNamedExpression) $3;
2404 indexer_parameters = (ParametersCompiled) $7;
2406 if (indexer_parameters.IsEmpty) {
2407 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2410 if (RootContext.Documentation != null) {
2411 tmpComment = Lexer.consume_doc_comment ();
2412 Lexer.doc_state = XmlCommentState.Allowed;
2415 lexer.PropertyParsing = true;
2416 parsing_indexer = true;
2419 accessor_declarations
2421 lexer.PropertyParsing = false;
2422 has_get = has_set = false;
2423 parsing_indexer = false;
2427 Accessors accessors = (Accessors) $11;
2428 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2429 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2430 bool order = accessors != null ? accessors.declared_in_reverse : false;
2432 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
2433 (MemberName)$4, (int) $2, (ParametersCompiled) $7, (Attributes) $1,
2434 get_block, set_block, order);
2436 if ($3 == TypeManager.system_void_expr)
2437 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2439 if (accessors == null)
2440 Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2442 if (current_container.Kind == Kind.Interface) {
2443 if (indexer.Get.Block != null)
2444 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2446 if (indexer.Set.Block != null)
2447 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2450 if (RootContext.Documentation != null)
2451 indexer.DocComment = ConsumeStoredComment ();
2453 current_container.AddIndexer (indexer);
2455 current_local_parameters = null;
2456 implicit_value_parameter_type = null;
2457 indexer_parameters = null;
2464 ENUM type_declaration_name
2466 if (RootContext.Documentation != null)
2467 enumTypeComment = Lexer.consume_doc_comment ();
2472 MemberName name = (MemberName) $4;
2473 if (name.IsGeneric) {
2474 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2477 name = MakeName (name);
2478 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2479 name, (Attributes) $1);
2481 if (RootContext.Documentation != null)
2482 e.DocComment = enumTypeComment;
2485 EnumMember em = null;
2486 foreach (VariableDeclaration ev in (ArrayList) $7) {
2487 em = new EnumMember (
2488 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2489 ev.OptAttributes, ev.Location);
2491 // if (RootContext.Documentation != null)
2492 em.DocComment = ev.DocComment;
2494 e.AddEnumMember (em);
2496 if (RootContext.EvalMode)
2497 undo.AddTypeContainer (current_container, e);
2499 current_container.AddTypeContainer (e);
2507 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2510 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2511 $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2512 $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2513 $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
2514 Enum.Error_1008 (GetLocation ($2));
2520 Error_TypeExpected (lexer.Location);
2527 if (RootContext.Documentation != null)
2528 Lexer.doc_state = XmlCommentState.Allowed;
2530 opt_enum_member_declarations
2532 // here will be evaluated after CLOSE_BLACE is consumed.
2533 if (RootContext.Documentation != null)
2534 Lexer.doc_state = XmlCommentState.Allowed;
2542 opt_enum_member_declarations
2543 : /* empty */ { $$ = new ArrayList (0); }
2544 | enum_member_declarations opt_comma { $$ = $1; }
2547 enum_member_declarations
2548 : enum_member_declaration
2550 ArrayList l = new ArrayList (4);
2555 | enum_member_declarations COMMA enum_member_declaration
2557 ArrayList l = (ArrayList) $1;
2565 enum_member_declaration
2566 : opt_attributes IDENTIFIER
2568 VariableDeclaration vd = new VariableDeclaration (
2569 (LocatedToken) $2, null, (Attributes) $1);
2571 if (RootContext.Documentation != null) {
2572 vd.DocComment = Lexer.consume_doc_comment ();
2573 Lexer.doc_state = XmlCommentState.Allowed;
2578 | opt_attributes IDENTIFIER
2580 ++lexer.parsing_block;
2581 if (RootContext.Documentation != null) {
2582 tmpComment = Lexer.consume_doc_comment ();
2583 Lexer.doc_state = XmlCommentState.NotAllowed;
2586 ASSIGN constant_expression
2588 --lexer.parsing_block;
2589 VariableDeclaration vd = new VariableDeclaration (
2590 (LocatedToken) $2, $5, (Attributes) $1);
2592 if (RootContext.Documentation != null)
2593 vd.DocComment = ConsumeStoredComment ();
2599 delegate_declaration
2603 member_type type_declaration_name
2606 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2608 opt_formal_parameter_list CLOSE_PARENS
2610 valid_param_mod = 0;
2612 MemberName name = MakeName ((MemberName) $5);
2613 ParametersCompiled p = (ParametersCompiled) $8;
2615 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2616 (int) $2, name, p, (Attributes) $1);
2618 if (RootContext.Documentation != null) {
2619 del.DocComment = Lexer.consume_doc_comment ();
2620 Lexer.doc_state = XmlCommentState.Allowed;
2623 current_container.AddDelegate (del);
2624 current_delegate = del;
2625 lexer.ConstraintsParsing = true;
2627 opt_type_parameter_constraints_clauses
2629 lexer.ConstraintsParsing = false;
2633 current_delegate.SetParameterInfo ((ArrayList) $11);
2634 $$ = current_delegate;
2636 current_delegate = null;
2647 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2648 Report.FeatureIsNotSupported (lexer.Location, "nullable types");
2649 else if (RootContext.Version < LanguageVersion.ISO_2)
2650 Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2656 namespace_or_type_name
2658 | qualified_alias_member IDENTIFIER opt_type_argument_list
2660 LocatedToken lt1 = (LocatedToken) $1;
2661 LocatedToken lt2 = (LocatedToken) $2;
2663 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2669 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2671 LocatedToken lt = (LocatedToken) $3;
2672 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2677 : IDENTIFIER opt_type_argument_list
2679 LocatedToken lt = (LocatedToken) $1;
2680 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2685 // Generics arguments (any type, without attributes)
2687 opt_type_argument_list
2688 : /* empty */ { $$ = null; }
2689 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2691 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2692 Report.FeatureIsNotSupported (lexer.Location, "generics");
2693 else if (RootContext.Version < LanguageVersion.ISO_2)
2694 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2698 | OP_GENERICS_LT error
2700 Error_TypeExpected (lexer.Location);
2701 $$ = new TypeArguments ();
2708 TypeArguments type_args = new TypeArguments ();
2709 type_args.Add ((FullNamedExpression) $1);
2712 | type_arguments COMMA type
2714 TypeArguments type_args = (TypeArguments) $1;
2715 type_args.Add ((FullNamedExpression) $3);
2721 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2723 type_declaration_name
2726 lexer.parsing_generic_declaration = true;
2728 opt_type_parameter_list
2730 lexer.parsing_generic_declaration = false;
2731 LocatedToken lt = (LocatedToken) $1;
2732 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2736 member_declaration_name
2737 : method_declaration_name
2739 MemberName mn = (MemberName)$1;
2740 if (mn.TypeArguments != null)
2741 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2742 mn.GetSignatureForError ()));
2746 method_declaration_name
2747 : type_declaration_name
2748 | explicit_interface IDENTIFIER opt_type_parameter_list
2750 lexer.parsing_generic_declaration = false;
2751 LocatedToken lt = (LocatedToken) $2;
2752 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2756 indexer_declaration_name
2759 lexer.parsing_generic_declaration = false;
2760 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2762 | explicit_interface THIS
2764 lexer.parsing_generic_declaration = false;
2765 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2770 : IDENTIFIER opt_type_argument_list DOT
2772 LocatedToken lt = (LocatedToken) $1;
2773 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2775 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2777 LocatedToken lt1 = (LocatedToken) $1;
2778 LocatedToken lt2 = (LocatedToken) $2;
2780 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2782 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2784 LocatedToken lt = (LocatedToken) $2;
2785 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2789 opt_type_parameter_list
2790 : /* empty */ { $$ = null; }
2791 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2793 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2794 Report.FeatureIsNotSupported (lexer.Location, "generics");
2795 else if (RootContext.Version < LanguageVersion.ISO_2)
2796 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2805 TypeArguments type_args = new TypeArguments ();
2806 type_args.Add ((FullNamedExpression)$1);
2809 | type_parameters COMMA type_parameter
2811 TypeArguments type_args = (TypeArguments) $1;
2812 type_args.Add ((FullNamedExpression)$3);
2818 : opt_attributes opt_type_parameter_variance IDENTIFIER
2820 LocatedToken lt = (LocatedToken)$3;
2821 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2825 if (GetTokenName (yyToken) == "type")
2826 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2828 Error_SyntaxError (yyToken);
2830 $$ = new TypeParameterName ("", null, lexer.Location);
2835 // All types where void is allowed
2838 : type_expression_or_array
2841 $$ = TypeManager.system_void_expr;
2848 lexer.parsing_generic_declaration = true;
2853 // A type which does not allow `void' to be used
2856 : type_expression_or_array
2859 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2860 $$ = TypeManager.system_void_expr;
2868 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2869 $$ = TypeManager.system_void_expr;
2874 : type_expression_or_array
2877 Report.Error (1536, lexer.Location, "Invalid parameter type `void'");
2878 $$ = TypeManager.system_void_expr;
2882 type_expression_or_array
2884 | type_expression rank_specifiers
2886 string rank_specifiers = (string) $2;
2887 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2892 : namespace_or_type_name opt_nullable
2894 MemberName name = (MemberName) $1;
2897 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2899 if (name.Left == null && name.Name == "var")
2900 $$ = current_array_type = new VarExpr (name.Location);
2902 $$ = name.GetTypeExpression ();
2905 | builtin_types opt_nullable
2908 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2910 | type_expression STAR
2913 // Note that here only unmanaged types are allowed but we
2914 // can't perform checks during this phase - we do it during
2915 // semantic analysis.
2917 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2921 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2928 ArrayList types = new ArrayList (2);
2932 | type_list COMMA base_type_name
2934 ArrayList types = (ArrayList) $1;
2943 if ($1 is ComposedCast)
2944 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2949 Error_TypeExpected (lexer.Location);
2954 * replaces all the productions for isolating the various
2955 * simple types, but we need this to reuse it easily in variable_type
2958 : OBJECT { $$ = TypeManager.system_object_expr; }
2959 | STRING { $$ = TypeManager.system_string_expr; }
2960 | BOOL { $$ = TypeManager.system_boolean_expr; }
2961 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2962 | FLOAT { $$ = TypeManager.system_single_expr; }
2963 | DOUBLE { $$ = TypeManager.system_double_expr; }
2968 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2969 | BYTE { $$ = TypeManager.system_byte_expr; }
2970 | SHORT { $$ = TypeManager.system_int16_expr; }
2971 | USHORT { $$ = TypeManager.system_uint16_expr; }
2972 | INT { $$ = TypeManager.system_int32_expr; }
2973 | UINT { $$ = TypeManager.system_uint32_expr; }
2974 | LONG { $$ = TypeManager.system_int64_expr; }
2975 | ULONG { $$ = TypeManager.system_uint64_expr; }
2976 | CHAR { $$ = TypeManager.system_char_expr; }
2983 $$ = TypeManager.system_void_expr;
2988 // Expressions, section 7.5
2993 : primary_expression_no_array_creation
2994 | array_creation_expression
2997 primary_expression_no_array_creation
2999 | IDENTIFIER opt_type_argument_list
3001 LocatedToken lt = (LocatedToken) $1;
3002 $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
3004 | IDENTIFIER GENERATE_COMPLETION {
3005 LocatedToken lt = (LocatedToken) $1;
3006 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3008 | parenthesized_expression
3009 | default_value_expression
3011 | invocation_expression
3015 | post_increment_expression
3016 | post_decrement_expression
3017 | object_or_delegate_creation_expression
3018 | anonymous_type_expression
3021 | checked_expression
3022 | unchecked_expression
3023 | pointer_member_access
3024 | anonymous_method_expression
3031 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3032 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
3033 | NULL { $$ = new NullLiteral (lexer.Location); }
3037 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3038 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3039 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3044 object v = lexer.Value;
3047 $$ = new IntLiteral ((int) v, lexer.Location);
3048 } else if (v is uint)
3049 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3051 $$ = new LongLiteral ((Int64) v, lexer.Location);
3052 else if (v is ulong)
3053 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3055 Console.WriteLine ("OOPS. Unexpected result from scanner");
3060 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3061 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3066 // Here is the trick, tokenizer may think that parens is a special but
3067 // parser is interested in open parens only, so we merge them.
3068 // Consider: if (a)foo ();
3073 | OPEN_PARENS_LAMBDA
3076 parenthesized_expression
3077 : OPEN_PARENS expression CLOSE_PARENS
3079 $$ = new ParenthesizedExpression ((Expression) $2);
3081 | OPEN_PARENS expression COMPLETE_COMPLETION
3083 $$ = new ParenthesizedExpression ((Expression) $2);
3088 : primary_expression DOT IDENTIFIER opt_type_argument_list
3090 LocatedToken lt = (LocatedToken) $3;
3091 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3093 | predefined_type DOT IDENTIFIER opt_type_argument_list
3095 LocatedToken lt = (LocatedToken) $3;
3096 // TODO: Location is wrong as some predefined types doesn't hold a location
3097 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3099 | qualified_alias_member IDENTIFIER opt_type_argument_list
3101 LocatedToken lt1 = (LocatedToken) $1;
3102 LocatedToken lt2 = (LocatedToken) $2;
3104 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3106 | primary_expression DOT GENERATE_COMPLETION {
3107 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3109 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3110 LocatedToken lt = (LocatedToken) $3;
3111 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3113 | predefined_type DOT GENERATE_COMPLETION
3115 // TODO: Location is wrong as some predefined types doesn't hold a location
3116 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3118 | predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
3119 LocatedToken lt = (LocatedToken) $3;
3120 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3124 invocation_expression
3125 : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
3127 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3131 opt_object_or_collection_initializer
3132 : /* empty */ { $$ = null; }
3133 | object_or_collection_initializer
3136 object_or_collection_initializer
3137 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3140 $$ = CollectionOrObjectInitializers.Empty;
3142 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3144 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3146 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3150 opt_member_initializer_list
3151 : /* empty */ { $$ = null; }
3152 | member_initializer_list
3158 member_initializer_list
3159 : member_initializer
3161 ArrayList a = new ArrayList ();
3165 | member_initializer_list COMMA member_initializer
3167 ArrayList a = (ArrayList)$1;
3174 : IDENTIFIER ASSIGN initializer_value
3176 LocatedToken lt = $1 as LocatedToken;
3177 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3179 | GENERATE_COMPLETION
3181 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3183 | non_assignment_expression opt_COMPLETE_COMPLETION {
3184 CompletionSimpleName csn = $1 as CompletionSimpleName;
3186 $$ = new CollectionElementInitializer ((Expression)$1);
3188 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3190 | OPEN_BRACE expression_list CLOSE_BRACE
3192 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3194 | OPEN_BRACE CLOSE_BRACE
3196 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3202 | object_or_collection_initializer
3206 : /* empty */ { $$ = null; }
3211 : argument_or_named_argument
3213 Arguments list = new Arguments (4);
3214 list.Add ((Argument) $1);
3217 | argument_list COMMA argument
3219 Arguments list = (Arguments) $1;
3220 if (list [list.Count - 1] is NamedArgument)
3221 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3223 list.Add ((Argument) $3);
3226 | argument_list COMMA named_argument
3228 Arguments list = (Arguments) $1;
3229 NamedArgument a = (NamedArgument) $3;
3230 for (int i = 0; i < list.Count; ++i) {
3231 NamedArgument na = list [i] as NamedArgument;
3232 if (na != null && na.Name.Value == a.Name.Value)
3233 Report.Error (1740, na.Name.Location, "Named argument `{0}' specified multiple times",
3240 | argument_list COMMA
3242 Report.Error (839, GetLocation ($2), "An argument is missing");
3245 | COMMA argument_or_named_argument
3247 Report.Error (839, GetLocation ($1), "An argument is missing");
3255 $$ = new Argument ((Expression) $1);
3257 | non_simple_argument
3260 argument_or_named_argument
3266 : REF variable_reference
3268 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3270 | OUT variable_reference
3272 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3274 | ARGLIST open_parens_any argument_list CLOSE_PARENS
3276 $$ = new Argument (new Arglist ((Arguments) $3, (Location) $1));
3278 | ARGLIST open_parens_any CLOSE_PARENS
3280 $$ = new Argument (new Arglist ((Location) $1));
3284 $$ = new Argument (new ArglistAccess ((Location) $1));
3293 : primary_expression_no_array_creation OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
3295 $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
3297 | array_creation_expression OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
3299 // LAMESPEC: Not allowed according to specification
3300 $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
3302 | primary_expression_no_array_creation rank_specifiers
3304 // So the super-trick is that primary_expression
3305 // can only be either a SimpleName or a MemberAccess.
3306 // The MemberAccess case arises when you have a fully qualified type-name like :
3308 // SimpleName is when you have
3311 Expression expr = (Expression) $1;
3312 if (expr is ComposedCast){
3313 $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3314 } else if (expr is ATypeNameExpression){
3316 // So we extract the string corresponding to the SimpleName
3319 $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3321 Error_ExpectingTypeName (expr);
3322 $$ = TypeManager.system_object_expr;
3325 current_array_type = (FullNamedExpression)$$;
3332 ArrayList list = new ArrayList (4);
3336 | expression_list COMMA expression
3338 ArrayList list = (ArrayList) $1;
3344 expression_list_arguments
3345 : expression_list_argument
3347 Arguments args = new Arguments (4);
3348 args.Add ((Argument) $1);
3351 | expression_list_arguments COMMA expression_list_argument
3353 Arguments args = (Arguments) $1;
3354 args.Add ((Argument) $3);
3359 expression_list_argument
3362 $$ = new Argument ((Expression) $1);
3370 $$ = new This (current_block, (Location) $1);
3375 : BASE DOT IDENTIFIER opt_type_argument_list
3377 LocatedToken lt = (LocatedToken) $3;
3378 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3380 | BASE OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
3382 $$ = new BaseIndexerAccess ((Arguments) $3, (Location) $1);
3386 Error_SyntaxError (yyToken);
3387 $$ = new BaseAccess (null, GetLocation ($2));
3391 post_increment_expression
3392 : primary_expression OP_INC
3394 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
3398 post_decrement_expression
3399 : primary_expression OP_DEC
3401 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
3405 object_or_delegate_creation_expression
3406 : new_expr_start open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3409 if (RootContext.Version <= LanguageVersion.ISO_2)
3410 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3412 $$ = new NewInitialize ((Expression) $1, (Arguments) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1));
3415 $$ = new New ((Expression) $1, (Arguments) $3, GetLocation ($1));
3417 | new_expr_start object_or_collection_initializer
3419 if (RootContext.Version <= LanguageVersion.ISO_2)
3420 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3422 $$ = new NewInitialize ((Expression) $1, null, (CollectionOrObjectInitializers) $2, GetLocation ($1));
3426 array_creation_expression
3427 : new_expr_start OPEN_BRACKET expression_list CLOSE_BRACKET
3428 opt_rank_specifier // shift/reduce on OPEN_BRACE
3429 opt_array_initializer
3431 $$ = new ArrayCreation ((FullNamedExpression) $1, (ArrayList) $3, (string) $5, (ArrayList) $6, GetLocation ($1));
3433 | new_expr_start rank_specifiers opt_array_initializer
3436 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3438 $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayList) $3, GetLocation ($1));
3440 | NEW rank_specifiers array_initializer
3442 if (RootContext.Version <= LanguageVersion.ISO_2)
3443 Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3445 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1));
3447 | new_expr_start error
3449 Report.Error (1526, GetLocation ($1), "A new expression requires () or [] after type");
3457 ++lexer.parsing_type;
3461 --lexer.parsing_type;
3466 anonymous_type_expression
3467 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3469 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3470 Report.FeatureIsNotSupported (lexer.Location, "anonymous types");
3471 else if (RootContext.Version <= LanguageVersion.ISO_2)
3472 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3474 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3478 anonymous_type_parameters_opt_comma
3479 : anonymous_type_parameters_opt
3480 | anonymous_type_parameters COMMA
3483 anonymous_type_parameters_opt
3485 | anonymous_type_parameters
3488 anonymous_type_parameters
3489 : anonymous_type_parameter
3491 ArrayList a = new ArrayList (4);
3495 | anonymous_type_parameters COMMA anonymous_type_parameter
3497 ArrayList a = (ArrayList) $1;
3503 anonymous_type_parameter
3504 : IDENTIFIER ASSIGN variable_initializer
3506 LocatedToken lt = (LocatedToken)$1;
3507 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3511 LocatedToken lt = (LocatedToken)$1;
3512 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3513 lt.Value, lt.Location);
3515 | BASE DOT IDENTIFIER opt_type_argument_list
3517 LocatedToken lt = (LocatedToken) $3;
3518 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3519 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3523 MemberAccess ma = (MemberAccess) $1;
3524 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3528 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3529 "Anonymous type members must be a member assignment, simple name or member access expression");
3544 opt_rank_specifier_or_nullable
3552 | opt_nullable rank_specifiers
3555 $$ = "?" + (string) $2;
3563 | rank_specifier rank_specifiers
3565 $$ = (string) $2 + (string) $1;
3570 : OPEN_BRACKET CLOSE_BRACKET
3574 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3576 $$ = "[" + (string) $2 + "]";
3578 | OPEN_BRACKET error CLOSE_BRACKET
3580 Report.Error (178, GetLocation ($1), "Invalid rank specifier: expected `,' or `]'");
3590 | dim_separators COMMA
3592 $$ = (string) $1 + ",";
3596 opt_array_initializer
3608 : OPEN_BRACE CLOSE_BRACE
3610 ArrayList list = new ArrayList (4);
3613 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3615 $$ = (ArrayList) $2;
3619 variable_initializer_list
3620 : variable_initializer
3622 ArrayList list = new ArrayList (4);
3626 | variable_initializer_list COMMA variable_initializer
3628 ArrayList list = (ArrayList) $1;
3634 Error_SyntaxError (yyToken);
3635 $$ = new ArrayList ();
3642 pushed_current_array_type = current_array_type;
3643 lexer.TypeOfParsing = true;
3645 open_parens_any typeof_type_expression CLOSE_PARENS
3647 lexer.TypeOfParsing = false;
3648 Expression type = (Expression)$4;
3649 if (type == TypeManager.system_void_expr)
3650 $$ = new TypeOfVoid ((Location) $1);
3652 $$ = new TypeOf (type, (Location) $1);
3653 current_array_type = pushed_current_array_type;
3657 typeof_type_expression
3662 Error_TypeExpected (lexer.Location);
3668 : IDENTIFIER generic_dimension
3670 LocatedToken lt = (LocatedToken) $1;
3672 $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
3674 | qualified_alias_member IDENTIFIER generic_dimension
3676 LocatedToken lt1 = (LocatedToken) $1;
3677 LocatedToken lt2 = (LocatedToken) $2;
3679 $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
3681 | unbound_type_name DOT IDENTIFIER
3683 LocatedToken lt = (LocatedToken) $3;
3685 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3687 | unbound_type_name DOT IDENTIFIER generic_dimension
3689 LocatedToken lt = (LocatedToken) $3;
3691 $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3693 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3695 LocatedToken lt = (LocatedToken) $3;
3696 MemberName name = (MemberName) $1;
3698 $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3705 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3706 Report.FeatureIsNotSupported (lexer.Location, "generics");
3707 else if (RootContext.Version < LanguageVersion.ISO_2)
3708 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3714 qualified_alias_member
3715 : IDENTIFIER DOUBLE_COLON
3717 LocatedToken lt = (LocatedToken) $1;
3718 if (RootContext.Version == LanguageVersion.ISO_1)
3719 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3726 : SIZEOF open_parens_any type CLOSE_PARENS {
3727 $$ = new SizeOf ((Expression) $3, (Location) $1);
3732 : CHECKED open_parens_any expression CLOSE_PARENS
3734 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3738 unchecked_expression
3739 : UNCHECKED open_parens_any expression CLOSE_PARENS
3741 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3745 pointer_member_access
3746 : primary_expression OP_PTR IDENTIFIER
3749 LocatedToken lt = (LocatedToken) $3;
3751 deref = new Indirection ((Expression) $1, lt.Location);
3752 $$ = new MemberAccess (deref, lt.Value);
3756 anonymous_method_expression
3757 : DELEGATE opt_anonymous_method_signature
3759 start_anonymous (false, (ParametersCompiled) $2, (Location) $1);
3763 $$ = end_anonymous ((ToplevelBlock) $4);
3767 opt_anonymous_method_signature
3770 $$ = ParametersCompiled.Undefined;
3772 | anonymous_method_signature
3775 anonymous_method_signature
3778 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3780 opt_formal_parameter_list CLOSE_PARENS
3782 valid_param_mod = 0;
3787 default_value_expression
3788 : DEFAULT open_parens_any type CLOSE_PARENS
3790 if (RootContext.Version < LanguageVersion.ISO_2)
3791 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3793 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3798 : primary_expression
3799 | BANG prefixed_unary_expression
3801 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
3803 | TILDE prefixed_unary_expression
3805 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
3811 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3813 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3815 | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
3817 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3822 // The idea to split this out is from Rhys' grammar
3823 // to solve the problem with casts.
3825 prefixed_unary_expression
3827 | PLUS prefixed_unary_expression
3829 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
3831 | MINUS prefixed_unary_expression
3833 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
3835 | OP_INC prefixed_unary_expression
3837 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
3839 | OP_DEC prefixed_unary_expression
3841 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
3843 | STAR prefixed_unary_expression
3845 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3847 | BITWISE_AND prefixed_unary_expression
3849 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
3853 multiplicative_expression
3854 : prefixed_unary_expression
3855 | multiplicative_expression STAR prefixed_unary_expression
3857 $$ = new Binary (Binary.Operator.Multiply,
3858 (Expression) $1, (Expression) $3);
3860 | multiplicative_expression DIV prefixed_unary_expression
3862 $$ = new Binary (Binary.Operator.Division,
3863 (Expression) $1, (Expression) $3);
3865 | multiplicative_expression PERCENT prefixed_unary_expression
3867 $$ = new Binary (Binary.Operator.Modulus,
3868 (Expression) $1, (Expression) $3);
3873 : multiplicative_expression
3874 | additive_expression PLUS multiplicative_expression
3876 $$ = new Binary (Binary.Operator.Addition,
3877 (Expression) $1, (Expression) $3);
3879 | additive_expression MINUS multiplicative_expression
3881 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3883 | parenthesized_expression MINUS multiplicative_expression
3885 // Shift/Reduce conflict
3886 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3888 | additive_expression AS type
3890 $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
3892 | additive_expression IS type
3894 $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
3899 : additive_expression
3900 | shift_expression OP_SHIFT_LEFT additive_expression
3902 $$ = new Binary (Binary.Operator.LeftShift,
3903 (Expression) $1, (Expression) $3);
3905 | shift_expression OP_SHIFT_RIGHT additive_expression
3907 $$ = new Binary (Binary.Operator.RightShift,
3908 (Expression) $1, (Expression) $3);
3912 relational_expression
3914 | relational_expression OP_LT shift_expression
3916 $$ = new Binary (Binary.Operator.LessThan,
3917 (Expression) $1, (Expression) $3);
3919 | relational_expression OP_GT shift_expression
3921 $$ = new Binary (Binary.Operator.GreaterThan,
3922 (Expression) $1, (Expression) $3);
3924 | relational_expression OP_LE shift_expression
3926 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3927 (Expression) $1, (Expression) $3);
3929 | relational_expression OP_GE shift_expression
3931 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3932 (Expression) $1, (Expression) $3);
3937 : relational_expression
3938 | equality_expression OP_EQ relational_expression
3940 $$ = new Binary (Binary.Operator.Equality,
3941 (Expression) $1, (Expression) $3);
3943 | equality_expression OP_NE relational_expression
3945 $$ = new Binary (Binary.Operator.Inequality,
3946 (Expression) $1, (Expression) $3);
3951 : equality_expression
3952 | and_expression BITWISE_AND equality_expression
3954 $$ = new Binary (Binary.Operator.BitwiseAnd,
3955 (Expression) $1, (Expression) $3);
3959 exclusive_or_expression
3961 | exclusive_or_expression CARRET and_expression
3963 $$ = new Binary (Binary.Operator.ExclusiveOr,
3964 (Expression) $1, (Expression) $3);
3968 inclusive_or_expression
3969 : exclusive_or_expression
3970 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3972 $$ = new Binary (Binary.Operator.BitwiseOr,
3973 (Expression) $1, (Expression) $3);
3977 conditional_and_expression
3978 : inclusive_or_expression
3979 | conditional_and_expression OP_AND inclusive_or_expression
3981 $$ = new Binary (Binary.Operator.LogicalAnd,
3982 (Expression) $1, (Expression) $3);
3986 conditional_or_expression
3987 : conditional_and_expression
3988 | conditional_or_expression OP_OR conditional_and_expression
3990 $$ = new Binary (Binary.Operator.LogicalOr,
3991 (Expression) $1, (Expression) $3);
3995 null_coalescing_expression
3996 : conditional_or_expression
3997 | conditional_or_expression OP_COALESCING null_coalescing_expression
3999 if (RootContext.Version < LanguageVersion.ISO_2)
4000 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4002 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
4006 conditional_expression
4007 : null_coalescing_expression
4008 | null_coalescing_expression INTERR expression COLON expression
4010 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
4014 assignment_expression
4015 : prefixed_unary_expression ASSIGN expression
4017 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4019 | prefixed_unary_expression OP_MULT_ASSIGN expression
4021 $$ = new CompoundAssign (
4022 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4024 | prefixed_unary_expression OP_DIV_ASSIGN expression
4026 $$ = new CompoundAssign (
4027 Binary.Operator.Division, (Expression) $1, (Expression) $3);
4029 | prefixed_unary_expression OP_MOD_ASSIGN expression
4031 $$ = new CompoundAssign (
4032 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4034 | prefixed_unary_expression OP_ADD_ASSIGN expression
4036 $$ = new CompoundAssign (
4037 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4039 | prefixed_unary_expression OP_SUB_ASSIGN expression
4041 $$ = new CompoundAssign (
4042 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4044 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4046 $$ = new CompoundAssign (
4047 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4049 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4051 $$ = new CompoundAssign (
4052 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4054 | prefixed_unary_expression OP_AND_ASSIGN expression
4056 $$ = new CompoundAssign (
4057 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4059 | prefixed_unary_expression OP_OR_ASSIGN expression
4061 $$ = new CompoundAssign (
4062 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4064 | prefixed_unary_expression OP_XOR_ASSIGN expression
4066 $$ = new CompoundAssign (
4067 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4071 lambda_parameter_list
4074 ArrayList pars = new ArrayList (4);
4079 | lambda_parameter_list COMMA lambda_parameter
4081 ArrayList pars = (ArrayList) $1;
4082 Parameter p = (Parameter)$3;
4083 if (pars[0].GetType () != p.GetType ()) {
4084 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4093 : parameter_modifier parameter_type IDENTIFIER
4095 LocatedToken lt = (LocatedToken) $3;
4097 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4099 | parameter_type IDENTIFIER
4101 LocatedToken lt = (LocatedToken) $2;
4103 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4107 LocatedToken lt = (LocatedToken) $1;
4108 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4112 opt_lambda_parameter_list
4113 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4114 | lambda_parameter_list {
4115 ArrayList pars_list = (ArrayList) $1;
4116 $$ = new ParametersCompiled ((Parameter[])pars_list.ToArray (typeof (Parameter)));
4120 lambda_expression_body
4122 start_block (lexer.Location);
4126 Block b = end_block (lexer.Location);
4127 b.AddStatement (new ContextualReturn ((Expression) $2));
4138 LocatedToken lt = (LocatedToken) $1;
4139 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4140 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
4142 lambda_expression_body
4144 $$ = end_anonymous ((ToplevelBlock) $4);
4146 | OPEN_PARENS_LAMBDA
4148 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4150 opt_lambda_parameter_list CLOSE_PARENS ARROW
4152 valid_param_mod = 0;
4153 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4155 lambda_expression_body
4157 $$ = end_anonymous ((ToplevelBlock) $7);
4162 : assignment_expression
4163 | non_assignment_expression
4166 non_assignment_expression
4167 : conditional_expression
4189 lexer.ConstraintsParsing = true;
4191 type_declaration_name
4193 MemberName name = MakeName ((MemberName) $6);
4194 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4197 opt_type_parameter_constraints_clauses
4199 lexer.ConstraintsParsing = false;
4201 current_class.SetParameterInfo ((ArrayList) $9);
4203 if (RootContext.Documentation != null) {
4204 current_container.DocComment = Lexer.consume_doc_comment ();
4205 Lexer.doc_state = XmlCommentState.Allowed;
4210 --lexer.parsing_declaration;
4211 if (RootContext.Documentation != null)
4212 Lexer.doc_state = XmlCommentState.Allowed;
4216 $$ = pop_current_class ();
4224 { $$ = $1; } // location
4228 : /* empty */ { $$ = (int) 0; }
4234 | modifiers modifier
4239 if ((m1 & m2) != 0) {
4240 Location l = lexer.Location;
4241 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4243 $$ = (int) (m1 | m2);
4251 if (current_container == RootContext.ToplevelTypes)
4252 Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
4254 | PUBLIC { $$ = Modifiers.PUBLIC; }
4255 | PROTECTED { $$ = Modifiers.PROTECTED; }
4256 | INTERNAL { $$ = Modifiers.INTERNAL; }
4257 | PRIVATE { $$ = Modifiers.PRIVATE; }
4258 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4259 | SEALED { $$ = Modifiers.SEALED; }
4260 | STATIC { $$ = Modifiers.STATIC; }
4261 | READONLY { $$ = Modifiers.READONLY; }
4262 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4263 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4264 | EXTERN { $$ = Modifiers.EXTERN; }
4265 | VOLATILE { $$ = Modifiers.VOLATILE; }
4266 | UNSAFE { $$ = Modifiers.UNSAFE; }
4275 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4278 opt_type_parameter_constraints_clauses
4279 : /* empty */ { $$ = null; }
4280 | type_parameter_constraints_clauses
4284 type_parameter_constraints_clauses
4285 : type_parameter_constraints_clause {
4286 ArrayList constraints = new ArrayList (1);
4287 constraints.Add ($1);
4290 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4291 ArrayList constraints = (ArrayList) $1;
4292 Constraints new_constraint = (Constraints)$2;
4294 foreach (Constraints c in constraints) {
4295 if (new_constraint.TypeParameter == c.TypeParameter) {
4296 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4297 new_constraint.TypeParameter);
4301 constraints.Add (new_constraint);
4306 type_parameter_constraints_clause
4307 : WHERE IDENTIFIER COLON type_parameter_constraints {
4308 LocatedToken lt = (LocatedToken) $2;
4309 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4313 type_parameter_constraints
4314 : type_parameter_constraint {
4315 ArrayList constraints = new ArrayList (1);
4316 constraints.Add ($1);
4319 | type_parameter_constraints COMMA type_parameter_constraint {
4320 ArrayList constraints = (ArrayList) $1;
4322 constraints.Add ($3);
4327 type_parameter_constraint
4329 | NEW OPEN_PARENS CLOSE_PARENS {
4330 $$ = SpecialConstraint.Constructor;
4333 $$ = SpecialConstraint.ReferenceType;
4336 $$ = SpecialConstraint.ValueType;
4340 opt_type_parameter_variance
4345 | type_parameter_variance
4347 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
4348 Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
4349 else if (RootContext.Version <= LanguageVersion.V_3)
4350 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4356 type_parameter_variance
4359 $$ = Variance.Covariant;
4363 $$ = Variance.Contravariant;
4372 // A block is "contained" on the following places:
4374 // property_declaration as part of the accessor body (get/set)
4375 // operator_declaration
4376 // constructor_declaration
4377 // destructor_declaration
4378 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4383 ++lexer.parsing_block;
4384 start_block ((Location) $1);
4386 opt_statement_list block_end
4395 --lexer.parsing_block;
4396 $$ = end_block ((Location) $1);
4398 | COMPLETE_COMPLETION
4400 --lexer.parsing_block;
4401 $$ = end_block (lexer.Location);
4409 ++lexer.parsing_block;
4410 current_block.StartLocation = GetLocation ($1);
4412 opt_statement_list CLOSE_BRACE
4414 --lexer.parsing_block;
4415 $$ = end_block ((Location) $4);
4426 | statement_list statement
4430 : declaration_statement
4432 if ($1 != null && (Block) $1 != current_block){
4433 current_block.AddStatement ((Statement) $1);
4434 current_block = (Block) $1;
4437 | valid_declaration_statement
4439 current_block.AddStatement ((Statement) $1);
4445 // The interactive_statement and its derivatives are only
4446 // used to provide a special version of `expression_statement'
4447 // that has a side effect of assigning the expression to
4450 interactive_statement_list
4451 : interactive_statement
4452 | interactive_statement_list interactive_statement
4455 interactive_statement
4456 : declaration_statement
4458 if ($1 != null && (Block) $1 != current_block){
4459 current_block.AddStatement ((Statement) $1);
4460 current_block = (Block) $1;
4463 | interactive_valid_declaration_statement
4465 current_block.AddStatement ((Statement) $1);
4470 valid_declaration_statement
4473 | expression_statement
4474 | selection_statement
4475 | iteration_statement
4479 | unchecked_statement
4486 interactive_valid_declaration_statement
4489 | interactive_expression_statement
4490 | selection_statement
4491 | iteration_statement
4495 | unchecked_statement
4503 : valid_declaration_statement
4504 | declaration_statement
4506 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4511 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4519 $$ = EmptyStatement.Value;
4526 LocatedToken lt = (LocatedToken) $1;
4527 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4529 if (current_block.AddLabel (labeled))
4530 current_block.AddStatement (labeled);
4535 declaration_statement
4536 : local_variable_declaration SEMICOLON
4538 current_array_type = null;
4540 DictionaryEntry de = (DictionaryEntry) $1;
4541 Expression e = (Expression) de.Key;
4543 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4547 | local_constant_declaration SEMICOLON
4549 current_array_type = null;
4551 DictionaryEntry de = (DictionaryEntry) $1;
4553 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4559 * The following is from Rhys' grammar:
4560 * > Types in local variable declarations must be recognized as
4561 * > expressions to prevent reduce/reduce errors in the grammar.
4562 * > The expressions are converted into types during semantic analysis.
4565 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4567 // FIXME: Do something smart here regarding the composition of the type.
4569 // Ok, the above "primary_expression" is there to get rid of
4570 // both reduce/reduce and shift/reduces in the grammar, it should
4571 // really just be "type_name". If you use type_name, a reduce/reduce
4572 // creeps up. If you use namespace_or_type_name (which is all we need
4573 // really) two shift/reduces appear.
4576 // So the super-trick is that primary_expression
4577 // can only be either a SimpleName or a MemberAccess.
4578 // The MemberAccess case arises when you have a fully qualified type-name like :
4580 // SimpleName is when you have
4583 Expression expr = (Expression) $1;
4584 string rank_or_nullable = (string) $2;
4586 if (expr is ComposedCast){
4587 $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4588 } else if (expr is ATypeNameExpression){
4590 // So we extract the string corresponding to the SimpleName
4593 if (rank_or_nullable.Length == 0) {
4594 SimpleName sn = expr as SimpleName;
4595 if (sn != null && sn.Name == "var")
4596 $$ = current_array_type = new VarExpr (sn.Location);
4600 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4603 Error_ExpectingTypeName (expr);
4604 $$ = TypeManager.system_object_expr;
4607 | builtin_types opt_rank_specifier_or_nullable
4609 if ((string) $2 == "")
4612 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4614 | VOID opt_rank_specifier
4616 Expression.Error_VoidInvalidInTheContext (lexer.Location);
4617 $$ = TypeManager.system_void_expr;
4621 local_variable_pointer_type
4622 : primary_expression_no_array_creation STAR
4624 ATypeNameExpression expr = $1 as ATypeNameExpression;
4627 $$ = new ComposedCast (expr, "*");
4629 Error_ExpectingTypeName ((Expression)$1);
4633 | builtin_types STAR
4635 $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
4639 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4641 | local_variable_pointer_type STAR
4643 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4649 | local_variable_pointer_type opt_rank_specifier
4652 string rank = (string)$2;
4657 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
4664 local_variable_declaration
4665 : local_variable_type local_variable_declarators
4668 VarExpr ve = $1 as VarExpr;
4670 ve.VariableInitializer = (ArrayList)$2;
4672 $$ = new DictionaryEntry ($1, $2);
4678 local_constant_declaration
4679 : CONST variable_type constant_declarators
4682 $$ = new DictionaryEntry ($2, $3);
4688 expression_statement
4689 : statement_expression SEMICOLON { $$ = $1; }
4690 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4693 interactive_expression_statement
4694 : interactive_statement_expression SEMICOLON { $$ = $1; }
4695 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4699 // We have to do the wrapping here and not in the case above,
4700 // because statement_expression is used for example in for_statement
4702 statement_expression
4705 ExpressionStatement s = $1 as ExpressionStatement;
4707 ((Expression) $1).Error_InvalidExpressionStatement ();
4708 s = EmptyExpressionStatement.Instance;
4711 $$ = new StatementExpression (s);
4715 Error_SyntaxError (yyToken);
4720 interactive_statement_expression
4723 Expression expr = (Expression) $1;
4724 ExpressionStatement s;
4726 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4727 $$ = new StatementExpression (s);
4731 Error_SyntaxError (yyToken);
4742 : IF open_parens_any boolean_expression CLOSE_PARENS
4745 Location l = (Location) $1;
4747 $$ = new If ((Expression) $3, (Statement) $5, l);
4749 // FIXME: location for warning should be loc property of $5.
4750 if ($5 == EmptyStatement.Value)
4751 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4754 | IF open_parens_any boolean_expression CLOSE_PARENS
4755 embedded_statement ELSE embedded_statement
4757 Location l = (Location) $1;
4759 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4761 // FIXME: location for warning should be loc property of $5 and $7.
4762 if ($5 == EmptyStatement.Value)
4763 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4764 if ($7 == EmptyStatement.Value)
4765 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4770 : SWITCH open_parens_any
4772 if (switch_stack == null)
4773 switch_stack = new Stack (2);
4774 switch_stack.Push (current_block);
4776 expression CLOSE_PARENS
4779 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4780 current_block = (Block) switch_stack.Pop ();
4796 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4797 $$ = new ArrayList ();
4805 ArrayList sections = new ArrayList (4);
4810 | switch_sections switch_section
4812 ArrayList sections = (ArrayList) $1;
4822 current_block = current_block.CreateSwitchBlock (lexer.Location);
4826 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4833 ArrayList labels = new ArrayList (4);
4838 | switch_labels switch_label
4840 ArrayList labels = (ArrayList) ($1);
4848 : CASE constant_expression COLON
4850 $$ = new SwitchLabel ((Expression) $2, (Location) $1);
4854 $$ = new SwitchLabel (null, (Location) $1);
4866 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
4868 Location l = (Location) $1;
4869 $$ = new While ((Expression) $3, (Statement) $5, l);
4874 : DO embedded_statement
4875 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
4877 Location l = (Location) $1;
4879 $$ = new Do ((Statement) $2, (Expression) $5, l);
4884 : FOR open_parens_any opt_for_initializer SEMICOLON
4886 Location l = lexer.Location;
4888 Block assign_block = current_block;
4890 if ($3 is DictionaryEntry){
4891 DictionaryEntry de = (DictionaryEntry) $3;
4893 Expression type = (Expression) de.Key;
4894 ArrayList var_declarators = (ArrayList) de.Value;
4896 foreach (VariableDeclaration decl in var_declarators){
4900 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4904 Expression expr = decl.expression_or_array_initializer;
4906 LocalVariableReference var;
4907 var = new LocalVariableReference (assign_block, decl.identifier, l);
4910 Assign a = new SimpleAssign (var, expr, decl.Location);
4912 assign_block.AddStatement (new StatementExpression (a));
4916 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4917 // This can be referred to as $5 below.
4923 opt_for_condition SEMICOLON
4924 opt_for_iterator CLOSE_PARENS
4927 Location l = (Location) $1;
4929 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4931 current_block.AddStatement (f);
4933 $$ = end_block (lexer.Location);
4938 : /* empty */ { $$ = EmptyStatement.Value; }
4943 : local_variable_declaration
4944 | statement_expression_list
4948 : /* empty */ { $$ = null; }
4949 | boolean_expression
4953 : /* empty */ { $$ = EmptyStatement.Value; }
4958 : statement_expression_list
4961 statement_expression_list
4962 : statement_expression
4964 // CHANGE: was `null'
4965 Statement s = (Statement) $1;
4966 Block b = new Block (current_block, s.loc, lexer.Location);
4971 | statement_expression_list COMMA statement_expression
4973 Block b = (Block) $1;
4975 b.AddStatement ((Statement) $3);
4981 : FOREACH open_parens_any type IN expression CLOSE_PARENS
4983 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4986 | FOREACH open_parens_any type IDENTIFIER IN
4987 expression CLOSE_PARENS
4989 start_block (lexer.Location);
4990 Block foreach_block = current_block;
4992 LocatedToken lt = (LocatedToken) $4;
4993 Location l = lt.Location;
4994 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4996 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4998 // Get a writable reference to this read-only variable.
5000 // Note that the $$ here refers to the value of _this_ code block,
5001 // not the value of the LHS non-terminal. This can be referred to as $8 below.
5002 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
5009 LocalVariableReference v = (LocalVariableReference) $8;
5010 Location l = (Location) $1;
5013 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
5014 current_block.AddStatement (f);
5017 $$ = end_block (lexer.Location);
5023 | continue_statement
5033 $$ = new Break ((Location) $1);
5038 : CONTINUE SEMICOLON
5040 $$ = new Continue ((Location) $1);
5045 : GOTO IDENTIFIER SEMICOLON
5047 LocatedToken lt = (LocatedToken) $2;
5048 $$ = new Goto (lt.Value, lt.Location);
5050 | GOTO CASE constant_expression SEMICOLON
5052 $$ = new GotoCase ((Expression) $3, (Location) $1);
5054 | GOTO DEFAULT SEMICOLON
5056 $$ = new GotoDefault ((Location) $1);
5061 : RETURN opt_expression SEMICOLON
5063 $$ = new Return ((Expression) $2, (Location) $1);
5068 : THROW opt_expression SEMICOLON
5070 $$ = new Throw ((Expression) $2, (Location) $1);
5075 : IDENTIFIER RETURN expression SEMICOLON
5077 LocatedToken lt = (LocatedToken) $1;
5078 string s = lt.Value;
5080 Report.Error (1003, lt.Location, "; expected");
5083 if (RootContext.Version == LanguageVersion.ISO_1){
5084 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5087 current_block.Toplevel.IsIterator = true;
5088 $$ = new Yield ((Expression) $3, lt.Location);
5090 | IDENTIFIER RETURN SEMICOLON
5092 Report.Error (1627, (Location) $2, "Expression expected after yield return");
5095 | IDENTIFIER BREAK SEMICOLON
5097 LocatedToken lt = (LocatedToken) $1;
5098 string s = lt.Value;
5100 Report.Error (1003, lt.Location, "; expected");
5103 if (RootContext.Version == LanguageVersion.ISO_1){
5104 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5108 current_block.Toplevel.IsIterator = true;
5109 $$ = new YieldBreak (lt.Location);
5119 : TRY block catch_clauses
5121 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
5123 | TRY block FINALLY block
5125 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
5127 | TRY block catch_clauses FINALLY block
5129 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
5133 Report.Error (1524, (Location) $1, "Expected catch or finally");
5141 ArrayList l = new ArrayList (4);
5146 | catch_clauses catch_clause
5148 ArrayList l = (ArrayList) $1;
5150 Catch c = (Catch) $2;
5151 if (((Catch) l [0]).IsGeneral) {
5152 Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5165 : /* empty */ { $$ = null; }
5170 : CATCH opt_catch_args
5172 Expression type = null;
5175 DictionaryEntry cc = (DictionaryEntry) $2;
5176 type = (Expression) cc.Key;
5177 LocatedToken lt = (LocatedToken) cc.Value;
5180 ArrayList one = new ArrayList (4);
5182 one.Add (new VariableDeclaration (lt, null));
5184 start_block (lexer.Location);
5185 current_block = declare_local_variables (type, one, lt.Location);
5189 Expression type = null;
5191 Block var_block = null;
5194 DictionaryEntry cc = (DictionaryEntry) $2;
5195 type = (Expression) cc.Key;
5196 LocatedToken lt = (LocatedToken) cc.Value;
5200 var_block = end_block (lexer.Location);
5204 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5209 : /* empty */ { $$ = null; }
5214 : open_parens_any type opt_identifier CLOSE_PARENS
5216 $$ = new DictionaryEntry ($2, $3);
5218 | open_parens_any CLOSE_PARENS
5220 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5227 $$ = new Checked ((Block) $2);
5234 $$ = new Unchecked ((Block) $2);
5241 RootContext.CheckUnsafeOption ((Location) $1);
5243 $$ = new Unsafe ((Block) $3);
5248 : FIXED open_parens_any
5249 type_and_void fixed_pointer_declarators
5252 ArrayList list = (ArrayList) $4;
5253 Expression type = (Expression) $3;
5254 Location l = (Location) $1;
5255 int top = list.Count;
5257 start_block (lexer.Location);
5259 for (int i = 0; i < top; i++){
5260 Pair p = (Pair) list [i];
5263 v = current_block.AddVariable (type, (string) p.First, l);
5267 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5275 Location l = (Location) $1;
5277 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5279 current_block.AddStatement (f);
5281 $$ = end_block (lexer.Location);
5285 fixed_pointer_declarators
5286 : fixed_pointer_declarator {
5287 ArrayList declarators = new ArrayList (4);
5289 declarators.Add ($1);
5292 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5294 ArrayList declarators = (ArrayList) $1;
5296 declarators.Add ($3);
5301 fixed_pointer_declarator
5302 : IDENTIFIER ASSIGN expression
5304 LocatedToken lt = (LocatedToken) $1;
5305 // FIXME: keep location
5306 $$ = new Pair (lt.Value, $3);
5310 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5316 : LOCK open_parens_any expression CLOSE_PARENS
5322 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5327 : USING open_parens_any local_variable_declaration CLOSE_PARENS
5329 start_block (lexer.Location);
5330 Block assign_block = current_block;
5332 DictionaryEntry de = (DictionaryEntry) $3;
5333 Location l = (Location) $1;
5335 Expression type = (Expression) de.Key;
5336 ArrayList var_declarators = (ArrayList) de.Value;
5338 Stack vars = new Stack ();
5340 foreach (VariableDeclaration decl in var_declarators) {
5341 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5344 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5346 Expression expr = decl.expression_or_array_initializer;
5348 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5351 LocalVariableReference var;
5353 // Get a writable reference to this read-only variable.
5354 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5356 // This is so that it is not a warning on using variables
5359 vars.Push (new DictionaryEntry (var, expr));
5361 // Assign a = new SimpleAssign (var, expr, decl.Location);
5362 // assign_block.AddStatement (new StatementExpression (a));
5365 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5366 // It can be referred to as $5 below.
5371 Statement stmt = (Statement) $6;
5372 Stack vars = (Stack) $5;
5373 Location l = (Location) $1;
5375 while (vars.Count > 0) {
5376 DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5377 stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5379 current_block.AddStatement (stmt);
5380 $$ = end_block (lexer.Location);
5382 | USING open_parens_any expression CLOSE_PARENS
5384 start_block (lexer.Location);
5388 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5389 $$ = end_block (lexer.Location);
5397 : first_from_clause query_body
5399 lexer.query_parsing = false;
5401 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5403 from.Tail.Next = (Linq.AQueryClause)$2;
5406 current_block.SetEndLocation (lexer.Location);
5407 current_block = current_block.Parent;
5409 | nested_from_clause query_body
5411 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5413 from.Tail.Next = (Linq.AQueryClause)$2;
5416 current_block.SetEndLocation (lexer.Location);
5417 current_block = current_block.Parent;
5422 : FROM_FIRST IDENTIFIER IN expression
5424 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5425 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5427 | FROM_FIRST type IDENTIFIER IN expression
5429 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5430 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5435 : FROM IDENTIFIER IN expression
5437 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5438 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5440 | FROM type IDENTIFIER IN expression
5442 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5443 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5448 : FROM IDENTIFIER IN
5450 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5454 LocatedToken lt = (LocatedToken) $2;
5455 $$ = new Linq.SelectMany (current_block.Toplevel, lt, (Expression)$5);
5457 current_block.SetEndLocation (lexer.Location);
5458 current_block = current_block.Parent;
5460 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5462 | FROM type IDENTIFIER IN
5464 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5468 LocatedToken lt = (LocatedToken) $3;
5469 FullNamedExpression type = (FullNamedExpression)$2;
5471 $$ = new Linq.SelectMany (current_block.Toplevel, lt, new Linq.Cast (type, (FullNamedExpression)$6));
5473 current_block.SetEndLocation (lexer.Location);
5474 current_block = current_block.Parent;
5476 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5481 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5483 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5486 head.Next = (Linq.AQueryClause)$3;
5489 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5490 clause.Tail.Next = head;
5498 select_or_group_clause
5501 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5505 $$ = new Linq.Select (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5507 current_block.SetEndLocation (lexer.Location);
5508 current_block = current_block.Parent;
5512 if (linq_clause_blocks == null)
5513 linq_clause_blocks = new Stack ();
5515 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5516 linq_clause_blocks.Push (current_block);
5520 current_block.SetEndLocation (lexer.Location);
5521 current_block = current_block.Parent;
5523 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5527 $$ = new Linq.GroupBy (current_block.Toplevel, (Expression)$3, (ToplevelBlock) linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5529 current_block.SetEndLocation (lexer.Location);
5530 current_block = current_block.Parent;
5534 opt_query_body_clauses
5536 | query_body_clauses
5541 | query_body_clauses query_body_clause
5543 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5557 : LET IDENTIFIER ASSIGN
5559 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5563 LocatedToken lt = (LocatedToken) $2;
5564 $$ = new Linq.Let (current_block.Toplevel, current_container, lt, (Expression)$5);
5566 current_block.SetEndLocation (lexer.Location);
5567 current_block = current_block.Parent;
5569 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5576 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5580 $$ = new Linq.Where (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5582 current_block.SetEndLocation (lexer.Location);
5583 current_block = current_block.Parent;
5588 : JOIN IDENTIFIER IN
5590 if (linq_clause_blocks == null)
5591 linq_clause_blocks = new Stack ();
5593 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5594 linq_clause_blocks.Push (current_block);
5598 current_block.SetEndLocation (lexer.Location);
5599 current_block = current_block.Parent;
5601 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5602 linq_clause_blocks.Push (current_block);
5606 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5607 current_block.SetEndLocation (lexer.Location);
5608 current_block = current_block.Parent;
5610 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, lexer.Location);
5612 expression opt_join_into
5614 LocatedToken lt = (LocatedToken) $2;
5616 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5617 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5620 $$ = new Linq.Join (block, lt, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
5622 $$ = new Linq.GroupJoin (block, lt, (Expression)$5, outer_selector, current_block.Toplevel,
5623 (LocatedToken) $12, GetLocation ($1));
5626 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5627 current_block.SetEndLocation (lexer.Location);
5628 current_block = current_block.Parent;
5631 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5633 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $12);
5635 | JOIN type IDENTIFIER IN
5637 if (linq_clause_blocks == null)
5638 linq_clause_blocks = new Stack ();
5640 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5641 linq_clause_blocks.Push (current_block);
5645 current_block.SetEndLocation (lexer.Location);
5646 current_block = current_block.Parent;
5648 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5649 linq_clause_blocks.Push (current_block);
5653 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5654 current_block.SetEndLocation (lexer.Location);
5655 current_block = current_block.Parent;
5657 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, lexer.Location);
5659 expression opt_join_into
5661 LocatedToken lt = (LocatedToken) $3;
5662 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5663 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5665 Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
5667 $$ = new Linq.Join (block, lt, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
5669 $$ = new Linq.GroupJoin (block, lt, cast, outer_selector, current_block.Toplevel,
5670 (LocatedToken) $13, GetLocation ($1));
5673 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5674 current_block.SetEndLocation (lexer.Location);
5675 current_block = current_block.Parent;
5678 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5680 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $13);
5695 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5699 current_block.SetEndLocation (lexer.Location);
5700 current_block = current_block.Parent;
5710 current_block.SetEndLocation (lexer.Location);
5711 current_block = current_block.Parent;
5713 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5717 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5724 | orderings_then_by COMMA
5726 current_block.SetEndLocation (lexer.Location);
5727 current_block = current_block.Parent;
5729 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5733 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5741 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5743 | expression ASCENDING
5745 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5747 | expression DESCENDING
5749 $$ = new Linq.OrderByDescending (current_block.Toplevel, (Expression)$1);
5756 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5758 | expression ASCENDING
5760 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5762 | expression DESCENDING
5764 $$ = new Linq.ThenByDescending (current_block.Toplevel, (Expression)$1);
5769 opt_query_continuation
5773 // query continuation block is not linked with query block but with block
5774 // before. This means each query can use same range variable names for
5775 // different identifiers.
5777 current_block.SetEndLocation (GetLocation ($1));
5778 current_block = current_block.Parent;
5780 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5784 $$ = new Linq.QueryExpression (current_block, (Linq.AQueryClause)$4);
5789 // Support for using the compiler as an interactive parser
5791 // The INTERACTIVE_PARSER token is first sent to parse our
5792 // productions; If the result is a Statement, the parsing
5793 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5794 // to setup the blocks in advance.
5796 // This setup is here so that in the future we can add
5797 // support for other constructs (type parsing, namespaces, etc)
5798 // that do not require a block to be setup in advance
5802 : EVAL_STATEMENT_PARSER EOF
5803 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5804 | EVAL_STATEMENT_PARSER {
5805 Evaluator.LoadAliases (current_namespace);
5807 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5808 Modifiers.PUBLIC, null), null);
5810 ArrayList baseclass_list = new ArrayList ();
5811 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5812 current_container.AddBasesForPart (current_class, baseclass_list);
5814 // (ref object retval)
5815 Parameter [] mpar = new Parameter [1];
5816 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5818 ParametersCompiled pars = new ParametersCompiled (mpar);
5819 current_local_parameters = pars;
5820 Method method = new Method (
5823 TypeManager.system_void_expr,
5824 Modifiers.PUBLIC | Modifiers.STATIC,
5825 new MemberName ("Host"),
5827 null /* attributes */);
5829 oob_stack.Push (method);
5830 ++lexer.parsing_block;
5831 start_block (lexer.Location);
5833 interactive_statement_list opt_COMPLETE_COMPLETION
5835 --lexer.parsing_block;
5836 Method method = (Method) oob_stack.Pop ();
5838 method.Block = (ToplevelBlock) end_block(lexer.Location);
5839 current_container.AddMethod (method);
5841 --lexer.parsing_declaration;
5842 InteractiveResult = pop_current_class ();
5843 current_local_parameters = null;
5845 | EVAL_COMPILATION_UNIT_PARSER {
5846 Evaluator.LoadAliases (current_namespace);
5848 interactive_compilation_unit
5851 interactive_compilation_unit
5852 : outer_declarations
5853 | outer_declarations global_attributes
5858 opt_COMPLETE_COMPLETION
5860 | COMPLETE_COMPLETION
5863 close_brace_or_complete_completion
5865 | COMPLETE_COMPLETION
5870 // A class used to pass around variable declarations and constants
5872 public class VariableDeclaration {
5873 public string identifier;
5874 public Expression expression_or_array_initializer;
5875 public Location Location;
5876 public Attributes OptAttributes;
5877 public string DocComment;
5879 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5881 this.identifier = lt.Value;
5882 if (eoai is ArrayList) {
5883 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5885 this.expression_or_array_initializer = (Expression)eoai;
5887 this.Location = lt.Location;
5888 this.OptAttributes = opt_attrs;
5891 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5896 class VariableMemberDeclaration
5898 public readonly MemberName MemberName;
5899 public Expression expression_or_array_initializer;
5901 public VariableMemberDeclaration (MemberName mn, object initializer)
5905 if (initializer is ArrayList) {
5906 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
5908 this.expression_or_array_initializer = (Expression)initializer;
5915 // A class used to hold info about an operator declarator
5917 struct OperatorDeclaration {
5918 public readonly Operator.OpType optype;
5919 public readonly FullNamedExpression ret_type;
5920 public readonly Location location;
5922 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5925 this.ret_type = ret_type;
5926 this.location = location;
5930 static void Error_ExpectingTypeName (Expression expr)
5932 if (expr is Invocation){
5933 Report.Error (1002, expr.Location, "Expecting `;'");
5935 expr.Error_InvalidExpressionStatement ();
5939 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5941 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5945 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5947 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5948 Parameter.GetModifierSignature (mod));
5951 static void Error_TypeExpected (Location loc)
5953 Report.Error (1031, loc, "Type expected");
5956 static void Error_NamedArgumentExpected (NamedArgument a)
5958 Report.Error (1738, a.Name.Location, "Named arguments must appear after the positional arguments");
5961 void push_current_class (TypeContainer tc, object partial_token)
5963 if (RootContext.EvalMode){
5964 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5965 undo.AddTypeContainer (current_container, tc);
5968 if (partial_token != null)
5969 current_container = current_container.AddPartial (tc);
5971 current_container = current_container.AddTypeContainer (tc);
5973 ++lexer.parsing_declaration;
5977 DeclSpace pop_current_class ()
5979 DeclSpace retval = current_class;
5981 current_class = current_class.Parent;
5982 current_container = current_class.PartialContainer;
5988 // Given the @class_name name, it creates a fully qualified name
5989 // based on the containing declaration space
5992 MakeName (MemberName class_name)
5994 Namespace ns = current_namespace.NS;
5996 if (current_container == RootContext.ToplevelTypes) {
5997 if (ns.Name.Length != 0)
5998 return new MemberName (ns.MemberName, class_name);
6002 return new MemberName (current_container.MemberName, class_name);
6006 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
6008 Block implicit_block;
6009 ArrayList inits = null;
6012 // If we are doing interactive editing, we want variable declarations
6013 // that are in the top block to be added instead to the class as
6016 if (RootContext.StatementMode){
6019 for (Block b = current_block; b != null; b = b.Parent){
6020 if (b is ExplicitBlock && !(b is ToplevelBlock)){
6021 // There has been an explicit block, we cant add to the class
6028 // We can use "current_block" since we know there are no explicit blocks
6030 foreach (VariableDeclaration decl in variable_declarators){
6031 // We can not use the super-handy f.Initializer, because
6032 // multiple lines would force code to be executed out of sync
6033 if (decl.expression_or_array_initializer != null){
6034 string id = "$" + decl.identifier;
6035 LocalInfo vi = current_block.AddVariable (type, id, decl.Location);
6037 // Avoid warning about this variable not being used.
6040 LocalVariableReference var;
6041 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location);
6042 Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
6043 current_block.AddStatement (new StatementExpression (assign));
6044 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
6045 current_block.AddStatement (new StatementExpression (assign));
6047 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
6048 new MemberName (decl.identifier, loc), null);
6049 current_container.AddField (f);
6051 // Register the field to be visible later as a global variable
6052 Evaluator.QueueField (f);
6056 return current_block;
6061 // We use the `Used' property to check whether statements
6062 // have been added to the current block. If so, we need
6063 // to create another block to contain the new declaration
6064 // otherwise, as an optimization, we use the same block to
6065 // add the declaration.
6067 // FIXME: A further optimization is to check if the statements
6068 // that were added were added as part of the initialization
6069 // below. In which case, no other statements have been executed
6070 // and we might be able to reduce the number of blocks for
6071 // situations like this:
6073 // int j = 1; int k = j + 1;
6075 if (current_block.Used)
6076 implicit_block = new Block (current_block, loc, lexer.Location);
6078 implicit_block = current_block;
6080 foreach (VariableDeclaration decl in variable_declarators){
6082 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
6083 if (decl.expression_or_array_initializer != null){
6085 inits = new ArrayList (4);
6092 return implicit_block;
6094 foreach (VariableDeclaration decl in inits){
6096 Expression expr = decl.expression_or_array_initializer;
6098 LocalVariableReference var;
6099 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
6101 assign = new SimpleAssign (var, expr, decl.Location);
6103 implicit_block.AddStatement (new StatementExpression (assign));
6106 return implicit_block;
6109 Block declare_local_constants (Expression type, ArrayList declarators)
6111 Block implicit_block;
6113 if (current_block.Used)
6114 implicit_block = new Block (current_block);
6116 implicit_block = current_block;
6118 foreach (VariableDeclaration decl in declarators){
6119 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
6122 return implicit_block;
6125 string CheckAttributeTarget (string a, Location l)
6128 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6132 Report.Warning (658, 1, l,
6133 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6134 return string.Empty;
6137 static bool IsUnaryOperator (Operator.OpType op)
6141 case Operator.OpType.LogicalNot:
6142 case Operator.OpType.OnesComplement:
6143 case Operator.OpType.Increment:
6144 case Operator.OpType.Decrement:
6145 case Operator.OpType.True:
6146 case Operator.OpType.False:
6147 case Operator.OpType.UnaryPlus:
6148 case Operator.OpType.UnaryNegation:
6154 void syntax_error (Location l, string msg)
6156 Report.Error (1003, l, "Syntax error, " + msg);
6161 public Tokenizer Lexer {
6167 static CSharpParser ()
6169 oob_stack = new Stack ();
6172 public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
6174 if (RootContext.EvalMode)
6178 current_namespace = new NamespaceEntry (null, file, null);
6179 current_class = current_namespace.SlaveDeclSpace;
6180 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6182 lexer = new Tokenizer (reader, file);
6185 public void parse ()
6187 eof_token = Token.EOF;
6190 if (yacc_verbose_flag > 1)
6191 yyparse (lexer, new yydebug.yyDebugSimple ());
6194 } catch (Exception e){
6195 if (e is yyParser.yyUnexpectedEof)
6196 UnexpectedEOF = true;
6197 else if (yacc_verbose_flag > 0)
6198 Console.WriteLine (e);
6199 if (e is yyParser.yyException)
6200 Report.Error (-25, lexer.Location, "Parsing error");
6202 Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
6204 Tokenizer tokenizer = lexer as Tokenizer;
6205 tokenizer.cleanup ();
6207 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6208 throw new InternalErrorException ("who set it?");
6211 static void CheckToken (int error, int yyToken, string msg, Location loc)
6213 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6214 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6216 Report.Error (error, loc, msg);
6219 void CheckIdentifierToken (int yyToken, Location loc)
6221 CheckToken (1041, yyToken, "Identifier expected", loc);
6224 string ConsumeStoredComment ()
6226 string s = tmpComment;
6228 Lexer.doc_state = XmlCommentState.Allowed;
6232 Location GetLocation (object obj)
6234 if (obj is MemberCore)
6235 return ((MemberCore) obj).Location;
6236 if (obj is MemberName)
6237 return ((MemberName) obj).Location;
6238 if (obj is LocatedToken)
6239 return ((LocatedToken) obj).Location;
6240 if (obj is Location)
6241 return (Location) obj;
6242 return lexer.Location;
6245 void start_block (Location loc)
6247 if (current_block == null || parsing_anonymous_method) {
6248 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
6249 parsing_anonymous_method = false;
6251 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6256 end_block (Location loc)
6258 Block retval = current_block.Explicit;
6259 retval.SetEndLocation (loc);
6260 current_block = retval.Parent;
6265 start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6267 if (RootContext.Version == LanguageVersion.ISO_1){
6268 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6271 oob_stack.Push (current_anonymous_method);
6272 oob_stack.Push (current_local_parameters);
6274 current_local_parameters = parameters;
6276 current_anonymous_method = lambda
6277 ? new LambdaExpression (loc)
6278 : new AnonymousMethodExpression (loc);
6280 // Force the next block to be created as a ToplevelBlock
6281 parsing_anonymous_method = true;
6285 * Completes the anonymous method processing, if lambda_expr is null, this
6286 * means that we have a Statement instead of an Expression embedded
6288 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
6290 AnonymousMethodExpression retval;
6292 current_anonymous_method.Block = anon_block;
6293 retval = current_anonymous_method;
6295 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6296 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6301 public NamespaceEntry CurrentNamespace {
6303 return current_namespace;
6308 void Error_SyntaxError (int token)
6310 Error_SyntaxError (0, token);
6313 void Error_SyntaxError (int error_code, int token)
6315 string symbol = GetSymbolName (token);
6316 string expecting = GetExpecting ();
6318 if (error_code == 0) {
6319 if (expecting == "`)'")
6325 if (expecting != null)
6326 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
6329 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
6332 string GetExpecting ()
6334 int [] tokens = yyExpectingTokens (yyExpectingState);
6335 ArrayList names = new ArrayList (tokens.Length);
6336 bool has_type = false;
6337 bool has_identifier = false;
6338 for (int i = 0; i < tokens.Length; i++){
6339 int token = tokens [i];
6340 has_identifier |= token == Token.IDENTIFIER;
6342 string name = GetTokenName (token);
6343 if (name == "<internal>")
6346 has_type |= name == "type";
6347 if (names.Contains (name))
6354 // Too many tokens to enumerate
6356 if (names.Count > 8)
6359 if (has_type && has_identifier)
6360 names.Remove ("identifier");
6362 if (names.Count == 1)
6363 return "`" + GetTokenName (tokens [0]) + "'";
6365 StringBuilder sb = new StringBuilder ();
6367 int count = names.Count;
6368 for (int i = 0; i < count; i++){
6369 bool last = i + 1 == count;
6373 sb.Append (names [i]);
6374 sb.Append (last ? "'" : "', ");
6376 return sb.ToString ();
6380 string GetSymbolName (int token)
6383 case Token.LITERAL_FLOAT:
6384 case Token.LITERAL_INTEGER:
6385 case Token.LITERAL_DOUBLE:
6386 case Token.LITERAL_DECIMAL:
6387 case Token.LITERAL_CHARACTER:
6388 case Token.LITERAL_STRING:
6389 return lexer.Value.ToString ();
6390 case Token.IDENTIFIER:
6391 return ((LocatedToken)lexer.Value).Value;
6433 case Token.BITWISE_AND:
6435 case Token.BITWISE_OR:
6449 case Token.OP_SHIFT_LEFT:
6451 case Token.OP_SHIFT_RIGHT:
6471 case Token.OP_COALESCING:
6473 case Token.OP_MULT_ASSIGN:
6475 case Token.OP_DIV_ASSIGN:
6477 case Token.OP_MOD_ASSIGN:
6479 case Token.OP_ADD_ASSIGN:
6481 case Token.OP_SUB_ASSIGN:
6483 case Token.OP_SHIFT_LEFT_ASSIGN:
6485 case Token.OP_SHIFT_RIGHT_ASSIGN:
6487 case Token.OP_AND_ASSIGN:
6489 case Token.OP_XOR_ASSIGN:
6491 case Token.OP_OR_ASSIGN:
6495 return GetTokenName (token);
6498 static string GetTokenName (int token)
6501 case Token.ABSTRACT:
6521 case Token.CONTINUE:
6525 case Token.DELEGATE:
6535 case Token.EXPLICIT:
6553 case Token.IMPLICIT:
6557 case Token.INTERFACE:
6559 case Token.INTERNAL:
6565 case Token.NAMESPACE:
6571 case Token.OPERATOR:
6575 case Token.OVERRIDE:
6581 case Token.PROTECTED:
6585 case Token.READONLY:
6597 case Token.STACKALLOC:
6598 return "stackalloc";
6615 case Token.UNCHECKED:
6623 case Token.VOLATILE:
6636 case Token.FROM_FIRST:
6654 case Token.ASCENDING:
6656 case Token.DESCENDING:
6657 return "descending";
6664 case Token.OPEN_BRACE:
6666 case Token.CLOSE_BRACE:
6668 case Token.OPEN_BRACKET:
6670 case Token.CLOSE_BRACKET:
6672 case Token.OPEN_PARENS_CAST:
6673 case Token.OPEN_PARENS_LAMBDA:
6674 case Token.OPEN_PARENS:
6676 case Token.CLOSE_PARENS:
6682 case Token.DEFAULT_COLON:
6686 case Token.SEMICOLON:
6697 case Token.BITWISE_AND:
6698 case Token.BITWISE_OR:
6705 case Token.OP_SHIFT_LEFT:
6706 case Token.OP_SHIFT_RIGHT:
6714 case Token.OP_COALESCING:
6715 case Token.OP_MULT_ASSIGN:
6716 case Token.OP_DIV_ASSIGN:
6717 case Token.OP_MOD_ASSIGN:
6718 case Token.OP_ADD_ASSIGN:
6719 case Token.OP_SUB_ASSIGN:
6720 case Token.OP_SHIFT_LEFT_ASSIGN:
6721 case Token.OP_SHIFT_RIGHT_ASSIGN:
6722 case Token.OP_AND_ASSIGN:
6723 case Token.OP_XOR_ASSIGN:
6724 case Token.OP_OR_ASSIGN:
6725 return "<operator>";
6747 case Token.OP_GENERICS_LT:
6748 case Token.GENERIC_DIMENSION:
6750 case Token.OP_GENERICS_GT:
6753 case Token.INTERR_NULLABLE:
6755 case Token.DOUBLE_COLON:
6757 case Token.LITERAL_FLOAT:
6758 case Token.LITERAL_INTEGER:
6759 case Token.LITERAL_DOUBLE:
6760 case Token.LITERAL_DECIMAL:
6761 case Token.LITERAL_CHARACTER:
6762 case Token.LITERAL_STRING:
6764 case Token.IDENTIFIER:
6765 return "identifier";
6767 // All of these are internal.
6770 case Token.FIRST_KEYWORD:
6772 case Token.EVAL_COMPILATION_UNIT_PARSER:
6773 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6774 case Token.EVAL_STATEMENT_PARSER:
6775 case Token.LAST_KEYWORD:
6776 case Token.GENERATE_COMPLETION:
6777 case Token.COMPLETE_COMPLETION:
6778 return "<internal>";
6780 // A bit more robust.
6782 return yyNames [token];