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 // Licensed under the terms of the GNU GPL
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.
29 using System.Collections;
34 public class CSharpParser {
35 NamespaceEntry current_namespace;
36 TypeContainer current_container;
37 DeclSpace current_class;
39 IAnonymousHost anonymous_host;
42 /// Current block is used to add statements as we find
45 Block current_block, top_current_block;
47 Delegate current_delegate;
49 GenericMethod current_generic_method;
50 AnonymousMethodExpression current_anonymous_method;
53 /// This is used by the unary_expression code to resolve
54 /// a name against a parameter.
56 Parameters current_local_parameters;
59 /// Using during property parsing to describe the implicit
60 /// value parameter that is passed to the "set" and "get"accesor
61 /// methods (properties and indexers).
63 Expression implicit_value_parameter_type;
64 Parameters indexer_parameters;
67 /// Hack to help create non-typed array initializer
69 public static Expression current_array_type;
70 Expression pushed_current_array_type;
73 /// Used to determine if we are parsing the get/set pair
74 /// of an indexer or a property
78 bool parsing_anonymous_method;
81 /// An out-of-band stack.
83 static Stack oob_stack;
90 static public int yacc_verbose_flag;
92 // Name of the file we are parsing
101 /// Temporary Xml documentation cache.
102 /// For enum types, we need one more temporary store.
105 string enumTypeComment;
107 /// Current attribute target
108 string current_attr_target;
110 /// assembly and module attribute definitions are enabled
111 bool global_attrs_enabled = true;
112 bool has_get, has_set;
117 %token NONE /* This token is never returned by our lexer */
118 %token ERROR // This is used not by the parser, but by the tokenizer.
122 *These are the C# keywords
209 %token QUERY_FIRST_TOKEN
222 %token QUERY_LAST_TOKEN
224 /* C# keywords which are not really keywords */
231 /* C# single character operators/punctuation. */
232 %token OPEN_BRACE "{"
233 %token CLOSE_BRACE "}"
234 %token OPEN_BRACKET "["
235 %token CLOSE_BRACKET "]"
236 %token OPEN_PARENS "("
237 %token CLOSE_PARENS ")"
249 %token OP_GENERICS_LT "<"
251 %token OP_GENERICS_GT ">"
252 %token BITWISE_AND "&"
253 %token BITWISE_OR "|"
260 /* C# multi-character operators. */
261 %token DOUBLE_COLON "::"
264 %token OP_SHIFT_LEFT "<<"
265 %token OP_SHIFT_RIGHT ">>"
272 %token OP_MULT_ASSIGN "*="
273 %token OP_DIV_ASSIGN "/="
274 %token OP_MOD_ASSIGN "%="
275 %token OP_ADD_ASSIGN "+="
276 %token OP_SUB_ASSIGN "-="
277 %token OP_SHIFT_LEFT_ASSIGN "<<="
278 %token OP_SHIFT_RIGHT_ASSIGN ">>="
279 %token OP_AND_ASSIGN "&="
280 %token OP_XOR_ASSIGN "^="
281 %token OP_OR_ASSIGN "|="
283 %token OP_COALESCING "??"
286 %token LITERAL_INTEGER "int literal"
287 %token LITERAL_FLOAT "float literal"
288 %token LITERAL_DOUBLE "double literal"
289 %token LITERAL_DECIMAL "decimal literal"
290 %token LITERAL_CHARACTER "character literal"
291 %token LITERAL_STRING "string literal"
294 %token OPEN_PARENS_LAMBDA
295 %token CLOSE_PARENS_CAST
296 %token CLOSE_PARENS_NO_CAST
297 %token CLOSE_PARENS_OPEN_PARENS
298 %token CLOSE_PARENS_MINUS
299 %token DEFAULT_OPEN_PARENS
300 %token GENERIC_DIMENSION
303 /* Add precedence rules to solve dangling else s/r conflict */
312 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
314 %left STAR DIV PERCENT
315 %right BANG CARRET UMINUS
316 %nonassoc OP_INC OP_DEC
318 %left OPEN_BRACKET OPEN_BRACE
322 %start compilation_unit
326 : outer_declarations opt_EOF
327 | outer_declarations global_attributes opt_EOF
328 | global_attributes opt_EOF
329 | opt_EOF /* allow empty files */
335 Lexer.check_incorrect_doc_comment ();
339 Lexer.check_incorrect_doc_comment ();
345 | outer_declarations outer_declaration
349 : extern_alias_directive
351 | namespace_member_declaration
354 extern_alias_directives
355 : extern_alias_directive
356 | extern_alias_directives extern_alias_directive;
358 extern_alias_directive
359 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
361 LocatedToken lt = (LocatedToken) $2;
364 Report.Error (1003, lt.Location, "'alias' expected");
365 } else if (RootContext.Version == LanguageVersion.ISO_1) {
366 Report.FeatureIsNotISO1 (lt.Location, "external alias");
368 lt = (LocatedToken) $3;
369 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
376 | using_directives using_directive
380 : using_alias_directive
382 if (RootContext.Documentation != null)
383 Lexer.doc_state = XmlCommentState.Allowed;
385 | using_namespace_directive
387 if (RootContext.Documentation != null)
388 Lexer.doc_state = XmlCommentState.Allowed;
392 using_alias_directive
393 : USING IDENTIFIER ASSIGN
394 namespace_or_type_name SEMICOLON
396 LocatedToken lt = (LocatedToken) $2;
397 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
400 CheckIdentifierToken (yyToken, GetLocation ($2));
404 using_namespace_directive
405 : USING namespace_name SEMICOLON
407 current_namespace.Using ((MemberName) $2, (Location) $1);
412 // Strictly speaking, namespaces don't have attributes but
413 // we parse global attributes along with namespace declarations and then
416 namespace_declaration
417 : opt_attributes NAMESPACE namespace_or_type_name
419 MemberName name = (MemberName) $3;
422 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
425 if (name.TypeArguments != null)
426 syntax_error (lexer.Location, "namespace name expected");
428 current_namespace = new NamespaceEntry (
429 current_namespace, file, name.GetName ());
430 current_class = current_namespace.SlaveDeclSpace;
431 current_container = current_class.PartialContainer;
433 namespace_body opt_semicolon
435 current_namespace = current_namespace.Parent;
436 current_class = current_namespace.SlaveDeclSpace;
437 current_container = current_class.PartialContainer;
452 : namespace_or_type_name {
453 MemberName name = (MemberName) $1;
455 if (name.TypeArguments != null)
456 syntax_error (lexer.Location, "namespace name expected");
465 if (RootContext.Documentation != null)
466 Lexer.doc_state = XmlCommentState.Allowed;
472 : opt_extern_alias_directives
474 opt_namespace_member_declarations
478 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
481 | opt_extern_alias_directives
483 opt_namespace_member_declarations
486 Report.Error (1513, lexer.Location, "} expected");
495 opt_extern_alias_directives
497 | extern_alias_directives
500 opt_namespace_member_declarations
502 | namespace_member_declarations
505 namespace_member_declarations
506 : namespace_member_declaration
507 | namespace_member_declarations namespace_member_declaration
510 namespace_member_declaration
514 DeclSpace ds = (DeclSpace)$1;
516 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
517 Report.Error (1527, ds.Location,
518 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
521 current_namespace.DeclarationFound = true;
523 | namespace_declaration {
524 current_namespace.DeclarationFound = true;
527 | field_declaration {
528 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
530 | method_declaration {
531 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
538 | interface_declaration
540 | delegate_declaration
542 // Enable this when we have handled all errors, because this acts as a generic fallback
545 // Console.WriteLine ("Token=" + yyToken);
546 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
558 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
566 global_attrs_enabled = false;
571 global_attrs_enabled = false;
580 if (current_attr_target != String.Empty) {
581 ArrayList sect = (ArrayList) $1;
583 if (global_attrs_enabled) {
584 if (current_attr_target == "module") {
585 CodeGen.Module.AddAttributes (sect);
587 } else if (current_attr_target != null && current_attr_target.Length > 0) {
588 CodeGen.Assembly.AddAttributes (sect);
591 $$ = new Attributes (sect);
594 if (RootContext.Documentation != null) {
595 Lexer.check_incorrect_doc_comment ();
597 XmlCommentState.Allowed;
601 $$ = new Attributes (sect);
606 current_attr_target = null;
608 | attribute_sections attribute_section
610 if (current_attr_target != String.Empty) {
611 Attributes attrs = $1 as Attributes;
612 ArrayList sect = (ArrayList) $2;
614 if (global_attrs_enabled) {
615 if (current_attr_target == "module") {
616 CodeGen.Module.AddAttributes (sect);
618 } else if (current_attr_target == "assembly") {
619 CodeGen.Assembly.AddAttributes (sect);
623 attrs = new Attributes (sect);
625 attrs.AddAttributes (sect);
629 attrs = new Attributes (sect);
631 attrs.AddAttributes (sect);
637 current_attr_target = null;
642 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
646 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
652 attribute_target_specifier
653 : attribute_target COLON
655 current_attr_target = (string)$1;
663 LocatedToken lt = (LocatedToken) $1;
664 $$ = CheckAttributeTarget (lt.Value, lt.Location);
666 | EVENT { $$ = "event"; }
667 | RETURN { $$ = "return"; }
670 string name = yyNames [yyToken].ToLower ();
671 $$ = CheckAttributeTarget (name, GetLocation ($1));
678 ArrayList attrs = new ArrayList (4);
684 | attribute_list COMMA attribute
686 ArrayList attrs = (ArrayList) $1;
694 : attribute_name opt_attribute_arguments
696 MemberName mname = (MemberName) $1;
697 if (mname.IsGeneric) {
698 Report.Error (404, lexer.Location,
699 "'<' unexpected: attributes cannot be generic");
702 object [] arguments = (object []) $2;
703 MemberName left = mname.Left;
704 string identifier = mname.Name;
706 Expression left_expr = left == null ? null : left.GetTypeExpression ();
708 if (current_attr_target == String.Empty)
710 else if (current_attr_target == "assembly" || current_attr_target == "module")
711 // FIXME: supply "nameEscaped" parameter here.
712 $$ = new GlobalAttribute (current_namespace, current_attr_target,
713 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
715 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
720 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
723 opt_attribute_arguments
724 : /* empty */ { $$ = null; }
725 | OPEN_PARENS attribute_arguments CLOSE_PARENS
733 : opt_positional_argument_list
738 $$ = new object [] { $1, null };
741 | positional_argument_list COMMA named_argument_list
743 $$ = new object[] { $1, $3 };
745 | named_argument_list
747 $$ = new object [] { null, $1 };
752 opt_positional_argument_list
753 : /* empty */ { $$ = null; }
754 | positional_argument_list
757 positional_argument_list
760 ArrayList args = new ArrayList (4);
761 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
765 | positional_argument_list COMMA expression
767 ArrayList args = (ArrayList) $1;
768 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
777 ArrayList args = new ArrayList (4);
782 | named_argument_list COMMA named_argument
784 ArrayList args = (ArrayList) $1;
789 | named_argument_list COMMA expression
791 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
797 : IDENTIFIER ASSIGN expression
799 // FIXME: keep location
800 $$ = new DictionaryEntry (
801 ((LocatedToken) $1).Value,
802 new Argument ((Expression) $3, Argument.AType.Expression));
808 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
811 opt_class_member_declarations
813 | class_member_declarations
816 class_member_declarations
817 : class_member_declaration
818 | class_member_declarations
819 class_member_declaration
822 class_member_declaration
823 : constant_declaration // done
824 | field_declaration // done
825 | method_declaration // done
826 | property_declaration // done
827 | event_declaration // done
828 | indexer_declaration // done
829 | operator_declaration // done
830 | constructor_declaration // done
831 | destructor_declaration // done
841 lexer.ConstraintsParsing = true;
845 MemberName name = MakeName ((MemberName) $6);
846 push_current_class (new Struct (
847 current_namespace, current_class, name, (int) $2,
848 (Attributes) $1), $3);
851 opt_type_parameter_constraints_clauses
853 lexer.ConstraintsParsing = false;
856 current_container.AddBasesForPart (current_class, (ArrayList) $8);
858 current_class.SetParameterInfo ((ArrayList) $9);
860 if (RootContext.Documentation != null)
861 current_container.DocComment = Lexer.consume_doc_comment ();
865 if (RootContext.Documentation != null)
866 Lexer.doc_state = XmlCommentState.Allowed;
870 $$ = pop_current_class ();
872 | opt_attributes opt_modifiers opt_partial STRUCT error {
873 CheckIdentifierToken (yyToken, GetLocation ($5));
880 if (RootContext.Documentation != null)
881 Lexer.doc_state = XmlCommentState.Allowed;
883 opt_struct_member_declarations CLOSE_BRACE
886 opt_struct_member_declarations
888 | struct_member_declarations
891 struct_member_declarations
892 : struct_member_declaration
893 | struct_member_declarations struct_member_declaration
896 struct_member_declaration
897 : constant_declaration
900 | property_declaration
902 | indexer_declaration
903 | operator_declaration
904 | constructor_declaration
908 * This is only included so we can flag error 575:
909 * destructors only allowed on class types
911 | destructor_declaration
922 int modflags = (int) $2;
923 foreach (VariableDeclaration constant in (ArrayList) $5){
924 Location l = constant.Location;
925 if ((modflags & Modifiers.STATIC) != 0) {
926 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
930 Const c = new Const (
931 current_class, (Expression) $4, (string) constant.identifier,
932 (Expression) constant.expression_or_array_initializer, modflags,
935 if (RootContext.Documentation != null) {
936 c.DocComment = Lexer.consume_doc_comment ();
937 Lexer.doc_state = XmlCommentState.Allowed;
939 current_container.AddConstant (c);
945 : constant_declarator
947 ArrayList constants = new ArrayList (4);
952 | constant_declarators COMMA constant_declarator
955 ArrayList constants = (ArrayList) $1;
962 : IDENTIFIER ASSIGN constant_expression
964 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
968 // A const field requires a value to be provided
969 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
981 Expression type = (Expression) $3;
984 current_array_type = null;
986 foreach (VariableDeclaration var in (ArrayList) $4){
987 Field field = new Field (current_class, type, mod, var.identifier,
988 (Attributes) $1, var.Location);
990 field.Initializer = var.expression_or_array_initializer;
992 if (RootContext.Documentation != null) {
993 field.DocComment = Lexer.consume_doc_comment ();
994 Lexer.doc_state = XmlCommentState.Allowed;
996 current_container.AddField (field);
997 $$ = field; // FIXME: might be better if it points to the top item
1004 fixed_variable_declarators
1007 Expression type = (Expression) $4;
1010 current_array_type = null;
1012 foreach (VariableDeclaration var in (ArrayList) $5) {
1013 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1014 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1016 if (RootContext.Documentation != null) {
1017 field.DocComment = Lexer.consume_doc_comment ();
1018 Lexer.doc_state = XmlCommentState.Allowed;
1020 current_container.AddField (field);
1021 $$ = field; // FIXME: might be better if it points to the top item
1030 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1035 variable_declarators
1037 current_array_type = null;
1038 Report.Error (670, (Location) $3, "Fields cannot have void type");
1042 fixed_variable_declarators
1043 : fixed_variable_declarator
1045 ArrayList decl = new ArrayList (2);
1049 | fixed_variable_declarators COMMA fixed_variable_declarator
1051 ArrayList decls = (ArrayList) $1;
1057 fixed_variable_declarator
1058 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1060 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1062 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1064 Report.Error (443, lexer.Location, "Value or constant expected");
1065 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1069 variable_declarators
1070 : variable_declarator
1072 ArrayList decl = new ArrayList (4);
1077 | variable_declarators COMMA variable_declarator
1079 ArrayList decls = (ArrayList) $1;
1086 : IDENTIFIER ASSIGN variable_initializer
1088 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1092 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1094 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1096 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1097 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1102 variable_initializer
1111 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1113 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1117 $$ = new ArglistAccess ((Location) $1);
1121 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1128 anonymous_host = (IAnonymousHost) $1;
1129 if (RootContext.Documentation != null)
1130 Lexer.doc_state = XmlCommentState.NotAllowed;
1131 Lexer.VarParsing = true;
1135 Method method = (Method) $1;
1136 method.Block = (ToplevelBlock) $3;
1137 current_container.AddMethod (method);
1139 anonymous_host = null;
1140 current_generic_method = null;
1141 current_local_parameters = null;
1143 if (RootContext.Documentation != null)
1144 Lexer.doc_state = XmlCommentState.Allowed;
1145 Lexer.VarParsing = false;
1158 Report.Error (1585, lexer.Location,
1159 "Member modifier `{0}' must precede the member type and name",
1160 Modifiers.Name (i));
1169 // This rule is used to handle the cases where OPEN_PARENS_LAMBDA
1170 // is returned (type followed by an identifier), these are the
1171 // declarations (methods, overloads, constructors, etc) and a handful
1172 // of expressions ("using", "fixed") or "catch".
1176 | OPEN_PARENS_LAMBDA
1182 type namespace_or_type_name
1183 open_parens opt_formal_parameter_list CLOSE_PARENS
1185 lexer.ConstraintsParsing = true;
1187 opt_type_parameter_constraints_clauses
1189 lexer.ConstraintsParsing = false;
1191 MemberName name = (MemberName) $4;
1193 if ($9 != null && name.TypeArguments == null)
1194 Report.Error (80, lexer.Location,
1195 "Constraints are not allowed on non-generic declarations");
1199 GenericMethod generic = null;
1200 if (name.TypeArguments != null) {
1201 generic = new GenericMethod (current_namespace, current_class, name,
1202 (Expression) $3, (Parameters) $6);
1204 generic.SetParameterInfo ((ArrayList) $9);
1207 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1208 name, (Parameters) $6, (Attributes) $1);
1210 anonymous_host = method;
1211 current_local_parameters = (Parameters) $6;
1212 current_generic_method = generic;
1214 if (RootContext.Documentation != null)
1215 method.DocComment = Lexer.consume_doc_comment ();
1221 VOID namespace_or_type_name
1222 open_parens opt_formal_parameter_list CLOSE_PARENS
1224 lexer.ConstraintsParsing = true;
1226 opt_type_parameter_constraints_clauses
1228 lexer.ConstraintsParsing = false;
1230 MemberName name = (MemberName) $4;
1232 if ($9 != null && name.TypeArguments == null)
1233 Report.Error (80, lexer.Location,
1234 "Constraints are not allowed on non-generic declarations");
1237 GenericMethod generic = null;
1238 if (name.TypeArguments != null) {
1239 generic = new GenericMethod (current_namespace, current_class, name,
1240 TypeManager.system_void_expr, (Parameters) $6);
1242 generic.SetParameterInfo ((ArrayList) $9);
1245 method = new Method (current_class, generic, TypeManager.system_void_expr,
1246 (int) $2, false, name, (Parameters) $6, (Attributes) $1);
1248 anonymous_host = method;
1249 current_local_parameters = (Parameters) $6;
1250 current_generic_method = generic;
1252 if (RootContext.Documentation != null)
1253 method.DocComment = Lexer.consume_doc_comment ();
1260 modifiers namespace_or_type_name open_parens opt_formal_parameter_list CLOSE_PARENS
1262 MemberName name = (MemberName) $5;
1263 Report.Error (1585, name.Location,
1264 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1266 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1267 0, false, name, (Parameters) $6, (Attributes) $1);
1269 current_local_parameters = (Parameters) $6;
1271 if (RootContext.Documentation != null)
1272 method.DocComment = Lexer.consume_doc_comment ();
1280 | SEMICOLON { $$ = null; }
1283 opt_formal_parameter_list
1284 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1285 | formal_parameter_list
1288 formal_parameter_list
1291 ArrayList pars_list = (ArrayList) $1;
1293 Parameter [] pars = new Parameter [pars_list.Count];
1294 pars_list.CopyTo (pars);
1296 $$ = new Parameters (pars);
1298 | fixed_parameters COMMA parameter_array
1300 ArrayList pars_list = (ArrayList) $1;
1303 Parameter [] pars = new Parameter [pars_list.Count];
1304 pars_list.CopyTo (pars);
1306 $$ = new Parameters (pars);
1308 | fixed_parameters COMMA ARGLIST
1310 ArrayList pars_list = (ArrayList) $1;
1311 //pars_list.Add (new ArglistParameter (GetLocation ($3)));
1313 Parameter [] pars = new Parameter [pars_list.Count];
1314 pars_list.CopyTo (pars);
1316 $$ = new Parameters (pars, true);
1318 | parameter_array COMMA error
1321 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1324 | fixed_parameters COMMA parameter_array COMMA error
1327 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1330 | ARGLIST COMMA error
1332 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1335 | fixed_parameters COMMA ARGLIST COMMA error
1337 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1342 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1346 $$ = new Parameters (new Parameter[0], true);
1353 ArrayList pars = new ArrayList (4);
1358 | fixed_parameters COMMA fixed_parameter
1360 ArrayList pars = (ArrayList) $1;
1361 Parameter p = (Parameter)$3;
1363 if ((p.modFlags & Parameter.Modifier.This) != 0)
1364 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1373 opt_parameter_modifier
1377 LocatedToken lt = (LocatedToken) $4;
1378 $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1381 opt_parameter_modifier
1383 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1385 LocatedToken lt = (LocatedToken) $4;
1386 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1390 opt_parameter_modifier
1393 Report.Error (1001, GetLocation ($3), "Identifier expected");
1397 opt_parameter_modifier
1400 CheckIdentifierToken (yyToken, GetLocation ($4));
1404 opt_parameter_modifier
1410 LocatedToken lt = (LocatedToken) $4;
1411 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1416 opt_parameter_modifier
1417 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1418 | parameter_modifiers
1422 : parameter_modifier
1426 | parameter_modifiers parameter_modifier
1428 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1429 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1430 if (((Parameter.Modifier)$1 & p2) == p2) {
1431 Error_DuplicateParameterModifier (lexer.Location, p2);
1433 switch (mod & ~Parameter.Modifier.This) {
1434 case Parameter.Modifier.REF:
1435 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1437 case Parameter.Modifier.OUT:
1438 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1441 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1450 : REF { $$ = Parameter.Modifier.REF; }
1451 | OUT { $$ = Parameter.Modifier.OUT; }
1452 | THIS { $$ = Parameter.Modifier.This; }
1456 : opt_attributes PARAMS type IDENTIFIER
1458 LocatedToken lt = (LocatedToken) $4;
1459 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1461 | opt_attributes PARAMS PARAMS type IDENTIFIER
1463 Error_DuplicateParameterModifier (lexer.Location, Parameter.Modifier.PARAMS);
1466 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1468 Parameter.Modifier mod = (Parameter.Modifier)$3;
1469 if ((mod & Parameter.Modifier.This) != 0) {
1470 Report.Error (1104, lexer.Location, "The parameter modifiers `this' and `params' cannot be used altogether");
1472 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1476 | opt_attributes PARAMS type error {
1477 CheckIdentifierToken (yyToken, GetLocation ($4));
1482 property_declaration
1486 namespace_or_type_name
1488 if (RootContext.Documentation != null)
1489 tmpComment = Lexer.consume_doc_comment ();
1493 implicit_value_parameter_type = (Expression) $3;
1495 lexer.PropertyParsing = true;
1497 accessor_declarations
1499 lexer.PropertyParsing = false;
1500 has_get = has_set = false;
1508 Accessors accessors = (Accessors) $8;
1509 Accessor get_block = accessors.get_or_add;
1510 Accessor set_block = accessors.set_or_remove;
1512 MemberName name = (MemberName) $4;
1514 if (name.TypeArguments != null)
1515 syntax_error (lexer.Location, "a property can't have type arguments");
1517 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1518 name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse);
1520 current_container.AddProperty (prop);
1521 implicit_value_parameter_type = null;
1523 if (RootContext.Documentation != null)
1524 prop.DocComment = ConsumeStoredComment ();
1529 accessor_declarations
1530 : get_accessor_declaration
1532 $$ = new Accessors ((Accessor) $1, null);
1534 | get_accessor_declaration accessor_declarations
1536 Accessors accessors = (Accessors) $2;
1537 accessors.get_or_add = (Accessor) $1;
1540 | set_accessor_declaration
1542 $$ = new Accessors (null, (Accessor) $1);
1544 | set_accessor_declaration accessor_declarations
1546 Accessors accessors = (Accessors) $2;
1547 accessors.set_or_remove = (Accessor) $1;
1548 accessors.declared_in_reverse = true;
1553 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1558 get_accessor_declaration
1559 : opt_attributes opt_modifiers GET
1561 // If this is not the case, then current_local_parameters has already
1562 // been set in indexer_declaration
1563 if (parsing_indexer == false)
1564 current_local_parameters = null;
1566 current_local_parameters = indexer_parameters;
1567 lexer.PropertyParsing = false;
1569 anonymous_host = SimpleAnonymousHost.GetSimple ();
1574 Report.Error (1007, (Location) $3, "Property accessor already defined");
1577 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1579 current_local_parameters = null;
1580 lexer.PropertyParsing = true;
1582 SimpleAnonymousHost.Simple.Propagate (accessor);
1583 anonymous_host = null;
1585 if (RootContext.Documentation != null)
1586 if (Lexer.doc_state == XmlCommentState.Error)
1587 Lexer.doc_state = XmlCommentState.NotAllowed;
1593 set_accessor_declaration
1594 : opt_attributes opt_modifiers SET
1597 Parameter implicit_value_parameter = new Parameter (
1598 implicit_value_parameter_type, "value",
1599 Parameter.Modifier.NONE, null, (Location) $3);
1601 if (parsing_indexer == false) {
1602 args = new Parameter [1];
1603 args [0] = implicit_value_parameter;
1604 current_local_parameters = new Parameters (args);
1606 Parameter [] fpars = indexer_parameters.FixedParameters;
1609 int count = fpars.Length;
1611 args = new Parameter [count + 1];
1612 fpars.CopyTo (args, 0);
1613 args [count] = implicit_value_parameter;
1616 current_local_parameters = new Parameters (
1620 lexer.PropertyParsing = false;
1622 anonymous_host = SimpleAnonymousHost.GetSimple ();
1627 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1630 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1632 current_local_parameters = null;
1633 lexer.PropertyParsing = true;
1635 SimpleAnonymousHost.Simple.Propagate (accessor);
1636 anonymous_host = null;
1638 if (RootContext.Documentation != null
1639 && Lexer.doc_state == XmlCommentState.Error)
1640 Lexer.doc_state = XmlCommentState.NotAllowed;
1648 | SEMICOLON { $$ = null; }
1651 interface_declaration
1657 lexer.ConstraintsParsing = true;
1661 MemberName name = MakeName ((MemberName) $6);
1663 push_current_class (new Interface (
1664 current_namespace, current_class, name, (int) $2,
1665 (Attributes) $1), $3);
1668 opt_type_parameter_constraints_clauses
1670 lexer.ConstraintsParsing = false;
1673 current_container.AddBasesForPart (current_class, (ArrayList) $8);
1675 current_class.SetParameterInfo ((ArrayList) $9);
1677 if (RootContext.Documentation != null) {
1678 current_container.DocComment = Lexer.consume_doc_comment ();
1679 Lexer.doc_state = XmlCommentState.Allowed;
1684 if (RootContext.Documentation != null)
1685 Lexer.doc_state = XmlCommentState.Allowed;
1689 $$ = pop_current_class ();
1691 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1692 CheckIdentifierToken (yyToken, GetLocation ($5));
1698 opt_interface_member_declarations
1702 opt_interface_member_declarations
1704 | interface_member_declarations
1707 interface_member_declarations
1708 : interface_member_declaration
1709 | interface_member_declarations interface_member_declaration
1712 interface_member_declaration
1713 : interface_method_declaration
1718 Method m = (Method) $1;
1720 if (m.IsExplicitImpl)
1721 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1722 m.GetSignatureForError ());
1724 current_container.AddMethod (m);
1726 if (RootContext.Documentation != null)
1727 Lexer.doc_state = XmlCommentState.Allowed;
1729 | interface_property_declaration
1734 Property p = (Property) $1;
1736 if (p.IsExplicitImpl)
1737 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1738 p.GetSignatureForError ());
1740 current_container.AddProperty (p);
1742 if (RootContext.Documentation != null)
1743 Lexer.doc_state = XmlCommentState.Allowed;
1745 | interface_event_declaration
1748 Event e = (Event) $1;
1750 if (e.IsExplicitImpl)
1751 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1752 e.GetSignatureForError ());
1754 current_container.AddEvent (e);
1757 if (RootContext.Documentation != null)
1758 Lexer.doc_state = XmlCommentState.Allowed;
1760 | interface_indexer_declaration
1765 Indexer i = (Indexer) $1;
1767 if (i.IsExplicitImpl)
1768 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1769 i.GetSignatureForError ());
1771 current_container.AddIndexer (i);
1773 if (RootContext.Documentation != null)
1774 Lexer.doc_state = XmlCommentState.Allowed;
1776 | delegate_declaration
1779 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1780 ((MemberCore)$1).GetSignatureForError ());
1786 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1787 ((MemberCore)$1).GetSignatureForError ());
1790 | struct_declaration
1793 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1794 ((MemberCore)$1).GetSignatureForError ());
1800 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1801 ((MemberCore)$1).GetSignatureForError ());
1804 | interface_declaration
1807 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1808 ((MemberCore)$1).GetSignatureForError ());
1811 | constant_declaration
1813 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1821 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1826 interface_method_declaration_body
1829 lexer.ConstraintsParsing = false;
1831 opt_statement_list CLOSE_BRACE
1833 Report.Error (531, lexer.Location,
1834 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1840 interface_method_declaration
1841 : opt_attributes opt_new type namespace_or_type_name
1842 open_parens opt_formal_parameter_list CLOSE_PARENS
1844 lexer.ConstraintsParsing = true;
1846 opt_type_parameter_constraints_clauses
1848 // Refer to the name as $-1 in interface_method_declaration_body
1851 interface_method_declaration_body
1853 lexer.ConstraintsParsing = false;
1855 MemberName name = (MemberName) $4;
1857 if ($9 != null && name.TypeArguments == null)
1858 Report.Error (80, lexer.Location,
1859 "Constraints are not allowed on non-generic declarations");
1861 GenericMethod generic = null;
1862 if (name.TypeArguments != null) {
1863 generic = new GenericMethod (current_namespace, current_class, name,
1864 (Expression) $3, (Parameters) $6);
1866 generic.SetParameterInfo ((ArrayList) $9);
1869 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1870 (Parameters) $6, (Attributes) $1);
1871 if (RootContext.Documentation != null)
1872 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1874 | opt_attributes opt_new VOID namespace_or_type_name
1875 open_parens opt_formal_parameter_list CLOSE_PARENS
1877 lexer.ConstraintsParsing = true;
1879 opt_type_parameter_constraints_clauses
1883 interface_method_declaration_body
1885 lexer.ConstraintsParsing = false;
1887 MemberName name = (MemberName) $4;
1889 if ($9 != null && name.TypeArguments == null)
1890 Report.Error (80, lexer.Location,
1891 "Constraints are not allowed on non-generic declarations");
1893 GenericMethod generic = null;
1894 if (name.TypeArguments != null) {
1895 generic = new GenericMethod (current_namespace, current_class, name,
1896 TypeManager.system_void_expr, (Parameters) $6);
1898 generic.SetParameterInfo ((ArrayList) $9);
1901 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1902 true, name, (Parameters) $6, (Attributes) $1);
1903 if (RootContext.Documentation != null)
1904 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1908 interface_property_declaration
1913 { lexer.PropertyParsing = true; }
1914 accessor_declarations
1916 has_get = has_set = false;
1917 lexer.PropertyParsing = false;
1921 LocatedToken lt = (LocatedToken) $4;
1922 MemberName name = new MemberName (lt.Value, lt.Location);
1924 if ($3 == TypeManager.system_void_expr) {
1925 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1931 p = new Property (current_class, (Expression) $3, (int) $2, true,
1932 name, (Attributes) $1,
1935 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1939 Accessors accessor = (Accessors) $7;
1940 p = new Property (current_class, (Expression) $3, (int) $2, true,
1941 name, (Attributes) $1,
1942 accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
1944 if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
1945 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1950 if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
1951 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1956 if (RootContext.Documentation != null)
1957 p.DocComment = Lexer.consume_doc_comment ();
1964 CheckIdentifierToken (yyToken, GetLocation ($4));
1970 interface_event_declaration
1971 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1973 LocatedToken lt = (LocatedToken) $5;
1974 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1975 new MemberName (lt.Value, lt.Location),
1977 if (RootContext.Documentation != null)
1978 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1980 | opt_attributes opt_new EVENT type error {
1981 CheckIdentifierToken (yyToken, GetLocation ($5));
1984 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1985 LocatedToken lt = (LocatedToken) $5;
1986 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1989 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1991 lexer.EventParsing = true;
1993 event_accessor_declarations
1995 lexer.EventParsing = false;
1998 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2003 interface_indexer_declaration
2004 : opt_attributes opt_new type THIS
2005 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
2007 { lexer.PropertyParsing = true; }
2008 accessor_declarations
2010 has_get = has_set = false;
2011 lexer.PropertyParsing = false;
2017 i = new Indexer (current_class, (Expression) $3,
2018 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2019 (int) $2, true, (Parameters) $6, (Attributes) $1,
2022 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
2026 Accessors accessors = (Accessors) $10;
2027 i = new Indexer (current_class, (Expression) $3,
2028 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2029 (int) $2, true, (Parameters) $6, (Attributes) $1,
2030 accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
2032 if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
2033 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
2038 if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
2039 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
2044 if (RootContext.Documentation != null)
2045 i.DocComment = ConsumeStoredComment ();
2051 operator_declaration
2052 : opt_attributes opt_modifiers operator_declarator
2054 anonymous_host = SimpleAnonymousHost.GetSimple ();
2061 OperatorDeclaration decl = (OperatorDeclaration) $3;
2063 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
2065 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
2066 if (decl.arg2type != null)
2067 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
2069 Operator op = new Operator (
2070 current_class, decl.optype, decl.ret_type, (int) $2,
2071 new Parameters (param_list),
2072 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2074 if (RootContext.Documentation != null) {
2075 op.DocComment = tmpComment;
2076 Lexer.doc_state = XmlCommentState.Allowed;
2079 SimpleAnonymousHost.Simple.Propagate (op);
2080 anonymous_host = null;
2082 // Note again, checking is done in semantic analysis
2083 current_container.AddOperator (op);
2085 current_local_parameters = null;
2091 | SEMICOLON { $$ = null; }
2094 : type OPERATOR overloadable_operator
2095 open_parens opt_attributes opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2097 // TODO: wrong location
2098 if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE)
2099 Error_ParameterModifierNotValid ((Location) $2);
2101 LocatedToken lt = (LocatedToken) $8;
2102 Operator.OpType op = (Operator.OpType) $3;
2103 CheckUnaryOperator (op, lt.Location);
2105 if (op == Operator.OpType.Addition)
2106 op = Operator.OpType.UnaryPlus;
2108 if (op == Operator.OpType.Subtraction)
2109 op = Operator.OpType.UnaryNegation;
2111 Parameter [] pars = new Parameter [1];
2112 Expression type = (Expression) $7;
2114 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, (Attributes) $5, lt.Location);
2116 current_local_parameters = new Parameters (pars);
2118 if (RootContext.Documentation != null) {
2119 tmpComment = Lexer.consume_doc_comment ();
2120 Lexer.doc_state = XmlCommentState.NotAllowed;
2123 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2124 null, null, (Location) $2);
2126 | type OPERATOR overloadable_operator
2128 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
2129 opt_attributes opt_parameter_modifier type IDENTIFIER
2132 // TODO: wrong location
2133 if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE || (Parameter.Modifier)$11 != Parameter.Modifier.NONE)
2134 Error_ParameterModifierNotValid ((Location) $2);
2136 LocatedToken ltParam1 = (LocatedToken) $8;
2137 LocatedToken ltParam2 = (LocatedToken) $13;
2138 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2140 Parameter [] pars = new Parameter [2];
2142 Expression typeL = (Expression) $7;
2143 Expression typeR = (Expression) $12;
2145 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, (Attributes) $5, ltParam1.Location);
2146 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, (Attributes) $10, ltParam2.Location);
2148 current_local_parameters = new Parameters (pars);
2150 if (RootContext.Documentation != null) {
2151 tmpComment = Lexer.consume_doc_comment ();
2152 Lexer.doc_state = XmlCommentState.NotAllowed;
2155 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2156 typeL, ltParam1.Value,
2157 typeR, ltParam2.Value, (Location) $2);
2159 | conversion_operator_declarator
2160 | type OPERATOR overloadable_operator
2162 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
2163 opt_attributes opt_parameter_modifier type IDENTIFIER COMMA error
2165 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2166 Operator.GetName ((Operator.OpType) $3));
2169 | type OPERATOR overloadable_operator
2170 open_parens CLOSE_PARENS
2172 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2173 Operator.GetName ((Operator.OpType) $3));
2178 overloadable_operator
2180 : BANG { $$ = Operator.OpType.LogicalNot; }
2181 | TILDE { $$ = Operator.OpType.OnesComplement; }
2182 | OP_INC { $$ = Operator.OpType.Increment; }
2183 | OP_DEC { $$ = Operator.OpType.Decrement; }
2184 | TRUE { $$ = Operator.OpType.True; }
2185 | FALSE { $$ = Operator.OpType.False; }
2186 // Unary and binary:
2187 | PLUS { $$ = Operator.OpType.Addition; }
2188 | MINUS { $$ = Operator.OpType.Subtraction; }
2190 | STAR { $$ = Operator.OpType.Multiply; }
2191 | DIV { $$ = Operator.OpType.Division; }
2192 | PERCENT { $$ = Operator.OpType.Modulus; }
2193 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2194 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2195 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2196 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2197 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2198 | OP_EQ { $$ = Operator.OpType.Equality; }
2199 | OP_NE { $$ = Operator.OpType.Inequality; }
2200 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2201 | OP_LT { $$ = Operator.OpType.LessThan; }
2202 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2203 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2206 conversion_operator_declarator
2207 : IMPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2209 // TODO: wrong location
2210 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2211 Error_ParameterModifierNotValid (GetLocation ($4));
2213 LocatedToken lt = (LocatedToken) $7;
2214 Parameter [] pars = new Parameter [1];
2216 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2218 current_local_parameters = new Parameters (pars);
2220 if (RootContext.Documentation != null) {
2221 tmpComment = Lexer.consume_doc_comment ();
2222 Lexer.doc_state = XmlCommentState.NotAllowed;
2225 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $6, lt.Value,
2226 null, null, (Location) $2);
2228 | EXPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2230 // TODO: wrong location
2231 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2232 Error_ParameterModifierNotValid (GetLocation ($4));
2234 LocatedToken lt = (LocatedToken) $7;
2235 Parameter [] pars = new Parameter [1];
2237 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2239 current_local_parameters = new Parameters (pars);
2241 if (RootContext.Documentation != null) {
2242 tmpComment = Lexer.consume_doc_comment ();
2243 Lexer.doc_state = XmlCommentState.NotAllowed;
2246 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $6, lt.Value,
2247 null, null, (Location) $2);
2251 syntax_error ((Location) $1, "'operator' expected");
2255 syntax_error ((Location) $1, "'operator' expected");
2259 constructor_declaration
2262 constructor_declarator
2265 Constructor c = (Constructor) $3;
2266 c.Block = (ToplevelBlock) $4;
2267 c.OptAttributes = (Attributes) $1;
2268 c.ModFlags = (int) $2;
2270 if (RootContext.Documentation != null)
2271 c.DocComment = ConsumeStoredComment ();
2273 if (c.Name == current_container.Basename){
2274 if ((c.ModFlags & Modifiers.STATIC) != 0){
2275 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2276 Report.Error (515, c.Location,
2277 "`{0}': access modifiers are not allowed on static constructors",
2278 c.GetSignatureForError ());
2281 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2283 if (c.Initializer != null){
2284 Report.Error (514, c.Location,
2285 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2286 c.GetSignatureForError ());
2289 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2292 // We let another layer check the validity of the constructor.
2293 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2296 current_container.AddConstructor (c);
2298 current_local_parameters = null;
2299 if (RootContext.Documentation != null)
2300 Lexer.doc_state = XmlCommentState.Allowed;
2304 constructor_declarator
2305 : constructor_header
2309 | constructor_header constructor_initializer
2311 ((Constructor)$1).Initializer = (ConstructorInitializer) $2;
2319 if (RootContext.Documentation != null) {
2320 tmpComment = Lexer.consume_doc_comment ();
2321 Lexer.doc_state = XmlCommentState.Allowed;
2324 open_parens opt_formal_parameter_list CLOSE_PARENS
2326 current_local_parameters = (Parameters) $4;
2327 current_block = top_current_block = new ToplevelBlock (null,
2328 current_local_parameters, null, Location.Null);
2330 LocatedToken lt = (LocatedToken) $1;
2331 $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
2334 anonymous_host = (IAnonymousHost) $$;
2340 | SEMICOLON { current_block = top_current_block = null; $$ = null; }
2343 constructor_initializer
2344 : COLON BASE open_parens opt_argument_list CLOSE_PARENS
2346 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2348 | COLON THIS open_parens opt_argument_list CLOSE_PARENS
2350 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2353 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2359 : /* EMPTY */ { $$ = 0; }
2360 | UNSAFE { $$ = Modifiers.UNSAFE; }
2361 | EXTERN { $$ = Modifiers.EXTERN; }
2364 destructor_declaration
2365 : opt_attributes opt_finalizer TILDE
2367 if (RootContext.Documentation != null) {
2368 tmpComment = Lexer.consume_doc_comment ();
2369 Lexer.doc_state = XmlCommentState.NotAllowed;
2372 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2374 LocatedToken lt = (LocatedToken) $5;
2375 if (lt.Value != current_container.MemberName.Name){
2376 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2377 } else if (current_container.Kind != Kind.Class){
2378 Report.Error (575, lt.Location, "Only class types can contain destructor");
2380 Location l = lt.Location;
2383 if (!RootContext.StdLib && current_container.Name == "System.Object")
2384 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2386 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2388 Method d = new Destructor (
2389 current_class, TypeManager.system_void_expr, m, "Finalize",
2390 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2391 if (RootContext.Documentation != null)
2392 d.DocComment = ConsumeStoredComment ();
2394 d.Block = (ToplevelBlock) $8;
2395 current_container.AddMethod (d);
2403 EVENT type variable_declarators SEMICOLON
2405 current_array_type = null;
2406 foreach (VariableDeclaration var in (ArrayList) $5) {
2408 MemberName name = new MemberName (var.identifier,
2411 EventField e = new EventField (
2412 current_class, (Expression) $4, (int) $2, false, name,
2415 e.Initializer = var.expression_or_array_initializer;
2417 current_container.AddEvent (e);
2419 if (RootContext.Documentation != null) {
2420 e.DocComment = Lexer.consume_doc_comment ();
2421 Lexer.doc_state = XmlCommentState.Allowed;
2427 EVENT type namespace_or_type_name
2430 implicit_value_parameter_type = (Expression) $4;
2431 lexer.EventParsing = true;
2433 event_accessor_declarations
2435 lexer.EventParsing = false;
2439 MemberName name = (MemberName) $5;
2442 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2443 current_container.Name, name.ToString ());
2446 Accessors accessors = (Accessors) $8;
2448 if (name.TypeArguments != null)
2449 syntax_error (lexer.Location, "an event can't have type arguments");
2451 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2452 // CS0073 is already reported, so no CS0065 here.
2455 Event e = new EventProperty (
2456 current_class, (Expression) $4, (int) $2, false, name,
2457 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2458 if (RootContext.Documentation != null) {
2459 e.DocComment = Lexer.consume_doc_comment ();
2460 Lexer.doc_state = XmlCommentState.Allowed;
2463 current_container.AddEvent (e);
2464 implicit_value_parameter_type = null;
2468 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2469 MemberName mn = (MemberName) $5;
2471 if (mn.Left != null)
2472 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2474 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2476 if (RootContext.Documentation != null)
2477 Lexer.doc_state = XmlCommentState.Allowed;
2481 event_accessor_declarations
2482 : add_accessor_declaration remove_accessor_declaration
2484 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2486 | remove_accessor_declaration add_accessor_declaration
2488 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2489 accessors.declared_in_reverse = true;
2492 | add_accessor_declaration { $$ = null; }
2493 | remove_accessor_declaration { $$ = null; }
2496 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2502 add_accessor_declaration
2503 : opt_attributes ADD
2505 Parameter [] args = new Parameter [1];
2506 Parameter implicit_value_parameter = new Parameter (
2507 implicit_value_parameter_type, "value",
2508 Parameter.Modifier.NONE, null, (Location) $2);
2510 args [0] = implicit_value_parameter;
2512 current_local_parameters = new Parameters (args);
2513 lexer.EventParsing = false;
2515 anonymous_host = SimpleAnonymousHost.GetSimple ();
2519 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2520 lexer.EventParsing = true;
2522 current_local_parameters = null;
2523 SimpleAnonymousHost.Simple.Propagate (accessor);
2524 anonymous_host = null;
2528 | opt_attributes ADD error {
2529 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2532 | opt_attributes modifiers ADD {
2533 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2538 remove_accessor_declaration
2539 : opt_attributes REMOVE
2541 Parameter [] args = new Parameter [1];
2542 Parameter implicit_value_parameter = new Parameter (
2543 implicit_value_parameter_type, "value",
2544 Parameter.Modifier.NONE, null, (Location) $2);
2546 args [0] = implicit_value_parameter;
2548 current_local_parameters = new Parameters (args);
2549 lexer.EventParsing = false;
2553 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2554 lexer.EventParsing = true;
2556 | opt_attributes REMOVE error {
2557 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2560 | opt_attributes modifiers REMOVE {
2561 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2567 : opt_attributes opt_modifiers indexer_declarator
2570 IndexerDeclaration decl = (IndexerDeclaration) $3;
2572 implicit_value_parameter_type = decl.type;
2574 lexer.PropertyParsing = true;
2575 parsing_indexer = true;
2577 indexer_parameters = decl.param_list;
2578 anonymous_host = SimpleAnonymousHost.GetSimple ();
2580 accessor_declarations
2582 lexer.PropertyParsing = false;
2583 has_get = has_set = false;
2584 parsing_indexer = false;
2591 // The signature is computed from the signature of the indexer. Look
2592 // at section 3.6 on the spec
2594 IndexerDeclaration decl = (IndexerDeclaration) $3;
2595 Accessors accessors = (Accessors) $6;
2596 Accessor get_block = accessors.get_or_add;
2597 Accessor set_block = accessors.set_or_remove;
2600 if (decl.interface_type != null)
2601 name = new MemberName (
2602 decl.interface_type, TypeContainer.DefaultIndexerName, decl.location);
2604 name = new MemberName (TypeContainer.DefaultIndexerName, decl.location);
2606 indexer = new Indexer (current_class, decl.type, name,
2607 (int) $2, false, decl.param_list, (Attributes) $1,
2608 get_block, set_block, accessors.declared_in_reverse);
2610 if (RootContext.Documentation != null)
2611 indexer.DocComment = ConsumeStoredComment ();
2613 current_container.AddIndexer (indexer);
2615 current_local_parameters = null;
2616 implicit_value_parameter_type = null;
2617 indexer_parameters = null;
2622 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2624 Parameters pars = (Parameters) $4;
2625 if (pars.HasArglist) {
2626 // "__arglist is not valid in this context"
2627 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2628 } else if (pars.Empty){
2629 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2631 if (RootContext.Documentation != null) {
2632 tmpComment = Lexer.consume_doc_comment ();
2633 Lexer.doc_state = XmlCommentState.Allowed;
2636 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2638 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2640 Parameters pars = (Parameters) $6;
2642 if (pars.HasArglist) {
2643 // "__arglist is not valid in this context"
2644 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2645 } else if (pars.Empty){
2646 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2649 MemberName name = (MemberName) $2;
2650 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2652 if (RootContext.Documentation != null) {
2653 tmpComment = Lexer.consume_doc_comment ();
2654 Lexer.doc_state = XmlCommentState.Allowed;
2664 if (RootContext.Documentation != null)
2665 enumTypeComment = Lexer.consume_doc_comment ();
2670 LocatedToken lt = (LocatedToken) $4;
2671 Location enum_location = lt.Location;
2673 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2674 Enum e = new Enum (current_namespace, current_class, (Expression) $5, (int) $2,
2675 name, (Attributes) $1);
2677 if (RootContext.Documentation != null)
2678 e.DocComment = enumTypeComment;
2681 EnumMember em = null;
2682 foreach (VariableDeclaration ev in (ArrayList) $7) {
2683 em = new EnumMember (
2684 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2685 ev.OptAttributes, ev.Location);
2687 // if (RootContext.Documentation != null)
2688 em.DocComment = ev.DocComment;
2690 e.AddEnumMember (em);
2693 current_container.AddTypeContainer (e);
2700 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2701 | COLON type { $$ = $2; }
2707 if (RootContext.Documentation != null)
2708 Lexer.doc_state = XmlCommentState.Allowed;
2710 opt_enum_member_declarations
2712 // here will be evaluated after CLOSE_BLACE is consumed.
2713 if (RootContext.Documentation != null)
2714 Lexer.doc_state = XmlCommentState.Allowed;
2722 opt_enum_member_declarations
2723 : /* empty */ { $$ = new ArrayList (4); }
2724 | enum_member_declarations opt_comma { $$ = $1; }
2727 enum_member_declarations
2728 : enum_member_declaration
2730 ArrayList l = new ArrayList (4);
2735 | enum_member_declarations COMMA enum_member_declaration
2737 ArrayList l = (ArrayList) $1;
2745 enum_member_declaration
2746 : opt_attributes IDENTIFIER
2748 VariableDeclaration vd = new VariableDeclaration (
2749 (LocatedToken) $2, null, (Attributes) $1);
2751 if (RootContext.Documentation != null) {
2752 vd.DocComment = Lexer.consume_doc_comment ();
2753 Lexer.doc_state = XmlCommentState.Allowed;
2758 | opt_attributes IDENTIFIER
2760 if (RootContext.Documentation != null) {
2761 tmpComment = Lexer.consume_doc_comment ();
2762 Lexer.doc_state = XmlCommentState.NotAllowed;
2767 VariableDeclaration vd = new VariableDeclaration (
2768 (LocatedToken) $2, $5, (Attributes) $1);
2770 if (RootContext.Documentation != null)
2771 vd.DocComment = ConsumeStoredComment ();
2777 delegate_declaration
2782 lexer.ConstraintsParsing = true;
2785 open_parens opt_formal_parameter_list CLOSE_PARENS
2787 MemberName name = MakeName ((MemberName) $6);
2788 Parameters p = (Parameters) $8;
2790 // TODO: wrong location
2791 Report.Error (1669, name.Location, "__arglist is not valid in this context");
2794 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2795 (int) $2, name, p, (Attributes) $1);
2797 if (RootContext.Documentation != null) {
2798 del.DocComment = Lexer.consume_doc_comment ();
2799 Lexer.doc_state = XmlCommentState.Allowed;
2802 current_container.AddDelegate (del);
2803 current_delegate = del;
2805 opt_type_parameter_constraints_clauses
2807 lexer.ConstraintsParsing = false;
2811 current_delegate.SetParameterInfo ((ArrayList) $11);
2812 $$ = current_delegate;
2814 current_delegate = null;
2821 lexer.CheckNullable (false);
2826 lexer.CheckNullable (true);
2831 namespace_or_type_name
2833 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2834 LocatedToken lt1 = (LocatedToken) $1;
2835 LocatedToken lt2 = (LocatedToken) $3;
2836 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2838 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2839 LocatedToken lt = (LocatedToken) $3;
2840 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2845 : IDENTIFIER opt_type_argument_list {
2846 LocatedToken lt = (LocatedToken) $1;
2847 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2851 opt_type_argument_list
2852 : /* empty */ { $$ = null; }
2853 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2856 if (RootContext.Version == LanguageVersion.ISO_1)
2857 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2861 $$ = new TypeArguments ((int) $1, lexer.Location);
2862 if (RootContext.Version == LanguageVersion.ISO_1)
2863 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2868 : opt_attributes type {
2869 TypeArguments type_args = new TypeArguments (lexer.Location);
2871 SimpleName sn = $2 as SimpleName;
2873 Report.Error (1031, lexer.Location, "Type expected");
2875 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2877 type_args.Add ((Expression) $2);
2880 | type_arguments COMMA opt_attributes type {
2881 TypeArguments type_args = (TypeArguments) $1;
2883 SimpleName sn = $4 as SimpleName;
2885 Report.Error (1031, lexer.Location, "Type expected");
2887 $4 = new TypeParameterName (sn.Name, (Attributes) $3, lexer.Location);
2889 type_args.Add ((Expression) $4);
2896 * Before you think of adding a return_type, notice that we have been
2897 * using two rules in the places where it matters (one rule using type
2898 * and another identical one that uses VOID as the return type). This
2899 * gets rid of a shift/reduce couple
2902 : namespace_or_type_name opt_nullable
2904 MemberName name = (MemberName) $1;
2905 $$ = name.GetTypeExpression ();
2908 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2910 | builtin_types opt_nullable
2913 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2919 $$ = new VarExpr (lexer.Location);
2927 // Note that here only unmanaged types are allowed but we
2928 // can't perform checks during this phase - we do it during
2929 // semantic analysis.
2931 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2935 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2940 : builtin_types opt_nullable
2943 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2945 | non_expression_type rank_specifier
2947 Location loc = GetLocation ($1);
2949 loc = lexer.Location;
2950 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2952 | non_expression_type STAR
2954 Location loc = GetLocation ($1);
2956 loc = lexer.Location;
2957 $$ = new ComposedCast ((Expression) $1, "*", loc);
2959 | expression rank_specifiers
2961 $$ = new ComposedCast ((Expression) $1, (string) $2);
2965 $$ = new ComposedCast ((Expression) $1, "*");
2969 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2970 // through this different path
2972 | multiplicative_expression STAR
2974 $$ = new ComposedCast ((Expression) $1, "*");
2981 ArrayList types = new ArrayList (4);
2986 | type_list COMMA type
2988 ArrayList types = (ArrayList) $1;
2996 * replaces all the productions for isolating the various
2997 * simple types, but we need this to reuse it easily in local_variable_type
3000 : OBJECT { $$ = TypeManager.system_object_expr; }
3001 | STRING { $$ = TypeManager.system_string_expr; }
3002 | BOOL { $$ = TypeManager.system_boolean_expr; }
3003 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
3004 | FLOAT { $$ = TypeManager.system_single_expr; }
3005 | DOUBLE { $$ = TypeManager.system_double_expr; }
3010 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
3011 | BYTE { $$ = TypeManager.system_byte_expr; }
3012 | SHORT { $$ = TypeManager.system_int16_expr; }
3013 | USHORT { $$ = TypeManager.system_uint16_expr; }
3014 | INT { $$ = TypeManager.system_int32_expr; }
3015 | UINT { $$ = TypeManager.system_uint32_expr; }
3016 | LONG { $$ = TypeManager.system_int64_expr; }
3017 | ULONG { $$ = TypeManager.system_uint64_expr; }
3018 | CHAR { $$ = TypeManager.system_char_expr; }
3019 | VOID { $$ = TypeManager.system_void_expr; }
3023 : type rank_specifiers opt_nullable
3025 string rank_specifiers = (string) $2;
3027 rank_specifiers += "?";
3029 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
3034 // Expressions, section 7.5
3043 MemberName mn = (MemberName) $1;
3044 $$ = mn.GetTypeExpression ();
3046 | IDENTIFIER DOUBLE_COLON IDENTIFIER
3048 LocatedToken lt1 = (LocatedToken) $1;
3049 LocatedToken lt2 = (LocatedToken) $3;
3050 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
3052 | parenthesized_expression
3053 | default_value_expression
3055 | invocation_expression
3059 | post_increment_expression
3060 | post_decrement_expression
3064 | checked_expression
3065 | unchecked_expression
3066 | pointer_member_access
3067 | anonymous_method_expression
3074 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3075 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
3076 | NULL { $$ = new NullLiteral (lexer.Location); }
3080 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3081 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3082 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3087 object v = lexer.Value;
3090 $$ = new IntLiteral ((int) v, lexer.Location);
3091 } else if (v is uint)
3092 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3094 $$ = new LongLiteral ((Int64) v, lexer.Location);
3095 else if (v is ulong)
3096 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3098 Console.WriteLine ("OOPS. Unexpected result from scanner");
3103 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3104 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3107 parenthesized_expression_0
3108 : OPEN_PARENS expression CLOSE_PARENS
3111 lexer.Deambiguate_CloseParens ($$);
3112 // After this, the next token returned is one of
3113 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
3114 // or CLOSE_PARENS_MINUS.
3116 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
3119 parenthesized_expression
3120 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
3124 | parenthesized_expression_0 CLOSE_PARENS
3128 | parenthesized_expression_0 CLOSE_PARENS_MINUS
3130 // If a parenthesized expression is followed by a minus, we need to wrap
3131 // the expression inside a ParenthesizedExpression for the CS0075 check
3132 // in Binary.DoResolve().
3133 $$ = new ParenthesizedExpression ((Expression) $1);
3138 : primary_expression DOT IDENTIFIER opt_type_argument_list
3140 LocatedToken lt = (LocatedToken) $3;
3141 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3143 | predefined_type DOT IDENTIFIER opt_type_argument_list
3145 LocatedToken lt = (LocatedToken) $3;
3146 // TODO: Location is wrong as some predefined types doesn't hold a location
3147 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3155 invocation_expression
3156 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3159 Report.Error (1, (Location) $2, "Parse error");
3161 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3163 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3165 $$ = new Invocation ((Expression) $1, new ArrayList ());
3167 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3169 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3171 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3173 ArrayList args = new ArrayList (1);
3175 $$ = new Invocation ((Expression) $1, args);
3177 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3179 ArrayList args = ((ArrayList) $4);
3181 $$ = new Invocation ((Expression) $1, args);
3185 opt_object_initializer
3186 : /* empty */ { $$ = null; }
3187 | OPEN_BRACE variable_declarators CLOSE_BRACE
3189 ArrayList vars = (ArrayList) $2;
3190 ArrayList inits = new ArrayList (vars.Count);
3191 foreach (VariableDeclaration variable in vars) {
3192 Initializer i = new Initializer (variable.identifier, variable.expression_or_array_initializer);
3200 : /* empty */ { $$ = null; }
3207 ArrayList list = new ArrayList (4);
3211 | argument_list COMMA argument
3213 ArrayList list = (ArrayList) $1;
3217 | argument_list error {
3218 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3226 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3228 | non_simple_argument
3235 : REF variable_reference
3237 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3239 | OUT variable_reference
3241 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3243 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3245 ArrayList list = (ArrayList) $3;
3246 Argument[] args = new Argument [list.Count];
3247 list.CopyTo (args, 0);
3249 Expression expr = new Arglist (args, (Location) $1);
3250 $$ = new Argument (expr, Argument.AType.Expression);
3252 | ARGLIST OPEN_PARENS CLOSE_PARENS
3254 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3258 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3263 : expression { note ("section 5.4"); $$ = $1; }
3267 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3269 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3271 | primary_expression rank_specifiers
3273 // So the super-trick is that primary_expression
3274 // can only be either a SimpleName or a MemberAccess.
3275 // The MemberAccess case arises when you have a fully qualified type-name like :
3277 // SimpleName is when you have
3280 Expression expr = (Expression) $1;
3281 if (expr is ComposedCast){
3282 $$ = new ComposedCast (expr, (string) $2);
3283 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3284 Error_ExpectingTypeName (expr);
3285 $$ = TypeManager.system_object_expr;
3288 // So we extract the string corresponding to the SimpleName
3291 $$ = new ComposedCast (expr, (string) $2);
3293 current_array_type = (Expression)$$;
3300 ArrayList list = new ArrayList (4);
3304 | expression_list COMMA expression
3306 ArrayList list = (ArrayList) $1;
3315 $$ = new This (current_block, (Location) $1);
3320 : BASE DOT IDENTIFIER opt_type_argument_list
3322 LocatedToken lt = (LocatedToken) $3;
3323 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3325 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3327 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3330 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3335 post_increment_expression
3336 : primary_expression OP_INC
3338 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3339 (Expression) $1, (Location) $2);
3343 post_decrement_expression
3344 : primary_expression OP_DEC
3346 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3347 (Expression) $1, (Location) $2);
3352 : object_or_delegate_creation_expression
3353 | array_creation_expression
3354 | collection_initialization_expression
3355 | anonymous_type_expression
3358 object_or_delegate_creation_expression
3359 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_initializer
3362 if (RootContext.Version < LanguageVersion.LINQ) {
3363 Error_ExpectingTypeName ((Expression) $2);
3367 $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (Location) $1, (ArrayList) $6);
3370 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3374 collection_initialization_expression
3375 : NEW type OPEN_BRACE argument_list CLOSE_BRACE
3377 if (RootContext.Version < LanguageVersion.LINQ) {
3378 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3382 $$ = new CollectionInitialize ((Expression) $2, new ArrayList (), (Location) $1, (ArrayList) $4);
3386 array_creation_expression
3387 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3389 opt_array_initializer
3391 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3393 | NEW type rank_specifiers array_initializer
3395 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3397 | NEW rank_specifiers array_initializer
3399 if (RootContext.Version < LanguageVersion.LINQ) {
3400 Report.Error (1031, (Location) $1, "Type expected");
3404 $$ = new ArrayCreation (new VarExpr((Location) $1), (string) $2, (ArrayList) $3, (Location) $1);
3408 Report.Error (1031, (Location) $1, "Type expected");
3413 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3418 anonymous_type_expression
3419 : NEW OPEN_BRACE anonymous_type_parameters CLOSE_BRACE
3421 if (RootContext.Version < LanguageVersion.LINQ) {
3422 Report.Error (1031, (Location) $1, "Type expected");
3426 $$ = new AnonymousType ((ArrayList) $3, current_container, lexer.Location);
3430 anonymous_type_parameters
3431 : anonymous_type_parameter
3433 ArrayList a = new ArrayList (4);
3437 | anonymous_type_parameters COMMA anonymous_type_parameter
3439 ArrayList a = (ArrayList) $1;
3445 anonymous_type_parameter
3446 : variable_declarator
3448 VariableDeclaration v = (VariableDeclaration) $1;
3449 Expression e = v.expression_or_array_initializer;
3451 e = new LocalVariableReference (current_block, v.identifier, lexer.Location);
3453 $$ = new AnonymousTypeParameter (e, v.identifier);
3457 MemberAccess ma = (MemberAccess) $1;
3458 $$ = new AnonymousTypeParameter (ma, ma.Identifier);
3473 opt_rank_specifier_or_nullable
3482 | opt_nullable rank_specifiers
3489 | opt_nullable rank_specifiers INTERR
3492 $$ = "?" + $2 + "?";
3499 : rank_specifier opt_rank_specifier
3501 $$ = (string) $2 + (string) $1;
3506 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3508 $$ = "[" + (string) $2 + "]";
3528 | dim_separators COMMA
3530 $$ = (string) $1 + ",";
3534 opt_array_initializer
3546 : OPEN_BRACE CLOSE_BRACE
3548 ArrayList list = new ArrayList (4);
3551 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3553 $$ = (ArrayList) $2;
3557 variable_initializer_list
3558 : variable_initializer
3560 ArrayList list = new ArrayList (4);
3564 | variable_initializer_list COMMA variable_initializer
3566 ArrayList list = (ArrayList) $1;
3575 pushed_current_array_type = current_array_type;
3576 lexer.TypeOfParsing = true;
3578 OPEN_PARENS type CLOSE_PARENS
3580 lexer.TypeOfParsing = false;
3581 Expression type = (Expression)$4;
3582 if (type == TypeManager.system_void_expr)
3583 $$ = new TypeOfVoid ((Location) $1);
3585 $$ = new TypeOf (type, (Location) $1);
3586 current_array_type = pushed_current_array_type;
3591 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3592 $$ = new SizeOf ((Expression) $3, (Location) $1);
3597 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3599 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3603 unchecked_expression
3604 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3606 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3610 pointer_member_access
3611 : primary_expression OP_PTR IDENTIFIER
3614 LocatedToken lt = (LocatedToken) $3;
3616 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3617 $$ = new MemberAccess (deref, lt.Value);
3621 anonymous_method_expression
3622 : DELEGATE opt_anonymous_method_signature
3624 start_anonymous (false, (Parameters) $2, (Location) $1);
3628 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
3632 opt_anonymous_method_signature
3633 : /* empty */ { $$ = null; }
3634 | anonymous_method_signature
3637 anonymous_method_signature
3638 : open_parens opt_anonymous_method_parameter_list CLOSE_PARENS
3641 $$ = Parameters.EmptyReadOnlyParameters;
3643 ArrayList par_list = (ArrayList) $2;
3644 Parameter [] pars = new Parameter [par_list.Count];
3645 par_list.CopyTo (pars);
3646 $$ = new Parameters (pars);
3651 opt_anonymous_method_parameter_list
3652 : /* empty */ { $$ = null; }
3653 | anonymous_method_parameter_list { $$ = $1; }
3656 anonymous_method_parameter_list
3657 : anonymous_method_parameter
3659 ArrayList a = new ArrayList (4);
3663 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3665 ArrayList a = (ArrayList) $1;
3671 anonymous_method_parameter
3672 : opt_parameter_modifier type IDENTIFIER {
3673 LocatedToken lt = (LocatedToken) $3;
3674 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3676 | PARAMS type IDENTIFIER {
3677 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3682 default_value_expression
3683 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3685 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3690 : primary_expression
3691 | BANG prefixed_unary_expression
3693 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3695 | TILDE prefixed_unary_expression
3697 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3703 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3705 $$ = new Cast ((Expression) $1, (Expression) $3);
3707 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3709 $$ = new Cast ((Expression) $1, (Expression) $3);
3711 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3713 $$ = new Cast ((Expression) $1, (Expression) $3);
3719 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3721 // TODO: wrong location
3722 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3727 // The idea to split this out is from Rhys' grammar
3728 // to solve the problem with casts.
3730 prefixed_unary_expression
3732 | PLUS prefixed_unary_expression
3734 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3736 | MINUS prefixed_unary_expression
3738 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3740 | OP_INC prefixed_unary_expression
3742 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3743 (Expression) $2, (Location) $1);
3745 | OP_DEC prefixed_unary_expression
3747 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3748 (Expression) $2, (Location) $1);
3750 | STAR prefixed_unary_expression
3752 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3754 | BITWISE_AND prefixed_unary_expression
3756 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3760 pre_increment_expression
3761 : OP_INC prefixed_unary_expression
3763 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3764 (Expression) $2, (Location) $1);
3768 pre_decrement_expression
3769 : OP_DEC prefixed_unary_expression
3771 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3772 (Expression) $2, (Location) $1);
3776 multiplicative_expression
3777 : prefixed_unary_expression
3778 | multiplicative_expression STAR prefixed_unary_expression
3780 $$ = new Binary (Binary.Operator.Multiply,
3781 (Expression) $1, (Expression) $3);
3783 | multiplicative_expression DIV prefixed_unary_expression
3785 $$ = new Binary (Binary.Operator.Division,
3786 (Expression) $1, (Expression) $3);
3788 | multiplicative_expression PERCENT prefixed_unary_expression
3790 $$ = new Binary (Binary.Operator.Modulus,
3791 (Expression) $1, (Expression) $3);
3796 : multiplicative_expression
3797 | additive_expression PLUS multiplicative_expression
3799 $$ = new Binary (Binary.Operator.Addition,
3800 (Expression) $1, (Expression) $3);
3802 | additive_expression MINUS multiplicative_expression
3804 $$ = new Binary (Binary.Operator.Subtraction,
3805 (Expression) $1, (Expression) $3);
3810 : additive_expression
3811 | shift_expression OP_SHIFT_LEFT additive_expression
3813 $$ = new Binary (Binary.Operator.LeftShift,
3814 (Expression) $1, (Expression) $3);
3816 | shift_expression OP_SHIFT_RIGHT additive_expression
3818 $$ = new Binary (Binary.Operator.RightShift,
3819 (Expression) $1, (Expression) $3);
3830 lexer.PutbackNullable ();
3835 nullable_type_or_conditional
3838 if (((bool) $2) && ($1 is ComposedCast))
3839 $$ = ((ComposedCast) $1).RemoveNullable ();
3845 relational_expression
3847 | relational_expression OP_LT shift_expression
3849 $$ = new Binary (Binary.Operator.LessThan,
3850 (Expression) $1, (Expression) $3);
3852 | relational_expression OP_GT shift_expression
3854 $$ = new Binary (Binary.Operator.GreaterThan,
3855 (Expression) $1, (Expression) $3);
3857 | relational_expression OP_LE shift_expression
3859 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3860 (Expression) $1, (Expression) $3);
3862 | relational_expression OP_GE shift_expression
3864 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3865 (Expression) $1, (Expression) $3);
3867 | relational_expression IS
3870 } nullable_type_or_conditional
3872 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
3874 | relational_expression AS
3877 } nullable_type_or_conditional
3879 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
3884 : relational_expression
3885 | equality_expression OP_EQ relational_expression
3887 $$ = new Binary (Binary.Operator.Equality,
3888 (Expression) $1, (Expression) $3);
3890 | equality_expression OP_NE relational_expression
3892 $$ = new Binary (Binary.Operator.Inequality,
3893 (Expression) $1, (Expression) $3);
3898 : equality_expression
3899 | and_expression BITWISE_AND equality_expression
3901 $$ = new Binary (Binary.Operator.BitwiseAnd,
3902 (Expression) $1, (Expression) $3);
3906 exclusive_or_expression
3908 | exclusive_or_expression CARRET and_expression
3910 $$ = new Binary (Binary.Operator.ExclusiveOr,
3911 (Expression) $1, (Expression) $3);
3915 inclusive_or_expression
3916 : exclusive_or_expression
3917 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3919 $$ = new Binary (Binary.Operator.BitwiseOr,
3920 (Expression) $1, (Expression) $3);
3924 conditional_and_expression
3925 : inclusive_or_expression
3926 | conditional_and_expression OP_AND inclusive_or_expression
3928 $$ = new Binary (Binary.Operator.LogicalAnd,
3929 (Expression) $1, (Expression) $3);
3933 conditional_or_expression
3934 : conditional_and_expression
3935 | conditional_or_expression OP_OR conditional_and_expression
3937 $$ = new Binary (Binary.Operator.LogicalOr,
3938 (Expression) $1, (Expression) $3);
3942 conditional_expression
3943 : conditional_or_expression
3944 | conditional_or_expression INTERR expression COLON expression
3946 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3948 | conditional_or_expression OP_COALESCING expression
3950 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
3952 // We'll be resolved into a `parenthesized_expression_0' later on.
3953 | conditional_or_expression INTERR CLOSE_PARENS
3955 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3956 lexer.PutbackCloseParens ();
3960 assignment_expression
3961 : prefixed_unary_expression ASSIGN expression
3963 $$ = new Assign ((Expression) $1, (Expression) $3);
3965 | prefixed_unary_expression OP_MULT_ASSIGN expression
3967 $$ = new CompoundAssign (
3968 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3970 | prefixed_unary_expression OP_DIV_ASSIGN expression
3972 $$ = new CompoundAssign (
3973 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3975 | prefixed_unary_expression OP_MOD_ASSIGN expression
3977 $$ = new CompoundAssign (
3978 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3980 | prefixed_unary_expression OP_ADD_ASSIGN expression
3982 $$ = new CompoundAssign (
3983 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3985 | prefixed_unary_expression OP_SUB_ASSIGN expression
3987 $$ = new CompoundAssign (
3988 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3990 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3992 $$ = new CompoundAssign (
3993 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3995 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3997 $$ = new CompoundAssign (
3998 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4000 | prefixed_unary_expression OP_AND_ASSIGN expression
4002 $$ = new CompoundAssign (
4003 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4005 | prefixed_unary_expression OP_OR_ASSIGN expression
4007 $$ = new CompoundAssign (
4008 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4010 | prefixed_unary_expression OP_XOR_ASSIGN expression
4012 $$ = new CompoundAssign (
4013 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4017 implicitly_typed_lambda_parameter_list
4019 LocatedToken lt = (LocatedToken) $1;
4020 ArrayList a = new ArrayList (4);
4022 a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
4025 | implicitly_typed_lambda_parameter_list COMMA IDENTIFIER {
4026 LocatedToken lt = (LocatedToken) $3;
4027 ArrayList a = (ArrayList) $1;
4028 a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
4033 explicitly_typed_lambda_parameter_list
4034 : explicitly_typed_lambda_parameter
4036 ArrayList pars = new ArrayList (4);
4041 | explicitly_typed_lambda_parameter_list COMMA explicitly_typed_lambda_parameter
4043 ArrayList pars = (ArrayList) $1;
4050 explicitly_typed_lambda_parameter
4051 : parameter_modifier type IDENTIFIER
4053 LocatedToken lt = (LocatedToken) $3;
4055 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4059 LocatedToken lt = (LocatedToken) $2;
4061 $$ = new Parameter ((Expression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4065 lambda_parameter_list
4066 : implicitly_typed_lambda_parameter_list { $$ = $1; }
4067 | explicitly_typed_lambda_parameter_list { $$ = $1; }
4070 opt_lambda_parameter_list
4071 : /* empty */ { $$ = null; }
4072 | lambda_parameter_list {
4073 ArrayList pars_list = (ArrayList) $1;
4075 Parameter [] pars = new Parameter [pars_list.Count];
4076 pars_list.CopyTo (pars);
4077 $$ = new Parameters (pars);
4081 lambda_expression_body
4083 start_block (lexer.Location);
4087 Block b = end_block (lexer.Location);
4088 b.AddStatement (new ContextualReturn ((Expression) $2));
4099 Parameter [] pars = new Parameter [1];
4100 LocatedToken lt = (LocatedToken) $1;
4101 pars [0] = new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4103 Parameters parameters = new Parameters (pars);
4105 start_anonymous (true, parameters, (Location) $2);
4107 lambda_expression_body
4109 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
4111 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4113 start_anonymous (true, (Parameters) $2, (Location) $4);
4115 lambda_expression_body
4117 $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
4122 : assignment_expression
4123 | non_assignment_expression
4126 non_assignment_expression
4127 : conditional_expression
4149 lexer.ConstraintsParsing = true;
4153 MemberName name = MakeName ((MemberName) $6);
4154 int mod_flags = (int) $2;
4156 push_current_class (new Class (
4157 current_namespace, current_class, name,
4158 mod_flags, (Attributes) $1), $3);
4161 opt_type_parameter_constraints_clauses
4163 lexer.ConstraintsParsing = false;
4166 if (current_class.Name == "System.Object") {
4167 Report.Error (537, current_class.Location,
4168 "The class System.Object cannot have a base " +
4169 "class or implement an interface.");
4171 current_container.AddBasesForPart (current_class, (ArrayList) $8);
4174 current_class.SetParameterInfo ((ArrayList) $9);
4176 if (RootContext.Documentation != null) {
4177 current_container.DocComment = Lexer.consume_doc_comment ();
4178 Lexer.doc_state = XmlCommentState.Allowed;
4183 if (RootContext.Documentation != null)
4184 Lexer.doc_state = XmlCommentState.Allowed;
4188 $$ = pop_current_class ();
4196 { $$ = $1; } // location
4200 : /* empty */ { $$ = (int) 0; }
4206 | modifiers modifier
4211 if ((m1 & m2) != 0) {
4212 Location l = lexer.Location;
4213 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4215 $$ = (int) (m1 | m2);
4220 : NEW { $$ = Modifiers.NEW; }
4221 | PUBLIC { $$ = Modifiers.PUBLIC; }
4222 | PROTECTED { $$ = Modifiers.PROTECTED; }
4223 | INTERNAL { $$ = Modifiers.INTERNAL; }
4224 | PRIVATE { $$ = Modifiers.PRIVATE; }
4225 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4226 | SEALED { $$ = Modifiers.SEALED; }
4227 | STATIC { $$ = Modifiers.STATIC; }
4228 | READONLY { $$ = Modifiers.READONLY; }
4229 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4230 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4231 | EXTERN { $$ = Modifiers.EXTERN; }
4232 | VOLATILE { $$ = Modifiers.VOLATILE; }
4233 | UNSAFE { $$ = Modifiers.UNSAFE; }
4237 : /* empty */ { $$ = null; }
4238 | class_base { $$ = $1; }
4242 : COLON type_list { $$ = $2; }
4245 opt_type_parameter_constraints_clauses
4246 : /* empty */ { $$ = null; }
4247 | type_parameter_constraints_clauses
4251 type_parameter_constraints_clauses
4252 : type_parameter_constraints_clause {
4253 ArrayList constraints = new ArrayList (1);
4254 constraints.Add ($1);
4257 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4258 ArrayList constraints = (ArrayList) $1;
4259 Constraints new_constraint = (Constraints)$2;
4261 foreach (Constraints c in constraints) {
4262 if (new_constraint.TypeParameter == c.TypeParameter) {
4263 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4264 new_constraint.TypeParameter);
4268 constraints.Add (new_constraint);
4273 type_parameter_constraints_clause
4274 : WHERE IDENTIFIER COLON type_parameter_constraints {
4275 LocatedToken lt = (LocatedToken) $2;
4276 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4280 type_parameter_constraints
4281 : type_parameter_constraint {
4282 ArrayList constraints = new ArrayList (1);
4283 constraints.Add ($1);
4286 | type_parameter_constraints COMMA type_parameter_constraint {
4287 ArrayList constraints = (ArrayList) $1;
4289 constraints.Add ($3);
4294 type_parameter_constraint
4296 | NEW OPEN_PARENS CLOSE_PARENS {
4297 $$ = SpecialConstraint.Constructor;
4300 $$ = SpecialConstraint.ReferenceType;
4303 $$ = SpecialConstraint.ValueType;
4312 // A block is "contained" on the following places:
4314 // property_declaration as part of the accessor body (get/set)
4315 // operator_declaration
4316 // constructor_declaration
4317 // destructor_declaration
4318 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4323 start_block ((Location) $1);
4325 opt_statement_list CLOSE_BRACE
4327 $$ = end_block ((Location) $4);
4333 opt_statement_list CLOSE_BRACE
4335 $$ = end_block ((Location) $3);
4346 | statement_list statement
4350 : declaration_statement
4352 if ($1 != null && (Block) $1 != current_block){
4353 current_block.AddStatement ((Statement) $1);
4354 current_block = (Block) $1;
4357 | valid_declaration_statement
4359 current_block.AddStatement ((Statement) $1);
4364 valid_declaration_statement
4367 | expression_statement
4368 | selection_statement
4369 | iteration_statement
4373 | unchecked_statement
4381 : valid_declaration_statement
4382 | declaration_statement
4384 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4389 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4397 $$ = EmptyStatement.Value;
4404 LocatedToken lt = (LocatedToken) $1;
4405 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4407 if (current_block.AddLabel (labeled))
4408 current_block.AddStatement (labeled);
4413 declaration_statement
4414 : local_variable_declaration SEMICOLON
4416 current_array_type = null;
4418 DictionaryEntry de = (DictionaryEntry) $1;
4419 Expression e = (Expression) de.Key;
4421 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4425 | local_constant_declaration SEMICOLON
4427 current_array_type = null;
4429 DictionaryEntry de = (DictionaryEntry) $1;
4431 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4437 * The following is from Rhys' grammar:
4438 * > Types in local variable declarations must be recognized as
4439 * > expressions to prevent reduce/reduce errors in the grammar.
4440 * > The expressions are converted into types during semantic analysis.
4443 : primary_expression opt_rank_specifier_or_nullable
4445 // FIXME: Do something smart here regarding the composition of the type.
4447 // Ok, the above "primary_expression" is there to get rid of
4448 // both reduce/reduce and shift/reduces in the grammar, it should
4449 // really just be "type_name". If you use type_name, a reduce/reduce
4450 // creeps up. If you use namespace_or_type_name (which is all we need
4451 // really) two shift/reduces appear.
4454 // So the super-trick is that primary_expression
4455 // can only be either a SimpleName or a MemberAccess.
4456 // The MemberAccess case arises when you have a fully qualified type-name like :
4458 // SimpleName is when you have
4461 Expression expr = (Expression) $1;
4462 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4463 Error_ExpectingTypeName (expr);
4467 // So we extract the string corresponding to the SimpleName
4471 if ((string) $2 == "")
4474 $$ = new ComposedCast ((Expression) $1, (string) $2);
4477 | builtin_types opt_rank_specifier_or_nullable
4479 if ((string) $2 == "")
4482 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4486 local_variable_pointer_type
4487 : primary_expression STAR
4489 Expression expr = (Expression) $1;
4491 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4492 Error_ExpectingTypeName (expr);
4496 $$ = new ComposedCast ((Expression) $1, "*");
4498 | builtin_types STAR
4500 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4504 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4506 | local_variable_pointer_type STAR
4508 $$ = new ComposedCast ((Expression) $1, "*");
4512 local_variable_declaration
4513 : local_variable_type variable_declarators
4516 $$ = new DictionaryEntry ($1, $2);
4520 | VAR variable_declarators
4522 $$ = new DictionaryEntry (new VarExpr (lexer.Location), $2);
4524 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4529 if ((string) $2 == "")
4530 t = (Expression) $1;
4532 t = new ComposedCast ((Expression) $1, (string) $2);
4533 $$ = new DictionaryEntry (t, $3);
4539 local_constant_declaration
4540 : CONST local_variable_type constant_declarators
4543 $$ = new DictionaryEntry ($2, $3);
4549 expression_statement
4550 : statement_expression SEMICOLON { $$ = $1; }
4554 // We have to do the wrapping here and not in the case above,
4555 // because statement_expression is used for example in for_statement
4557 statement_expression
4560 Expression expr = (Expression) $1;
4561 ExpressionStatement s = expr as ExpressionStatement;
4563 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
4566 $$ = new StatementExpression (s);
4570 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4575 object_creation_expression
4576 : object_or_delegate_creation_expression
4577 { note ("complain if this is a delegate maybe?"); }
4586 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4589 Location l = (Location) $1;
4591 $$ = new If ((Expression) $3, (Statement) $5, l);
4593 // FIXME: location for warning should be loc property of $5.
4594 if ($5 == EmptyStatement.Value)
4595 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4598 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4599 embedded_statement ELSE embedded_statement
4601 Location l = (Location) $1;
4603 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4605 // FIXME: location for warning should be loc property of $5 and $7.
4606 if ($5 == EmptyStatement.Value)
4607 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4608 if ($7 == EmptyStatement.Value)
4609 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4614 : SWITCH OPEN_PARENS
4616 if (switch_stack == null)
4617 switch_stack = new Stack (2);
4618 switch_stack.Push (current_block);
4620 expression CLOSE_PARENS
4623 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4624 current_block = (Block) switch_stack.Pop ();
4640 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4641 $$ = new ArrayList ();
4649 ArrayList sections = new ArrayList (4);
4654 | switch_sections switch_section
4656 ArrayList sections = (ArrayList) $1;
4666 current_block = current_block.CreateSwitchBlock (lexer.Location);
4670 Block topmost = current_block;
4672 while (topmost.Implicit)
4673 topmost = topmost.Parent;
4674 $$ = new SwitchSection ((ArrayList) $1, topmost);
4681 ArrayList labels = new ArrayList (4);
4686 | switch_labels switch_label
4688 ArrayList labels = (ArrayList) ($1);
4696 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4697 | DEFAULT_COLON { $$ = new SwitchLabel (null, (Location) $1); }
4700 1523, GetLocation ($1),
4701 "The keyword case or default must precede code in switch block");
4713 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4715 Location l = (Location) $1;
4716 $$ = new While ((Expression) $3, (Statement) $5, l);
4721 : DO embedded_statement
4722 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4724 Location l = (Location) $1;
4726 $$ = new Do ((Statement) $2, (Expression) $5, l);
4732 opt_for_initializer SEMICOLON
4734 Block assign_block = new Block (current_block);
4735 current_block = assign_block;
4737 if ($3 is DictionaryEntry){
4738 DictionaryEntry de = (DictionaryEntry) $3;
4740 Expression type = (Expression) de.Key;
4741 ArrayList var_declarators = (ArrayList) de.Value;
4743 foreach (VariableDeclaration decl in var_declarators){
4747 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4751 Location l = lexer.Location;
4752 Expression expr = decl.expression_or_array_initializer;
4754 LocalVariableReference var;
4755 var = new LocalVariableReference (assign_block, decl.identifier, l);
4758 Assign a = new Assign (var, expr, decl.Location);
4760 assign_block.AddStatement (new StatementExpression (a));
4764 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4765 // This can be referred to as $5 below.
4771 opt_for_condition SEMICOLON
4772 opt_for_iterator CLOSE_PARENS
4775 Location l = (Location) $1;
4777 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4779 current_block.AddStatement (f);
4780 while (current_block.Implicit)
4781 current_block = current_block.Parent;
4783 current_block = current_block.Parent;
4788 : /* empty */ { $$ = EmptyStatement.Value; }
4793 : local_variable_declaration
4794 | statement_expression_list
4798 : /* empty */ { $$ = null; }
4799 | boolean_expression
4803 : /* empty */ { $$ = EmptyStatement.Value; }
4808 : statement_expression_list
4811 statement_expression_list
4812 : statement_expression
4814 // CHANGE: was `null'
4815 Statement s = (Statement) $1;
4816 Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);
4821 | statement_expression_list COMMA statement_expression
4823 Block b = (Block) $1;
4825 b.AddStatement ((Statement) $3);
4831 : FOREACH open_parens type IN expression CLOSE_PARENS
4833 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4836 | FOREACH open_parens type IDENTIFIER IN
4837 expression CLOSE_PARENS
4839 Block foreach_block = new Block (current_block);
4840 current_block = foreach_block;
4842 LocatedToken lt = (LocatedToken) $4;
4843 Location l = lt.Location;
4846 vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4848 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4850 // Get a writable reference to this read-only variable.
4852 // Note that the $$ here refers to the value of _this_ code block,
4853 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4854 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4861 LocalVariableReference v = (LocalVariableReference) $8;
4862 Location l = (Location) $1;
4865 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4866 current_block.AddStatement (f);
4869 while (current_block.Implicit)
4870 current_block = current_block.Parent;
4872 current_block = current_block.Parent;
4878 | continue_statement
4888 $$ = new Break ((Location) $1);
4893 : CONTINUE SEMICOLON
4895 $$ = new Continue ((Location) $1);
4900 : GOTO IDENTIFIER SEMICOLON
4902 LocatedToken lt = (LocatedToken) $2;
4903 $$ = new Goto (lt.Value, lt.Location);
4905 | GOTO CASE constant_expression SEMICOLON
4907 $$ = new GotoCase ((Expression) $3, (Location) $1);
4909 | GOTO DEFAULT SEMICOLON
4911 $$ = new GotoDefault ((Location) $1);
4916 : RETURN opt_expression SEMICOLON
4918 $$ = new Return ((Expression) $2, (Location) $1);
4923 : THROW opt_expression SEMICOLON
4925 $$ = new Throw ((Expression) $2, (Location) $1);
4930 : IDENTIFIER RETURN expression SEMICOLON
4932 LocatedToken lt = (LocatedToken) $1;
4933 string s = lt.Value;
4935 Report.Error (1003, lt.Location, "; expected");
4938 if (RootContext.Version == LanguageVersion.ISO_1){
4939 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
4942 if (anonymous_host == null){
4943 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4946 anonymous_host.SetYields ();
4947 $$ = new Yield ((Expression) $3, lt.Location);
4950 | IDENTIFIER RETURN SEMICOLON
4952 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4955 | IDENTIFIER BREAK SEMICOLON
4957 LocatedToken lt = (LocatedToken) $1;
4958 string s = lt.Value;
4960 Report.Error (1003, lt.Location, "; expected");
4963 if (RootContext.Version == LanguageVersion.ISO_1){
4964 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
4967 if (anonymous_host == null){
4968 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4971 anonymous_host.SetYields ();
4972 $$ = new YieldBreak (lt.Location);
4983 : TRY block catch_clauses
4987 ArrayList c = (ArrayList)$3;
4988 for (int i = 0; i < c.Count; ++i) {
4989 Catch cc = (Catch) c [i];
4991 if (i != c.Count - 1)
4992 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
4999 // Now s contains the list of specific catch clauses
5000 // and g contains the general one.
5002 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
5004 | TRY block opt_catch_clauses FINALLY block
5007 ArrayList s = new ArrayList (4);
5008 ArrayList catch_list = (ArrayList) $3;
5010 if (catch_list != null){
5011 foreach (Catch cc in catch_list) {
5019 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
5023 Report.Error (1524, (Location) $1, "Expected catch or finally");
5029 : /* empty */ { $$ = null; }
5036 ArrayList l = new ArrayList (4);
5041 | catch_clauses catch_clause
5043 ArrayList l = (ArrayList) $1;
5051 : /* empty */ { $$ = null; }
5056 : CATCH opt_catch_args
5058 Expression type = null;
5061 DictionaryEntry cc = (DictionaryEntry) $2;
5062 type = (Expression) cc.Key;
5063 LocatedToken lt = (LocatedToken) cc.Value;
5066 ArrayList one = new ArrayList (4);
5068 one.Add (new VariableDeclaration (lt, null));
5070 current_block = new Block (current_block);
5071 Block b = declare_local_variables (type, one, lt.Location);
5076 Expression type = null;
5078 Block var_block = null;
5081 DictionaryEntry cc = (DictionaryEntry) $2;
5082 type = (Expression) cc.Key;
5083 LocatedToken lt = (LocatedToken) cc.Value;
5087 while (current_block.Implicit)
5088 current_block = current_block.Parent;
5089 var_block = current_block;
5090 current_block = current_block.Parent;
5094 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5099 : /* empty */ { $$ = null; }
5104 : open_parens type opt_identifier CLOSE_PARENS
5106 $$ = new DictionaryEntry ($2, $3);
5114 $$ = new Checked ((Block) $2);
5121 $$ = new Unchecked ((Block) $2);
5128 RootContext.CheckUnsafeOption ((Location) $1);
5130 $$ = new Unsafe ((Block) $3);
5136 type fixed_pointer_declarators
5139 ArrayList list = (ArrayList) $4;
5140 Expression type = (Expression) $3;
5141 Location l = (Location) $1;
5142 int top = list.Count;
5144 Block assign_block = new Block (current_block);
5145 current_block = assign_block;
5147 for (int i = 0; i < top; i++){
5148 Pair p = (Pair) list [i];
5151 v = current_block.AddVariable (type, (string) p.First, l);
5155 if (type is VarExpr)
5156 v.VariableType = typeof(VarExpr); // Kinda lame. Avoids a problem in the VariableMap ctor
5158 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5166 Location l = (Location) $1;
5168 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5170 current_block.AddStatement (f);
5171 while (current_block.Implicit)
5172 current_block = current_block.Parent;
5174 current_block = current_block.Parent;
5178 fixed_pointer_declarators
5179 : fixed_pointer_declarator {
5180 ArrayList declarators = new ArrayList (4);
5182 declarators.Add ($1);
5185 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5187 ArrayList declarators = (ArrayList) $1;
5189 declarators.Add ($3);
5194 fixed_pointer_declarator
5195 : IDENTIFIER ASSIGN expression
5197 LocatedToken lt = (LocatedToken) $1;
5198 // FIXME: keep location
5199 $$ = new Pair (lt.Value, $3);
5203 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5209 : LOCK OPEN_PARENS expression CLOSE_PARENS
5215 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5220 : USING open_parens resource_acquisition CLOSE_PARENS
5222 Block assign_block = new Block (current_block);
5223 current_block = assign_block;
5225 if ($3 is DictionaryEntry){
5226 DictionaryEntry de = (DictionaryEntry) $3;
5227 Location l = (Location) $1;
5229 Expression type = (Expression) de.Key;
5230 ArrayList var_declarators = (ArrayList) de.Value;
5232 ArrayList vars = new ArrayList (4);
5234 foreach (VariableDeclaration decl in var_declarators){
5236 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5239 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5241 Expression expr = decl.expression_or_array_initializer;
5243 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5246 LocalVariableReference var;
5248 // Get a writable reference to this read-only variable.
5249 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5251 // This is so that it is not a warning on using variables
5254 vars.Add (new DictionaryEntry (var, expr));
5256 // Assign a = new Assign (var, expr, decl.Location);
5257 // assign_block.AddStatement (new StatementExpression (a));
5260 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5261 // It can be referred to as $5 below.
5262 $$ = new DictionaryEntry (type, vars);
5269 Using u = new Using ($5, (Statement) $6, (Location) $1);
5270 current_block.AddStatement (u);
5271 while (current_block.Implicit)
5272 current_block = current_block.Parent;
5274 current_block = current_block.Parent;
5278 resource_acquisition
5279 : local_variable_declaration
5287 : from_clause query_body
5289 lexer.QueryParsing = false;
5290 $$ = new QueryExpression ((Expression)$1, (Expression)$2);
5291 current_block = current_block.Parent;
5296 : FROM IDENTIFIER IN expression opt_join_clauses
5298 current_block = new Block (current_block);
5299 LocatedToken lt = (LocatedToken) $2;
5301 LocalInfo vi = current_block.AddVariable (TypeManager.system_object_expr, lt.Value, lt.Location); // TODO: null is var type
5303 $$ = new LocalVariableReference (current_block, lt.Value, lt.Location, vi, false);
5307 | FROM type IDENTIFIER IN expression opt_join_clauses
5309 current_block = new Block (current_block);
5310 LocatedToken lt = (LocatedToken) $3;
5312 LocalInfo vi = current_block.AddVariable ((Expression)$2, lt.Value, lt.Location);
5324 | join_clauses join_clause
5328 : JOIN join_clause_body
5329 | JOIN join_clause_body INTO IDENTIFIER
5330 | JOIN type join_clause_body
5331 | JOIN type join_clause_body INTO IDENTIFIER
5335 : IDENTIFIER IN expression ON expression EQUALS expression
5339 : opt_from_let_where_clauses opt_orderby_clause SELECT expression opt_query_continuation
5341 $$ = new Select (current_container, current_block, (Expression)$4, GetLocation ($3));
5343 | opt_from_let_where_clauses opt_orderby_clause group_clause opt_query_continuation
5346 opt_from_let_where_clauses
5348 | from_let_where_clauses
5351 from_let_where_clauses
5352 : from_let_where_clause
5353 | from_let_where_clauses from_let_where_clause
5356 from_let_where_clause
5363 : LET IDENTIFIER ASSIGN expression
5367 : WHERE boolean_expression
5381 | orderings COMMA ordering
5386 | expression ASCENDING
5387 | expression DESCENDING
5392 : GROUP expression BY expression
5395 opt_query_continuation
5397 | query_continuation
5401 : INTO IDENTIFIER opt_join_clauses query_body
5407 // A class used to pass around variable declarations and constants
5409 public class VariableDeclaration {
5410 public string identifier;
5411 public Expression expression_or_array_initializer;
5412 public Location Location;
5413 public Attributes OptAttributes;
5414 public string DocComment;
5416 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5418 this.identifier = lt.Value;
5419 if (eoai is ArrayList) {
5420 if (CSharpParser.current_array_type == null)
5421 Report.Error (622, lt.Location,
5422 "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
5423 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5425 this.expression_or_array_initializer = (Expression)eoai;
5427 this.Location = lt.Location;
5428 this.OptAttributes = opt_attrs;
5431 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5437 // A class used to hold info about an indexer declarator
5439 public class IndexerDeclaration {
5440 public Expression type;
5441 public MemberName interface_type;
5442 public Parameters param_list;
5443 public Location location;
5445 public IndexerDeclaration (Expression type, MemberName interface_type,
5446 Parameters param_list, Location loc)
5449 this.interface_type = interface_type;
5450 this.param_list = param_list;
5451 this.location = loc;
5456 // We use this when we do not have an object in advance that is an IAnonymousHost
5458 public class SimpleAnonymousHost : IAnonymousHost {
5459 public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
5462 ArrayList anonymous_methods;
5464 public static SimpleAnonymousHost GetSimple () {
5465 Simple.yields = false;
5466 Simple.anonymous_methods = null;
5470 public void SetYields ()
5475 public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
5477 if (anonymous_methods == null)
5478 anonymous_methods = new ArrayList ();
5479 anonymous_methods.Add (anonymous);
5482 public void Propagate (IAnonymousHost real_host)
5485 real_host.SetYields ();
5486 if (anonymous_methods != null) {
5487 foreach (AnonymousMethodExpression ame in anonymous_methods)
5488 real_host.AddAnonymousMethod (ame);
5494 // A class used to hold info about an operator declarator
5496 public class OperatorDeclaration {
5497 public Operator.OpType optype;
5498 public Expression ret_type, arg1type, arg2type;
5499 public string arg1name, arg2name;
5500 public Location location;
5502 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5503 Expression arg1type, string arg1name,
5504 Expression arg2type, string arg2name, Location location)
5507 this.ret_type = ret_type;
5508 this.arg1type = arg1type;
5509 this.arg1name = arg1name;
5510 this.arg2type = arg2type;
5511 this.arg2name = arg2name;
5512 this.location = location;
5517 void Error_ExpectingTypeName (Expression expr)
5519 if (expr is Invocation){
5520 Report.Error (1002, expr.Location, "Expecting `;'");
5522 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5526 public static void Error_ParameterModifierNotValid (Location loc)
5528 Report.Error (631, loc, "The modifiers `ref' and `out' are not valid in this context");
5531 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5533 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5534 Parameter.GetModifierSignature (mod));
5537 void push_current_class (TypeContainer tc, object partial_token)
5539 if (partial_token != null)
5540 current_container = current_container.AddPartial (tc);
5542 current_container = current_container.AddTypeContainer (tc);
5546 DeclSpace pop_current_class ()
5548 DeclSpace retval = current_class;
5550 current_class = current_class.Parent;
5551 current_container = current_class.PartialContainer;
5557 // Given the @class_name name, it creates a fully qualified name
5558 // based on the containing declaration space
5561 MakeName (MemberName class_name)
5563 Namespace ns = current_namespace.NS;
5565 if (current_container.Name.Length == 0){
5566 if (ns.Name.Length != 0)
5567 return new MemberName (ns.MemberName, class_name);
5571 return new MemberName (current_container.MemberName, class_name);
5575 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5577 Block implicit_block;
5578 ArrayList inits = null;
5581 // We use the `Used' property to check whether statements
5582 // have been added to the current block. If so, we need
5583 // to create another block to contain the new declaration
5584 // otherwise, as an optimization, we use the same block to
5585 // add the declaration.
5587 // FIXME: A further optimization is to check if the statements
5588 // that were added were added as part of the initialization
5589 // below. In which case, no other statements have been executed
5590 // and we might be able to reduce the number of blocks for
5591 // situations like this:
5593 // int j = 1; int k = j + 1;
5595 if (current_block.Used)
5596 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
5598 implicit_block = current_block;
5600 foreach (VariableDeclaration decl in variable_declarators){
5602 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5603 if (decl.expression_or_array_initializer != null){
5605 inits = new ArrayList (4);
5612 return implicit_block;
5614 foreach (VariableDeclaration decl in inits){
5616 Expression expr = decl.expression_or_array_initializer;
5618 LocalVariableReference var;
5619 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5621 assign = new Assign (var, expr, decl.Location);
5623 implicit_block.AddStatement (new StatementExpression (assign));
5626 return implicit_block;
5629 Block declare_local_constants (Expression type, ArrayList declarators)
5631 Block implicit_block;
5633 if (current_block.Used)
5634 implicit_block = new Block (current_block, Block.Flags.Implicit);
5636 implicit_block = current_block;
5638 foreach (VariableDeclaration decl in declarators){
5639 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5642 return implicit_block;
5645 string CheckAttributeTarget (string a, Location l)
5648 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5652 Report.Warning (658, 1, l,
5653 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5654 return string.Empty;
5657 void CheckUnaryOperator (Operator.OpType op, Location l)
5661 case Operator.OpType.LogicalNot:
5662 case Operator.OpType.OnesComplement:
5663 case Operator.OpType.Increment:
5664 case Operator.OpType.Decrement:
5665 case Operator.OpType.True:
5666 case Operator.OpType.False:
5667 case Operator.OpType.Addition:
5668 case Operator.OpType.Subtraction:
5673 Report.Error (1019, l, "Overloadable unary operator expected");
5679 void CheckBinaryOperator (Operator.OpType op, Location l)
5683 case Operator.OpType.Addition:
5684 case Operator.OpType.Subtraction:
5685 case Operator.OpType.Multiply:
5686 case Operator.OpType.Division:
5687 case Operator.OpType.Modulus:
5688 case Operator.OpType.BitwiseAnd:
5689 case Operator.OpType.BitwiseOr:
5690 case Operator.OpType.ExclusiveOr:
5691 case Operator.OpType.LeftShift:
5692 case Operator.OpType.RightShift:
5693 case Operator.OpType.Equality:
5694 case Operator.OpType.Inequality:
5695 case Operator.OpType.GreaterThan:
5696 case Operator.OpType.LessThan:
5697 case Operator.OpType.GreaterThanOrEqual:
5698 case Operator.OpType.LessThanOrEqual:
5702 Report.Error (1020, l, "Overloadable binary operator expected");
5708 void syntax_error (Location l, string msg)
5710 Report.Error (1003, l, "Syntax error, " + msg);
5713 void note (string s)
5715 // Used to put annotations
5720 public Tokenizer Lexer {
5726 static CSharpParser ()
5728 oob_stack = new Stack ();
5731 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5733 this.name = file.Name;
5735 current_namespace = new NamespaceEntry (null, file, null);
5736 current_class = current_namespace.SlaveDeclSpace;
5737 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5739 lexer = new Tokenizer (reader, file, defines);
5742 public void parse ()
5744 int errors = Report.Errors;
5746 if (yacc_verbose_flag > 1)
5747 yyparse (lexer, new yydebug.yyDebugSimple ());
5750 Tokenizer tokenizer = lexer as Tokenizer;
5751 tokenizer.cleanup ();
5752 } catch (Exception e){
5754 // Removed for production use, use parser verbose to get the output.
5756 // Console.WriteLine (e);
5757 if (Report.Errors == errors)
5758 Report.Error (-25, lexer.Location, "Parsing error");
5759 if (yacc_verbose_flag > 0)
5760 Console.WriteLine (e);
5763 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5764 throw new InternalErrorException ("who set it?");
5767 static void CheckToken (int error, int yyToken, string msg, Location loc)
5769 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5770 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5772 Report.Error (error, loc, msg);
5775 void CheckIdentifierToken (int yyToken, Location loc)
5777 CheckToken (1041, yyToken, "Identifier expected", loc);
5780 string ConsumeStoredComment ()
5782 string s = tmpComment;
5784 Lexer.doc_state = XmlCommentState.Allowed;
5788 Location GetLocation (object obj)
5790 if (obj is MemberCore)
5791 return ((MemberCore) obj).Location;
5792 if (obj is MemberName)
5793 return ((MemberName) obj).Location;
5794 if (obj is LocatedToken)
5795 return ((LocatedToken) obj).Location;
5796 if (obj is Location)
5797 return (Location) obj;
5798 return lexer.Location;
5802 start_block (Location loc)
5804 if (parsing_anonymous_method) {
5805 top_current_block = new ToplevelBlock (
5806 current_block, current_local_parameters, current_generic_method, loc);
5807 if (current_block != null)
5808 current_block.AddAnonymousChild ((ToplevelBlock) top_current_block);
5809 current_block = top_current_block;
5810 parsing_anonymous_method = false;
5811 } else if (current_block == null) {
5812 current_block = new ToplevelBlock (
5813 (ToplevelBlock) top_current_block, current_local_parameters,
5814 current_generic_method, loc);
5815 top_current_block = current_block;
5817 current_block = new Block (current_block, loc, Location.Null);
5822 end_block (Location loc)
5826 while (current_block.Implicit)
5827 current_block = current_block.Parent;
5828 retval = current_block;
5829 current_block.SetEndLocation (loc);
5830 current_block = current_block.Parent;
5831 if (current_block == null)
5832 top_current_block = null;
5837 start_anonymous (bool lambda, Parameters parameters, Location loc)
5839 oob_stack.Push (current_anonymous_method);
5840 oob_stack.Push (current_local_parameters);
5842 current_local_parameters = parameters;
5844 // Force the next block to be created as a ToplevelBlock
5845 oob_stack.Push (current_block);
5846 oob_stack.Push (top_current_block);
5848 current_anonymous_method = lambda
5849 ? new LambdaExpression (
5850 current_anonymous_method, current_generic_method, current_container,
5851 parameters, (ToplevelBlock) top_current_block, loc)
5852 : new AnonymousMethodExpression (
5853 current_anonymous_method, current_generic_method, current_container,
5854 parameters, (ToplevelBlock) top_current_block, loc);
5856 parsing_anonymous_method = true;
5860 * Completes the anonymous method processing, if lambda_expr is null, this
5861 * means that we have a Statement instead of an Expression embedded
5863 AnonymousMethodExpression
5864 end_anonymous (ToplevelBlock anon_block, Location loc)
5866 AnonymousMethodExpression retval;
5868 top_current_block = (Block) oob_stack.Pop ();
5869 current_block = (Block) oob_stack.Pop ();
5871 if (RootContext.Version == LanguageVersion.ISO_1){
5872 Report.FeatureIsNotISO1 (loc, "anonymous methods");
5875 anon_block.Parent = current_block;
5877 current_anonymous_method.Block = anon_block;
5878 if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
5879 anonymous_host.AddAnonymousMethod (current_anonymous_method);
5881 retval = current_anonymous_method;
5884 current_local_parameters = (Parameters) oob_stack.Pop ();
5885 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();