3
// cs-parser.jay: The Parser for the C# compiler
5
// Authors: Miguel de Icaza (miguel@gnome.org)
6
// Ravi Pratap (ravi@ximian.com)
7
// Marek Safar (marek.safar@gmail.com)
9
// Dual Licensed under the terms of the GNU GPL and the MIT X11 license
11
// (C) 2001 Ximian, Inc (http://www.ximian.com)
12
// (C) 2004-2011 Novell, Inc
13
// Copyright 2011-2012 Xamarin Inc.
19
using System.Collections.Generic;
26
public class CSharpParser
29
enum ParameterModifierType
36
DefaultValue = 1 << 6,
38
All = Ref | Out | This | Params | Arglist | DefaultValue
41
static readonly object ModifierNone = 0;
43
NamespaceContainer current_namespace;
44
TypeContainer current_container;
45
TypeDefinition current_type;
46
PropertyBase current_property;
47
EventProperty current_event;
48
EventField current_event_field;
49
FieldBase current_field;
52
/// Current block is used to add statements as we find
57
BlockVariableDeclaration current_variable;
59
Delegate current_delegate;
61
AnonymousMethodExpression current_anonymous_method;
64
/// This is used by the unary_expression code to resolve
65
/// a name against a parameter.
68
// FIXME: This is very ugly and it's very hard to reset it correctly
69
// on all places, especially when some parameters are autogenerated.
70
ParametersCompiled current_local_parameters;
72
bool parsing_anonymous_method;
77
/// An out-of-band stack.
79
Stack<object> oob_stack;
82
/// Controls the verbosity of the errors produced by the parser
84
int yacc_verbose_flag;
87
/// Used by the interactive shell, flags whether EOF was reached
88
/// and an error was produced
90
public bool UnexpectedEOF;
95
readonly CompilationSourceFile file;
98
/// Temporary Xml documentation cache.
99
/// For enum types, we need one more temporary store.
102
string enumTypeComment;
104
/// Current attribute target
105
string current_attr_target;
107
ParameterModifierType valid_param_mod;
109
bool default_parameter_used;
111
/// When using the interactive parser, this holds the
112
/// resulting expression
113
public Class InteractiveResult;
116
// Keeps track of global data changes to undo on parser error
120
Stack<Linq.QueryBlock> linq_clause_blocks;
122
ModuleContainer module;
124
readonly CompilerContext compiler;
125
readonly LanguageVersion lang_version;
126
readonly bool doc_support;
127
readonly CompilerSettings settings;
128
readonly Report report;
131
// Instead of allocating carrier array everytime we
132
// share the bucket for very common constructs which can never
135
List<Parameter> parameters_bucket;
138
// Full AST support members
141
List<Tuple<Modifiers, Location>> mod_locations;
142
Location parameterModifierLocation, savedLocation, savedOpenLocation, savedCloseLocation, savedEventAssignLocation;
143
Location savedAttrParenOpenLocation, savedAttrParenCloseLocation, savedOperatorLocation;
144
Stack<List<Location>> locationListStack = new Stack<List<Location>> (); // used for type parameters
145
Stack<Location> opt_intoStack = new Stack<Location> ();
147
bool HadAttributeParens;
148
List<Location> attributeCommas = new List<Location> ();
149
List<Location> attributeArgumentCommas = new List<Location> ();
150
List<Location> parameterListCommas = new List<Location> ();
151
Stack<Location> location_stack;
155
%token NONE /* This token is never returned by our lexer */
156
%token ERROR // This is used not by the parser, but by the tokenizer.
160
*These are the C# keywords
259
%token INTERR_NULLABLE
267
/* C# keywords which are not really keywords */
273
/* C# single character operators/punctuation. */
301
/* C# multi-character operators. */
306
%token OP_SHIFT_RIGHT
313
%token OP_MULT_ASSIGN
318
%token OP_SHIFT_LEFT_ASSIGN
319
%token OP_SHIFT_RIGHT_ASSIGN
326
/* Generics <,> tokens */
327
%token OP_GENERICS_LT
328
%token OP_GENERICS_LT_DECL
329
%token OP_GENERICS_GT
334
%token OPEN_PARENS_LAMBDA
335
%token OPEN_PARENS_CAST
336
%token GENERIC_DIMENSION
338
%token OPEN_BRACKET_EXPR
340
// Make the parser go into eval mode parsing (statements and compilation units).
341
%token EVAL_STATEMENT_PARSER
342
%token EVAL_COMPILATION_UNIT_PARSER
343
%token EVAL_USING_DECLARATIONS_UNIT_PARSER
348
// This token is generated to trigger the completion engine at this point
350
%token GENERATE_COMPLETION
353
// This token is return repeatedly after the first GENERATE_COMPLETION
354
// token is produced and before the final EOF
356
%token COMPLETE_COMPLETION
358
/* Add precedence rules to solve dangling else s/r conflict */
362
/* Define the operator tokens and their precedences */
370
%left OP_SHIFT_LEFT OP_SHIFT_RIGHT
372
%left STAR DIV PERCENT
373
%right BANG CARRET UMINUS
374
%nonassoc OP_INC OP_DEC
376
%left OPEN_BRACKET OPEN_BRACE
379
%start compilation_unit
383
: outer_declaration opt_EOF
385
Lexer.check_incorrect_doc_comment ();
387
| interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
388
| documentation_parsing
392
: opt_extern_alias_directives opt_using_directives
393
| opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
396
Attributes attrs = (Attributes) $4;
397
report.Error (1730, attrs.Attrs [0].Location,
398
"Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
400
current_namespace.UnattachedAttributes = attrs;
403
| opt_extern_alias_directives opt_using_directives attribute_sections
405
module.AddAttributes ((Attributes) $3, current_namespace);
409
if (yyToken == Token.EXTERN_ALIAS)
410
report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
412
Error_SyntaxError (yyToken);
421
extern_alias_directives
422
: extern_alias_directive
423
| extern_alias_directives extern_alias_directive
426
extern_alias_directive
427
: EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
429
var lt = (Tokenizer.LocatedToken) $2;
432
syntax_error (lt.Location, "`alias' expected");
434
if (lang_version == LanguageVersion.ISO_1)
435
FeatureIsNotAvailable (lt.Location, "external alias");
437
lt = (Tokenizer.LocatedToken) $3;
438
if (lt.Value == QualifiedAliasMember.GlobalAlias) {
439
RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
442
var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
443
current_namespace.AddUsing (na);
445
lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
450
Error_SyntaxError (yyToken);
456
| using_directives using_directive
463
Lexer.doc_state = XmlCommentState.Allowed;
468
: USING namespace_or_type_expr SEMICOLON
470
var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
471
current_namespace.AddUsing (un);
473
lbag.AddLocation (un, GetLocation ($3));
475
| USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
477
var lt = (Tokenizer.LocatedToken) $2;
478
if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
479
report.Warning (440, 2, lt.Location,
480
"An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
483
var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
484
current_namespace.AddUsing (un);
485
lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
489
Error_SyntaxError (yyToken);
495
// Strictly speaking, namespaces don't have attributes but
496
// we parse global attributes along with namespace declarations and then
499
namespace_declaration
500
: opt_attributes NAMESPACE namespace_name
502
Attributes attrs = (Attributes) $1;
503
var name = (MemberName) $3;
505
bool valid_global_attrs = true;
506
if ((current_namespace.DeclarationFound || current_namespace != file)) {
507
valid_global_attrs = false;
509
foreach (var a in attrs.Attrs) {
510
if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
513
valid_global_attrs = false;
518
if (!valid_global_attrs)
519
report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
522
module.AddAttributes (attrs, current_namespace);
524
var ns = new NamespaceContainer (name, current_namespace);
525
current_namespace.AddTypeContainer (ns);
526
current_container = current_namespace = ns;
531
Lexer.doc_state = XmlCommentState.Allowed;
533
opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
536
lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
538
lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
540
current_container = current_namespace = current_namespace.Parent;
542
| opt_attributes NAMESPACE namespace_name
544
report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
546
var name = (MemberName) $3;
547
var ns = new NamespaceContainer (name, current_namespace);
548
lbag.AddLocation (ns, GetLocation ($2));
549
current_namespace.AddTypeContainer (ns);
558
Error_SyntaxError (yyToken);
566
var lt = (Tokenizer.LocatedToken) $1;
567
$$ = new MemberName (lt.Value, lt.Location);
569
| namespace_name DOT IDENTIFIER
571
var lt = (Tokenizer.LocatedToken) $3;
572
$$ = new MemberName ((MemberName) $1, lt.Value, lt.Location) {
573
DotLocation = GetLocation ($2)
578
Error_SyntaxError (yyToken);
579
$$ = new MemberName ("<invalid>", lexer.Location);
598
opt_extern_alias_directives
600
| extern_alias_directives
603
opt_namespace_or_type_declarations
605
| namespace_or_type_declarations
608
namespace_or_type_declarations
609
: namespace_or_type_declaration
610
| namespace_or_type_declarations namespace_or_type_declaration
613
namespace_or_type_declaration
617
TypeContainer ds = (TypeContainer)$1;
619
if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
620
report.Error (1527, ds.Location,
621
"Namespace elements cannot be explicitly declared as private, protected or protected internal");
624
// Here is a trick, for explicit attributes we don't know where they belong to until
625
// we parse succeeding declaration hence we parse them as normal and re-attach them
626
// when we know whether they are global (assembly:, module:) or local (type:).
627
if (ds.OptAttributes != null) {
628
ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
631
current_namespace.DeclarationFound = true;
633
| namespace_declaration
635
current_namespace.DeclarationFound = true;
637
| attribute_sections CLOSE_BRACE {
638
current_namespace.UnattachedAttributes = (Attributes) $1;
639
report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
647
| interface_declaration
649
| delegate_declaration
651
// Enable this when we have handled all errors, because this acts as a generic fallback
654
// Console.WriteLine ("Token=" + yyToken);
655
// report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
671
var sect = (List<Attribute>) $1;
672
$$ = new Attributes (sect);
673
if (locationListStack.Count > 0)
674
lbag.AddLocation (sect, locationListStack.Pop ());
675
if (attributeCommas.Count > 0) {
676
lbag.AddLocation (sect, attributeCommas);
677
attributeCommas.Clear ();
680
| attribute_sections attribute_section
682
Attributes attrs = $1 as Attributes;
683
var sect = (List<Attribute>) $2;
685
if (locationListStack.Count > 0)
686
lbag.AddLocation (sect, locationListStack.Pop ());
688
attrs = new Attributes (sect);
690
attrs.AddAttributes (sect);
698
PushLocation (GetLocation ($1));
699
lexer.parsing_attribute_section = true;
700
savedOpenLocation = GetLocation ($1);
702
attribute_section_cont
704
lexer.parsing_attribute_section = false;
709
attribute_section_cont
710
: attribute_target COLON
712
current_attr_target = (string) $1;
713
if (current_attr_target == "assembly" || current_attr_target == "module") {
714
Lexer.check_incorrect_doc_comment ();
717
attribute_list opt_comma CLOSE_BRACKET
719
// when attribute target is invalid
720
if (current_attr_target == string.Empty)
721
$$ = new List<Attribute> (0);
725
lbag.InsertLocation ($$, 0, PopLocation ());
727
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
729
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
732
current_attr_target = null;
733
lexer.parsing_attribute_section = false;
735
| attribute_list opt_comma CLOSE_BRACKET
739
lbag.InsertLocation ($$, 0, PopLocation ());
741
lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
743
lbag.AddLocation ($$, GetLocation($3));
748
Error_SyntaxError (yyToken);
750
var lt = (Tokenizer.LocatedToken) $1;
751
var tne = new SimpleName (lt.Value, null, lt.Location);
753
$$ = new List<Attribute> () {
754
new Attribute (null, tne, null, GetLocation ($1), false)
759
$$ = CheckAttributeTarget (GetTokenName (yyToken), GetLocation ($1));
767
var lt = (Tokenizer.LocatedToken) $1;
768
$$ = CheckAttributeTarget (lt.Value, lt.Location);
769
savedCloseLocation = GetLocation ($1);
771
| EVENT { $$ = "event"; savedCloseLocation = GetLocation ($1); }
772
| RETURN { $$ = "return"; savedCloseLocation = GetLocation ($1); }
778
$$ = new List<Attribute> (4) { (Attribute) $1 };
780
| attribute_list COMMA attribute
782
var attrs = (List<Attribute>) $1;
784
attrs.Add ((Attribute) $3);
785
lbag.AddLocation (attrs, GetLocation ($2));
795
++lexer.parsing_block;
797
opt_attribute_arguments
799
--lexer.parsing_block;
801
var tne = (ATypeNameExpression) $1;
802
if (tne.HasTypeArguments) {
803
report.Error (404, tne.Location, "Attributes cannot be generic");
805
Arguments [] arguments = (Arguments []) $3;
807
$$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
808
if (arguments != null) {
809
attributeArgumentCommas.Insert (0, savedAttrParenOpenLocation);
810
attributeArgumentCommas.Add (savedAttrParenCloseLocation);
811
lbag.AddLocation ($$, attributeArgumentCommas);
812
attributeArgumentCommas.Clear ();
813
} else if (HadAttributeParens) {
814
lbag.AddLocation ($$, savedAttrParenOpenLocation, savedAttrParenCloseLocation);
820
: namespace_or_type_expr
823
opt_attribute_arguments
824
: /* empty */ { $$ = null; HadAttributeParens = false; }
825
| OPEN_PARENS attribute_arguments CLOSE_PARENS
827
savedAttrParenOpenLocation = GetLocation ($1);
828
savedAttrParenCloseLocation = GetLocation ($3);
830
HadAttributeParens = true;
836
: /* empty */ { $$ = null; }
837
| positional_or_named_argument
839
Arguments a = new Arguments (4);
840
a.Add ((Argument) $1);
841
$$ = new Arguments [] { a, null };
843
| named_attribute_argument
845
Arguments a = new Arguments (4);
846
a.Add ((Argument) $1);
847
$$ = new Arguments [] { null, a };
849
| attribute_arguments COMMA positional_or_named_argument
851
Arguments[] o = (Arguments[]) $1;
853
report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
854
o [0] = new Arguments (4);
857
Arguments args = ((Arguments) o [0]);
858
if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
859
Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
861
args.Add ((Argument) $3);
862
attributeArgumentCommas.Add (GetLocation ($2));
864
| attribute_arguments COMMA named_attribute_argument
866
Arguments[] o = (Arguments[]) $1;
868
o [1] = new Arguments (4);
871
((Arguments) o [1]).Add ((Argument) $3);
872
attributeArgumentCommas.Add (GetLocation ($2));
876
positional_or_named_argument
879
$$ = new Argument ((Expression) $1);
884
Error_SyntaxError (yyToken);
889
named_attribute_argument
892
++lexer.parsing_block;
896
--lexer.parsing_block;
897
var lt = (Tokenizer.LocatedToken) $1;
898
$$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
899
lbag.AddLocation ($$, GetLocation($2));
904
: identifier_inside_body COLON opt_named_modifier expression
906
if (lang_version <= LanguageVersion.V_3)
907
FeatureIsNotAvailable (GetLocation ($1), "named argument");
909
// Avoid boxing in common case (no modifier)
910
var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
912
var lt = (Tokenizer.LocatedToken) $1;
913
$$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
914
lbag.AddLocation ($$, GetLocation($2));
919
: /* empty */ { $$ = null; }
922
$$ = Argument.AType.Ref;
926
$$ = Argument.AType.Out;
930
opt_class_member_declarations
932
| class_member_declarations
935
class_member_declarations
936
: class_member_declaration
938
lexer.parsing_modifiers = true;
940
| class_member_declarations class_member_declaration
942
lexer.parsing_modifiers = true;
946
class_member_declaration
947
: constant_declaration
950
| property_declaration
952
| indexer_declaration
953
| operator_declaration
954
| constructor_declaration
955
| destructor_declaration
957
| attributes_without_members
961
report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
962
GetSymbolName (yyToken));
964
lexer.parsing_generic_declaration = false;
975
type_declaration_name
977
lexer.ConstraintsParsing = true;
978
push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
979
lbag.AddMember (current_container, GetModifierLocations (), GetLocation ($4));
982
opt_type_parameter_constraints_clauses
984
lexer.ConstraintsParsing = false;
987
current_container.SetConstraints ((List<Constraints>) $9);
990
current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
993
lexer.parsing_modifiers = true;
998
Lexer.doc_state = XmlCommentState.Allowed;
1000
opt_class_member_declarations CLOSE_BRACE
1002
--lexer.parsing_declaration;
1004
Lexer.doc_state = XmlCommentState.Allowed;
1009
lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14));
1011
lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
1013
$$ = pop_current_class ();
1015
| opt_attributes opt_modifiers opt_partial STRUCT error
1017
Error_SyntaxError (yyToken);
1021
constant_declaration
1024
CONST type IDENTIFIER
1026
var lt = (Tokenizer.LocatedToken) $5;
1027
var mod = (Modifiers) $2;
1028
current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1029
current_type.AddMember (current_field);
1031
if ((mod & Modifiers.STATIC) != 0) {
1032
report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1037
constant_initializer opt_constant_declarators SEMICOLON
1040
current_field.DocComment = Lexer.consume_doc_comment ();
1041
Lexer.doc_state = XmlCommentState.Allowed;
1044
current_field.Initializer = (ConstInitializer) $7;
1045
lbag.AddMember (current_field, GetModifierLocations (), GetLocation ($3), GetLocation ($9));
1046
current_field = null;
1052
Error_SyntaxError (yyToken);
1054
current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1058
opt_constant_declarators
1060
| constant_declarators
1063
constant_declarators
1064
: constant_declarator
1066
current_field.AddDeclarator ((FieldDeclarator) $1);
1068
| constant_declarators constant_declarator
1070
current_field.AddDeclarator ((FieldDeclarator) $2);
1075
: COMMA IDENTIFIER constant_initializer
1077
var lt = (Tokenizer.LocatedToken) $2;
1078
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1079
lbag.AddLocation ($$, GetLocation ($1));
1083
constant_initializer
1086
++lexer.parsing_block;
1088
constant_initializer_expr
1090
--lexer.parsing_block;
1091
$$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1092
lbag.AddLocation ($$, GetLocation ($1));
1096
report.Error (145, lexer.Location, "A const field requires a value to be provided");
1101
constant_initializer_expr
1102
: constant_expression
1109
member_type IDENTIFIER
1111
lexer.parsing_generic_declaration = false;
1113
FullNamedExpression type = (FullNamedExpression) $3;
1114
if (type.Type != null && type.Type.Kind == MemberKind.Void)
1115
report.Error (670, GetLocation ($3), "Fields cannot have void type");
1117
var lt = (Tokenizer.LocatedToken) $4;
1118
current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1119
current_type.AddField (current_field);
1122
opt_field_initializer
1123
opt_field_declarators
1127
current_field.DocComment = Lexer.consume_doc_comment ();
1128
Lexer.doc_state = XmlCommentState.Allowed;
1131
lbag.AddMember (current_field, GetModifierLocations (), GetLocation ($8));
1133
current_field = null;
1137
FIXED simple_type IDENTIFIER
1139
if (lang_version < LanguageVersion.ISO_2)
1140
FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1142
var lt = (Tokenizer.LocatedToken) $5;
1143
current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1144
new MemberName (lt.Value, lt.Location), (Attributes) $1);
1146
current_type.AddField (current_field);
1148
fixed_field_size opt_fixed_field_declarators SEMICOLON
1151
current_field.DocComment = Lexer.consume_doc_comment ();
1152
Lexer.doc_state = XmlCommentState.Allowed;
1155
current_field.Initializer = (ConstInitializer) $7;
1156
lbag.AddMember (current_field, GetModifierLocations (), GetLocation ($3), GetLocation ($9));
1158
current_field = null;
1162
FIXED simple_type error
1165
report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1169
opt_field_initializer
1173
++lexer.parsing_block;
1174
current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1175
start_block (GetLocation ($1));
1177
variable_initializer
1179
--lexer.parsing_block;
1180
current_field.Initializer = (Expression) $3;
1181
lbag.AppendToMember (current_field, GetLocation ($1));
1182
end_block (lexer.Location);
1183
current_local_parameters = null;
1187
opt_field_declarators
1195
current_field.AddDeclarator ((FieldDeclarator) $1);
1197
| field_declarators field_declarator
1199
current_field.AddDeclarator ((FieldDeclarator) $2);
1206
var lt = (Tokenizer.LocatedToken) $2;
1207
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1208
lbag.AddLocation ($$, GetLocation ($1));
1210
| COMMA IDENTIFIER ASSIGN
1212
++lexer.parsing_block;
1214
variable_initializer
1216
--lexer.parsing_block;
1217
var lt = (Tokenizer.LocatedToken) $2;
1218
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1219
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1223
opt_fixed_field_declarators
1225
| fixed_field_declarators
1228
fixed_field_declarators
1229
: fixed_field_declarator
1231
current_field.AddDeclarator ((FieldDeclarator) $1);
1233
| fixed_field_declarators fixed_field_declarator
1235
current_field.AddDeclarator ((FieldDeclarator) $2);
1239
fixed_field_declarator
1240
: COMMA IDENTIFIER fixed_field_size
1242
var lt = (Tokenizer.LocatedToken) $2;
1243
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1244
lbag.AddLocation ($$, GetLocation ($1));
1251
++lexer.parsing_block;
1253
expression CLOSE_BRACKET
1255
--lexer.parsing_block;
1256
$$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1257
lbag.AddLocation ($$, GetLocation ($4));
1259
| OPEN_BRACKET error
1261
report.Error (443, lexer.Location, "Value or constant expected");
1266
variable_initializer
1271
// It has to be here for the parent to safely restore artificial block
1272
Error_SyntaxError (yyToken);
1281
Lexer.doc_state = XmlCommentState.NotAllowed;
1283
// Was added earlier in the case of body being eof for full ast
1287
Method method = (Method) $1;
1288
method.Block = (ToplevelBlock) $3;
1289
async_block = false;
1291
if (method.Block == null) {
1292
lbag.AppendToMember (method, savedLocation); // semicolon
1293
method.ParameterInfo.CheckParameters (method);
1295
if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1296
report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1297
method.GetSignatureForError ());
1300
if (current_container.Kind == MemberKind.Interface) {
1301
report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1302
method.GetSignatureForError ());
1306
current_local_parameters = null;
1309
Lexer.doc_state = XmlCommentState.Allowed;
1317
method_declaration_name OPEN_PARENS
1319
valid_param_mod = ParameterModifierType.All;
1321
opt_formal_parameter_list CLOSE_PARENS
1323
valid_param_mod = 0;
1324
MemberName name = (MemberName) $4;
1325
current_local_parameters = (ParametersCompiled) $7;
1327
var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1328
name, current_local_parameters, (Attributes) $1);
1330
current_type.AddMember (method);
1332
async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1335
method.DocComment = Lexer.consume_doc_comment ();
1337
lbag.AddMember (method, GetModifierLocations (), GetLocation ($5), GetLocation ($8));
1340
lexer.ConstraintsParsing = true;
1342
opt_type_parameter_constraints_clauses
1344
lexer.ConstraintsParsing = false;
1347
var method = (Method) $9;
1348
method.SetConstraints ((List<Constraints>) $10);
1358
lexer.parsing_generic_declaration = true;
1360
method_declaration_name
1363
lexer.parsing_generic_declaration = false;
1364
valid_param_mod = ParameterModifierType.All;
1366
opt_formal_parameter_list CLOSE_PARENS
1368
lexer.ConstraintsParsing = true;
1370
opt_type_parameter_constraints_clauses
1372
lexer.ConstraintsParsing = false;
1373
valid_param_mod = 0;
1375
MemberName name = (MemberName) $6;
1376
current_local_parameters = (ParametersCompiled) $9;
1378
var modifiers = (Modifiers) $2;
1379
modifiers |= Modifiers.PARTIAL;
1381
var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1382
modifiers, name, current_local_parameters, (Attributes) $1);
1384
current_type.AddMember (method);
1387
method.SetConstraints ((List<Constraints>) $11);
1390
method.DocComment = Lexer.consume_doc_comment ();
1392
StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1393
lbag.AddMember (method, GetModifierLocations (), GetLocation ($7), GetLocation ($10));
1399
modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1401
MemberName name = (MemberName) $5;
1402
report.Error (1585, name.Location,
1403
"Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1405
var method = Method.Create (current_type, (FullNamedExpression) $3,
1406
0, name, (ParametersCompiled) $7, (Attributes) $1);
1408
current_type.AddMember (method);
1410
current_local_parameters = (ParametersCompiled) $7;
1413
method.DocComment = Lexer.consume_doc_comment ();
1420
method_declaration_name error
1422
Error_SyntaxError (yyToken);
1423
current_local_parameters = ParametersCompiled.Undefined;
1425
MemberName name = (MemberName) $4;
1426
var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1427
name, current_local_parameters, (Attributes) $1);
1429
current_type.AddMember (method);
1432
method.DocComment = Lexer.consume_doc_comment ();
1440
| SEMICOLON { savedLocation = GetLocation ($1); $$ = null; }
1443
opt_formal_parameter_list
1444
: /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1445
| formal_parameter_list
1448
formal_parameter_list
1451
var pars_list = (List<Parameter>) $1;
1452
$$ = new ParametersCompiled (pars_list.ToArray ());
1453
lbag.AddLocation ($$, parameterListCommas);
1455
| fixed_parameters COMMA parameter_array
1457
var pars_list = (List<Parameter>) $1;
1458
pars_list.Add ((Parameter) $3);
1459
parameterListCommas.Add (GetLocation ($2));
1461
$$ = new ParametersCompiled (pars_list.ToArray ());
1462
lbag.AddLocation ($$, parameterListCommas);
1464
| fixed_parameters COMMA arglist_modifier
1466
var pars_list = (List<Parameter>) $1;
1467
pars_list.Add (new ArglistParameter (GetLocation ($3)));
1468
parameterListCommas.Add (GetLocation ($2));
1470
$$ = new ParametersCompiled (pars_list.ToArray (), true);
1471
lbag.AddLocation ($$, parameterListCommas);
1473
| parameter_array COMMA error
1476
report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1478
$$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1479
lbag.AddLocation ($$, parameterListCommas);
1481
| fixed_parameters COMMA parameter_array COMMA error
1484
report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1486
var pars_list = (List<Parameter>) $1;
1487
pars_list.Add (new ArglistParameter (GetLocation ($3)));
1488
parameterListCommas.Add (GetLocation ($2));
1489
parameterListCommas.Add (GetLocation ($4));
1491
$$ = new ParametersCompiled (pars_list.ToArray (), true);
1492
lbag.AddLocation ($$, parameterListCommas);
1494
| arglist_modifier COMMA error
1496
report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1498
$$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1499
lbag.AddLocation ($$, parameterListCommas);
1501
| fixed_parameters COMMA ARGLIST COMMA error
1503
report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1505
var pars_list = (List<Parameter>) $1;
1506
pars_list.Add (new ArglistParameter (GetLocation ($3)));
1507
parameterListCommas.Add (GetLocation ($2));
1508
parameterListCommas.Add (GetLocation ($4));
1510
$$ = new ParametersCompiled (pars_list.ToArray (), true);
1511
lbag.AddLocation ($$, parameterListCommas);
1515
$$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1519
$$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1523
Error_SyntaxError (yyToken);
1524
$$ = ParametersCompiled.EmptyReadOnlyParameters;
1531
parameters_bucket.Clear ();
1532
Parameter p = (Parameter) $1;
1533
parameters_bucket.Add (p);
1534
parameterListCommas.Clear ();
1535
default_parameter_used = p.HasDefaultValue;
1536
$$ = parameters_bucket;
1538
| fixed_parameters COMMA fixed_parameter
1540
var pars = (List<Parameter>) $1;
1541
Parameter p = (Parameter) $3;
1543
if (p.HasExtensionMethodModifier)
1544
report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1545
else if (!p.HasDefaultValue && default_parameter_used)
1546
report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1548
default_parameter_used |= p.HasDefaultValue;
1551
parameterListCommas.Add (GetLocation ($2));
1560
opt_parameter_modifier
1562
identifier_inside_body
1564
var lt = (Tokenizer.LocatedToken) $4;
1565
$$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1566
lbag.AddLocation ($$, parameterModifierLocation);
1569
opt_parameter_modifier
1571
identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1573
var lt = (Tokenizer.LocatedToken) $4;
1574
report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1575
$$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1576
lbag.AddLocation ($$, parameterModifierLocation);
1578
| attribute_sections error
1580
Error_SyntaxError (yyToken);
1581
Location l = GetLocation ($2);
1582
$$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1585
opt_parameter_modifier
1589
Error_SyntaxError (yyToken);
1590
Location l = GetLocation ($4);
1591
$$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1592
lbag.AddLocation ($$, parameterModifierLocation);
1595
opt_parameter_modifier
1597
identifier_inside_body
1600
++lexer.parsing_block;
1604
--lexer.parsing_block;
1605
if (lang_version <= LanguageVersion.V_3) {
1606
FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1609
Parameter.Modifier mod = (Parameter.Modifier) $2;
1610
if (mod != Parameter.Modifier.NONE) {
1612
case Parameter.Modifier.REF:
1613
case Parameter.Modifier.OUT:
1614
report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1615
Parameter.GetModifierSignature (mod));
1618
case Parameter.Modifier.This:
1619
report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1620
Parameter.GetModifierSignature (mod));
1623
throw new NotImplementedException (mod.ToString ());
1626
mod = Parameter.Modifier.NONE;
1629
if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1630
report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1632
var lt = (Tokenizer.LocatedToken) $4;
1633
$$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1634
lbag.AddLocation ($$, parameterModifierLocation, GetLocation ($5)); // parameterModifierLocation should be ignored when mod == NONE
1637
((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1641
opt_parameter_modifier
1642
: /* empty */ { $$ = Parameter.Modifier.NONE; }
1643
| parameter_modifiers
1647
: parameter_modifier
1651
| parameter_modifiers parameter_modifier
1653
Parameter.Modifier p2 = (Parameter.Modifier)$2;
1654
Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1655
if (((Parameter.Modifier)$1 & p2) == p2) {
1656
Error_DuplicateParameterModifier (lexer.Location, p2);
1658
switch (mod & ~Parameter.Modifier.This) {
1659
case Parameter.Modifier.REF:
1660
report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1662
case Parameter.Modifier.OUT:
1663
report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1666
report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1677
if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1678
Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1679
parameterModifierLocation = GetLocation ($1);
1680
$$ = Parameter.Modifier.REF;
1684
if ((valid_param_mod & ParameterModifierType.Out) == 0)
1685
Error_ParameterModifierNotValid ("out", GetLocation ($1));
1686
parameterModifierLocation = GetLocation ($1);
1687
$$ = Parameter.Modifier.OUT;
1691
if ((valid_param_mod & ParameterModifierType.This) == 0)
1692
Error_ParameterModifierNotValid ("this", GetLocation ($1));
1694
if (lang_version <= LanguageVersion.ISO_2)
1695
FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1696
parameterModifierLocation = GetLocation ($1);
1697
$$ = Parameter.Modifier.This;
1702
: opt_attributes params_modifier type IDENTIFIER
1704
var lt = (Tokenizer.LocatedToken) $4;
1705
$$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1706
lbag.AddLocation ($$, savedLocation);
1708
| opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1710
report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1712
var lt = (Tokenizer.LocatedToken) $4;
1713
$$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1714
lbag.AddLocation ($$, savedLocation);
1716
| opt_attributes params_modifier type error
1718
Error_SyntaxError (yyToken);
1720
$$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1727
if ((valid_param_mod & ParameterModifierType.Params) == 0)
1728
report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1729
savedLocation = GetLocation ($1);
1731
| PARAMS parameter_modifier
1733
Parameter.Modifier mod = (Parameter.Modifier)$2;
1734
if ((mod & Parameter.Modifier.This) != 0) {
1735
report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1737
report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1739
savedLocation = GetLocation ($1);
1741
| PARAMS params_modifier
1743
Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1750
if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1751
report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1755
property_declaration
1759
member_declaration_name
1762
tmpComment = Lexer.consume_doc_comment ();
1766
var type = (FullNamedExpression) $3;
1767
current_property = new Property (current_type, type, (Modifiers) $2,
1768
(MemberName) $4, (Attributes) $1);
1770
if (type.Type != null && type.Type.Kind == MemberKind.Void)
1771
report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1773
current_type.AddMember (current_property);
1774
lbag.AddMember (current_property, GetModifierLocations (), GetLocation ($6));
1776
lexer.PropertyParsing = true;
1778
accessor_declarations
1780
lexer.PropertyParsing = false;
1783
current_property.DocComment = ConsumeStoredComment ();
1787
lbag.AppendToMember (current_property, GetLocation ($10));
1788
current_property = null;
1794
: opt_attributes opt_modifiers
1795
member_type indexer_declaration_name OPEN_BRACKET
1797
valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1799
opt_formal_parameter_list CLOSE_BRACKET
1801
valid_param_mod = 0;
1802
var type = (FullNamedExpression) $3;
1803
Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1805
current_property = indexer;
1807
current_type.AddIndexer (indexer);
1808
lbag.AddMember (current_property, GetModifierLocations (), GetLocation ($5), GetLocation ($8));
1810
if (type.Type != null && type.Type.Kind == MemberKind.Void)
1811
report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1813
if (indexer.ParameterInfo.IsEmpty) {
1814
report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1818
tmpComment = Lexer.consume_doc_comment ();
1819
Lexer.doc_state = XmlCommentState.Allowed;
1822
lexer.PropertyParsing = true;
1824
OPEN_BRACE accessor_declarations
1826
lexer.PropertyParsing = false;
1830
if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1831
((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1834
current_property.DocComment = ConsumeStoredComment ();
1836
lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
1837
current_property = null;
1842
accessor_declarations
1843
: get_accessor_declaration
1844
| get_accessor_declaration accessor_declarations
1845
| set_accessor_declaration
1846
| set_accessor_declaration accessor_declarations
1849
if (yyToken == Token.CLOSE_BRACE) {
1850
report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1852
if (yyToken == Token.SEMICOLON)
1853
report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1855
report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1860
get_accessor_declaration
1861
: opt_attributes opt_modifiers GET
1863
if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1864
FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1867
if (current_property.Get != null) {
1868
report.Error (1007, GetLocation ($3), "Property accessor already defined");
1871
if (current_property is Indexer) {
1872
current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1873
(Attributes) $1, GetLocation ($3));
1875
current_property.Get = new Property.GetMethod (current_property,
1876
(Modifiers) $2, (Attributes) $1, GetLocation ($3));
1879
current_local_parameters = current_property.Get.ParameterInfo;
1880
lexer.PropertyParsing = false;
1885
current_property.Get.Block = (ToplevelBlock) $5;
1887
if (current_container.Kind == MemberKind.Interface) {
1888
report.Error (531, current_property.Get.Block.StartLocation,
1889
"`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1891
lbag.AddMember (current_property.Get, GetModifierLocations ());
1893
lbag.AddMember (current_property.Get, GetModifierLocations (), savedLocation);
1896
current_local_parameters = null;
1897
lexer.PropertyParsing = true;
1900
if (Lexer.doc_state == XmlCommentState.Error)
1901
Lexer.doc_state = XmlCommentState.NotAllowed;
1905
set_accessor_declaration
1906
: opt_attributes opt_modifiers SET
1908
if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1909
FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1912
if (current_property.Set != null) {
1913
report.Error (1007, GetLocation ($3), "Property accessor already defined");
1916
if (current_property is Indexer) {
1917
current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1918
ParametersCompiled.MergeGenerated (compiler,
1919
((Indexer)current_property).ParameterInfo, true, new Parameter (
1920
current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1922
(Attributes) $1, GetLocation ($3));
1924
current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1925
ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1926
(Attributes) $1, GetLocation ($3));
1929
current_local_parameters = current_property.Set.ParameterInfo;
1930
lexer.PropertyParsing = false;
1935
current_property.Set.Block = (ToplevelBlock) $5;
1937
if (current_container.Kind == MemberKind.Interface) {
1938
report.Error (531, current_property.Set.Block.StartLocation,
1939
"`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1941
lbag.AddMember (current_property.Set, GetModifierLocations ());
1943
lbag.AddMember (current_property.Set, GetModifierLocations (), savedLocation);
1946
current_local_parameters = null;
1947
lexer.PropertyParsing = true;
1950
&& Lexer.doc_state == XmlCommentState.Error)
1951
Lexer.doc_state = XmlCommentState.NotAllowed;
1959
savedLocation = GetLocation ($1);
1964
Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1969
interface_declaration
1976
type_declaration_name
1978
lexer.ConstraintsParsing = true;
1979
push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1980
lbag.AddMember (current_container, GetModifierLocations (), GetLocation ($4));
1983
opt_type_parameter_constraints_clauses
1985
lexer.ConstraintsParsing = false;
1988
current_container.SetConstraints ((List<Constraints>) $9);
1991
current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1992
Lexer.doc_state = XmlCommentState.Allowed;
1995
lexer.parsing_modifiers = true;
1997
OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1999
--lexer.parsing_declaration;
2001
Lexer.doc_state = XmlCommentState.Allowed;
2006
lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2008
lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2010
$$ = pop_current_class ();
2012
| opt_attributes opt_modifiers opt_partial INTERFACE error
2014
Error_SyntaxError (yyToken);
2018
opt_interface_member_declarations
2020
| interface_member_declarations
2023
interface_member_declarations
2024
: interface_member_declaration
2026
lexer.parsing_modifiers = true;
2028
| interface_member_declarations interface_member_declaration
2030
lexer.parsing_modifiers = true;
2034
interface_member_declaration
2035
: constant_declaration
2037
report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2041
report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2043
| method_declaration
2044
| property_declaration
2046
| indexer_declaration
2047
| operator_declaration
2049
report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2051
| constructor_declaration
2053
report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2057
report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2061
operator_declaration
2062
: opt_attributes opt_modifiers operator_declarator
2067
OperatorDeclaration decl = (OperatorDeclaration) $3;
2069
Operator op = new Operator (
2070
current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2071
current_local_parameters,
2072
(ToplevelBlock) $5, (Attributes) $1, decl.location);
2074
if (op.Block == null)
2075
op.ParameterInfo.CheckParameters (op);
2078
op.DocComment = tmpComment;
2079
Lexer.doc_state = XmlCommentState.Allowed;
2082
// Note again, checking is done in semantic analysis
2083
current_type.AddOperator (op);
2085
lbag.AddMember (op, GetModifierLocations (), lbag.GetLocations (decl));
2086
if ($5 == null) { // Semicolon
2087
lbag.AddLocation (op, savedLocation);
2091
current_local_parameters = null;
2097
| SEMICOLON { savedLocation = GetLocation ($1); $$ = null; }
2101
: type_expression_or_array
2104
report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2105
$$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2110
: operator_type OPERATOR overloadable_operator OPEN_PARENS
2112
valid_param_mod = ParameterModifierType.DefaultValue;
2114
opt_formal_parameter_list CLOSE_PARENS
2116
valid_param_mod = 0;
2118
Location loc = GetLocation ($2);
2119
Operator.OpType op = (Operator.OpType) $3;
2120
current_local_parameters = (ParametersCompiled)$6;
2122
int p_count = current_local_parameters.Count;
2124
if (op == Operator.OpType.Addition)
2125
op = Operator.OpType.UnaryPlus;
2126
else if (op == Operator.OpType.Subtraction)
2127
op = Operator.OpType.UnaryNegation;
2130
if (IsUnaryOperator (op)) {
2132
report.Error (1020, loc, "Overloadable binary operator expected");
2133
} else if (p_count != 1) {
2134
report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2135
Operator.GetName (op));
2139
report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2140
Operator.GetName (op));
2141
} else if (p_count != 2) {
2142
report.Error (1019, loc, "Overloadable unary operator expected");
2147
tmpComment = Lexer.consume_doc_comment ();
2148
Lexer.doc_state = XmlCommentState.NotAllowed;
2151
$$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2152
lbag.AddLocation ($$, GetLocation ($2), savedOperatorLocation, GetLocation ($4), GetLocation ($7));
2154
| conversion_operator_declarator
2157
overloadable_operator
2159
: BANG { $$ = Operator.OpType.LogicalNot; savedOperatorLocation = GetLocation ($1); }
2160
| TILDE { $$ = Operator.OpType.OnesComplement; savedOperatorLocation = GetLocation ($1); }
2161
| OP_INC { $$ = Operator.OpType.Increment; savedOperatorLocation = GetLocation ($1); }
2162
| OP_DEC { $$ = Operator.OpType.Decrement; savedOperatorLocation = GetLocation ($1); }
2163
| TRUE { $$ = Operator.OpType.True; savedOperatorLocation = GetLocation ($1); }
2164
| FALSE { $$ = Operator.OpType.False; savedOperatorLocation = GetLocation ($1); }
2165
// Unary and binary:
2166
| PLUS { $$ = Operator.OpType.Addition; savedOperatorLocation = GetLocation ($1); }
2167
| MINUS { $$ = Operator.OpType.Subtraction; savedOperatorLocation = GetLocation ($1); }
2169
| STAR { $$ = Operator.OpType.Multiply; savedOperatorLocation = GetLocation ($1); }
2170
| DIV { $$ = Operator.OpType.Division; savedOperatorLocation = GetLocation ($1); }
2171
| PERCENT { $$ = Operator.OpType.Modulus; savedOperatorLocation = GetLocation ($1); }
2172
| BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; savedOperatorLocation = GetLocation ($1); }
2173
| BITWISE_OR { $$ = Operator.OpType.BitwiseOr; savedOperatorLocation = GetLocation ($1); }
2174
| CARRET { $$ = Operator.OpType.ExclusiveOr; savedOperatorLocation = GetLocation ($1); }
2175
| OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; savedOperatorLocation = GetLocation ($1); }
2176
| OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; savedOperatorLocation = GetLocation ($1); }
2177
| OP_EQ { $$ = Operator.OpType.Equality; savedOperatorLocation = GetLocation ($1); }
2178
| OP_NE { $$ = Operator.OpType.Inequality; savedOperatorLocation = GetLocation ($1); }
2179
| OP_GT { $$ = Operator.OpType.GreaterThan; savedOperatorLocation = GetLocation ($1); }
2180
| OP_LT { $$ = Operator.OpType.LessThan; savedOperatorLocation = GetLocation ($1); }
2181
| OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; savedOperatorLocation = GetLocation ($1); }
2182
| OP_LE { $$ = Operator.OpType.LessThanOrEqual; savedOperatorLocation = GetLocation ($1); }
2185
conversion_operator_declarator
2186
: IMPLICIT OPERATOR type OPEN_PARENS
2188
valid_param_mod = ParameterModifierType.DefaultValue;
2190
opt_formal_parameter_list CLOSE_PARENS
2192
valid_param_mod = 0;
2194
Location loc = GetLocation ($2);
2195
current_local_parameters = (ParametersCompiled)$6;
2197
if (current_local_parameters.Count != 1) {
2198
report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2202
tmpComment = Lexer.consume_doc_comment ();
2203
Lexer.doc_state = XmlCommentState.NotAllowed;
2206
$$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2207
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2209
| EXPLICIT OPERATOR type OPEN_PARENS
2211
valid_param_mod = ParameterModifierType.DefaultValue;
2213
opt_formal_parameter_list CLOSE_PARENS
2215
valid_param_mod = 0;
2217
Location loc = GetLocation ($2);
2218
current_local_parameters = (ParametersCompiled)$6;
2220
if (current_local_parameters.Count != 1) {
2221
report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2225
tmpComment = Lexer.consume_doc_comment ();
2226
Lexer.doc_state = XmlCommentState.NotAllowed;
2229
$$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2230
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2234
Error_SyntaxError (yyToken);
2235
current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2236
$$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2240
Error_SyntaxError (yyToken);
2241
current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2242
$$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2246
constructor_declaration
2247
: constructor_declarator
2250
Constructor c = (Constructor) $1;
2251
c.Block = (ToplevelBlock) $2;
2254
c.DocComment = ConsumeStoredComment ();
2256
current_local_parameters = null;
2258
Lexer.doc_state = XmlCommentState.Allowed;
2262
constructor_declarator
2268
tmpComment = Lexer.consume_doc_comment ();
2269
Lexer.doc_state = XmlCommentState.Allowed;
2272
valid_param_mod = ParameterModifierType.All;
2274
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2276
valid_param_mod = 0;
2277
current_local_parameters = (ParametersCompiled) $6;
2279
var lt = (Tokenizer.LocatedToken) $3;
2280
var mods = (Modifiers) $2;
2281
var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2283
if (lt.Value != current_container.MemberName.Name) {
2284
report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2285
} else if ((mods & Modifiers.STATIC) != 0) {
2286
if ((mods & Modifiers.AccessibilityMask) != 0){
2287
report.Error (515, c.Location,
2288
"`{0}': static constructor cannot have an access modifier",
2289
c.GetSignatureForError ());
2293
current_type.AddConstructor (c);
2294
lbag.AddMember (c, GetModifierLocations (), GetLocation ($5), GetLocation ($7));
2298
// start block here, so possible anonymous methods inside
2299
// constructor initializer can get correct parent block
2301
start_block (lexer.Location);
2303
opt_constructor_initializer
2306
var c = (Constructor) $8;
2307
c.Initializer = (ConstructorInitializer) $9;
2310
report.Error (514, c.Location,
2311
"`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2312
c.GetSignatureForError ());
2322
| SEMICOLON { current_block = null; $$ = null; }
2325
opt_constructor_initializer
2327
| constructor_initializer
2330
constructor_initializer
2331
: COLON BASE OPEN_PARENS
2333
++lexer.parsing_block;
2335
opt_argument_list CLOSE_PARENS
2337
--lexer.parsing_block;
2338
$$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2339
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2341
| COLON THIS OPEN_PARENS
2343
++lexer.parsing_block;
2345
opt_argument_list CLOSE_PARENS
2347
--lexer.parsing_block;
2348
$$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2349
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2353
Error_SyntaxError (yyToken);
2354
$$ = new ConstructorThisInitializer (null, GetLocation ($2));
2355
lbag.AddLocation ($$, GetLocation ($1));
2359
Error_SyntaxError (yyToken);
2364
destructor_declaration
2365
: opt_attributes opt_modifiers TILDE
2368
tmpComment = Lexer.consume_doc_comment ();
2369
Lexer.doc_state = XmlCommentState.NotAllowed;
2372
current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2374
IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2376
var lt = (Tokenizer.LocatedToken) $5;
2377
if (lt.Value != current_container.MemberName.Name){
2378
report.Error (574, lt.Location, "Name of destructor must match name of class");
2379
} else if (current_container.Kind != MemberKind.Class){
2380
report.Error (575, lt.Location, "Only class types can contain destructor");
2383
Destructor d = new Destructor (current_type, (Modifiers) $2,
2384
ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2385
d.Identifier = lt.Value;
2387
d.DocComment = ConsumeStoredComment ();
2389
d.Block = (ToplevelBlock) $8;
2390
current_type.AddMember (d);
2391
lbag.AddMember (d, GetModifierLocations (), GetLocation ($3), GetLocation ($6), GetLocation ($7));
2393
current_local_parameters = null;
2400
EVENT type member_declaration_name
2402
current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2403
current_type.AddMember (current_event_field);
2405
if (current_event_field.MemberName.ExplicitInterface != null) {
2406
report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2407
current_event_field.GetSignatureForError ());
2410
$$ = current_event_field;
2412
opt_event_initializer
2413
opt_event_declarators
2417
current_event_field.DocComment = Lexer.consume_doc_comment ();
2418
Lexer.doc_state = XmlCommentState.Allowed;
2420
if (current_event_field.Initializer != null) {
2421
lbag.AddMember (current_event_field, GetModifierLocations (), GetLocation ($3), savedEventAssignLocation, GetLocation ($9));
2423
lbag.AddMember (current_event_field, GetModifierLocations (), GetLocation ($3), GetLocation ($9));
2425
current_event_field = null;
2429
EVENT type member_declaration_name
2432
current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2433
current_type.AddMember (current_event);
2434
lbag.AddMember (current_event, GetModifierLocations (), GetLocation ($3), GetLocation ($6));
2436
lexer.EventParsing = true;
2438
event_accessor_declarations
2440
if (current_container.Kind == MemberKind.Interface)
2441
report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2443
lexer.EventParsing = false;
2448
current_event.DocComment = Lexer.consume_doc_comment ();
2449
Lexer.doc_state = XmlCommentState.Allowed;
2452
lbag.AppendToMember (current_event, GetLocation ($9));
2453
current_event = null;
2454
current_local_parameters = null;
2460
Error_SyntaxError (yyToken);
2462
current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2466
opt_event_initializer
2470
++lexer.parsing_block;
2472
event_variable_initializer
2474
--lexer.parsing_block;
2475
savedEventAssignLocation = GetLocation ($1);
2476
current_event_field.Initializer = (Expression) $3;
2480
opt_event_declarators
2488
current_event_field.AddDeclarator ((FieldDeclarator) $1);
2490
| event_declarators event_declarator
2492
current_event_field.AddDeclarator ((FieldDeclarator) $2);
2499
var lt = (Tokenizer.LocatedToken) $2;
2500
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2501
lbag.AddLocation ($$, GetLocation ($1));
2503
| COMMA IDENTIFIER ASSIGN
2505
++lexer.parsing_block;
2507
event_variable_initializer
2509
--lexer.parsing_block;
2510
var lt = (Tokenizer.LocatedToken) $2;
2511
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2512
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2516
event_variable_initializer
2518
if (current_container.Kind == MemberKind.Interface) {
2519
report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2520
current_event_field.GetSignatureForError ());
2523
if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2524
report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2525
current_event_field.GetSignatureForError ());
2528
variable_initializer
2534
event_accessor_declarations
2535
: add_accessor_declaration remove_accessor_declaration
2536
| remove_accessor_declaration add_accessor_declaration
2537
| add_accessor_declaration
2539
report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2540
current_event.GetSignatureForError ());
2542
| remove_accessor_declaration
2544
report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2545
current_event.GetSignatureForError ());
2549
report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2554
add_accessor_declaration
2555
: opt_attributes opt_modifiers ADD
2557
if ($2 != ModifierNone) {
2558
report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2561
current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2562
current_local_parameters = current_event.Add.ParameterInfo;
2564
lbag.AddMember (current_event.Add, GetModifierLocations ());
2565
lexer.EventParsing = false;
2567
event_accessor_block
2569
lexer.EventParsing = true;
2571
current_event.Add.Block = (ToplevelBlock) $5;
2573
if (current_container.Kind == MemberKind.Interface) {
2574
report.Error (531, current_event.Add.Block.StartLocation,
2575
"`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2578
current_local_parameters = null;
2582
remove_accessor_declaration
2583
: opt_attributes opt_modifiers REMOVE
2585
if ($2 != ModifierNone) {
2586
report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2589
current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2590
current_local_parameters = current_event.Remove.ParameterInfo;
2592
lbag.AddMember (current_event.Remove, GetModifierLocations ());
2593
lexer.EventParsing = false;
2595
event_accessor_block
2597
lexer.EventParsing = true;
2599
current_event.Remove.Block = (ToplevelBlock) $5;
2601
if (current_container.Kind == MemberKind.Interface) {
2602
report.Error (531, current_event.Remove.Block.StartLocation,
2603
"`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2606
current_local_parameters = null;
2610
event_accessor_block
2613
report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2619
attributes_without_members
2620
: attribute_sections CLOSE_BRACE
2622
current_type.UnattachedAttributes = (Attributes) $1;
2623
report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2624
lexer.putback ('}');
2628
// For full ast try to recover incomplete ambiguous member
2629
// declaration in form on class X { public int }
2631
: opt_attributes opt_modifiers member_type CLOSE_BRACE
2633
report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2635
lexer.putback ('}');
2637
lexer.parsing_generic_declaration = false;
2638
FullNamedExpression type = (FullNamedExpression) $3;
2639
current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2640
current_type.AddField (current_field);
2641
lbag.AddMember (current_field, GetModifierLocations ());
2650
type_declaration_name
2654
enumTypeComment = Lexer.consume_doc_comment ();
2659
Lexer.doc_state = XmlCommentState.Allowed;
2661
MemberName name = (MemberName) $4;
2662
if (name.IsGeneric) {
2663
report.Error (1675, name.Location, "Enums cannot have type parameters");
2666
push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2668
lbag.AddMember (current_container, GetModifierLocations (), GetLocation ($3), savedLocation, GetLocation ($7));
2670
lbag.AddMember (current_container, GetModifierLocations (), GetLocation ($3), GetLocation ($7));
2673
opt_enum_member_declarations
2675
// here will be evaluated after CLOSE_BLACE is consumed.
2677
Lexer.doc_state = XmlCommentState.Allowed;
2679
CLOSE_BRACE opt_semicolon
2681
lbag.AppendToMember (current_container, GetLocation ($11));
2683
lbag.AppendToMember (current_container, GetLocation ($12));
2686
current_container.DocComment = enumTypeComment;
2688
--lexer.parsing_declaration;
2691
// em.DocComment = ev.DocComment;
2693
$$ = pop_current_class ();
2701
savedLocation = GetLocation ($1);
2706
Error_TypeExpected (GetLocation ($1));
2711
opt_enum_member_declarations
2713
| enum_member_declarations
2714
| enum_member_declarations COMMA
2716
lbag.AppendToMember (current_container, GetLocation ($2));
2720
enum_member_declarations
2721
: enum_member_declaration
2722
| enum_member_declarations COMMA enum_member_declaration
2724
lbag.AppendToMember (current_container, GetLocation ($2));
2729
enum_member_declaration
2730
: opt_attributes IDENTIFIER
2732
var lt = (Tokenizer.LocatedToken) $2;
2733
var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2734
((Enum) current_type).AddEnumMember (em);
2737
em.DocComment = Lexer.consume_doc_comment ();
2738
Lexer.doc_state = XmlCommentState.Allowed;
2743
| opt_attributes IDENTIFIER
2745
++lexer.parsing_block;
2747
tmpComment = Lexer.consume_doc_comment ();
2748
Lexer.doc_state = XmlCommentState.NotAllowed;
2751
ASSIGN constant_expression
2753
--lexer.parsing_block;
2755
var lt = (Tokenizer.LocatedToken) $2;
2756
var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2757
em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2758
((Enum) current_type).AddEnumMember (em);
2761
em.DocComment = ConsumeStoredComment ();
2765
| opt_attributes IDENTIFIER error
2767
Error_SyntaxError (yyToken);
2769
var lt = (Tokenizer.LocatedToken) $2;
2770
var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2771
((Enum) current_type).AddEnumMember (em);
2774
em.DocComment = Lexer.consume_doc_comment ();
2775
Lexer.doc_state = XmlCommentState.Allowed;
2780
| attributes_without_members
2783
delegate_declaration
2787
member_type type_declaration_name
2790
valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2792
opt_formal_parameter_list CLOSE_PARENS
2794
valid_param_mod = 0;
2796
ParametersCompiled p = (ParametersCompiled) $8;
2798
Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2800
p.CheckParameters (del);
2802
current_container.AddTypeContainer (del);
2804
current_delegate = del;
2805
lexer.ConstraintsParsing = true;
2807
opt_type_parameter_constraints_clauses
2809
lexer.ConstraintsParsing = false;
2814
current_delegate.DocComment = Lexer.consume_doc_comment ();
2815
Lexer.doc_state = XmlCommentState.Allowed;
2819
current_delegate.SetConstraints ((List<Constraints>) $11);
2820
lbag.AddMember (current_delegate, GetModifierLocations (), GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2822
$$ = current_delegate;
2824
current_delegate = null;
2832
if (lang_version < LanguageVersion.ISO_2)
2833
FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2835
$$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2839
namespace_or_type_expr
2841
| qualified_alias_member IDENTIFIER opt_type_argument_list
2843
var lt1 = (Tokenizer.LocatedToken) $1;
2844
var lt2 = (Tokenizer.LocatedToken) $2;
2846
$$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2847
lbag.AddLocation ($$, savedLocation, GetLocation ($2));
2853
| namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2855
var lt = (Tokenizer.LocatedToken) $3;
2856
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location) {
2857
DotLocation = GetLocation ($2)
2863
: IDENTIFIER opt_type_argument_list
2865
var lt = (Tokenizer.LocatedToken) $1;
2866
$$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2871
// Generics arguments (any type, without attributes)
2873
opt_type_argument_list
2875
| OP_GENERICS_LT type_arguments OP_GENERICS_GT
2877
if (lang_version < LanguageVersion.ISO_2)
2878
FeatureIsNotAvailable (GetLocation ($1), "generics");
2879
var list = locationListStack.Pop ();
2880
list.Add (GetLocation ($1));
2881
list.Add (GetLocation ($2));
2882
lbag.AddLocation ($2, list);
2886
| OP_GENERICS_LT error
2888
Error_TypeExpected (lexer.Location);
2889
$$ = new TypeArguments ();
2896
TypeArguments type_args = new TypeArguments ();
2897
type_args.Add ((FullNamedExpression) $1);
2899
locationListStack.Push (new List<Location> ());
2901
| type_arguments COMMA type
2903
TypeArguments type_args = (TypeArguments) $1;
2904
type_args.Add ((FullNamedExpression) $3);
2906
locationListStack.Peek ().Add (GetLocation ($2));
2911
// Generics parameters (identifiers only, with attributes), used in type or method declarations
2913
type_declaration_name
2916
lexer.parsing_generic_declaration = true;
2918
opt_type_parameter_list
2920
lexer.parsing_generic_declaration = false;
2921
var lt = (Tokenizer.LocatedToken) $1;
2922
$$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2926
member_declaration_name
2927
: method_declaration_name
2929
MemberName mn = (MemberName)$1;
2930
if (mn.TypeParameters != null)
2931
syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2932
mn.GetSignatureForError ()));
2936
method_declaration_name
2937
: type_declaration_name
2938
| explicit_interface IDENTIFIER opt_type_parameter_list
2940
lexer.parsing_generic_declaration = false;
2941
var lt = (Tokenizer.LocatedToken) $2;
2942
$$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2946
indexer_declaration_name
2949
lexer.parsing_generic_declaration = false;
2950
$$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2952
| explicit_interface THIS
2954
lexer.parsing_generic_declaration = false;
2955
$$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2960
: IDENTIFIER opt_type_argument_list DOT
2962
var lt = (Tokenizer.LocatedToken) $1;
2963
$$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2964
lbag.AddLocation ($$, GetLocation ($3));
2966
| qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2968
var lt1 = (Tokenizer.LocatedToken) $1;
2969
var lt2 = (Tokenizer.LocatedToken) $2;
2971
$$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2972
lbag.AddLocation ($$, savedLocation, GetLocation ($4));
2974
| explicit_interface IDENTIFIER opt_type_argument_list DOT
2976
var lt = (Tokenizer.LocatedToken) $2;
2977
$$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2978
lbag.AddLocation ($$, GetLocation ($4));
2982
opt_type_parameter_list
2984
| OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2986
if (lang_version < LanguageVersion.ISO_2)
2987
FeatureIsNotAvailable (GetLocation ($1), "generics");
2990
var list = locationListStack.Pop ();
2991
list.Add (GetLocation ($1));
2992
list.Add (GetLocation ($2));
2993
lbag.AddLocation ($2, list);
3000
var tparams = new TypeParameters ();
3001
tparams.Add ((TypeParameter)$1);
3003
locationListStack.Push (new List<Location> ());
3005
| type_parameters COMMA type_parameter
3007
var tparams = (TypeParameters) $1;
3008
tparams.Add ((TypeParameter)$3);
3010
locationListStack.Peek ().Add (GetLocation ($2));
3015
: opt_attributes opt_type_parameter_variance IDENTIFIER
3017
var lt = (Tokenizer.LocatedToken)$3;
3018
var variance = (Variance) $2;
3019
$$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, variance);
3020
if (variance != Variance.None)
3021
lbag.AddLocation ($$, savedLocation);
3025
if (GetTokenName (yyToken) == "type")
3026
report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3028
Error_SyntaxError (yyToken);
3030
$$ = new TypeParameter (MemberName.Null, null, Variance.None);
3035
// All types where void is allowed
3038
: type_expression_or_array
3041
$$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3048
lexer.parsing_generic_declaration = true;
3053
// A type which does not allow `void' to be used
3056
: type_expression_or_array
3059
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3060
$$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3068
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3069
$$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3074
: type_expression_or_array
3077
report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3078
$$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3082
type_expression_or_array
3084
| type_expression rank_specifiers
3086
$$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3091
: namespace_or_type_expr opt_nullable
3094
$$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3096
var sn = $1 as SimpleName;
3097
if (sn != null && sn.Name == "var")
3098
$$ = new VarExpr (sn.Location);
3103
| namespace_or_type_expr pointer_stars
3105
$$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3107
| builtin_types opt_nullable
3110
$$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3112
| builtin_types pointer_stars
3114
$$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3116
| VOID pointer_stars
3118
$$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3125
var types = new List<FullNamedExpression> (2);
3126
types.Add ((FullNamedExpression) $1);
3129
| type_list COMMA base_type_name
3131
var types = (List<FullNamedExpression>) $1;
3132
types.Add ((FullNamedExpression) $3);
3133
lbag.AddLocation (types, GetLocation ($2));
3141
if ($1 is ComposedCast) {
3142
report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3149
* replaces all the productions for isolating the various
3150
* simple types, but we need this to reuse it easily in variable_type
3153
: OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3154
| STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3155
| BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3156
| DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3157
| FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3158
| DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3163
: SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3164
| BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3165
| SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3166
| USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3167
| INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3168
| UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3169
| LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3170
| ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3171
| CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3175
// Expressions, section 7.5
3180
: primary_expression_or_type
3182
| array_creation_expression
3183
| parenthesized_expression
3184
| default_value_expression
3185
| invocation_expression
3189
| post_increment_expression
3190
| post_decrement_expression
3191
| object_or_delegate_creation_expression
3192
| anonymous_type_expression
3195
| checked_expression
3196
| unchecked_expression
3197
| pointer_member_access
3198
| anonymous_method_expression
3199
| undocumented_expressions
3202
primary_expression_or_type
3203
: IDENTIFIER opt_type_argument_list
3205
var lt = (Tokenizer.LocatedToken) $1;
3206
$$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3208
| IDENTIFIER GENERATE_COMPLETION {
3209
var lt = (Tokenizer.LocatedToken) $1;
3210
$$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3218
| NULL { $$ = new NullLiteral (GetLocation ($1)); }
3222
: TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3223
| FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3228
// Here is the trick, tokenizer may think that parens is a special but
3229
// parser is interested in open parens only, so we merge them.
3230
// Consider: if (a)foo ();
3238
// Use this production to accept closing parenthesis or
3239
// performing completion
3243
| COMPLETE_COMPLETION
3247
parenthesized_expression
3248
: OPEN_PARENS expression CLOSE_PARENS
3250
$$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3251
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3253
| OPEN_PARENS expression COMPLETE_COMPLETION
3255
$$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3260
: primary_expression DOT identifier_inside_body opt_type_argument_list
3262
var lt = (Tokenizer.LocatedToken) $3;
3263
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location) {
3264
DotLocation = GetLocation ($2)
3267
| builtin_types DOT identifier_inside_body opt_type_argument_list
3269
var lt = (Tokenizer.LocatedToken) $3;
3270
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location) {
3271
DotLocation = GetLocation ($2)
3274
| BASE DOT identifier_inside_body opt_type_argument_list
3276
var lt = (Tokenizer.LocatedToken) $3;
3277
$$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location) {
3278
DotLocation = GetLocation ($2)
3281
| qualified_alias_member identifier_inside_body opt_type_argument_list
3283
var lt1 = (Tokenizer.LocatedToken) $1;
3284
var lt2 = (Tokenizer.LocatedToken) $2;
3286
$$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3287
lbag.AddLocation ($$, savedLocation, GetLocation ($2));
3289
| primary_expression DOT GENERATE_COMPLETION {
3290
$$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3292
| primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3293
var lt = (Tokenizer.LocatedToken) $3;
3294
$$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3296
| builtin_types DOT GENERATE_COMPLETION
3298
$$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3300
| builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3301
var lt = (Tokenizer.LocatedToken) $3;
3302
$$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3306
invocation_expression
3307
: primary_expression open_parens_any opt_argument_list close_parens
3309
$$ = new Invocation ((Expression) $1, (Arguments) $3);
3310
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3312
| primary_expression open_parens_any argument_list error
3314
Error_SyntaxError (yyToken);
3316
$$ = new Invocation ((Expression) $1, (Arguments) $3);
3317
lbag.AddLocation ($$, GetLocation ($2));
3319
| primary_expression open_parens_any error
3321
Error_SyntaxError (yyToken);
3323
$$ = new Invocation ((Expression) $1, null);
3324
lbag.AddLocation ($$, GetLocation ($2));
3328
opt_object_or_collection_initializer
3329
: /* empty */ { $$ = null; }
3330
| object_or_collection_initializer
3333
object_or_collection_initializer
3334
: OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3337
$$ = new CollectionOrObjectInitializers (GetLocation ($1));
3339
$$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3341
lbag.AddLocation ($$, GetLocation ($3));
3343
| OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3345
$$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3346
lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3350
opt_member_initializer_list
3351
: /* empty */ { $$ = null; }
3352
| member_initializer_list
3358
member_initializer_list
3359
: member_initializer
3361
var a = new List<Expression> ();
3362
a.Add ((Expression) $1);
3365
| member_initializer_list COMMA member_initializer
3367
var a = (List<Expression>)$1;
3368
a.Add ((Expression) $3);
3369
lbag.AddLocation (a, GetLocation ($2));
3372
| member_initializer_list error {
3373
Error_SyntaxError (yyToken);
3379
: IDENTIFIER ASSIGN initializer_value
3381
var lt = (Tokenizer.LocatedToken) $1;
3382
$$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3383
lbag.AddLocation ($$, GetLocation ($2));
3385
| AWAIT ASSIGN initializer_value
3387
var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
3388
$$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3389
lbag.AddLocation ($$, GetLocation ($2));
3391
| GENERATE_COMPLETION
3393
$$ = new CompletionElementInitializer (null, GetLocation ($1));
3395
| non_assignment_expression opt_COMPLETE_COMPLETION {
3396
CompletionSimpleName csn = $1 as CompletionSimpleName;
3398
$$ = new CollectionElementInitializer ((Expression)$1);
3400
$$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3402
| OPEN_BRACE expression_list CLOSE_BRACE
3407
$$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3408
lbag.AddLocation ($$, GetLocation ($2));
3411
| OPEN_BRACE CLOSE_BRACE
3413
report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3414
$$ = new CollectionElementInitializer (new List<Expression> (), GetLocation ($1));
3415
lbag.AddLocation ($$, GetLocation ($2));
3421
| object_or_collection_initializer
3425
: /* empty */ { $$ = null; }
3430
: argument_or_named_argument
3432
Arguments list = new Arguments (4);
3433
list.Add ((Argument) $1);
3436
| argument_list COMMA argument
3438
Arguments list = (Arguments) $1;
3439
if (list [list.Count - 1] is NamedArgument)
3440
Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3442
list.Add ((Argument) $3);
3443
lbag.AddLocation (list, GetLocation ($2));
3446
| argument_list COMMA named_argument
3448
Arguments list = (Arguments) $1;
3449
NamedArgument a = (NamedArgument) $3;
3450
for (int i = 0; i < list.Count; ++i) {
3451
NamedArgument na = list [i] as NamedArgument;
3452
if (na != null && na.Name == a.Name)
3453
report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3458
lbag.AddLocation (list, GetLocation ($2));
3461
| argument_list COMMA error
3463
if (lexer.putback_char == -1)
3464
lexer.putback (')'); // TODO: Wrong but what can I do
3465
Error_SyntaxError (yyToken);
3470
report.Error (839, GetLocation ($1), "An argument is missing");
3478
$$ = new Argument ((Expression) $1);
3480
| non_simple_argument
3483
argument_or_named_argument
3489
: REF variable_reference
3491
$$ = new Argument ((Expression) $2, Argument.AType.Ref);
3492
lbag.AddLocation ($$, GetLocation ($1));
3494
| OUT variable_reference
3496
$$ = new Argument ((Expression) $2, Argument.AType.Out);
3497
lbag.AddLocation ($$, GetLocation ($1));
3499
| ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3501
$$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3502
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3504
| ARGLIST OPEN_PARENS CLOSE_PARENS
3506
$$ = new Argument (new Arglist (GetLocation ($1)));
3507
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3516
: primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3518
$$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3519
lbag.AddLocation ($$, GetLocation ($4));
3521
| primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3523
Error_SyntaxError (yyToken);
3524
$$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3526
| primary_expression OPEN_BRACKET_EXPR error
3528
Error_SyntaxError (yyToken);
3529
$$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3534
: expression_or_error
3536
var list = new List<Expression> (4);
3537
list.Add ((Expression) $1);
3540
| expression_list COMMA expression_or_error
3542
var list = (List<Expression>) $1;
3543
list.Add ((Expression) $3);
3544
lbag.AddLocation (list, GetLocation ($2));
3549
expression_list_arguments
3550
: expression_list_argument
3552
Arguments args = new Arguments (4);
3553
args.Add ((Argument) $1);
3556
| expression_list_arguments COMMA expression_list_argument
3558
Arguments args = (Arguments) $1;
3559
if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3560
Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3562
args.Add ((Argument) $3);
3563
lbag.AddLocation (args, GetLocation ($2));
3568
expression_list_argument
3571
$$ = new Argument ((Expression) $1);
3579
$$ = new This (GetLocation ($1));
3584
: BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3586
$$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3587
lbag.AddLocation ($$, GetLocation ($4));
3589
| BASE OPEN_BRACKET error
3591
Error_SyntaxError (yyToken);
3592
$$ = new ElementAccess (null, null, GetLocation ($2));
3596
post_increment_expression
3597
: primary_expression OP_INC
3599
$$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3603
post_decrement_expression
3604
: primary_expression OP_DEC
3606
$$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3610
object_or_delegate_creation_expression
3611
: NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3614
if (lang_version <= LanguageVersion.ISO_2)
3615
FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3617
$$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3619
$$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3622
lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3624
| NEW new_expr_type object_or_collection_initializer
3626
if (lang_version <= LanguageVersion.ISO_2)
3627
FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3629
$$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3633
array_creation_expression
3634
: NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3636
opt_array_initializer
3638
$$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3639
new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3640
Next = (ComposedTypeSpecifier) $6
3641
}, (ArrayInitializer) $7, GetLocation ($1));
3642
lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3644
| NEW new_expr_type rank_specifiers opt_array_initializer
3647
report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3649
$$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3651
| NEW rank_specifier array_initializer
3653
if (lang_version <= LanguageVersion.ISO_2)
3654
FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3656
$$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3658
| NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3660
report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3661
$$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3663
| NEW new_expr_type error
3665
Error_SyntaxError (yyToken);
3666
// It can be any of new expression, create the most common one
3667
$$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3673
++lexer.parsing_type;
3677
--lexer.parsing_type;
3682
anonymous_type_expression
3683
: NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3685
if (lang_version <= LanguageVersion.ISO_2)
3686
FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3688
$$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3690
// TODO: lbag comma location
3691
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3695
anonymous_type_parameters_opt_comma
3696
: anonymous_type_parameters_opt
3697
| anonymous_type_parameters COMMA
3700
anonymous_type_parameters_opt
3702
| anonymous_type_parameters
3705
anonymous_type_parameters
3706
: anonymous_type_parameter
3708
var a = new List<AnonymousTypeParameter> (4);
3709
a.Add ((AnonymousTypeParameter) $1);
3712
| anonymous_type_parameters COMMA anonymous_type_parameter
3714
var a = (List<AnonymousTypeParameter>) $1;
3715
a.Add ((AnonymousTypeParameter) $3);
3716
lbag.AddLocation (a, GetLocation ($2));
3722
anonymous_type_parameter
3723
: identifier_inside_body ASSIGN variable_initializer
3725
var lt = (Tokenizer.LocatedToken)$1;
3726
$$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3727
lbag.AddLocation ($$, GetLocation ($2));
3729
| identifier_inside_body
3731
var lt = (Tokenizer.LocatedToken)$1;
3732
$$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3733
lt.Value, lt.Location);
3737
MemberAccess ma = (MemberAccess) $1;
3738
$$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3742
report.Error (746, lexer.Location,
3743
"Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3755
| rank_specifier rank_specifiers
3757
((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3763
: OPEN_BRACKET CLOSE_BRACKET
3765
$$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3766
lbag.AddLocation ($$, GetLocation ($2));
3768
| OPEN_BRACKET dim_separators CLOSE_BRACKET
3770
$$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3771
lbag.AddLocation ($$, GetLocation ($3));
3780
| dim_separators COMMA
3782
$$ = ((int) $1) + 1;
3786
opt_array_initializer
3798
: OPEN_BRACE CLOSE_BRACE
3800
var ai = new ArrayInitializer (0, GetLocation ($1));
3801
ai.VariableDeclaration = current_variable;
3802
lbag.AddLocation (ai, GetLocation ($2));
3805
| OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3807
var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3808
ai.VariableDeclaration = current_variable;
3810
lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3812
lbag.AddLocation (ai, GetLocation ($4));
3818
variable_initializer_list
3819
: variable_initializer
3821
var list = new List<Expression> (4);
3822
list.Add ((Expression) $1);
3825
| variable_initializer_list COMMA variable_initializer
3827
var list = (List<Expression>) $1;
3828
list.Add ((Expression) $3);
3829
lbag.AddLocation (list, GetLocation ($2));
3837
lexer.TypeOfParsing = true;
3839
open_parens_any typeof_type_expression CLOSE_PARENS
3841
lexer.TypeOfParsing = false;
3842
$$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3843
lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3847
typeof_type_expression
3852
Error_TypeExpected (lexer.Location);
3858
: identifier_inside_body generic_dimension
3860
var lt = (Tokenizer.LocatedToken) $1;
3861
var sn = new SimpleName (lt.Value, (int) $2, lt.Location);
3863
lbag.AddLocation (sn.TypeArguments, Lexer.GetGenericDimensionLocations ());
3865
| qualified_alias_member identifier_inside_body generic_dimension
3867
var lt1 = (Tokenizer.LocatedToken) $1;
3868
var lt2 = (Tokenizer.LocatedToken) $2;
3869
var qam = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3871
lbag.AddLocation (qam.TypeArguments, Lexer.GetGenericDimensionLocations ());
3872
lbag.AddLocation ($$, savedLocation, GetLocation ($2));
3874
| unbound_type_name DOT identifier_inside_body
3876
var lt = (Tokenizer.LocatedToken) $3;
3878
$$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location) {
3879
DotLocation = GetLocation ($2)
3882
| unbound_type_name DOT identifier_inside_body generic_dimension
3884
var lt = (Tokenizer.LocatedToken) $3;
3886
var ma = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location) {
3887
DotLocation = GetLocation ($2)
3890
lbag.AddLocation (ma.TypeArguments, Lexer.GetGenericDimensionLocations ());
3892
| namespace_or_type_expr DOT identifier_inside_body generic_dimension
3894
var tne = (ATypeNameExpression) $1;
3895
if (tne.HasTypeArguments)
3896
Error_TypeExpected (GetLocation ($4));
3898
var lt = (Tokenizer.LocatedToken) $3;
3899
var ma = new MemberAccess (tne, lt.Value, (int) $4, lt.Location) {
3900
DotLocation = GetLocation ($2)
3903
lbag.AddLocation (ma.TypeArguments, Lexer.GetGenericDimensionLocations ());
3910
if (lang_version < LanguageVersion.ISO_2)
3911
FeatureIsNotAvailable (GetLocation ($1), "generics");
3917
qualified_alias_member
3918
: IDENTIFIER DOUBLE_COLON
3920
var lt = (Tokenizer.LocatedToken) $1;
3921
if (lang_version == LanguageVersion.ISO_1)
3922
FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3923
savedLocation = GetLocation ($2);
3929
: SIZEOF open_parens_any type CLOSE_PARENS
3931
$$ = new SizeOf ((Expression) $3, GetLocation ($1));
3932
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3934
| SIZEOF open_parens_any type error
3936
Error_SyntaxError (yyToken);
3938
$$ = new SizeOf ((Expression) $3, GetLocation ($1));
3939
lbag.AddLocation ($$, GetLocation ($2));
3944
: CHECKED open_parens_any expression CLOSE_PARENS
3946
$$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3947
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3951
Error_SyntaxError (yyToken);
3953
$$ = new CheckedExpr (null, GetLocation ($1));
3957
unchecked_expression
3958
: UNCHECKED open_parens_any expression CLOSE_PARENS
3960
$$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3961
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3965
Error_SyntaxError (yyToken);
3967
$$ = new UnCheckedExpr (null, GetLocation ($1));
3971
pointer_member_access
3972
: primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3974
var lt = (Tokenizer.LocatedToken) $3;
3975
$$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3979
anonymous_method_expression
3980
: DELEGATE opt_anonymous_method_signature
3982
start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3986
$$ = end_anonymous ((ParametersBlock) $4);
3987
if ((ParametersCompiled) $2 != ParametersCompiled.Undefined) {
3988
lbag.AddLocation ($$, GetLocation ($1), savedOpenLocation, savedCloseLocation);
3990
lbag.AddLocation ($$, GetLocation ($1));
3993
| ASYNC DELEGATE opt_anonymous_method_signature
3995
start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3999
$$ = end_anonymous ((ParametersBlock) $5);
4001
if ((ParametersCompiled) $3 != ParametersCompiled.Undefined) {
4002
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), savedOpenLocation, savedCloseLocation);
4004
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2));
4009
opt_anonymous_method_signature
4012
$$ = ParametersCompiled.Undefined;
4014
| anonymous_method_signature
4017
anonymous_method_signature
4020
valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4022
opt_formal_parameter_list CLOSE_PARENS
4024
valid_param_mod = 0;
4026
savedOpenLocation = GetLocation ($1);
4027
savedCloseLocation = GetLocation ($2);
4031
default_value_expression
4032
: DEFAULT open_parens_any type CLOSE_PARENS
4034
if (lang_version < LanguageVersion.ISO_2)
4035
FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4037
$$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4038
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4043
: primary_expression
4044
| BANG prefixed_unary_expression
4046
$$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4048
| TILDE prefixed_unary_expression
4050
$$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4052
| OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4054
$$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4055
lbag.AddLocation ($$, GetLocation ($3));
4057
| AWAIT prefixed_unary_expression
4060
if (current_anonymous_method is LambdaExpression) {
4061
report.Error (4034, GetLocation ($1),
4062
"The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4063
} else if (current_anonymous_method is AnonymousMethodExpression) {
4064
report.Error (4035, GetLocation ($1),
4065
"The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4067
report.Error (4033, GetLocation ($1),
4068
"The `await' operator can only be used when its containing method is marked with the `async' modifier");
4071
current_block.Explicit.RegisterAsyncAwait ();
4074
$$ = new Await ((Expression) $2, GetLocation ($1));
4078
Error_SyntaxError (yyToken);
4080
$$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4084
Error_SyntaxError (yyToken);
4086
$$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4088
| OPEN_PARENS_CAST type CLOSE_PARENS error
4090
Error_SyntaxError (yyToken);
4092
$$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4093
lbag.AddLocation ($$, GetLocation ($3));
4097
Error_SyntaxError (yyToken);
4099
$$ = new Await (null, GetLocation ($1));
4104
// The idea to split this out is from Rhys' grammar
4105
// to solve the problem with casts.
4107
prefixed_unary_expression
4109
| PLUS prefixed_unary_expression
4111
$$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4113
| MINUS prefixed_unary_expression
4115
$$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4117
| OP_INC prefixed_unary_expression
4119
$$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4121
| OP_DEC prefixed_unary_expression
4123
$$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4125
| STAR prefixed_unary_expression
4127
$$ = new Indirection ((Expression) $2, GetLocation ($1));
4129
| BITWISE_AND prefixed_unary_expression
4131
$$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4135
Error_SyntaxError (yyToken);
4137
$$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4141
Error_SyntaxError (yyToken);
4143
$$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4147
Error_SyntaxError (yyToken);
4149
$$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4153
Error_SyntaxError (yyToken);
4155
$$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4159
Error_SyntaxError (yyToken);
4161
$$ = new Indirection (null, GetLocation ($1));
4165
Error_SyntaxError (yyToken);
4167
$$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4171
multiplicative_expression
4172
: prefixed_unary_expression
4173
| multiplicative_expression STAR prefixed_unary_expression
4175
$$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4176
lbag.AddLocation ($$, GetLocation ($2));
4178
| multiplicative_expression DIV prefixed_unary_expression
4180
$$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4181
lbag.AddLocation ($$, GetLocation ($2));
4183
| multiplicative_expression PERCENT prefixed_unary_expression
4185
$$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4186
lbag.AddLocation ($$, GetLocation ($2));
4188
| multiplicative_expression STAR error
4190
Error_SyntaxError (yyToken);
4192
$$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4193
lbag.AddLocation ($$, GetLocation ($2));
4195
| multiplicative_expression DIV error
4197
Error_SyntaxError (yyToken);
4199
$$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4200
lbag.AddLocation ($$, GetLocation ($2));
4202
| multiplicative_expression PERCENT error
4204
Error_SyntaxError (yyToken);
4206
$$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4207
lbag.AddLocation ($$, GetLocation ($2));
4212
: multiplicative_expression
4213
| additive_expression PLUS multiplicative_expression
4215
$$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4216
lbag.AddLocation ($$, GetLocation ($2));
4218
| additive_expression MINUS multiplicative_expression
4220
$$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4221
lbag.AddLocation ($$, GetLocation ($2));
4223
| additive_expression AS type
4225
$$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4227
| additive_expression IS type
4229
$$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4231
| additive_expression PLUS error
4233
Error_SyntaxError (yyToken);
4235
$$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4236
lbag.AddLocation ($$, GetLocation ($2));
4238
| additive_expression MINUS error
4240
Error_SyntaxError (yyToken);
4242
$$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4243
lbag.AddLocation ($$, GetLocation ($2));
4245
| additive_expression AS error
4247
Error_SyntaxError (yyToken);
4249
$$ = new As ((Expression) $1, null, GetLocation ($2));
4251
| additive_expression IS error
4253
Error_SyntaxError (yyToken);
4255
$$ = new Is ((Expression) $1, null, GetLocation ($2));
4260
: additive_expression
4261
| shift_expression OP_SHIFT_LEFT additive_expression
4263
$$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4264
lbag.AddLocation ($$, GetLocation ($2));
4266
| shift_expression OP_SHIFT_RIGHT additive_expression
4268
$$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4269
lbag.AddLocation ($$, GetLocation ($2));
4271
| shift_expression OP_SHIFT_LEFT error
4273
Error_SyntaxError (yyToken);
4275
$$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4276
lbag.AddLocation ($$, GetLocation ($2));
4278
| shift_expression OP_SHIFT_RIGHT error
4280
Error_SyntaxError (yyToken);
4282
$$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4283
lbag.AddLocation ($$, GetLocation ($2));
4287
relational_expression
4289
| relational_expression OP_LT shift_expression
4291
$$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4292
lbag.AddLocation ($$, GetLocation ($2));
4294
| relational_expression OP_GT shift_expression
4296
$$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4297
lbag.AddLocation ($$, GetLocation ($2));
4299
| relational_expression OP_LE shift_expression
4301
$$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4302
lbag.AddLocation ($$, GetLocation ($2));
4304
| relational_expression OP_GE shift_expression
4306
$$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4307
lbag.AddLocation ($$, GetLocation ($2));
4309
| relational_expression OP_LT error
4311
Error_SyntaxError (yyToken);
4313
$$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4314
lbag.AddLocation ($$, GetLocation ($2));
4316
| relational_expression OP_GT error
4318
Error_SyntaxError (yyToken);
4320
$$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4321
lbag.AddLocation ($$, GetLocation ($2));
4323
| relational_expression OP_LE error
4325
Error_SyntaxError (yyToken);
4327
$$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4328
lbag.AddLocation ($$, GetLocation ($2));
4330
| relational_expression OP_GE error
4332
Error_SyntaxError (yyToken);
4334
$$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4335
lbag.AddLocation ($$, GetLocation ($2));
4340
: relational_expression
4341
| equality_expression OP_EQ relational_expression
4343
$$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4344
lbag.AddLocation ($$, GetLocation ($2));
4346
| equality_expression OP_NE relational_expression
4348
$$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4349
lbag.AddLocation ($$, GetLocation ($2));
4351
| equality_expression OP_EQ error
4353
Error_SyntaxError (yyToken);
4355
$$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4356
lbag.AddLocation ($$, GetLocation ($2));
4358
| equality_expression OP_NE error
4360
Error_SyntaxError (yyToken);
4362
$$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4363
lbag.AddLocation ($$, GetLocation ($2));
4368
: equality_expression
4369
| and_expression BITWISE_AND equality_expression
4371
$$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4372
lbag.AddLocation ($$, GetLocation ($2));
4374
| and_expression BITWISE_AND error
4376
Error_SyntaxError (yyToken);
4378
$$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4379
lbag.AddLocation ($$, GetLocation ($2));
4383
exclusive_or_expression
4385
| exclusive_or_expression CARRET and_expression
4387
$$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4388
lbag.AddLocation ($$, GetLocation ($2));
4390
| exclusive_or_expression CARRET error
4392
Error_SyntaxError (yyToken);
4394
$$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4395
lbag.AddLocation ($$, GetLocation ($2));
4399
inclusive_or_expression
4400
: exclusive_or_expression
4401
| inclusive_or_expression BITWISE_OR exclusive_or_expression
4403
$$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4404
lbag.AddLocation ($$, GetLocation ($2));
4406
| inclusive_or_expression BITWISE_OR error
4408
Error_SyntaxError (yyToken);
4410
$$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4411
lbag.AddLocation ($$, GetLocation ($2));
4415
conditional_and_expression
4416
: inclusive_or_expression
4417
| conditional_and_expression OP_AND inclusive_or_expression
4419
$$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4420
lbag.AddLocation ($$, GetLocation ($2));
4422
| conditional_and_expression OP_AND error
4424
Error_SyntaxError (yyToken);
4426
$$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4427
lbag.AddLocation ($$, GetLocation ($2));
4431
conditional_or_expression
4432
: conditional_and_expression
4433
| conditional_or_expression OP_OR conditional_and_expression
4435
$$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4436
lbag.AddLocation ($$, GetLocation ($2));
4438
| conditional_or_expression OP_OR error
4440
Error_SyntaxError (yyToken);
4442
$$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4443
lbag.AddLocation ($$, GetLocation ($2));
4447
null_coalescing_expression
4448
: conditional_or_expression
4449
| conditional_or_expression OP_COALESCING null_coalescing_expression
4451
if (lang_version < LanguageVersion.ISO_2)
4452
FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4454
$$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4455
lbag.AddLocation ($$, GetLocation ($2));
4459
conditional_expression
4460
: null_coalescing_expression
4461
| null_coalescing_expression INTERR expression COLON expression
4463
$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4464
lbag.AddLocation ($$, GetLocation ($4));
4466
| null_coalescing_expression INTERR expression error
4468
Error_SyntaxError (yyToken);
4470
$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4472
| null_coalescing_expression INTERR expression COLON error
4474
Error_SyntaxError (yyToken);
4476
$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4477
lbag.AddLocation ($$, GetLocation ($4));
4479
| null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4481
Error_SyntaxError (Token.CLOSE_BRACE);
4483
$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4484
lbag.AddLocation ($$, GetLocation ($4));
4485
lexer.putback ('}');
4489
assignment_expression
4490
: prefixed_unary_expression ASSIGN expression
4492
$$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4493
lbag.AddLocation ($$, GetLocation ($2));
4495
| prefixed_unary_expression OP_MULT_ASSIGN expression
4497
$$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4498
lbag.AddLocation ($$, GetLocation ($2));
4500
| prefixed_unary_expression OP_DIV_ASSIGN expression
4502
$$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4503
lbag.AddLocation ($$, GetLocation ($2));
4505
| prefixed_unary_expression OP_MOD_ASSIGN expression
4507
$$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4508
lbag.AddLocation ($$, GetLocation ($2));
4510
| prefixed_unary_expression OP_ADD_ASSIGN expression
4512
$$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4513
lbag.AddLocation ($$, GetLocation ($2));
4515
| prefixed_unary_expression OP_SUB_ASSIGN expression
4517
$$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4518
lbag.AddLocation ($$, GetLocation ($2));
4520
| prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4522
$$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4523
lbag.AddLocation ($$, GetLocation ($2));
4525
| prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4527
$$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4528
lbag.AddLocation ($$, GetLocation ($2));
4530
| prefixed_unary_expression OP_AND_ASSIGN expression
4532
$$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4533
lbag.AddLocation ($$, GetLocation ($2));
4535
| prefixed_unary_expression OP_OR_ASSIGN expression
4537
$$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4538
lbag.AddLocation ($$, GetLocation ($2));
4540
| prefixed_unary_expression OP_XOR_ASSIGN expression
4542
$$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4543
lbag.AddLocation ($$, GetLocation ($2));
4547
lambda_parameter_list
4550
var pars = new List<Parameter> (4);
4551
pars.Add ((Parameter) $1);
4552
parameterListCommas.Clear ();
4555
| lambda_parameter_list COMMA lambda_parameter
4557
var pars = (List<Parameter>) $1;
4558
Parameter p = (Parameter)$3;
4559
if (pars[0].GetType () != p.GetType ()) {
4560
report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4564
parameterListCommas.Add (GetLocation ($2));
4571
: parameter_modifier parameter_type identifier_inside_body
4573
var lt = (Tokenizer.LocatedToken) $3;
4575
$$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4577
| parameter_type identifier_inside_body
4579
var lt = (Tokenizer.LocatedToken) $2;
4581
$$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4585
var lt = (Tokenizer.LocatedToken) $1;
4586
$$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4590
var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
4591
$$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4595
opt_lambda_parameter_list
4596
: /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4597
| lambda_parameter_list {
4598
var pars_list = (List<Parameter>) $1;
4599
$$ = new ParametersCompiled (pars_list.ToArray ());
4600
lbag.AddLocation ($$, parameterListCommas);
4604
lambda_expression_body
4606
start_block (Location.Null);
4608
expression // All expressions must handle error or current block won't be restored and breaking ast completely
4610
Block b = end_block (Location.Null);
4611
b.IsCompilerGenerated = true;
4612
b.AddStatement (new ContextualReturn ((Expression) $2));
4618
// Handles only cases like foo = x.FirstOrDefault (l => );
4619
// where we must restore current_variable
4620
Block b = end_block (Location.Null);
4621
b.IsCompilerGenerated = true;
4623
Error_SyntaxError (yyToken);
4632
Error_SyntaxError (yyToken);
4640
var lt = (Tokenizer.LocatedToken) $1;
4641
Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4642
start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4644
lambda_expression_body
4646
$$ = end_anonymous ((ParametersBlock) $4);
4647
lbag.AddLocation ($$, GetLocation ($2));
4651
var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
4652
Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4653
start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4655
lambda_expression_body
4657
$$ = end_anonymous ((ParametersBlock) $4);
4658
lbag.AddLocation ($$, GetLocation ($2));
4660
| ASYNC identifier_inside_body ARROW
4662
var lt = (Tokenizer.LocatedToken) $2;
4663
Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4664
start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4666
lambda_expression_body
4668
$$ = end_anonymous ((ParametersBlock) $5);
4669
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4671
| OPEN_PARENS_LAMBDA
4673
valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4675
opt_lambda_parameter_list CLOSE_PARENS ARROW
4677
valid_param_mod = 0;
4678
start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4680
lambda_expression_body
4682
$$ = end_anonymous ((ParametersBlock) $7);
4683
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4685
| ASYNC OPEN_PARENS_LAMBDA
4687
valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4689
opt_lambda_parameter_list CLOSE_PARENS ARROW
4691
valid_param_mod = 0;
4692
start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4694
lambda_expression_body
4696
$$ = end_anonymous ((ParametersBlock) $8);
4697
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4702
: assignment_expression
4703
| non_assignment_expression
4706
non_assignment_expression
4707
: conditional_expression
4712
$$ = new ArglistAccess (GetLocation ($1));
4716
undocumented_expressions
4717
: REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4719
$$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4720
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4722
| REFTYPE open_parens_any expression CLOSE_PARENS
4724
$$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4725
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4727
| MAKEREF open_parens_any expression CLOSE_PARENS
4729
$$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4730
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4741
$$ = new BooleanExpression ((Expression) $1);
4755
type_declaration_name
4757
lexer.ConstraintsParsing = true;
4759
Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4760
if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4761
FeatureIsNotAvailable (c.Location, "static classes");
4764
push_current_container (c, $3);
4765
lbag.AddMember (current_container, GetModifierLocations (), GetLocation ($4));
4768
opt_type_parameter_constraints_clauses
4770
lexer.ConstraintsParsing = false;
4773
current_container.SetConstraints ((List<Constraints>) $9);
4776
current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4777
Lexer.doc_state = XmlCommentState.Allowed;
4780
lexer.parsing_modifiers = true;
4782
OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4784
--lexer.parsing_declaration;
4786
Lexer.doc_state = XmlCommentState.Allowed;
4791
lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4793
lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4795
$$ = pop_current_class ();
4803
{ $$ = $1; StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($1)); } // location
4809
mod_locations = null;
4811
lexer.parsing_modifiers = false;
4815
lexer.parsing_modifiers = false;
4821
| modifiers modifier
4823
var m1 = (Modifiers) $1;
4824
var m2 = (Modifiers) $2;
4826
if ((m1 & m2) != 0) {
4827
report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4828
"Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4829
} else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4830
((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4831
report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4832
"More than one protection modifier specified");
4843
StoreModifierLocation ($$, GetLocation ($1));
4845
if (current_container.Kind == MemberKind.Namespace)
4846
report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4850
$$ = Modifiers.PUBLIC;
4851
StoreModifierLocation ($$, GetLocation ($1));
4855
$$ = Modifiers.PROTECTED;
4856
StoreModifierLocation ($$, GetLocation ($1));
4860
$$ = Modifiers.INTERNAL;
4861
StoreModifierLocation ($$, GetLocation ($1));
4865
$$ = Modifiers.PRIVATE;
4866
StoreModifierLocation ($$, GetLocation ($1));
4870
$$ = Modifiers.ABSTRACT;
4871
StoreModifierLocation ($$, GetLocation ($1));
4875
$$ = Modifiers.SEALED;
4876
StoreModifierLocation ($$, GetLocation ($1));
4880
$$ = Modifiers.STATIC;
4881
StoreModifierLocation ($$, GetLocation ($1));
4885
$$ = Modifiers.READONLY;
4886
StoreModifierLocation ($$, GetLocation ($1));
4890
$$ = Modifiers.VIRTUAL;
4891
StoreModifierLocation ($$, GetLocation ($1));
4895
$$ = Modifiers.OVERRIDE;
4896
StoreModifierLocation ($$, GetLocation ($1));
4900
$$ = Modifiers.EXTERN;
4901
StoreModifierLocation ($$, GetLocation ($1));
4905
$$ = Modifiers.VOLATILE;
4906
StoreModifierLocation ($$, GetLocation ($1));
4910
$$ = Modifiers.UNSAFE;
4911
StoreModifierLocation ($$, GetLocation ($1));
4912
if (!settings.Unsafe)
4913
Error_UnsafeCodeNotAllowed (GetLocation ($1));
4917
$$ = Modifiers.ASYNC;
4918
StoreModifierLocation ($$, GetLocation ($1));
4926
current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4927
lbag.AppendToMember (current_type, GetLocation ($1));
4929
| COLON type_list error
4931
Error_SyntaxError (yyToken);
4933
current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4937
opt_type_parameter_constraints_clauses
4939
| type_parameter_constraints_clauses
4945
type_parameter_constraints_clauses
4946
: type_parameter_constraints_clause
4948
var constraints = new List<Constraints> (1);
4949
constraints.Add ((Constraints) $1);
4952
| type_parameter_constraints_clauses type_parameter_constraints_clause
4954
var constraints = (List<Constraints>) $1;
4955
Constraints new_constraint = (Constraints)$2;
4957
foreach (Constraints c in constraints) {
4958
if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4959
report.Error (409, new_constraint.Location,
4960
"A constraint clause has already been specified for type parameter `{0}'",
4961
new_constraint.TypeParameter.Value);
4965
constraints.Add (new_constraint);
4970
type_parameter_constraints_clause
4971
: WHERE IDENTIFIER COLON type_parameter_constraints
4973
var lt = (Tokenizer.LocatedToken) $2;
4974
$$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4975
lbag.AddLocation ($$, GetLocation ($3));
4977
| WHERE IDENTIFIER error
4979
Error_SyntaxError (yyToken);
4981
var lt = (Tokenizer.LocatedToken) $2;
4982
$$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4986
type_parameter_constraints
4987
: type_parameter_constraint
4989
var constraints = new List<FullNamedExpression> (1);
4990
constraints.Add ((FullNamedExpression) $1);
4993
| type_parameter_constraints COMMA type_parameter_constraint
4995
var constraints = (List<FullNamedExpression>) $1;
4996
var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4997
if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4998
report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5001
prev = $3 as SpecialContraintExpr;
5003
if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5004
report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5006
prev = constraints [0] as SpecialContraintExpr;
5007
if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5008
report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5013
constraints.Add ((FullNamedExpression) $3);
5014
lbag.AddLocation (constraints, GetLocation ($2));
5019
type_parameter_constraint
5022
if ($1 is ComposedCast)
5023
report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5027
| NEW OPEN_PARENS CLOSE_PARENS
5029
$$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5030
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5034
$$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5038
$$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5042
opt_type_parameter_variance
5047
| type_parameter_variance
5049
if (lang_version <= LanguageVersion.V_3)
5050
FeatureIsNotAvailable (lexer.Location, "generic type variance");
5056
type_parameter_variance
5059
$$ = Variance.Covariant;
5060
savedLocation = GetLocation ($1);
5064
$$ = Variance.Contravariant;
5065
savedLocation = GetLocation ($1);
5074
// A block is "contained" on the following places:
5076
// property_declaration as part of the accessor body (get/set)
5077
// operator_declaration
5078
// constructor_declaration
5079
// destructor_declaration
5080
// event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5085
++lexer.parsing_block;
5086
start_block (GetLocation ($1));
5088
opt_statement_list block_end
5097
--lexer.parsing_block;
5098
$$ = end_block (GetLocation ($1));
5100
| COMPLETE_COMPLETION
5102
--lexer.parsing_block;
5103
$$ = end_block (lexer.Location);
5111
++lexer.parsing_block;
5112
current_block.StartLocation = GetLocation ($1);
5114
opt_statement_list CLOSE_BRACE
5116
--lexer.parsing_block;
5117
$$ = end_block (GetLocation ($4));
5120
report.Error (1525, GetLocation ($1), "Unexpected symbol '}', expected '{'");
5121
lexer.putback ('}');
5122
$$ = end_block (GetLocation ($1));
5126
block_prepared_strict
5129
++lexer.parsing_block;
5130
current_block.StartLocation = GetLocation ($1);
5132
opt_statement_list CLOSE_BRACE
5134
--lexer.parsing_block;
5135
$$ = end_block (GetLocation ($4));
5146
| statement_list statement
5150
: block_variable_declaration
5152
current_block.AddStatement ((Statement) $1);
5154
| valid_declaration_statement
5156
current_block.AddStatement ((Statement) $1);
5159
// WORKAROUND:Remove that rule, if it is >really< fixed.
5162
Error_SyntaxError (yyToken);
5163
var lt =(Tokenizer.LocatedToken) $1;
5164
var sn = new SimpleName (lt.Value, lt.Location);
5165
current_block.AddStatement(new StatementErrorExpression (sn));
5171
Error_SyntaxError (yyToken);
5177
// The interactive_statement and its derivatives are only
5178
// used to provide a special version of `expression_statement'
5179
// that has a side effect of assigning the expression to
5182
interactive_statement_list
5183
: interactive_statement
5184
| interactive_statement_list interactive_statement
5187
interactive_statement
5188
: block_variable_declaration
5190
current_block.AddStatement ((Statement) $1);
5192
| interactive_valid_declaration_statement
5194
current_block.AddStatement ((Statement) $1);
5199
valid_declaration_statement
5202
| expression_statement
5203
| selection_statement
5204
| iteration_statement
5208
| unchecked_statement
5215
interactive_valid_declaration_statement
5218
| interactive_expression_statement
5219
| selection_statement
5220
| iteration_statement
5224
| unchecked_statement
5232
: valid_declaration_statement
5233
| block_variable_declaration
5235
report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5240
report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5245
Error_SyntaxError (yyToken);
5246
$$ = new EmptyStatement (GetLocation ($1));
5253
// Uses lexer.Location because semicolon location is not kept in quick mode
5254
$$ = new EmptyStatement (lexer.Location);
5259
: identifier_inside_body COLON
5261
var lt = (Tokenizer.LocatedToken) $1;
5262
LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5263
lbag.AddLocation (labeled, GetLocation ($2));
5264
current_block.AddLabel (labeled);
5265
current_block.AddStatement (labeled);
5271
: variable_type_simple
5272
| variable_type_simple rank_specifiers
5275
$1 = new SimpleName ("var", ((VarExpr) $1).Location);
5277
$$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5282
* The following is from Rhys' grammar:
5283
* > Types in local variable declarations must be recognized as
5284
* > expressions to prevent reduce/reduce errors in the grammar.
5285
* > The expressions are converted into types during semantic analysis.
5287
variable_type_simple
5288
: primary_expression_or_type opt_nullable
5290
// Ok, the above "primary_expression" is there to get rid of
5291
// both reduce/reduce and shift/reduces in the grammar, it should
5292
// really just be "type_name". If you use type_name, a reduce/reduce
5293
// creeps up. If you use namespace_or_type_name (which is all we need
5294
// really) two shift/reduces appear.
5297
// So the super-trick is that primary_expression
5298
// can only be either a SimpleName or a MemberAccess.
5299
// The MemberAccess case arises when you have a fully qualified type-name like :
5301
// SimpleName is when you have
5304
Expression expr = (Expression) $1;
5306
SimpleName sn = expr as SimpleName;
5307
if (sn != null && sn.Name == "var")
5308
$$ = new VarExpr (sn.Location);
5311
} else if (expr is ATypeNameExpression) {
5312
$$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5314
Error_ExpectingTypeName (expr);
5318
| primary_expression_or_type pointer_stars
5320
ATypeNameExpression expr = $1 as ATypeNameExpression;
5323
$$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5325
Error_ExpectingTypeName ((Expression)$1);
5329
| builtin_types opt_nullable
5334
$$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5336
| builtin_types pointer_stars
5338
$$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5340
| VOID pointer_stars
5342
$$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5346
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5347
$$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5353
| pointer_star pointer_stars
5355
((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5363
$$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5367
identifier_inside_body
5371
$$ = Error_AwaitAsIdentifier ($1);
5375
block_variable_declaration
5376
: variable_type identifier_inside_body
5378
var lt = (Tokenizer.LocatedToken) $2;
5379
var li = new LocalVariable (current_block, lt.Value, lt.Location);
5380
current_block.AddLocalName (li);
5381
current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5383
opt_local_variable_initializer opt_variable_declarators semicolon_or_handle_error_close_brace
5385
$$ = current_variable;
5386
current_variable = null;
5388
lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5390
lbag.AddLocation ($$, GetLocation ($6));
5392
| CONST variable_type identifier_inside_body
5394
var lt = (Tokenizer.LocatedToken) $3;
5395
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5396
current_block.AddLocalName (li);
5397
current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
5399
const_variable_initializer opt_const_declarators SEMICOLON
5401
if (current_variable.Initializer != null) {
5402
lbag.AddLocation (current_variable, GetLocation ($1), savedLocation, GetLocation ($7));
5404
lbag.AddLocation (current_variable, GetLocation ($1), GetLocation ($7));
5406
$$ = current_variable;;
5407
current_variable = null;
5411
semicolon_or_handle_error_close_brace
5414
// Redundant, but wont regress
5415
report.Error (1525, lexer.Location, "Unexpected symbol }");
5416
lexer.putback ('}');
5421
opt_local_variable_initializer
5423
| ASSIGN block_variable_initializer
5425
current_variable.Initializer = (Expression) $2;
5426
PushLocation (GetLocation ($1));
5427
$$ = current_variable;
5431
if (yyToken == Token.OPEN_BRACKET_EXPR) {
5432
report.Error (650, lexer.Location,
5433
"Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type");
5435
Error_SyntaxError (yyToken);
5440
opt_variable_declarators
5442
| variable_declarators
5445
opt_using_or_fixed_variable_declarators
5447
| variable_declarators
5449
foreach (var d in current_variable.Declarators) {
5450
if (d.Initializer == null)
5451
Error_MissingInitializer (d.Variable.Location);
5456
variable_declarators
5457
: variable_declarator
5458
| variable_declarators variable_declarator
5462
: COMMA identifier_inside_body
5464
var lt = (Tokenizer.LocatedToken) $2;
5465
var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5466
var d = new BlockVariableDeclaration.Declarator (li, null);
5467
current_variable.AddDeclarator (d);
5468
current_block.AddLocalName (li);
5469
lbag.AddLocation (d, GetLocation ($1));
5471
| COMMA identifier_inside_body ASSIGN block_variable_initializer
5473
var lt = (Tokenizer.LocatedToken) $2;
5474
var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5475
var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5476
current_variable.AddDeclarator (d);
5477
current_block.AddLocalName (li);
5478
lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5482
const_variable_initializer
5485
report.Error (145, lexer.Location, "A const field requires a value to be provided");
5487
| ASSIGN constant_initializer_expr
5489
savedLocation = GetLocation ($1);
5490
current_variable.Initializer = (Expression) $2;
5494
opt_const_declarators
5501
| const_declarators const_declarator
5505
: COMMA identifier_inside_body ASSIGN constant_initializer_expr
5507
var lt = (Tokenizer.LocatedToken) $2;
5508
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5509
var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5510
current_variable.AddDeclarator (d);
5511
current_block.AddLocalName (li);
5512
lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5516
block_variable_initializer
5517
: variable_initializer
5518
| STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5520
$$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5521
lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5523
| STACKALLOC simple_type
5525
report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5526
$$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5530
expression_statement
5531
: statement_expression SEMICOLON
5534
lbag.AddStatement ($$, GetLocation ($2));
5536
| statement_expression COMPLETE_COMPLETION { $$ = $1; }
5537
| statement_expression CLOSE_BRACE
5540
report.Error (1002, GetLocation ($2), "; expected");
5541
lexer.putback ('}');
5545
interactive_expression_statement
5546
: interactive_statement_expression SEMICOLON { $$ = $1; }
5547
| interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5551
// We have to do the wrapping here and not in the case above,
5552
// because statement_expression is used for example in for_statement
5554
statement_expression
5557
ExpressionStatement s = $1 as ExpressionStatement;
5559
var expr = $1 as Expression;
5560
expr.Error_InvalidExpressionStatement (report);
5561
$$ = new StatementErrorExpression (expr);
5563
$$ = new StatementExpression (s);
5568
interactive_statement_expression
5571
Expression expr = (Expression) $1;
5572
ExpressionStatement s;
5574
s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
5575
$$ = new StatementExpression (s);
5579
Error_SyntaxError (yyToken);
5580
$$ = new EmptyStatement (GetLocation ($1));
5590
: IF open_parens_any boolean_expression CLOSE_PARENS
5593
if ($5 is EmptyStatement)
5594
Warning_EmptyStatement (GetLocation ($5));
5596
$$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5597
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5599
| IF open_parens_any boolean_expression CLOSE_PARENS
5600
embedded_statement ELSE embedded_statement
5602
$$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5603
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5605
if ($5 is EmptyStatement)
5606
Warning_EmptyStatement (GetLocation ($5));
5607
if ($7 is EmptyStatement)
5608
Warning_EmptyStatement (GetLocation ($7));
5610
| IF open_parens_any boolean_expression error
5612
Error_SyntaxError (yyToken);
5614
$$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5615
lbag.AddStatement ($$, GetLocation ($2));
5620
: SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5622
start_block (GetLocation ($5));
5624
opt_switch_sections CLOSE_BRACE
5626
$$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5627
end_block (GetLocation ($8));
5628
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($5), GetLocation ($8));
5630
| SWITCH open_parens_any expression error
5632
Error_SyntaxError (yyToken);
5634
$$ = new Switch ((Expression) $3, null, GetLocation ($1));
5635
lbag.AddStatement ($$, GetLocation ($2));
5642
report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5649
| switch_sections switch_section
5652
Error_SyntaxError (yyToken);
5657
: switch_labels statement_list
5663
var label = (SwitchLabel) $1;
5664
label.SectionStart = true;
5665
current_block.AddStatement (label);
5667
| switch_labels switch_label
5669
current_block.AddStatement ((Statement) $2);
5674
: CASE constant_expression COLON
5676
$$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5677
lbag.AddLocation ($$, GetLocation ($3));
5679
| CASE constant_expression error
5681
Error_SyntaxError (yyToken);
5682
$$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5686
$$ = new SwitchLabel (null, GetLocation ($1));
5698
: WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5700
if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5701
Warning_EmptyStatement (GetLocation ($5));
5703
$$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5704
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5706
| WHILE open_parens_any boolean_expression error
5708
Error_SyntaxError (yyToken);
5710
$$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5711
lbag.AddStatement ($$, GetLocation ($2));
5716
: DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5718
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5719
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5721
| DO embedded_statement error
5723
Error_SyntaxError (yyToken);
5724
$$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5726
| DO embedded_statement WHILE open_parens_any boolean_expression error
5728
Error_SyntaxError (yyToken);
5730
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5731
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5736
: FOR open_parens_any
5738
start_block (GetLocation ($2));
5739
current_block.IsCompilerGenerated = true;
5740
For f = new For (GetLocation ($1));
5741
current_block.AddStatement (f);
5742
lbag.AddStatement (f, current_block.StartLocation);
5751
// Has to use be extra rule to recover started block
5753
: opt_for_initializer SEMICOLON
5756
f.Initializer = (Statement) $1;
5757
lbag.AddLocation (f, GetLocation ($2));
5760
for_statement_condition
5764
| opt_for_initializer CLOSE_PARENS {
5765
report.Error (1525, GetLocation ($2), "Unexpected symbol ')', expected ';'");
5767
f.Initializer = (Statement) $1;
5768
lbag.AddLocation (f, GetLocation ($2));
5769
$$ = end_block (GetLocation ($2));
5773
for_statement_condition
5774
: opt_for_condition SEMICOLON
5777
f.Condition = (BooleanExpression) $1;
5778
lbag.AddLocation (f, GetLocation ($2));
5786
| boolean_expression CLOSE_PARENS {
5787
report.Error (1525, GetLocation ($2), "Unexpected symbol ')', expected ';'");
5789
f.Condition = (BooleanExpression) $1;
5790
lbag.AddLocation (f, GetLocation ($2));
5791
$$ = end_block (GetLocation ($2));
5796
: opt_for_iterator CLOSE_PARENS
5800
f.Iterator = (Statement) $1;
5802
if ($3 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5803
Warning_EmptyStatement (GetLocation ($3));
5805
f.Statement = (Statement) $3;
5806
lbag.AddLocation (f, GetLocation ($2));
5808
$$ = end_block (GetLocation ($2));
5812
Error_SyntaxError (yyToken);
5813
$$ = end_block (current_block.StartLocation);
5818
: /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5823
: variable_type identifier_inside_body
5825
var lt = (Tokenizer.LocatedToken) $2;
5826
var li = new LocalVariable (current_block, lt.Value, lt.Location);
5827
current_block.AddLocalName (li);
5828
current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5830
opt_local_variable_initializer opt_variable_declarators
5832
$$ = current_variable;
5834
lbag.AddLocation (current_variable, PopLocation ());
5836
current_variable = null;
5838
| statement_expression_list
5842
: /* empty */ { $$ = null; }
5843
| boolean_expression
5847
: /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5852
: statement_expression_list
5855
statement_expression_list
5856
: statement_expression
5857
| statement_expression_list COMMA statement_expression
5859
var sl = $1 as StatementList;
5861
sl = new StatementList ((Statement) $1, (Statement) $3);
5862
lbag.AddStatement (sl, GetLocation ($2));
5864
sl.Add ((Statement) $3);
5865
lbag.AddLocation (sl, GetLocation ($2));
5874
: FOREACH open_parens_any type error
5876
report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5878
start_block (GetLocation ($2));
5879
current_block.IsCompilerGenerated = true;
5881
Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5882
current_block.AddStatement (f);
5884
lbag.AddStatement (f, GetLocation ($2));
5885
$$ = end_block (GetLocation ($4));
5887
| FOREACH open_parens_any type identifier_inside_body error
5889
Error_SyntaxError (yyToken);
5891
start_block (GetLocation ($2));
5892
current_block.IsCompilerGenerated = true;
5894
var lt = (Tokenizer.LocatedToken) $4;
5895
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5896
current_block.AddLocalName (li);
5898
Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5899
current_block.AddStatement (f);
5901
lbag.AddStatement (f, GetLocation ($2));
5902
$$ = end_block (GetLocation ($5));
5904
| FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5906
start_block (GetLocation ($2));
5907
current_block.IsCompilerGenerated = true;
5908
var lt = (Tokenizer.LocatedToken) $4;
5909
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5910
current_block.AddLocalName (li);
5915
if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5916
Warning_EmptyStatement (GetLocation ($9));
5918
Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5919
lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5920
end_block (GetLocation ($7));
5924
| FOREACH open_parens_any type identifier_inside_body error
5926
start_block (GetLocation ($2));
5927
current_block.IsCompilerGenerated = true;
5928
var lt = $4 as Tokenizer.LocatedToken;
5929
var li = lt != null ? new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location) : null;
5931
Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5932
current_block.AddStatement (f);
5934
lbag.AddStatement (f, GetLocation ($2));
5935
$$ = end_block (GetLocation ($5));
5937
| FOREACH open_parens_any type error
5939
Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5940
current_block.AddStatement (f);
5942
lbag.AddStatement (f, GetLocation ($2));
5949
| continue_statement
5959
$$ = new Break (GetLocation ($1));
5960
lbag.AddStatement ($$, GetLocation ($2));
5965
: CONTINUE SEMICOLON
5967
$$ = new Continue (GetLocation ($1));
5968
lbag.AddStatement ($$, GetLocation ($2));
5972
Error_SyntaxError (yyToken);
5973
$$ = new Continue (GetLocation ($1));
5978
: GOTO identifier_inside_body SEMICOLON
5980
var lt = (Tokenizer.LocatedToken) $2;
5981
$$ = new Goto (lt.Value, GetLocation ($1));
5982
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5984
| GOTO CASE constant_expression SEMICOLON
5986
$$ = new GotoCase ((Expression) $3, GetLocation ($1));
5987
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5989
| GOTO DEFAULT SEMICOLON
5991
$$ = new GotoDefault (GetLocation ($1));
5992
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5997
: RETURN opt_expression SEMICOLON
5999
$$ = new Return ((Expression) $2, GetLocation ($1));
6000
lbag.AddStatement ($$, GetLocation ($3));
6002
| RETURN expression error
6004
Error_SyntaxError (yyToken);
6005
$$ = new Return ((Expression) $2, GetLocation ($1));
6009
Error_SyntaxError (yyToken);
6010
$$ = new Return (null, GetLocation ($1));
6015
: THROW opt_expression SEMICOLON
6017
$$ = new Throw ((Expression) $2, GetLocation ($1));
6018
lbag.AddStatement ($$, GetLocation ($3));
6022
Error_SyntaxError (yyToken);
6023
$$ = new Throw (null, GetLocation ($1));
6028
: identifier_inside_body RETURN opt_expression SEMICOLON
6030
var lt = (Tokenizer.LocatedToken) $1;
6031
string s = lt.Value;
6033
report.Error (1003, lt.Location, "; expected");
6034
} else if ($3 == null) {
6035
report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6036
} else if (lang_version == LanguageVersion.ISO_1){
6037
FeatureIsNotAvailable (lt.Location, "iterators");
6040
current_block.Explicit.RegisterIteratorYield ();
6041
$$ = new Yield ((Expression) $3, lt.Location);
6042
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6044
| identifier_inside_body RETURN expression error
6046
Error_SyntaxError (yyToken);
6048
var lt = (Tokenizer.LocatedToken) $1;
6049
string s = lt.Value;
6051
report.Error (1003, lt.Location, "; expected");
6052
} else if ($3 == null) {
6053
report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6054
} else if (lang_version == LanguageVersion.ISO_1){
6055
FeatureIsNotAvailable (lt.Location, "iterators");
6058
current_block.Explicit.RegisterIteratorYield ();
6059
$$ = new Yield ((Expression) $3, lt.Location);
6060
lbag.AddStatement ($$, GetLocation ($2));
6062
| identifier_inside_body BREAK SEMICOLON
6064
var lt = (Tokenizer.LocatedToken) $1;
6065
string s = lt.Value;
6067
report.Error (1003, lt.Location, "; expected");
6068
} else if (lang_version == LanguageVersion.ISO_1){
6069
FeatureIsNotAvailable (lt.Location, "iterators");
6072
current_block.Explicit.RegisterIteratorYield ();
6073
$$ = new YieldBreak (lt.Location);
6074
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6084
: TRY block catch_clauses
6086
$$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6088
| TRY block FINALLY block
6090
$$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
6091
lbag.AddStatement ($$, GetLocation ($3));
6093
| TRY block catch_clauses FINALLY block
6095
$$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
6096
lbag.AddStatement ($$, GetLocation ($4));
6100
Error_SyntaxError (1524, yyToken);
6101
$$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6108
var l = new List<Catch> (2);
6113
| catch_clauses catch_clause
6115
var l = (List<Catch>) $1;
6117
Catch c = (Catch) $2;
6118
if (l [l.Count - 1].IsGeneral) {
6119
report.Error (1017, c.loc, "Try statement already has an empty catch block");
6129
| identifier_inside_body
6135
$$ = new Catch ((Block) $2, GetLocation ($1));
6137
| CATCH open_parens_any type opt_identifier CLOSE_PARENS
6139
start_block (GetLocation ($2));
6140
var c = new Catch (current_block, GetLocation ($1));
6141
c.TypeExpression = (FullNamedExpression) $3;
6144
var lt = (Tokenizer.LocatedToken) $4;
6145
c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6146
current_block.AddLocalName (c.Variable);
6149
lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6152
block_prepared_strict
6156
| CATCH open_parens_any error
6158
if (yyToken == Token.CLOSE_PARENS) {
6159
report.Error (1015, lexer.Location,
6160
"A type that derives from `System.Exception', `object', or `string' expected");
6162
Error_SyntaxError (yyToken);
6165
$$ = new Catch (null, GetLocation ($1));
6167
| CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6169
Error_SyntaxError (yyToken);
6171
// Required otherwise missing block could not be detected because
6172
// start_block is run early
6173
var c = new Catch (null, GetLocation ($1));
6174
c.TypeExpression = (FullNamedExpression) $3;
6177
var lt = (Tokenizer.LocatedToken) $4;
6178
c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6182
var lt = (Tokenizer.LocatedToken) $4;
6183
c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6186
lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6195
$$ = new Checked ((Block) $2, GetLocation ($1));
6202
$$ = new Unchecked ((Block) $2, GetLocation ($1));
6209
if (!settings.Unsafe)
6210
Error_UnsafeCodeNotAllowed (GetLocation ($1));
6212
$$ = new Unsafe ((Block) $3, GetLocation ($1));
6217
: LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6219
if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6220
Warning_EmptyStatement (GetLocation ($5));
6222
$$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6223
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6225
| LOCK open_parens_any expression error
6227
Error_SyntaxError (yyToken);
6229
$$ = new Lock ((Expression) $3, null, GetLocation ($1));
6230
lbag.AddStatement ($$, GetLocation ($2));
6235
: FIXED open_parens_any variable_type identifier_inside_body
6237
start_block (GetLocation ($2));
6239
current_block.IsCompilerGenerated = true;
6240
var lt = (Tokenizer.LocatedToken) $4;
6241
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6242
current_block.AddLocalName (li);
6243
current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6245
using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6247
$$ = current_variable;
6248
current_variable = null;
6252
if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6253
Warning_EmptyStatement (GetLocation ($10));
6255
Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6256
current_block.AddStatement (f);
6257
lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6258
$$ = end_block (GetLocation ($8));
6263
: USING open_parens_any variable_type identifier_inside_body
6265
start_block (GetLocation ($2));
6267
current_block.IsCompilerGenerated = true;
6268
var lt = (Tokenizer.LocatedToken) $4;
6269
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6270
current_block.AddLocalName (li);
6271
current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6273
using_initialization CLOSE_PARENS
6275
$$ = current_variable;
6276
current_variable = null;
6280
if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6281
Warning_EmptyStatement (GetLocation ($9));
6283
Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6284
lbag.AddStatement (u, GetLocation ($2), GetLocation ($7));
6285
current_block.AddStatement (u);
6286
$$ = end_block (GetLocation ($7));
6288
| USING open_parens_any expression CLOSE_PARENS embedded_statement
6290
if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6291
Warning_EmptyStatement (GetLocation ($5));
6293
$$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6294
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6296
| USING open_parens_any expression error
6298
Error_SyntaxError (yyToken);
6300
$$ = new Using ((Expression) $3, null, GetLocation ($1));
6301
lbag.AddStatement ($$, GetLocation ($2));
6305
using_initialization
6306
: using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6309
// It has to be here for the parent to safely restore artificial block
6310
Error_SyntaxError (yyToken);
6314
using_or_fixed_variable_initializer
6317
Error_MissingInitializer (lexer.Location);
6319
| ASSIGN variable_initializer
6321
current_variable.Initializer = (Expression) $2;
6322
lbag.AddLocation (current_variable, GetLocation ($1));
6323
$$ = current_variable;
6331
: first_from_clause query_body
6333
lexer.query_parsing = false;
6335
Linq.AQueryClause from = $1 as Linq.AQueryClause;
6337
from.Tail.Next = (Linq.AQueryClause)$2;
6340
current_block.SetEndLocation (lexer.Location);
6341
current_block = current_block.Parent;
6343
| nested_from_clause query_body
6345
Linq.AQueryClause from = $1 as Linq.AQueryClause;
6347
from.Tail.Next = (Linq.AQueryClause)$2;
6350
current_block.SetEndLocation (lexer.Location);
6351
current_block = current_block.Parent;
6354
// Bubble up COMPLETE_COMPLETION productions
6355
| first_from_clause COMPLETE_COMPLETION {
6356
lexer.query_parsing = false;
6359
current_block.SetEndLocation (lexer.Location);
6360
current_block = current_block.Parent;
6362
| nested_from_clause COMPLETE_COMPLETION {
6364
current_block.SetEndLocation (lexer.Location);
6365
current_block = current_block.Parent;
6370
: FROM_FIRST identifier_inside_body IN expression
6372
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6374
var lt = (Tokenizer.LocatedToken) $2;
6375
var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6376
var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6377
lbag.AddLocation (start, GetLocation ($3));
6378
$$ = new Linq.QueryExpression (start);
6380
| FROM_FIRST type identifier_inside_body IN expression
6382
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6384
var lt = (Tokenizer.LocatedToken) $3;
6385
var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6386
var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6387
IdentifierType = (FullNamedExpression)$2
6389
lbag.AddLocation (start, GetLocation ($4));
6390
$$ = new Linq.QueryExpression (start);
6395
: FROM identifier_inside_body IN expression
6397
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6399
var lt = (Tokenizer.LocatedToken) $2;
6400
var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6401
var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6402
lbag.AddLocation (start, GetLocation ($3));
6403
$$ = new Linq.QueryExpression (start);
6405
| FROM type identifier_inside_body IN expression
6407
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6409
var lt = (Tokenizer.LocatedToken) $3;
6410
var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6411
var start = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6412
IdentifierType = (FullNamedExpression)$2
6414
lbag.AddLocation (start, GetLocation ($4));
6415
$$ = new Linq.QueryExpression (start);
6420
: FROM identifier_inside_body IN
6422
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6426
var lt = (Tokenizer.LocatedToken) $2;
6427
var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6428
$$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6430
current_block.SetEndLocation (lexer.Location);
6431
current_block = current_block.Parent;
6432
((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6434
lbag.AddLocation ($$, GetLocation ($3));
6436
| FROM type identifier_inside_body IN
6438
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6442
var lt = (Tokenizer.LocatedToken) $3;
6443
var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6445
$$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6446
IdentifierType = (FullNamedExpression)$2
6449
current_block.SetEndLocation (lexer.Location);
6450
current_block = current_block.Parent;
6452
((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6454
lbag.AddLocation ($$, GetLocation ($4));
6459
: query_body_clauses select_or_group_clause opt_query_continuation
6461
Linq.AQueryClause head = (Linq.AQueryClause)$2;
6464
head.Next = (Linq.AQueryClause)$3;
6467
Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6468
clause.Tail.Next = head;
6474
| select_or_group_clause opt_query_continuation
6476
Linq.AQueryClause head = (Linq.AQueryClause)$2;
6479
Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6480
clause.Tail.Next = head;
6486
| query_body_clauses COMPLETE_COMPLETION
6487
| query_body_clauses error
6489
report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6494
Error_SyntaxError (yyToken);
6499
select_or_group_clause
6502
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6506
$$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6508
current_block.SetEndLocation (lexer.Location);
6509
current_block = current_block.Parent;
6513
if (linq_clause_blocks == null)
6514
linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6516
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6517
linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6521
current_block.SetEndLocation (lexer.Location);
6522
current_block = current_block.Parent;
6524
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6528
var obj = (object[]) $5;
6530
$$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6531
lbag.AddLocation ($$, (Location) obj[1]);
6533
current_block.SetEndLocation (lexer.Location);
6534
current_block = current_block.Parent;
6539
: BY expression_or_error
6541
$$ = new object[] { $2, GetLocation ($1) };
6545
Error_SyntaxError (yyToken);
6546
$$ = new object[2] { null, Location.Null };
6552
| query_body_clauses query_body_clause
6554
((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6568
: LET identifier_inside_body ASSIGN
6570
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6574
var lt = (Tokenizer.LocatedToken) $2;
6575
var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6576
$$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6577
lbag.AddLocation ($$, GetLocation ($3));
6579
current_block.SetEndLocation (lexer.Location);
6580
current_block = current_block.Parent;
6582
((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6589
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6593
$$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6595
current_block.SetEndLocation (lexer.Location);
6596
current_block = current_block.Parent;
6601
: JOIN identifier_inside_body IN
6603
if (linq_clause_blocks == null)
6604
linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6606
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6607
linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6609
expression_or_error ON
6611
current_block.SetEndLocation (lexer.Location);
6612
current_block = current_block.Parent;
6614
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6615
linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6617
expression_or_error EQUALS
6619
current_block.AddStatement (new ContextualReturn ((Expression) $8));
6620
current_block.SetEndLocation (lexer.Location);
6621
current_block = current_block.Parent;
6623
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6625
expression_or_error opt_join_into
6627
current_block.AddStatement (new ContextualReturn ((Expression) $11));
6628
current_block.SetEndLocation (lexer.Location);
6630
var outer_selector = linq_clause_blocks.Pop ();
6631
var block = linq_clause_blocks.Pop ();
6633
var lt = (Tokenizer.LocatedToken) $2;
6634
var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6635
Linq.RangeVariable into;
6639
$$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6640
lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6643
// Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6645
var parent = block.Parent;
6646
while (parent is Linq.QueryBlock) {
6647
parent = parent.Parent;
6649
current_block.Parent = parent;
6651
((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6653
lt = (Tokenizer.LocatedToken) $12;
6654
into = new Linq.RangeVariable (lt.Value, lt.Location);
6656
$$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6657
lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), opt_intoStack.Pop ());
6660
current_block = block.Parent;
6661
((Linq.QueryBlock)current_block).AddRangeVariable (into);
6663
| JOIN type identifier_inside_body IN
6665
if (linq_clause_blocks == null)
6666
linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6668
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6669
linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6671
expression_or_error ON
6673
current_block.SetEndLocation (lexer.Location);
6674
current_block = current_block.Parent;
6676
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6677
linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6679
expression_or_error EQUALS
6681
current_block.AddStatement (new ContextualReturn ((Expression) $9));
6682
current_block.SetEndLocation (lexer.Location);
6683
current_block = current_block.Parent;
6685
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6687
expression_or_error opt_join_into
6689
current_block.AddStatement (new ContextualReturn ((Expression) $12));
6690
current_block.SetEndLocation (lexer.Location);
6692
var outer_selector = linq_clause_blocks.Pop ();
6693
var block = linq_clause_blocks.Pop ();
6695
var lt = (Tokenizer.LocatedToken) $3;
6696
var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6697
Linq.RangeVariable into;
6701
$$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6702
IdentifierType = (FullNamedExpression)$2
6704
lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6707
// Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6709
var parent = block.Parent;
6710
while (parent is Linq.QueryBlock) {
6711
parent = parent.Parent;
6713
current_block.Parent = parent;
6715
((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6717
lt = (Tokenizer.LocatedToken) $13;
6718
into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6720
$$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6721
IdentifierType = (FullNamedExpression)$2
6723
lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), opt_intoStack.Pop ());
6726
current_block = block.Parent;
6727
((Linq.QueryBlock)current_block).AddRangeVariable (into);
6733
| INTO identifier_inside_body
6735
opt_intoStack.Push (GetLocation ($1));
6743
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6744
lbag.AddLocation (current_block, GetLocation ($1));
6748
current_block.SetEndLocation (lexer.Location);
6749
current_block = current_block.Parent;
6759
current_block.SetEndLocation (lexer.Location);
6760
current_block = current_block.Parent;
6762
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6766
((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6773
| orderings_then_by COMMA
6775
current_block.SetEndLocation (lexer.Location);
6776
current_block = current_block.Parent;
6778
current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6782
((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6790
$$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6792
| expression ASCENDING
6794
$$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6795
lbag.AddLocation ($$, GetLocation ($2));
6797
| expression DESCENDING
6799
$$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6800
lbag.AddLocation ($$, GetLocation ($2));
6807
$$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6809
| expression ASCENDING
6811
$$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6812
lbag.AddLocation ($$, GetLocation ($2));
6814
| expression DESCENDING
6816
$$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6817
lbag.AddLocation ($$, GetLocation ($2));
6822
opt_query_continuation
6824
| INTO identifier_inside_body
6826
// query continuation block is not linked with query block but with block
6827
// before. This means each query can use same range variable names for
6828
// different identifiers.
6830
current_block.SetEndLocation (GetLocation ($1));
6831
current_block = current_block.Parent;
6833
current_block = new Linq.QueryBlock (current_block, lexer.Location);
6835
if (linq_clause_blocks == null)
6836
linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6838
linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6842
var current_block = linq_clause_blocks.Pop ();
6843
var lt = (Tokenizer.LocatedToken) $2;
6844
var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6845
$$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6846
next = (Linq.AQueryClause)$4
6852
// Support for using the compiler as an interactive parser
6854
// The INTERACTIVE_PARSER token is first sent to parse our
6855
// productions; If the result is a Statement, the parsing
6856
// is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6857
// to setup the blocks in advance.
6859
// This setup is here so that in the future we can add
6860
// support for other constructs (type parsing, namespaces, etc)
6861
// that do not require a block to be setup in advance
6865
: EVAL_STATEMENT_PARSER EOF
6866
| EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6867
| EVAL_STATEMENT_PARSER
6869
current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6871
// (ref object retval)
6872
Parameter [] mpar = new Parameter [1];
6873
mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6875
ParametersCompiled pars = new ParametersCompiled (mpar);
6876
var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6877
if (settings.Unsafe)
6878
mods |= Modifiers.UNSAFE;
6880
current_local_parameters = pars;
6881
Method method = new Method (
6883
new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6885
new MemberName ("Host"),
6887
null /* attributes */);
6889
current_type.AddMember (method);
6891
oob_stack.Push (method);
6892
++lexer.parsing_block;
6893
start_block (lexer.Location);
6895
interactive_statement_list opt_COMPLETE_COMPLETION
6897
--lexer.parsing_block;
6898
Method method = (Method) oob_stack.Pop ();
6900
method.Block = (ToplevelBlock) end_block(lexer.Location);
6902
InteractiveResult = (Class) pop_current_class ();
6903
current_local_parameters = null;
6905
| EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6908
interactive_compilation_unit
6909
: opt_extern_alias_directives opt_using_directives
6910
| opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6913
opt_COMPLETE_COMPLETION
6915
| COMPLETE_COMPLETION
6918
close_brace_or_complete_completion
6920
| COMPLETE_COMPLETION
6924
// XML documentation code references micro parser
6926
documentation_parsing
6929
module.DocumentationBuilder.ParsedName = (MemberName) $2;
6934
: doc_type_declaration_name opt_doc_method_sig
6936
module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6938
| builtin_types opt_doc_method_sig
6940
module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6941
module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6944
| builtin_types DOT IDENTIFIER opt_doc_method_sig
6946
module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6947
module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6948
var lt = (Tokenizer.LocatedToken) $3;
6949
$$ = new MemberName (lt.Value);
6951
| doc_type_declaration_name DOT THIS
6953
$$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6955
| doc_type_declaration_name DOT THIS OPEN_BRACKET
6957
valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6959
opt_doc_parameters CLOSE_BRACKET
6961
module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6962
$$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6964
| EXPLICIT OPERATOR type opt_doc_method_sig
6966
var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6967
p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6968
module.DocumentationBuilder.ParsedParameters = p;
6969
module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6972
| IMPLICIT OPERATOR type opt_doc_method_sig
6974
var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6975
p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6976
module.DocumentationBuilder.ParsedParameters = p;
6977
module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6980
| OPERATOR overloadable_operator opt_doc_method_sig
6982
var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6983
module.DocumentationBuilder.ParsedParameters = p;
6984
module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6989
doc_type_declaration_name
6990
: type_declaration_name
6991
| doc_type_declaration_name DOT type_declaration_name
6993
$$ = new MemberName (((MemberName) $1), (MemberName) $3);
7001
valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7003
opt_doc_parameters CLOSE_PARENS
7012
$$ = new List<DocumentationParameter> (0);
7020
var parameters = new List<DocumentationParameter> ();
7021
parameters.Add ((DocumentationParameter) $1);
7024
| doc_parameters COMMA doc_parameter
7026
var parameters = $1 as List<DocumentationParameter>;
7027
parameters.Add ((DocumentationParameter) $3);
7033
: opt_parameter_modifier parameter_type
7036
$$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7038
$$ = new DocumentationParameter ((FullNamedExpression) $2);
7045
// A class used to hold info about an operator declarator
7047
class OperatorDeclaration {
7048
public readonly Operator.OpType optype;
7049
public readonly FullNamedExpression ret_type;
7050
public readonly Location location;
7052
public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7055
this.ret_type = ret_type;
7056
this.location = location;
7060
void Error_ExpectingTypeName (Expression expr)
7062
if (expr is Invocation){
7063
report.Error (1002, expr.Location, "Expecting `;'");
7065
expr.Error_InvalidExpressionStatement (report);
7069
void Error_ParameterModifierNotValid (string modifier, Location loc)
7071
report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7075
void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7077
report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7078
Parameter.GetModifierSignature (mod));
7081
void Error_TypeExpected (Location loc)
7083
report.Error (1031, loc, "Type expected");
7086
void Error_UnsafeCodeNotAllowed (Location loc)
7088
report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7091
void Warning_EmptyStatement (Location loc)
7093
report.Warning (642, 3, loc, "Possible mistaken empty statement");
7096
void Error_NamedArgumentExpected (NamedArgument a)
7098
report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7101
void Error_MissingInitializer (Location loc)
7103
report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7106
object Error_AwaitAsIdentifier (object token)
7109
report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7110
return new Tokenizer.LocatedToken ("await", GetLocation (token));
7116
void push_current_container (TypeDefinition tc, object partial_token)
7118
if (module.Evaluator != null){
7119
tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7123
undo.AddTypeContainer (current_container, tc);
7126
if (partial_token != null)
7127
current_container.AddPartial (tc);
7129
current_container.AddTypeContainer (tc);
7131
++lexer.parsing_declaration;
7132
current_container = tc;
7136
TypeContainer pop_current_class ()
7138
var retval = current_container;
7140
current_container = current_container.Parent;
7141
current_type = current_type.Parent as TypeDefinition;
7146
[System.Diagnostics.Conditional ("FULL_AST")]
7147
void StoreModifierLocation (object token, Location loc)
7152
if (mod_locations == null)
7153
mod_locations = new List<Tuple<Modifiers, Location>> ();
7155
mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7158
List<Tuple<Modifiers, Location>> GetModifierLocations ()
7160
var result = mod_locations;
7161
mod_locations = null;
7165
[System.Diagnostics.Conditional ("FULL_AST")]
7166
void PushLocation (Location loc)
7168
if (location_stack == null)
7169
location_stack = new Stack<Location> ();
7171
location_stack.Push (loc);
7174
Location PopLocation ()
7176
if (location_stack == null)
7177
return Location.Null;
7179
return location_stack.Pop ();
7182
string CheckAttributeTarget (string a, Location l)
7185
case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7189
report.Warning (658, 1, l,
7190
"`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7191
return string.Empty;
7194
static bool IsUnaryOperator (Operator.OpType op)
7198
case Operator.OpType.LogicalNot:
7199
case Operator.OpType.OnesComplement:
7200
case Operator.OpType.Increment:
7201
case Operator.OpType.Decrement:
7202
case Operator.OpType.True:
7203
case Operator.OpType.False:
7204
case Operator.OpType.UnaryPlus:
7205
case Operator.OpType.UnaryNegation:
7211
void syntax_error (Location l, string msg)
7213
report.Error (1003, l, "Syntax error, " + msg);
7218
public Tokenizer Lexer {
7224
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7225
: this (reader, file, file.Compiler.Report, session)
7229
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7232
current_container = current_namespace = file;
7234
this.module = file.Module;
7235
this.compiler = file.Compiler;
7236
this.settings = compiler.Settings;
7237
this.report = report;
7239
lang_version = settings.Version;
7240
yacc_verbose_flag = settings.VerboseParserFlag;
7241
doc_support = settings.DocumentationFile != null;
7242
lexer = new Tokenizer (reader, file, session);
7243
oob_stack = new Stack<object> ();
7244
lbag = session.LocationsBag;
7245
use_global_stacks = session.UseJayGlobalArrays;
7246
parameters_bucket = session.ParametersStack;
7249
public void parse ()
7251
eof_token = Token.EOF;
7254
if (yacc_verbose_flag > 1)
7255
yyparse (lexer, new yydebug.yyDebugSimple ());
7259
Tokenizer tokenizer = lexer as Tokenizer;
7260
tokenizer.cleanup ();
7261
} catch (Exception e){
7262
if (e is yyParser.yyUnexpectedEof) {
7263
Error_SyntaxError (yyToken);
7264
UnexpectedEOF = true;
7268
if (e is yyParser.yyException) {
7269
if (report.Errors == 0)
7270
report.Error (-25, lexer.Location, "Parsing error");
7272
// Used by compiler-tester to test internal errors
7273
if (yacc_verbose_flag > 0 || e is FatalException)
7276
report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7281
void CheckToken (int error, int yyToken, string msg, Location loc)
7283
if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7284
report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7286
report.Error (error, loc, msg);
7289
string ConsumeStoredComment ()
7291
string s = tmpComment;
7293
Lexer.doc_state = XmlCommentState.Allowed;
7297
void FeatureIsNotAvailable (Location loc, string feature)
7299
report.FeatureIsNotAvailable (compiler, loc, feature);
7302
Location GetLocation (object obj)
7304
var lt = obj as Tokenizer.LocatedToken;
7308
var mn = obj as MemberName;
7312
var expr = obj as Expression;
7314
return expr.Location;
7316
return lexer.Location;
7319
void start_block (Location loc)
7321
if (current_block == null) {
7322
current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7323
parsing_anonymous_method = false;
7324
} else if (parsing_anonymous_method) {
7325
current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7326
parsing_anonymous_method = false;
7328
current_block = new ExplicitBlock (current_block, loc, Location.Null);
7333
end_block (Location loc)
7335
Block retval = current_block.Explicit;
7336
retval.SetEndLocation (loc);
7337
current_block = retval.Parent;
7341
void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7343
oob_stack.Push (current_anonymous_method);
7344
oob_stack.Push (current_local_parameters);
7345
oob_stack.Push (current_variable);
7346
oob_stack.Push (async_block);
7348
current_local_parameters = parameters;
7350
if (lang_version <= LanguageVersion.ISO_2)
7351
FeatureIsNotAvailable (loc, "lambda expressions");
7353
current_anonymous_method = new LambdaExpression (loc);
7355
if (lang_version == LanguageVersion.ISO_1)
7356
FeatureIsNotAvailable (loc, "anonymous methods");
7358
current_anonymous_method = new AnonymousMethodExpression (loc);
7360
current_anonymous_method.IsAsync = isAsync;
7362
async_block = isAsync;
7363
// Force the next block to be created as a ToplevelBlock
7364
parsing_anonymous_method = true;
7368
* Completes the anonymous method processing, if lambda_expr is null, this
7369
* means that we have a Statement instead of an Expression embedded
7371
AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7373
AnonymousMethodExpression retval;
7376
anon_block.IsAsync = true;
7378
current_anonymous_method.Block = anon_block;
7379
retval = current_anonymous_method;
7381
async_block = (bool) oob_stack.Pop ();
7382
current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
7383
current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7384
current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7389
void Error_SyntaxError (int token)
7391
Error_SyntaxError (0, token);
7394
void Error_SyntaxError (int error_code, int token)
7396
Error_SyntaxError (error_code, token, "Unexpected symbol");
7399
void Error_SyntaxError (int error_code, int token, string msg)
7401
Lexer.CompleteOnEOF = false;
7403
// An error message has been reported by tokenizer
7404
if (token == Token.ERROR)
7407
// Avoid duplicit error message after unterminated string literals
7408
if (token == Token.LITERAL && lexer.Location.Column == 0)
7411
string symbol = GetSymbolName (token);
7412
string expecting = GetExpecting ();
7413
var loc = lexer.Location - symbol.Length;
7415
if (error_code == 0) {
7416
if (expecting == "`identifier'") {
7417
if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7418
report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7423
expecting = "identifier";
7424
} else if (expecting == "`)'") {
7431
if (string.IsNullOrEmpty (expecting))
7432
report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7434
report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7437
string GetExpecting ()
7439
int [] tokens = yyExpectingTokens (yyExpectingState);
7440
var names = new List<string> (tokens.Length);
7441
bool has_type = false;
7442
bool has_identifier = false;
7443
for (int i = 0; i < tokens.Length; i++){
7444
int token = tokens [i];
7445
has_identifier |= token == Token.IDENTIFIER;
7447
string name = GetTokenName (token);
7448
if (name == "<internal>")
7451
has_type |= name == "type";
7452
if (names.Contains (name))
7459
// Too many tokens to enumerate
7461
if (names.Count > 8)
7464
if (has_type && has_identifier)
7465
names.Remove ("identifier");
7467
if (names.Count == 1)
7468
return "`" + GetTokenName (tokens [0]) + "'";
7470
StringBuilder sb = new StringBuilder ();
7472
int count = names.Count;
7473
for (int i = 0; i < count; i++){
7474
bool last = i + 1 == count;
7478
sb.Append (names [i]);
7479
sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7481
return sb.ToString ();
7485
string GetSymbolName (int token)
7489
return ((Constant)lexer.Value).GetValue ().ToString ();
7490
case Token.IDENTIFIER:
7491
return ((Tokenizer.LocatedToken)lexer.Value).Value;
7533
case Token.BITWISE_AND:
7535
case Token.BITWISE_OR:
7549
case Token.OP_SHIFT_LEFT:
7551
case Token.OP_SHIFT_RIGHT:
7571
case Token.OP_COALESCING:
7573
case Token.OP_MULT_ASSIGN:
7575
case Token.OP_DIV_ASSIGN:
7577
case Token.OP_MOD_ASSIGN:
7579
case Token.OP_ADD_ASSIGN:
7581
case Token.OP_SUB_ASSIGN:
7583
case Token.OP_SHIFT_LEFT_ASSIGN:
7585
case Token.OP_SHIFT_RIGHT_ASSIGN:
7587
case Token.OP_AND_ASSIGN:
7589
case Token.OP_XOR_ASSIGN:
7591
case Token.OP_OR_ASSIGN:
7595
return GetTokenName (token);
7598
static string GetTokenName (int token)
7601
case Token.ABSTRACT:
7623
case Token.CONTINUE:
7627
case Token.DELEGATE:
7637
case Token.EXPLICIT:
7640
case Token.EXTERN_ALIAS:
7656
case Token.IMPLICIT:
7660
case Token.INTERFACE:
7662
case Token.INTERNAL:
7668
case Token.NAMESPACE:
7674
case Token.OPERATOR:
7678
case Token.OVERRIDE:
7684
case Token.PROTECTED:
7688
case Token.READONLY:
7700
case Token.STACKALLOC:
7701
return "stackalloc";
7718
case Token.UNCHECKED:
7726
case Token.VOLATILE:
7734
case Token.REFVALUE:
7735
return "__refvalue";
7745
case Token.FROM_FIRST:
7763
case Token.ASCENDING:
7765
case Token.DESCENDING:
7766
return "descending";
7773
case Token.OPEN_BRACE:
7775
case Token.CLOSE_BRACE:
7777
case Token.OPEN_BRACKET:
7778
case Token.OPEN_BRACKET_EXPR:
7780
case Token.CLOSE_BRACKET:
7782
case Token.OPEN_PARENS_CAST:
7783
case Token.OPEN_PARENS_LAMBDA:
7784
case Token.OPEN_PARENS:
7786
case Token.CLOSE_PARENS:
7792
case Token.DEFAULT_COLON:
7796
case Token.SEMICOLON:
7807
case Token.BITWISE_AND:
7808
case Token.BITWISE_OR:
7815
case Token.OP_SHIFT_LEFT:
7816
case Token.OP_SHIFT_RIGHT:
7824
case Token.OP_COALESCING:
7825
case Token.OP_MULT_ASSIGN:
7826
case Token.OP_DIV_ASSIGN:
7827
case Token.OP_MOD_ASSIGN:
7828
case Token.OP_ADD_ASSIGN:
7829
case Token.OP_SUB_ASSIGN:
7830
case Token.OP_SHIFT_LEFT_ASSIGN:
7831
case Token.OP_SHIFT_RIGHT_ASSIGN:
7832
case Token.OP_AND_ASSIGN:
7833
case Token.OP_XOR_ASSIGN:
7834
case Token.OP_OR_ASSIGN:
7835
return "<operator>";
7857
case Token.OP_GENERICS_LT:
7858
case Token.GENERIC_DIMENSION:
7860
case Token.OP_GENERICS_GT:
7863
case Token.INTERR_NULLABLE:
7865
case Token.DOUBLE_COLON:
7869
case Token.IDENTIFIER:
7871
return "identifier";
7874
return "end-of-file";
7876
// All of these are internal.
7879
case Token.FIRST_KEYWORD:
7880
case Token.EVAL_COMPILATION_UNIT_PARSER:
7881
case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7882
case Token.EVAL_STATEMENT_PARSER:
7883
case Token.LAST_KEYWORD:
7884
case Token.GENERATE_COMPLETION:
7885
case Token.COMPLETE_COMPLETION:
7886
return "<internal>";
7888
// A bit more robust.
7890
return yyNames [token];