-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcs.y
1713 lines (1387 loc) · 28.2 KB
/
cs.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%output=parser.cs
%token ABSTRACT AS BASE BOOL BREAK BYTE CASE CATCH CHAR CHECKED CLASS CONST
%token CONTINUE DECIMAL DEFAULT DELEGATE DO DOUBLE ELSE ENUM EVENT EXPLICIT
%token EXTERN FALSE FINALLY FIXED FLOAT FOR FOREACH GOTO IF IMPLICIT IN
%token INT INTERFACE INTERNAL IS LOCK LONG NAMESPACE NEW NULL OBJECT OPERATOR
%token OUT OVERRIDE PARAMS PRIVATE PROTECTED PUBLIC READONLY REF RETURN
%token SBYTE SEALED SHORT SIZEOF STACKALLOC STATIC STRING STRUCT SWITCH
%token THIS THROW TRUE TRY TYPEOF UINT ULONG UNCHECKED UNSAFE USHORT USING
%token VIRTUAL VOID VOLATILE WHILE REF OUT NEW YIELD ALIAS PARTIAL ADD
%token REMOVE EXTERN GET SET WHERE STAR_EQ SLASH_EQ SEMI_SEMI RIGHT_SHIFT_ASSIGNMENT
%token RIGHT_SHIFT QM_QM PLUS_PLUS PLUS_EQ PERCENT_EQ NE MINUS_MINUS MINUS_EQ
%token LT_LT_EQ LT_LT LITERAL LE IDENTIFIER GE EQ_EQ CARET_EQ BAR_EQ BAR_BAR
%token AMP_EQ AMP_AMP
%%
// A.2.1 Basic concepts
compilation_unit:
extern_alias_directivesopt using_directivesopt global_attributesopt
|namespace_member_declarationsopt
;
namespace_name:
namespace_or_type_name
;
type_name:
namespace_or_type_name
;
namespace_or_type_name:
IDENTIFIER type_argument_listopt
|qualified_alias_member
|namespace_or_type_name '.' IDENTIFIER type_argument_listopt
;
// A.2.2 Types
type:
value_type
|reference_type
|type_parameter
;
value_type:
struct_type
|enum_type
;
struct_type:
type_name
|simple_type
|nullable_type
;
simple_type:
numeric_type
|BOOL
;
numeric_type:
integral_type
|floating_point_type
|DECIMAL
;
integral_type:
SBYTE
|BYTE
|SHORT
|USHORT
|INT
|UINT
|LONG
|ULONG
|CHAR
;
floating_point_type:
FLOAT
|DOUBLE
;
enum_type:
type_name
;
nullable_type:
non_nullable_value_type '?'
;
non_nullable_value_type:
enum_type
|type_name
|simple_type
;
reference_type:
class_type
|interface_type
|array_type
|delegate_type
;
class_type:
type_name
|OBJECT
|STRING
;
interface_type:
type_name
;
array_type:
non_array_type rank_specifiers
;
non_array_type:
value_type
|class_type
|interface_type
|delegate_type
|type_parameter
;
rank_specifiers:
rank_specifier
|rank_specifiers rank_specifier
;
rank_specifier:
'[' dim_separatorsopt ']'
;
dim_separators:
','
|dim_separators ','
;
delegate_type:
type_name
;
// A.2.3 Variables
variable_reference:
expression
;
// A.2.4 Expressions
argument_list:
argument
|argument_list ',' argument
;
argument:
expression
|REF variable_reference
|OUT variable_reference
;
primary_expression:
array_creation_expression
|primary_no_array_creation_expression
;
primary_no_array_creation_expression:
LITERAL
|simple_name
|parenthesized_expression
|member_access
|invocation_expression
|element_access
|this_access
|base_access
|post_increment_expression
|post_decrement_expression
|object_creation_expression
|delegate_creation_expression
|typeof_expression
|checked_expression
|unchecked_expression
|default_value_expression
|anonymous_method_expression
;
simple_name:
IDENTIFIER type_argument_listopt
;
parenthesized_expression:
'(' expression ')'
;
member_access:
primary_expression '.' IDENTIFIER type_argument_listopt
|predefined_type '.' IDENTIFIER type_argument_listopt
|qualified_alias_member '.' IDENTIFIER type_argument_listopt
;
predefined_type:
BOOL | BYTE | CHAR | DECIMAL | DOUBLE | FLOAT | INT | LONG
|OBJECT | SBYTE | SHORT | STRING | UINT | ULONG | USHORT
;
invocation_expression:
primary_expression '(' argument_listopt ')'
;
element_access:
primary_no_array_creation_expression '[' expression_list ']'
;
expression_list:
expression
|expression_list ',' expression
;
this_access:
THIS
;
base_access:
BASE '.' IDENTIFIER type_argument_listopt
|BASE '[' expression_list ']'
;
post_increment_expression:
primary_expression PLUS_PLUS
;
post_decrement_expression:
primary_expression MINUS_MINUS
;
object_creation_expression:
NEW type '(' argument_listopt ')'
;
array_creation_expression:
NEW non_array_type '[' expression_list ']' rank_specifiersopt array_initializeropt
|NEW array_type array_initializer
;
delegate_creation_expression:
NEW delegate_type '(' expression ')'
;
typeof_expression:
TYPEOF '(' type ')'
|TYPEOF '(' unbound_type_name ')'
|TYPEOF '(' VOID ')'
;
unbound_type_name:
IDENTIFIER generic_dimension_specifieropt
|IDENTIFIER SEMI_SEMI IDENTIFIER generic_dimension_specifieropt
|unbound_type_name '.' IDENTIFIER generic_dimension_specifieropt
;
generic_dimension_specifier:
'<' commasopt '>'
;
commas:
','
|commas ','
;
checked_expression:
CHECKED '(' expression ')'
;
unchecked_expression:
UNCHECKED '(' expression ')'
;
default_value_expression:
DEFAULT '(' type ')'
;
anonymous_method_expression:
DELEGATE anonymous_method_signatureopt block
;
anonymous_method_signature:
'(' anonymous_method_parameter_listopt ')'
;
anonymous_method_parameter_list:
anonymous_method_parameter
|anonymous_method_parameter_list ',' anonymous_method_parameter
;
anonymous_method_parameter:
parameter_modifieropt type IDENTIFIER
;
unary_expression:
primary_expression
|'+' unary_expression
|'-' unary_expression
|'!' unary_expression
|'~' unary_expression
|pre_increment_expression
|pre_decrement_expression
|cast_expression
;
pre_increment_expression:
PLUS_PLUS unary_expression
;
pre_decrement_expression:
MINUS_MINUS unary_expression
;
cast_expression:
'(' type ')' unary_expression
;
multiplicative_expression:
unary_expression
|multiplicative_expression '*' unary_expression
|multiplicative_expression '/' unary_expression
|multiplicative_expression '%' unary_expression
;
additive_expression:
multiplicative_expression
|additive_expression '+' multiplicative_expression
|additive_expression '-' multiplicative_expression
;
shift_expression:
additive_expression
|shift_expression LT_LT additive_expression
|shift_expression RIGHT_SHIFT additive_expression
;
relational_expression:
shift_expression
|relational_expression '<' shift_expression
|relational_expression '>' shift_expression
|relational_expression LE shift_expression
|relational_expression GE shift_expression
|relational_expression IS type
|relational_expression AS type
;
equality_expression:
relational_expression
|equality_expression EQ_EQ relational_expression
|equality_expression NE relational_expression
;
and_expression:
equality_expression
|and_expression '&' equality_expression
;
exclusive_or_expression:
and_expression
|exclusive_or_expression '^' and_expression
;
inclusive_or_expression:
exclusive_or_expression
|inclusive_or_expression '|' exclusive_or_expression
;
conditional_and_expression:
inclusive_or_expression
|conditional_and_expression AMP_AMP inclusive_or_expression
;
conditional_or_expression:
conditional_and_expression
|conditional_or_expression BAR_BAR conditional_and_expression
;
null_coalescing_expression:
conditional_or_expression
|conditional_or_expression QM_QM null_coalescing_expression
;
conditional_expression:
null_coalescing_expression
|null_coalescing_expression '?' expression ':' expression
;
assignment:
unary_expression assignment_operator expression
;
assignment_operator:
'=' | PLUS_EQ | MINUS_EQ | STAR_EQ | SLASH_EQ | PERCENT_EQ | AMP_EQ | BAR_EQ | CARET_EQ | LT_LT_EQ | RIGHT_SHIFT_ASSIGNMENT
;
expression:
conditional_expression
|assignment
;
constant_expression:
expression
;
boolean_expression:
expression
;
// A.2.5 Statements
statement:
labeled_statement
|declaration_statement
|embedded_statement
;
embedded_statement:
block
|empty_statement
|expression_statement
|selection_statement
|iteration_statement
|jump_statement
|try_statement
|checked_statement
|unchecked_statement
|lock_statement
|using_statement
|yield_statement
;
block:
'{' statement_listopt '}'
;
statement_list:
statement
|statement_list statement
;
empty_statement:
';'
;
labeled_statement:
IDENTIFIER ':' statement
;
declaration_statement:
local_variable_declaration ';'
|local_constant_declaration ';'
;
local_variable_declaration:
type local_variable_declarators
;
local_variable_declarators:
local_variable_declarator
|local_variable_declarators ',' local_variable_declarator
;
local_variable_declarator:
IDENTIFIER
|IDENTIFIER '=' local_variable_initializer
;
local_variable_initializer:
expression
|array_initializer
;
local_constant_declaration:
CONST type constant_declarators
;
constant_declarators:
constant_declarator
|constant_declarators ',' constant_declarator
;
constant_declarator:
IDENTIFIER '=' constant_expression
;
expression_statement:
statement_expression ';'
;
statement_expression:
invocation_expression
|object_creation_expression
|assignment
|post_increment_expression
|post_decrement_expression
|pre_increment_expression
|pre_decrement_expression
;
selection_statement:
if_statement
|switch_statement
;
if_statement:
IF '(' boolean_expression ')' embedded_statement
|IF '(' boolean_expression ')' embedded_statement ELSE embedded_statement
;
switch_statement:
SWITCH '(' expression ')' switch_block
;
switch_block:
'{' switch_sectionsopt '}'
;
switch_sections:
switch_section
|switch_sections switch_section
;
switch_section:
switch_labels statement_list
;
switch_labels:
switch_label
|switch_labels switch_label
;
switch_label:
CASE constant_expression ':'
|DEFAULT ':'
;
iteration_statement:
while_statement
|do_statement
|for_statement
|foreach_statement
;
while_statement:
WHILE '(' boolean_expression ')' embedded_statement
;
do_statement:
DO embedded_statement WHILE '(' boolean_expression ')' ';'
;
for_statement:
FOR '(' for_initializeropt ';' for_conditionopt ';' for_iteratoropt ')' embedded_statement
;
for_initializer:
local_variable_declaration
|statement_expression_list
;
for_condition:
boolean_expression
;
for_iterator:
statement_expression_list
;
statement_expression_list:
statement_expression
|statement_expression_list ',' statement_expression
;
foreach_statement:
FOREACH '(' type IDENTIFIER IN expression ')' embedded_statement
;
jump_statement:
break_statement
|continue_statement
|goto_statement
|return_statement
|throw_statement
;
break_statement:
BREAK ';'
;
continue_statement:
CONTINUE ';'
;
goto_statement:
GOTO IDENTIFIER ';'
|GOTO CASE constant_expression ';'
|GOTO DEFAULT ';'
;
return_statement:
RETURN expressionopt ';'
;
throw_statement:
THROW expressionopt ';'
;
try_statement:
TRY block catch_clauses
|TRY block catch_clausesopt finally_clause
;
catch_clauses:
specific_catch_clauses
|specific_catch_clausesopt general_catch_clause
;
specific_catch_clauses:
specific_catch_clause
|specific_catch_clauses specific_catch_clause
;
specific_catch_clause:
CATCH '(' class_type identifieropt ')' block
;
general_catch_clause:
CATCH block
;
finally_clause:
FINALLY block
;
checked_statement:
CHECKED block
;
unchecked_statement:
UNCHECKED block
;
lock_statement:
LOCK '(' expression ')' embedded_statement
;
using_statement:
USING '(' resource_acquisition ')' embedded_statement
;
resource_acquisition:
local_variable_declaration
|expression
;
yield_statement:
YIELD RETURN expression ';'
|YIELD BREAK ';'
;
namespace_declaration:
NAMESPACE qualified_identifier namespace_body SemicolonOpt
;
qualified_identifier:
IDENTIFIER
|qualified_identifier '.' IDENTIFIER
;
namespace_body:
'{' extern_alias_directivesopt using_directivesopt namespace_member_declarationsopt '}'
;
extern_alias_directives:
extern_alias_directive
|extern_alias_directives extern_alias_directive
;
extern_alias_directive:
EXTERN ALIAS IDENTIFIER ';'
;
using_directives:
using_directive
|using_directives using_directive
;
using_directive:
using_alias_directive
|using_namespace_directive
;
using_alias_directive:
USING IDENTIFIER '=' namespace_or_type_name ';'
;
using_namespace_directive:
USING namespace_name ';'
;
namespace_member_declarations:
namespace_member_declaration
|namespace_member_declarations namespace_member_declaration
;
namespace_member_declaration:
namespace_declaration
|type_declaration
;
type_declaration:
class_declaration
|struct_declaration
|interface_declaration
|enum_declaration
|delegate_declaration
;
qualified_alias_member:
IDENTIFIER SEMI_SEMI IDENTIFIER type_argument_listopt
;
// A.2.6 Classes
class_declaration:
attributesopt class_modifiersopt partialopt CLASS IDENTIFIER type_parameter_listopt
|class_baseopt type_parameter_constraints_clausesopt class_body SemicolonOpt
;
class_modifiers:
class_modifier
|class_modifiers class_modifier
;
class_modifier:
NEW
|PUBLIC
|PROTECTED
|INTERNAL
|PRIVATE
|ABSTRACT
|SEALED
|STATIC
;
class_base:
':' class_type
|':' interface_type_list
|':' class_type ',' interface_type_list
;
interface_type_list:
interface_type
|interface_type_list ',' interface_type
;
class_body:
'{' class_member_declarationsopt '}'
;
class_member_declarations:
class_member_declaration
|class_member_declarations class_member_declaration
;
class_member_declaration:
constant_declaration
|field_declaration
|method_declaration
|property_declaration
|event_declaration
|indexer_declaration
|operator_declaration
|constructor_declaration
|finalizer_declaration
|static_constructor_declaration
|type_declaration
;
constant_declaration:
attributesopt constant_modifiersopt CONST type constant_declarators ';'
;
constant_modifiers:
constant_modifier
|constant_modifiers constant_modifier
;
constant_modifier:
NEW
|PUBLIC
|PROTECTED
|INTERNAL
|PRIVATE
;
constant_declarators:
constant_declarator
|constant_declarators ',' constant_declarator
;
constant_declarator:
IDENTIFIER '=' constant_expression
;
field_declaration:
attributesopt field_modifiersopt type variable_declarators ';'
;
field_modifiers:
field_modifier
|field_modifiers field_modifier
;
field_modifier:
NEW
|PUBLIC
|PROTECTED
|INTERNAL
|PRIVATE
|STATIC
|READONLY
|VOLATILE
;
variable_declarators:
variable_declarator
|variable_declarators ',' variable_declarator
;
variable_declarator:
IDENTIFIER
|IDENTIFIER '=' variable_initializer
;
variable_initializer:
expression
|array_initializer
;
method_declaration:
method_header method_body
;
method_header:
attributesopt method_modifiersopt return_type member_name type_parameter_listopt
|'(' formal_parameter_listopt ')' type_parameter_constraints_clausesopt
;
method_modifiers:
method_modifier
|method_modifiers method_modifier
;
method_modifier:
NEW
|PUBLIC
|PROTECTED
|INTERNAL
|PRIVATE
|STATIC
|VIRTUAL
|SEALED
|OVERRIDE
|ABSTRACT
|EXTERN
;
return_type:
type
|VOID
;
member_name:
IDENTIFIER
|interface_type '.' IDENTIFIER
;
method_body:
block
|';'
;
formal_parameter_list:
fixed_parameters
|fixed_parameters ',' parameter_array
|parameter_array
;
fixed_parameters:
fixed_parameter
|fixed_parameters ',' fixed_parameter
;
fixed_parameter:
attributesopt parameter_modifieropt type IDENTIFIER
;
parameter_modifier:
REF
|OUT
;
parameter_array:
attributesopt PARAMS array_type IDENTIFIER
;
property_declaration:
attributesopt property_modifiersopt type member_name '{' accessor_declarations '}'
;
property_modifiers:
property_modifier
|property_modifiers property_modifier
;
property_modifier:
NEW
|PUBLIC
|PROTECTED
|INTERNAL
|PRIVATE
|STATIC
|VIRTUAL
|SEALED
|OVERRIDE
|ABSTRACT
|EXTERN
;
accessor_declarations:
get_accessor_declaration set_accessor_declarationopt
|set_accessor_declaration get_accessor_declarationopt
;
get_accessor_declaration:
attributesopt accessor_modifieropt GET accessor_body
;
set_accessor_declaration:
attributesopt accessor_modifieropt SET accessor_body
;
accessor_modifier:
PROTECTED
|INTERNAL
|PRIVATE
|PROTECTED INTERNAL
|INTERNAL PROTECTED
;
accessor_body:
block
|';'
;
event_declaration:
attributesopt event_modifiersopt EVENT type variable_declarators ';'
|attributesopt event_modifiersopt EVENT type member_name
|'{' event_accessor_declarations '}'
;
event_modifiers:
event_modifier
|event_modifiers event_modifier
;
event_modifier:
NEW
|PUBLIC
|PROTECTED
|INTERNAL
|PRIVATE
|STATIC
|VIRTUAL
|SEALED
|OVERRIDE
|ABSTRACT
|EXTERN
;
event_accessor_declarations:
add_accessor_declaration remove_accessor_declaration
|remove_accessor_declaration add_accessor_declaration
;
add_accessor_declaration:
attributesopt ADD block
;
remove_accessor_declaration:
attributesopt REMOVE block
;
indexer_declaration:
attributesopt indexer_modifiersopt indexer_declarator '{' accessor_declarations '}'
;
indexer_modifiers:
indexer_modifier
|indexer_modifiers indexer_modifier
;
indexer_modifier: