-
Notifications
You must be signed in to change notification settings - Fork 102
/
ABCPascal.y
3787 lines (3454 loc) · 92.8 KB
/
ABCPascal.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
// SSM 21/11/16 Ëÿìáäà âûðàæåíèÿ âûíåñåíû íà âåðõíèé óðîâåíü (ï.÷. ïðèñâàèâàíèÿ è ïàðàìåòðû)
%{
// Ýòè îáúÿâëåíèÿ äîáàâëÿþòñÿ â êëàññ GPPGParser, ïðåäñòàâëÿþùèé ñîáîé ïàðñåð, ãåíåðèðóåìûé ñèñòåìîé gppg
public syntax_tree_node root; // Êîðíåâîé óçåë ñèíòàêñè÷åñêîãî äåðåâà
public List<Error> errors;
public string current_file_name;
public int max_errors = 10;
public PT parsertools;
public List<compiler_directive> CompilerDirectives;
public ParserLambdaHelper lambdaHelper = new ParserLambdaHelper();
public GPPGParser(AbstractScanner<PascalABCSavParser.Union, LexLocation> scanner) : base(scanner) { }
%}
%output=ABCPascalYacc.cs
%partial
%parsertype GPPGParser
%using PascalABCCompiler.SyntaxTree;
%using PascalABCSavParser;
%using PascalABCCompiler.ParserTools;
%using PascalABCCompiler.Errors;
%using System.Linq;
%namespace GPPGParserScanner
%YYSTYPE PascalABCSavParser.Union
%start parse_goal
%token <ti> tkDirectiveName tkAmpersend tkColon tkDotDot tkPoint tkRoundOpen tkRoundClose tkSemiColon tkSquareOpen tkSquareClose tkQuestion tkQuestionPoint
%token <ti> tkSizeOf tkTypeOf tkWhere tkArray tkCase tkClass tkAuto tkConst tkConstructor tkDestructor tkElse tkExcept tkFile tkFor tkForeach tkFunction
%token <ti> tkIf tkImplementation tkInherited tkInterface tkProcedure tkOperator tkProperty tkRaise tkRecord tkSet tkType tkThen tkUses tkVar tkWhile tkWith tkNil
%token <ti> tkGoto tkOf tkLabel tkLock tkProgram tkEvent tkDefault tkTemplate tkPacked tkExports tkResourceString tkThreadvar tkSealed tkPartial tkTo tkDownto
%token <ti> tkCycle tkSequence tkYield
%token <id> tkNew
%token <id> tkOn
%token <id> tkName tkPrivate tkProtected tkPublic tkInternal tkRead tkWrite
%token <ti> tkParseModeExpression tkParseModeStatement tkParseModeType tkBegin tkEnd
%token <ti> tkAsmBody tkILCode tkError INVISIBLE
%token <ti> tkRepeat tkUntil tkDo tkComma tkFinally tkTry
%token <ti> tkInitialization tkFinalization tkUnit tkLibrary tkExternal tkParams
%token <op> tkAssign tkPlusEqual tkMinusEqual tkMultEqual tkDivEqual tkMinus tkPlus tkSlash tkStar tkEqual tkGreater tkGreaterEqual tkLower tkLowerEqual
%token <op> tkNotEqual tkCSharpStyleOr tkArrow tkOr tkXor tkAnd tkDiv tkMod tkShl tkShr tkNot tkAs tkIn tkIs tkImplicit tkExplicit tkAddressOf tkDeref
%token <id> tkDirectiveName tkIdentifier
%token <stn> tkStringLiteral tkAsciiChar
%token <id> tkAbstract tkForward tkOverload tkReintroduce tkOverride tkVirtual tkExtensionMethod
%token <ex> tkInteger tkFloat tkHex
%type <ti> unit_key_word
%type <stn> assignment
%type <stn> optional_array_initializer
%type <stn> attribute_declarations
%type <stn> ot_visibility_specifier
%type <stn> one_attribute attribute_variable
%type <ex> const_factor const_variable_2 const_term const_variable literal_or_number unsigned_number
%type <stn> program_block
%type <ob> optional_var class_attribute class_attributes class_attributes1
%type <stn> member_list_section optional_component_list_seq_end
%type <stn> const_decl only_const_decl
%type <stn> const_decl_sect
%type <td> object_type record_type
%type <stn> member_list method_decl_list field_or_const_definition_list
%type <stn> case_stmt
%type <stn> case_list
%type <stn> program_decl_sect_list int_decl_sect_list1 inclass_decl_sect_list1 interface_decl_sect_list decl_sect_list decl_sect_list1 inclass_decl_sect_list
%type <stn> field_or_const_definition abc_decl_sect decl_sect int_decl_sect type_decl simple_type_decl simple_field_or_const_definition res_str_decl_sect
%type <stn> method_decl_withattr method_or_property_decl property_definition fp_sect
%type <ex> default_expr tuple
%type <stn> expr_as_stmt
%type <stn> exception_block
%type <stn> external_block
%type <stn> exception_handler
%type <stn> exception_handler_list
%type <stn> exception_identifier
%type <stn> typed_const_list1 typed_const_list optional_expr_list elem_list optional_expr_list_with_bracket expr_list const_elem_list1 const_func_expr_list case_label_list const_elem_list optional_const_func_expr_list elem_list1
%type <stn> enumeration_id expr_l1_list
%type <stn> enumeration_id_list
%type <ex> const_simple_expr term typed_const typed_const_plus typed_var_init_expression expr expr_with_func_decl_lambda const_expr elem range_expr const_elem array_const factor relop_expr expr_l1 simple_expr range_term range_factor
%type <ex> external_directive_ident init_const_expr case_label variable var_reference simple_expr_or_nothing // var_question_colon
%type <ob> for_cycle_type
%type <ex> format_expr
%type <stn> foreach_stmt
%type <stn> for_stmt yield_stmt yield_sequence_stmt
%type <stn> fp_list fp_sect_list
%type <td> file_type sequence_type
%type <stn> var_address
%type <stn> goto_stmt
%type <id> func_name_ident param_name const_field_name func_name_with_template_args identifier_or_keyword unit_name exception_variable const_name func_meth_name_ident label_name type_decl_identifier template_identifier_with_equal
%type <id> program_param identifier identifier_keyword_operatorname func_class_name_ident optional_identifier visibility_specifier
%type <id> property_specifier_directives non_reserved
%type <stn> if_stmt
%type <stn> initialization_part
%type <stn> template_arguments label_list ident_or_keyword_pointseparator_list ident_list param_name_list
%type <stn> inherited_message
%type <stn> implementation_part
%type <stn> interface_part abc_interface_part
%type <stn> simple_type_list
%type <ex> literal one_literal
%type <stn> literal_list
%type <stn> label_decl_sect
%type <stn> lock_stmt
%type <stn> func_name proc_name optional_proc_name qualified_identifier
%type <ex> new_expr allowable_expr_as_stmt
%type <stn> parse_goal parts inclass_block block proc_func_external_block
%type <td> exception_class_type_identifier simple_type_identifier //idp
%type <stn> base_class_name
%type <stn> base_classes_names_list optional_base_classes
%type <ob> one_compiler_directive optional_head_compiler_directives head_compiler_directives program_heading_2 optional_tk_point program_param_list optional_semicolon
%type <ex> operator_name_ident
%type <op> const_relop const_addop assign_operator const_mulop relop addop mulop sign overload_operator
%type <ob> typecast_op
%type <stn> property_specifiers
%type <stn> array_defaultproperty
%type <stn> meth_modificators optional_method_modificators optional_method_modificators1
%type <id> meth_modificator
%type <stn> proc_call
%type <stn> proc_func_constr_destr_decl proc_func_decl inclass_proc_func_decl inclass_proc_func_decl_noclass constr_destr_decl inclass_constr_destr_decl
%type <stn> method_decl proc_func_constr_destr_decl_with_attr proc_func_decl_noclass
%type <td> method_header proc_type_decl procedural_type_kind proc_header procedural_type constr_destr_header proc_func_header
%type <td> func_header method_procfunc_header int_func_header int_proc_header
%type <stn> property_interface
%type <stn> program_file
%type <stn> program_header
%type <stn> parameter_decl
%type <stn> parameter_decl_list property_parameter_list
%type <ex> const_set
%type <ex> question_expr question_constexpr
%type <ex> record_const const_field_list_1 const_field_list
%type <stn> const_field
%type <stn> repeat_stmt
%type <stn> raise_stmt
%type <td> pointer_type
%type <stn> attribute_declaration one_or_some_attribute
%type <stn> stmt_list else_case exception_block_else_branch compound_stmt
%type <td> string_type
%type <ex> sizeof_expr
%type <stn> simple_prim_property_definition simple_property_definition
%type <stn> stmt_or_expression unlabelled_stmt stmt case_item
%type <td> set_type
%type <ex> as_is_expr as_is_constexpr
%type <td> unsized_array_type simple_type_or_ simple_type array_name_for_new_expr foreach_stmt_ident_dype_opt fptype type_ref fptype_noproctype array_type
%type <td> template_param structured_type unpacked_structured_type simple_or_template_type_reference type_ref_or_secific for_stmt_decl_or_assign type_decl_type
%type <stn> type_ref_and_secific_list
%type <stn> type_decl_sect
%type <stn> try_handler
%type <ti> class_or_interface_keyword optional_tk_do keyword reserved_keyword
%type <ex> typeof_expr
%type <stn> simple_fp_sect
%type <stn> template_param_list template_type_params
%type <td> template_type
%type <stn> try_stmt
%type <stn> uses_clause used_units_list
%type <stn> unit_file
%type <stn> used_unit_name
%type <stn> unit_header
%type <stn> var_decl_sect
%type <stn> var_decl var_decl_part /*var_decl_internal*/ field_definition
%type <stn> var_stmt
%type <stn> where_part
%type <stn> where_part_list optional_where_section
%type <stn> while_stmt
%type <stn> with_stmt
%type <ex> variable_as_type dotted_identifier
%type <ex> func_decl_lambda expl_func_decl_lambda
%type <td> lambda_type_ref lambda_type_ref_noproctype
%type <stn> full_lambda_fp_list lambda_simple_fp_sect lambda_function_body lambda_procedure_body optional_full_lambda_fp_list
%type <ob> field_in_unnamed_object list_fields_in_unnamed_object func_class_name_ident_list rem_lambda variable_list var_variable_list
%type <ti> tkAssignOrEqual
%%
parse_goal
: program_file
{ root = $1; }
| unit_file
{ root = $1; }
| parts
{ root = $1; }
;
parts
: tkParseModeExpression expr
{ $$ = $2; }
| tkParseModeType variable_as_type
{ $$ = $2; }
| tkParseModeStatement stmt_or_expression
{ $$ = $2; }
;
stmt_or_expression
: expr
{ $$ = new expression_as_statement($1,@$);}
| assignment
{ $$ = $1; }
| var_stmt
{ $$ = $1; }
;
optional_head_compiler_directives
:
{ $$ = null; }
| head_compiler_directives
{ $$ = null; }
;
head_compiler_directives
: one_compiler_directive
{ $$ = null; }
| head_compiler_directives one_compiler_directive
{ $$ = null; }
;
one_compiler_directive
: tkDirectiveName tkIdentifier
{
parsertools.AddErrorFromResource("UNSUPPORTED_OLD_DIRECTIVES",@$);
$$ = null;
}
| tkDirectiveName tkStringLiteral
{
parsertools.AddErrorFromResource("UNSUPPORTED_OLD_DIRECTIVES",@$);
$$ = null;
}
;
program_file
: program_header optional_head_compiler_directives uses_clause program_block optional_tk_point
{
$$ = NewProgramModule($1 as program_name, $2, $3 as uses_list, $4, $5, @$);
}
;
optional_tk_point /* ýòî íóæíî äëÿ intellisensà ÷òîáû ñòðîèëîñü äåðåâî ïðè îòñóòñòâèè òî÷êè â êîíöå */
: tkPoint
{ $$ = $1; }
| tkSemiColon
{ $$ = null; }
| tkColon
{ $$ = null; }
| tkComma
{ $$ = null; }
| tkDotDot
{ $$ = null; }
|
;
program_header
:
{ $$ = null; }
| tkProgram identifier program_heading_2
{ $$ = new program_name($2,@$); }
;
program_heading_2
: tkSemiColon
{ $$ = null; }
| tkRoundOpen program_param_list tkRoundClose tkSemiColon
{ $$ = null; }
;
program_param_list
: program_param
{ $$ = null; }
| program_param_list tkComma program_param
{ $$ = null; }
;
program_param
: identifier
{ $$ = $1; }
;
program_block
: program_decl_sect_list compound_stmt
{
$$ = new block($1 as declarations, $2 as statement_list, @$);
}
;
program_decl_sect_list
: decl_sect_list
{ $$ = $1; }
;
ident_or_keyword_pointseparator_list
: identifier_or_keyword
{
$$ = new ident_list($1, @$);
}
| ident_or_keyword_pointseparator_list tkPoint identifier_or_keyword
{
$$ = ($1 as ident_list).Add($3, @$);
}
;
uses_clause
:
{
$$ = null;
}
| uses_clause tkUses used_units_list tkSemiColon
{
if (parsertools.build_tree_for_formatter)
{
if ($1 == null)
$1 = new uses_closure($3 as uses_list,@$);
else ($1 as uses_closure).AddUsesList($3 as uses_list,@$);
$$ = $1;
}
else
{
if ($1 == null)
$1 = $3;
else ($1 as uses_list).AddUsesList($3 as uses_list,@$);
$$ = $1;
$$.source_context = @$;
}
}
;
used_units_list
: used_unit_name
{
$$ = new uses_list($1 as unit_or_namespace,@$);
}
| used_units_list tkComma used_unit_name
{
$$ = ($1 as uses_list).Add($3 as unit_or_namespace, @$);
}
;
used_unit_name
: ident_or_keyword_pointseparator_list
{
$$ = new unit_or_namespace($1 as ident_list,@$);
}
| ident_or_keyword_pointseparator_list tkIn tkStringLiteral
{
$$ = new uses_unit_in($1 as ident_list, $3 as string_const, @$);
}
;
unit_file
: attribute_declarations unit_header interface_part implementation_part initialization_part tkPoint
{
$$ = new unit_module($2 as unit_name, $3 as interface_node, $4 as implementation_node, ($5 as initfinal_part).initialization_sect, ($5 as initfinal_part).finalization_sect, $1 as attribute_list, @$);
}
| attribute_declarations unit_header abc_interface_part initialization_part tkPoint
{
$$ = new unit_module($2 as unit_name, $3 as interface_node, null, ($4 as initfinal_part).initialization_sect, ($4 as initfinal_part).finalization_sect, $1 as attribute_list, @$);
}
;
unit_header
: unit_key_word unit_name tkSemiColon optional_head_compiler_directives
{
$$ = NewUnitHeading(new ident($1.text, @1), $2, @$);
}
;
unit_key_word
: tkUnit
{ $$ = $1; }
| tkLibrary
{ $$ = $1; }
;
unit_name
: identifier
{ $$ = $1; }
;
interface_part
: tkInterface uses_clause interface_decl_sect_list
{
$$ = new interface_node($3 as declarations, $2 as uses_list, null, LexLocation.MergeAll(@1,@2,@3));
}
;
implementation_part
: tkImplementation uses_clause decl_sect_list
{
$$ = new implementation_node($2 as uses_list, $3 as declarations, null, LexLocation.MergeAll(@1,@2,@3));
}
;
abc_interface_part
: uses_clause decl_sect_list
{
$$ = new interface_node($2 as declarations, $1 as uses_list, null, null);
}
;
initialization_part
: tkEnd
{
$$ = new initfinal_part();
$$.source_context = @$;
}
| tkInitialization stmt_list tkEnd
{
$$ = new initfinal_part($1, $2 as statement_list, $3, null, null, @$);
}
| tkInitialization stmt_list tkFinalization stmt_list tkEnd
{
$$ = new initfinal_part($1, $2 as statement_list, $3, $4 as statement_list, $5, @$);
}
| tkBegin stmt_list tkEnd
{
$$ = new initfinal_part($1, $2 as statement_list, $3, null, null, @$);
}
;
interface_decl_sect_list
: int_decl_sect_list1
{
if (($1 as declarations).defs.Count > 0)
$$ = $1;
else
$$ = $1;
}
;
int_decl_sect_list1
:
{
$$ = new declarations();
if (GlobalDecls==null)
GlobalDecls = $$ as declarations;
}
| int_decl_sect_list1 int_decl_sect
{
$$ = ($1 as declarations).Add($2 as declaration, @$);
}
;
decl_sect_list
: decl_sect_list1
{
if (($1 as declarations).defs.Count > 0)
$$ = $1;
else
$$ = $1;
}
;
decl_sect_list1
:
{
$$ = new declarations();
if (GlobalDecls==null)
GlobalDecls = $$ as declarations;
}
| decl_sect_list1 decl_sect
{
$$ = ($1 as declarations).Add($2 as declaration, @$);
}
;
inclass_decl_sect_list
: inclass_decl_sect_list1
{
if (($1 as declarations).defs.Count > 0)
$$ = $1;
else
$$ = $1;
}
;
inclass_decl_sect_list1
:
{
$$ = new declarations();
}
| inclass_decl_sect_list1 abc_decl_sect
{
$$ = ($1 as declarations).Add($2 as declaration, @$);
}
;
int_decl_sect
: const_decl_sect
{ $$ = $1; }
| res_str_decl_sect
{ $$ = $1; }
| type_decl_sect
{ $$ = $1; }
| var_decl_sect
{ $$ = $1; }
| int_proc_header
{ $$ = $1; }
| int_func_header
{ $$ = $1; }
;
decl_sect
: label_decl_sect
{ $$ = $1; }
| const_decl_sect
{ $$ = $1; }
| res_str_decl_sect
{ $$ = $1; }
| type_decl_sect
{ $$ = $1; }
| var_decl_sect
{ $$ = $1; }
| proc_func_constr_destr_decl_with_attr
{ $$ = $1; }
;
proc_func_constr_destr_decl /* SSM 2.1.13 óïðîùåíèå ãðàììàòèêè */
: proc_func_decl
{ $$ = $1; }
| constr_destr_decl
{ $$ = $1; }
;
proc_func_constr_destr_decl_with_attr
: attribute_declarations proc_func_constr_destr_decl
{
($2 as procedure_definition).AssignAttrList($1 as attribute_list);
$$ = $2;
}
;
abc_decl_sect
: label_decl_sect
{ $$ = $1; }
| const_decl_sect
{ $$ = $1; }
| res_str_decl_sect
{ $$ = $1; }
| type_decl_sect
{ $$ = $1; }
| var_decl_sect
{ $$ = $1; }
;
int_proc_header
: attribute_declarations proc_header
{
$$ = $2;
($$ as procedure_header).attributes = $1 as attribute_list;
}
| attribute_declarations proc_header tkForward tkSemiColon
{
$$ = NewProcedureHeader($1 as attribute_list, $2 as procedure_header, $3 as procedure_attribute, @$);
}
;
int_func_header
: attribute_declarations func_header
{
$$ = $2;
($$ as procedure_header).attributes = $1 as attribute_list;
}
| attribute_declarations func_header tkForward tkSemiColon
{
$$ = NewProcedureHeader($1 as attribute_list, $2 as procedure_header, $3 as procedure_attribute, @$);
}
;
label_decl_sect
: tkLabel label_list tkSemiColon
{
$$ = new label_definitions($2 as ident_list, @$);
}
;
label_list
: label_name
{
$$ = new ident_list($1, @$);
}
| label_list tkComma label_name
{
$$ = ($1 as ident_list).Add($3, @$);
}
;
label_name
: tkInteger
{
$$ = new ident($1.ToString(), @$);
}
| tkFloat
{
$$ = new ident($1.ToString(), @$);
}
| identifier
{
$$ = $1;
}
;
const_decl_sect
: tkConst const_decl
{
$$ = new consts_definitions_list($2 as const_definition, @$);
}
| const_decl_sect const_decl
{
$$ = ($1 as consts_definitions_list).Add($2 as const_definition, @$);
}
;
res_str_decl_sect
: tkResourceString const_decl
{
$$ = $2;
}
| res_str_decl_sect const_decl
{
$$ = $1;
}
;
type_decl_sect
: tkType type_decl
{
$$ = new type_declarations($2 as type_declaration, @$);
}
| type_decl_sect type_decl
{
$$ = ($1 as type_declarations).Add($2 as type_declaration, @$);
}
;
var_decl_sect
: tkVar var_decl
{
$$ = new variable_definitions($2 as var_def_statement, @$);
}
| tkEvent var_decl
{
$$ = new variable_definitions($2 as var_def_statement, @$);
($2 as var_def_statement).is_event = true;
}
| var_decl_sect var_decl
{
$$ = ($1 as variable_definitions).Add($2 as var_def_statement, @$);
}
;
const_decl
: only_const_decl tkSemiColon
{ $$ = $1; }
;
only_const_decl
: const_name tkEqual init_const_expr
{
$$ = new simple_const_definition($1, $3, @$);
}
| const_name tkColon type_ref tkEqual typed_const
{
$$ = new typed_const_definition($1, $5, $3, @$);
}
;
init_const_expr
: const_expr
{ $$ = $1; }
| array_const
{ $$ = $1; }
;
const_name
: identifier
{ $$ = $1; }
;
expr_l1_list
: expr_l1
{
$$ = new expression_list($1, @$);
}
| expr_l1_list tkComma expr_l1
{
$$ = ($1 as expression_list).Add($3, @$);
}
;
const_expr
: const_simple_expr
{
$$ = $1;
}
| const_simple_expr const_relop const_simple_expr
{
$$ = new bin_expr($1, $3, $2.type, @$);
}
| question_constexpr
{
$$ = $1;
}
;
question_constexpr
: const_expr tkQuestion const_expr tkColon const_expr
{ $$ = new question_colon_expression($1, $3, $5, @$); }
;
const_relop
: tkEqual
{ $$ = $1; }
| tkNotEqual
{ $$ = $1; }
| tkLower
{ $$ = $1; }
| tkGreater
{ $$ = $1; }
| tkLowerEqual
{ $$ = $1; }
| tkGreaterEqual
{ $$ = $1; }
| tkIn
{ $$ = $1; }
;
const_simple_expr
: const_term
{ $$ = $1; }
| const_simple_expr const_addop const_term
{ $$ = new bin_expr($1, $3, $2.type, @$); }
;
const_addop
: tkPlus
{ $$ = $1; }
| tkMinus
{ $$ = $1; }
| tkOr
{ $$ = $1; }
| tkXor
{ $$ = $1; }
;
as_is_constexpr
: const_term typecast_op simple_or_template_type_reference
{
$$ = NewAsIsConstexpr($1, (op_typecast)$2, $3, @$);
}
;
const_term
: const_factor
{ $$ = $1; }
| as_is_constexpr
{ $$ = $1; }
| const_term const_mulop const_factor
{ $$ = new bin_expr($1, $3, $2.type, @$); }
;
const_mulop
: tkStar
{ $$ = $1; }
| tkSlash
{ $$ = $1; }
| tkDiv
{ $$ = $1; }
| tkMod
{ $$ = $1; }
| tkShl
{ $$ = $1; }
| tkShr
{ $$ = $1; }
| tkAnd
{ $$ = $1; }
;
const_factor
: const_variable
{ $$ = $1; }
| const_set
{ $$ = $1; }
| unsigned_number
{ $$ = $1; }
| literal
{ $$ = $1; }
| tkNil
{
$$ = new nil_const();
$$.source_context = @$;
}
| tkAddressOf const_factor
{
$$ = new get_address($2 as addressed_value, @$);
}
| tkRoundOpen const_expr tkRoundClose
{
$$ = new bracket_expr($2, @$);
}
| tkNot const_factor
{
$$ = new un_expr($2, $1.type, @$);
}
| sign const_factor
{
$$ = new un_expr($2, $1.type, @$);
}
| tkDeref const_factor
{
$$ = new roof_dereference($2 as addressed_value, @$);
}
;
const_set
: tkSquareOpen const_elem_list tkSquareClose
{
$$ = new pascal_set_constant($2 as expression_list, @$);
}
;
sign
: tkPlus
{ $$ = $1; }
| tkMinus
{ $$ = $1; }
;
const_variable
: identifier
{ $$ = $1; }
| sizeof_expr
{ $$ = $1; }
| typeof_expr
{ $$ = $1; }
| const_variable const_variable_2
{
$$ = NewConstVariable($1, $2, @$);
}
;
const_variable_2
: tkPoint identifier_or_keyword
{
$$ = new dot_node(null, $2 as addressed_value, @$);
}
| tkDeref
{
$$ = new roof_dereference();
$$.source_context = @$;
}
| tkRoundOpen optional_const_func_expr_list tkRoundClose
{
$$ = new method_call($2 as expression_list, @$);
}
| tkSquareOpen const_elem_list tkSquareClose
{
$$ = new indexer($2 as expression_list, @$);
}
;
optional_const_func_expr_list
: const_func_expr_list
{ $$ = $1; }
|
{ $$ = null; }
;
const_func_expr_list
: const_expr
{
$$ = new expression_list($1, @$);
}
| const_func_expr_list tkComma const_expr
{
$$ = ($1 as expression_list).Add($3, @$);
}
;
const_elem_list
: const_elem_list1
{ $$ = $1; }
|
;
const_elem_list1
: const_elem
{
$$ = new expression_list($1, @$);
}
| const_elem_list1 tkComma const_elem
{
$$ = ($1 as expression_list).Add($3, @$);
}
;
const_elem
: const_expr
{ $$ = $1; }
| const_expr tkDotDot const_expr
{
$$ = new diapason_expr($1, $3, @$);
}
;
unsigned_number
: tkInteger
{ $$ = $1; }
| tkHex
{ $$ = $1; }
| tkFloat
{ $$ = $1; }
;
typed_const
: const_expr
{ $$ = $1; }
| array_const
{ $$ = $1; }
| record_const
{ $$ = $1; }
;
array_const
: tkRoundOpen typed_const_list tkRoundClose
{
$$ = new array_const($2 as expression_list, @$);
}
| tkRoundOpen record_const tkRoundClose
{ $$ = $2; }
| tkRoundOpen array_const tkRoundClose
{ $$ = $2; }
;
typed_const_list
:
| typed_const_list1
{
$$ = $1;
}
;
typed_const_list1
: typed_const_plus
{
$$ = new expression_list($1, @$);
}
| typed_const_list1 tkComma typed_const_plus
{
$$ = ($1 as expression_list).Add($3, @$);
}
;
record_const
: tkRoundOpen const_field_list tkRoundClose
{
$$ = $2;
$$.source_context = @$;
}
;
const_field_list
: const_field_list_1
{ $$ = $1; }
| const_field_list_1 tkSemiColon
{ $$ = $1; }
;
const_field_list_1
: const_field
{
$$ = new record_const($1 as record_const_definition, @$);
}
| const_field_list_1 tkSemiColon const_field
{
$$ = ($1 as record_const).Add($3 as record_const_definition, @$);
}
;
const_field
: const_field_name tkColon typed_const
{
$$ = new record_const_definition($1, $3, @$);
}
;
const_field_name
: identifier
{ $$ = $1; }
;
type_decl
: attribute_declarations simple_type_decl
{
($2 as declaration).attributes = $1 as attribute_list;
$$ = $2;
$$.source_context = @2;
}
;
attribute_declarations
: attribute_declaration
{
$$ = new attribute_list($1 as simple_attribute_list, @$);