-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathfor90.y
More file actions
1993 lines (1896 loc) · 66.3 KB
/
for90.y
File metadata and controls
1993 lines (1896 loc) · 66.3 KB
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
/*
* Calvin Neo
* Copyright (C) 2016 Calvin Neo <calvinneo@calvinneo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
%{
#include <cstdio>
#include <string>
#include <sstream>
#include <iostream>
#include <stdarg.h>
#include <tuple>
#include <stdint.h>
#include "../parser/attribute.h"
#include "../parser/parser.h"
#include "../target/gen_common.h"
#include "../parser/Function.h"
void yyerror(const char* s);
#ifdef USE_LEX
int pure_yylex(void);
void set_buff(const std::string & code);
void release_buff();
#else
#include "simple_lexer.h"
#endif
#define YYDEBUG 1
#define YYERROR_VERBOSE
#define YYINITDEPTH 2000
// update pos os non-terminal tokens(terminal tokens have pos updated in flex using update_flex and update_yylval)
void update_pos(ParseNode & current) {
if (current.length() == 0) {
// do nothing
current.fs.parse_pos = 0;
current.fs.parse_line = 0;
current.fs.parse_len = 0;
current.fs.line_pos = 0;
}
else if (current.length() == 1) {
current.fs.parse_pos = current.get(0).fs.parse_pos;
current.fs.parse_line = current.get(0).fs.parse_line;
current.fs.parse_len = current.get(0).fs.parse_len;
current.fs.line_pos = current.get(0).fs.line_pos;
}
else {
int tot_len = 0;
for (int i = 0; i < current.length(); i++)
{
tot_len += current.get(i).fs.parse_len;
}
current.fs.parse_pos = current.get(0).fs.parse_pos;
current.fs.parse_line = current.get(0).fs.parse_line;
current.fs.parse_len = tot_len;
current.fs.line_pos = current.get(0).fs.line_pos;
}
}
void update_pos(ParseNode & current, const ParseNode & start, const ParseNode & end) {
// if replace $$ with newnode then need to update_pos
if (start.fs.parse_len == 0) {
current.fs.parse_pos = end.fs.parse_pos;
current.fs.parse_line = end.fs.parse_line;
current.fs.parse_len = end.fs.parse_len;
current.fs.line_pos = end.fs.line_pos;
}
else if (end.fs.parse_len == 0) {
current.fs.parse_pos = start.fs.parse_pos;
current.fs.parse_line = start.fs.parse_line;
current.fs.parse_len = start.fs.parse_len;
current.fs.line_pos = start.fs.line_pos;
}
else {
current.fs.parse_pos = start.fs.parse_pos;
current.fs.parse_line = start.fs.parse_line;
current.fs.parse_len = end.fs.parse_len + end.fs.parse_pos - start.fs.parse_pos;
current.fs.line_pos = start.fs.line_pos;
}
}
using namespace std;
%}
%debug
// %glr-parser
//%define api.value.type union
%token /*_YY_VOID*/ YY_IGNORE_THIS YY_CRLF
%token /*_YY_OP*/ YY_GT YY_GE YY_EQ YY_LE YY_LT YY_NEQ YY_NEQV YY_EQV YY_ANDAND YY_OROR YY_NOT YY_POWER YY_DOUBLECOLON YY_NEG YY_POS YY_EXPONENT
%token /*_YY_TYPE*/ YY_INTEGER YY_FLOAT YY_WORD YY_OPERATOR /* Lead to error YY_OPERATOR_UNARY */ YY_STRING YY_ILLEGAL YY_COMPLEX YY_TRUE YY_FALSE YY_FORMAT_STMT YY_COMMENT
%token /*_YY_CONTROL_FLOW*/ YY_LABEL YY_END YY_IF YY_THEN YY_ELSE YY_ELSEIF YY_ENDIF YY_DO YY_ENDDO YY_CONTINUE YY_BREAK YY_EXIT YY_CYCLE YY_WHILE YY_ENDWHILE YY_WHERE YY_ENDWHERE YY_CASE YY_ENDCASE YY_SELECT YY_ENDSELECT YY_GOTO YY_DOWHILE YY_DEFAULT
%token /*_YY_DELIM*/ YY_PROGRAM YY_ENDPROGRAM YY_FUNCTION YY_ENDFUNCTION YY_RECURSIVE YY_RESULT YY_SUBROUTINE YY_ENDSUBROUTINE YY_MODULE YY_ENDMODULE YY_BLOCK YY_ENDBLOCK YY_INTERFACE YY_ENDINTERFACE YY_COMMON YY_DATA
%token /*_YY_DESCRIBER*/ YY_IMPLICIT YY_NONE YY_USE YY_PARAMETER YY_ENTRY YY_DIMENSION YY_ARRAYBUILDER_START YY_ARRAYBUILDER_END YY_INTENT YY_IN YY_OUT YY_INOUT YY_OPTIONAL YY_LEN YY_KIND YY_SAVE YY_ALLOCATABLE YY_TARGET YY_POINTER
%token /*_YY_TYPEDEF*/ YY_INTEGER_T YY_FLOAT_T YY_STRING_T YY_COMPLEX_T YY_BOOL_T YY_CHARACTER_T YY_DOUBLE_T
%token /*_YY_COMMAND*/ YY_WRITE YY_READ YY_PRINT YY_CALL YY_STOP YY_PAUSE YY_RETURN
%token /*_YY_CONFIG*/ YY_CONFIG_IMPLICIT
%token /*_YY_SYSFUNCTION*/ YY_ALLOCATE
/*******************
* TODO: As it's appeared in `exp` rules,
* we must assign priority to `YY_OPERATOR`
* inorder to avoid shift-reduce conflict.
* According to fortran, unary operators have highest priority,
* while binary operators have lowest priority.
* ref http://krsna.lamost.org/popular/fortran/8.htm
* Error on For3d14.for
*******************/
// %left YY_OPERATOR
%left YY_EQV YY_NEQV
%left YY_OROR
%left YY_ANDAND
%right YY_NOT
%left YY_EQ YY_NEQ
%left YY_GT YY_GE YY_LE YY_LT
%right YY_NEG YY_POS
%left '+' '-'
%left '*' '/'
/*******************
* YY_POWER is right associative
* x**y**z -> x**(y**z)
*******************/
%right YY_POWER
// %right YY_OPERATOR_UNARY // Error on For3d14.for
%start fortran_program
%%
crlf_or_not : YY_CRLF
{
$$ = RETURN_NT(gen_token(Term{ TokenMeta::CRLF, "\n" }));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
|
{
$$ = RETURN_NT(gen_token(Term{ TokenMeta::Nop, "" }));
update_pos(YY2ARG($$));
}
at_least_one_end_line : end_of_stmt
{
$$ = RETURN_NT(gen_token(Term{ TokenMeta::CRLF, "\n" }));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| at_least_one_end_line end_of_stmt
{
$$ = RETURN_NT(gen_token(Term{ TokenMeta::CRLF, "\n" }));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($2));
CLEAN_DELETE($1, $2);
}
semicolon : ';'
{
$$ = RETURN_NT(gen_token(Term{ TokenMeta::Semicolon, ";" }));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
end_of_stmt : YY_CRLF
{
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| semicolon
{
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
dummy_function_iden : YY_RECURSIVE
{
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
|
{
$$ = RETURN_NT(gen_dummy());
update_pos(YY2ARG($$));
}
variable_desc_elem : YY_INTENT '(' YY_IN ')'
{
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") }); // intent(in)
set_variabledesc_attr(newnode, true, true, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($4));
CLEAN_DELETE($1, $2, $3, $4);
}
| YY_INTENT '(' YY_OUT ')'
{
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") }); // intent(out)
set_variabledesc_attr(newnode, true, false, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($4));
CLEAN_DELETE($1, $2, $3, $4);
}
| YY_INTENT '(' YY_INOUT ')'
{
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") }); // intent(inout)
set_variabledesc_attr(newnode, true, false, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, true);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($4));
CLEAN_DELETE($1, $2, $3, $4);
}
| YY_DIMENSION '(' paramtable ')'
{
// if write `',' YY_DIMENSION` in `var_def` will cause conflict at ','
// if is array reduce immediately and goto `var_def`
// do not parse array slices here because this is difficult
ARG_OUT dimen_slice = YY2ARG($3);
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN VARDEF") }, dimen_slice);
set_variabledesc_attr(newnode, boost::none, boost::none, boost::none, dimen_slice, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($4));
CLEAN_DELETE($1, $2, $3, $4);
}
| YY_DIMENSION '(' exp ')'
{
// define array like a(1)
ARG_OUT exp_to = YY2ARG($3);
ParseNode slice = promote_exp_to_slice(exp_to);
ParseNode dimen_slice = gen_promote("", TokenMeta::NT_DIMENSLICE, slice);
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN VARDEF") }, dimen_slice);
set_variabledesc_attr(newnode, boost::none, boost::none, boost::none, dimen_slice, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($4));
CLEAN_DELETE($1, $2, $3, $4);
}
| YY_DIMENSION
{
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") });
set_variabledesc_attr(newnode, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_OPTIONAL
{
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") }); // optional
set_variabledesc_attr(newnode, boost::none, boost::none, true, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_PARAMETER
{
// const value
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") }); // const
set_variabledesc_attr(newnode, boost::none, true, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_SAVE
{
// static value
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") }); // static
set_variabledesc_attr(newnode, boost::none, boost::none, boost::none, boost::none, boost::none, true, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_ALLOCATABLE
{
/* allocatable value */
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") }); // allocatable
set_variabledesc_attr(newnode, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, true, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_TARGET
{
// target value
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") }); // target
set_variabledesc_attr(newnode, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, boost::none, true, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
variable_desc : ',' variable_desc_elem variable_desc
{
ParseNode variable_elem = YY2ARG($2);
ParseNode variable_desc = YY2ARG($3);
// target code of slice depend on context
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") });
// merge attrs
newnode.setattr(variable_elem.attr->clone());
get_variabledesc_attr(newnode).merge(get_variabledesc_attr(variable_desc));
// TODO do not add child
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
|
{
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") });
newnode.setattr(new VariableDescAttr());
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$));
}
/*
* (3) The suffix “ - spec” is used consistently for specifiers, such as keyword actual arguments and
* input / output statement specifiers.It also is used for type declaration attribute specifications(for
* example, “array - spec” in R512), and in a few other cases.
* (4) When reference is made to a type parameter, including the surrounding parentheses, the term
* “selector” is used.See, for example, “length - selector”(R507) and “kind - selector”(R505).
*/
type_selector : YY_KIND '=' YY_INTEGER
{
int kind;
ARG_OUT integer = YY2ARG($3);
sscanf(integer.get_what().c_str(), "%d", &kind);
/* type size */
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, "NT_VARIABLEDESC" });
set_variabledesc_attr(newnode, boost::none, boost::none, boost::none, boost::none, kind, boost::none, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| YY_LEN '=' exp
{
// though use std::string
// still need to initialize the string to YY_LEN
int len;
ARG_OUT integer = YY2ARG($3);
sscanf(integer.get_what().c_str(), "%d", &len);
/* string length */
ParseNode newnode = gen_token(Term{ TokenMeta::NT_VARIABLEDESC, WHEN_DEBUG_OR_EMPTY("NT_VARIABLEDESC GENERATED IN") });
set_variabledesc_attr(newnode, boost::none, boost::none, boost::none, boost::none, len, boost::none, boost::none, boost::none, boost::none, boost::none);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
literal : YY_FLOAT
{
// all arguments under `literal` rule is directly from tokenizer
ARG_OUT lit = YY2ARG($1);
$$ = RETURN_NT(gen_token(Term{ TokenMeta::Float, lit.get_what() })); // float number
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_INTEGER YY_EXPONENT YY_INTEGER
{
ARG_OUT base = YY2ARG($1);
ARG_OUT expo = YY2ARG($3);
$$ = RETURN_NT(gen_token(Term{ TokenMeta::Float, base.get_what() + "e" + expo.get_what() })); // float number
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| YY_INTEGER
{
ARG_OUT lit = YY2ARG($1);
$$ = RETURN_NT(gen_token(Term{ TokenMeta::Int, lit.get_what() })); // int number
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_STRING
{
// replace `'` with `"`
ARG_OUT lit = YY2ARG($1);
std::string s = lit.get_what().substr(1, lit.get_what().size() - 2);
$$ = RETURN_NT(gen_token(Term{ TokenMeta::String, "\"" + s + "\"" })); // string
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_TRUE
{
$$ = RETURN_NT(gen_token(Term{ TokenMeta::Bool, "true" })); // bool true
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_FALSE
{
$$ = RETURN_NT(gen_token(Term{ TokenMeta::Bool, "false" })); // bool false
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_COMPLEX
{
ARG_OUT lit = YY2ARG($1);
string strcplx = lit.get_what();
auto splitter = strcplx.find_first_of('_', 0);
$$ = RETURN_NT(gen_token(Term{ TokenMeta::Complex, "forcomplex(" + strcplx.substr(0, splitter) + ", " + strcplx.substr(splitter + 1) + ") " })); //complex
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| error '\n'
{
$$ = $1;
print_error("exp parse error");
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($2));
CLEAN_DELETE($2);
}
variable : YY_WORD
{
ARG_OUT lit = YY2ARG($1);
ParseNode newnode = gen_token(Term{ TokenMeta::UnknownVariant, lit.get_what() });
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
/******************
* R618 section - subscript is subscript
or subscript - triplet
or vector - subscript
* R619 subscript - triplet is[subscript] : [subscript] [: stride]
* R620 stride is scalar - int - expr
* R621 vector - subscript is int - expr
******************/
slice : exp ':' exp
{
// arr[from : to]
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT exp2 = YY2ARG($3);
// target code of slice depend on context
$$ = RETURN_NT(gen_token(Term{ TokenMeta::NT_SLICE, "" }, exp1, exp2));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp ':' exp ':' exp
{
// arr[from : to : step]
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT exp2 = YY2ARG($3);
ARG_OUT exp3 = YY2ARG($5);
// target code of slice depend on context
$$ = RETURN_NT(gen_token(Term{ TokenMeta::NT_SLICE, "" }, exp1, exp2, exp3));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($5));
CLEAN_DELETE($1, $2, $3, $4, $5);
}
| ':'
{
ParseNode from = gen_token(Term{ TokenMeta::META_INTEGER, "foroptional<int>()" });
ParseNode to = gen_token(Term{ TokenMeta::META_INTEGER, "foroptional<int>()" });
ParseNode lb = gen_token(Term{ TokenMeta::NT_VARIABLEINITIALDUMMY, from.get_what() }, from);
ParseNode ub = gen_token(Term{ TokenMeta::NT_VARIABLEINITIALDUMMY, to.get_what() }, to);
// target code of slice depend on context
$$ = RETURN_NT(gen_token(Term{ TokenMeta::NT_SLICE, "" }, lb, ub));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
keyvalue : exp '=' exp
{
// initial value is required in parse tree because it can be an non-terminal `exp`
// non-array initial values
// array_builder is exp
ARG_OUT exp2 = YY2ARG($3);
$$ = RETURN_NT(gen_keyvalue_from_exp(YY2ARG($1), YY2ARG($3)));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
argtable : exp
{
// argtable is used in function call
ARG_OUT exp = YY2ARG($1);
ParseNode newnode = gen_token(Term{ TokenMeta::NT_ARGTABLE_PURE , exp.get_what()}, exp);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| argtable ',' exp
{
ARG_OUT exp = YY2ARG($3);
ARG_OUT argtable = YY2ARG($1);
#ifdef USE_REUSE
ParseNode * newnode = new ParseNode();
reuse_flatten(*newnode, exp, argtable, "%s, %s", TokenMeta::NT_ARGTABLE_PURE, true);
$$ = newnode;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($2);
CLEAN_REUSE($1, $3);
#else
$$ = RETURN_NT(gen_flatten(exp, argtable, "%s, %s", TokenMeta::NT_ARGTABLE_PURE, true));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
#endif
}
dimen_slice : slice
{
/******************
* 1d array
* arr[from : to]
* target code of slice depend on context
******************/
ARG_OUT slice = YY2ARG($1);
// only 1 slice
$$ = RETURN_NT(gen_promote("", TokenMeta::NT_DIMENSLICE, slice));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| dimen_slice ',' slice
{
/******************
* multi dimension array
* arr[from:to, from:to, ...]
* target code of slice depend on context
******************/
ARG_OUT dimen_slice = YY2ARG($1);
ARG_OUT slice = YY2ARG($3);
#ifdef USE_REUSE
ParseNode * newnode = new ParseNode();
reuse_flatten(*newnode, slice, dimen_slice, "%s, %s", TokenMeta::NT_DIMENSLICE, true);
$$ = newnode;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($2);
CLEAN_REUSE($1, $3);
#else
$$ = RETURN_NT(gen_flatten(slice, dimen_slice, "%s, %s", TokenMeta::NT_DIMENSLICE, true));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
#endif
}
| dimen_slice ',' exp
{
/******************
* multi dimension array
* arr[from:to, index, ...]
* target code of slice depend on context
******************/
ARG_OUT dimen_slice = YY2ARG($1);
ARG_OUT exp = YY2ARG($3);
#ifdef USE_REUSE
ParseNode * newnode = new ParseNode();
reuse_flatten(*newnode, exp, dimen_slice, "%s, %s", TokenMeta::NT_DIMENSLICE, true);
$$ = newnode;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($2);
CLEAN_REUSE($1, $3);
#else
$$ = RETURN_NT(gen_flatten(exp, dimen_slice, "%s, %s", TokenMeta::NT_DIMENSLICE, true));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
#endif
}
| argtable ',' slice
{
ARG_OUT argtable = YY2ARG($1);
ARG_OUT slice = YY2ARG($3);
if (!argtable.token_equals(TokenMeta::NT_ARGTABLE_PURE))
{
print_error("Illegal dimen_slice", argtable);
}
// IMPORTANT: can't promote here, or `s(i, 1:j)` cause error, ref `regen_slice`
//newnode = gen_flatten(slice, promote_argtable_to_dimenslice(argtable), "%s, %s", TokenMeta::NT_DIMENSLICE, true);
#ifdef USE_REUSE
ParseNode * newnode = new ParseNode();
reuse_flatten(*newnode, slice, argtable, "%s, %s", TokenMeta::NT_DIMENSLICE, true);
$$ = newnode;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($2);
CLEAN_REUSE($1, $3);
#else
$$ = RETURN_NT(gen_flatten(slice, argtable, "%s, %s", TokenMeta::NT_DIMENSLICE, true));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
#endif
}
function_array_body : variable '(' paramtable ')'
{
// function call OR array index
// NOTE that array index can be A(1:2, 3:4)
ARG_OUT callable_head = YY2ARG($1);
ARG_OUT argtable = YY2ARG($3);
ParseNode newnode = gen_token(Term{TokenMeta::NT_FUCNTIONARRAY, WHEN_DEBUG_OR_EMPTY("FUNCTIONARRAY GENERATED IN REGEN_SUITE") }, callable_head, argtable);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($4));
CLEAN_DELETE($1, $2, $3, $4);
}
| type_name '(' paramtable ')'
{
// function call OR array index
// NOTE that array index can be A(1:2, 3:4)
ARG_OUT callable_head = YY2ARG($1);
ARG_OUT argtable = YY2ARG($3);
ParseNode newnode = gen_token(Term{ TokenMeta::NT_FUCNTIONARRAY, WHEN_DEBUG_OR_EMPTY("FUNCTIONARRAY GENERATED IN REGEN_SUITE") }, callable_head, argtable);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($4));
CLEAN_DELETE($1, $2, $3, $4);
}
function_array : function_array_body
{
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| YY_CALL function_array_body
{
$$ = $2;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_CALL variable
{
/******************
* call-stmt
* function call can omit trailing `()` if there's no arguments
* e.g.
* ```
* call func
* ```
* `func` is not a variable, but a function
* SHOULDN"T GENERATE VARDEF FOR `func`
*******************/
ARG_OUT callable_head = YY2ARG($2);
ParseNode newnode = gen_token(Term{TokenMeta::NT_FUCNTIONARRAY, WHEN_DEBUG_OR_EMPTY("FUNCTIONARRAY GENERATED IN REGEN_SUITE") }
, callable_head, gen_token(Term{TokenMeta::NT_ARGTABLE_PURE, ""}) );
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($2));
CLEAN_DELETE($1, $2);
}
exp : function_array
{
/******************
* this is sth callable, maybe array section(NT_DIMENSLICE) or function
******************/
ARG_OUT function_array = YY2ARG($1);
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| array_builder
{
// don't promote to exp, and gen_vardel_array will consider this node as array_builder
ARG_OUT array_builder_elem = YY2ARG($1);
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| '(' exp ')'
{
// `function_array` rule MUST have priority over this rule
ARG_OUT exp = YY2ARG($2);
ParseNode opnew = gen_token(Term{ TokenMeta::LB, "( %s )" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp '+' exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::Add, "%s + %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp '-' exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::Minus, "%s - %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp '*' exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::Multiply, "%s * %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp '/' exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::Divide, "%s / %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp YY_POWER exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::Power, "power(%s, %s)" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| '-' %prec YY_NEG exp
{
ARG_OUT exp1 = YY2ARG($2);
ARG_OUT op = YY2ARG($1);
ParseNode opnew = gen_token(Term{ TokenMeta::Neg, "(-%s)" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($2));
CLEAN_DELETE($1, $2);
}
| '+' %prec YY_POS exp
{
ARG_OUT exp1 = YY2ARG($2);
ARG_OUT op = YY2ARG($1);
ParseNode opnew = gen_token(Term{ TokenMeta::Pos, "%s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($2));
CLEAN_DELETE($1, $2);
}
| exp YY_NEQ exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::NEQ, "%s != %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp YY_NEQV exp
{
// xor
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::NEQV, "%s ^ %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp YY_EQ exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::EQ, "%s == %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp YY_EQV exp
{
// nor
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::EQV, "!(%s ^ %s)" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp YY_ANDAND exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::AndAnd, "%s && %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp YY_OROR exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::OrOr, "%s || %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| YY_NOT exp
{
ARG_OUT exp1 = YY2ARG($2);
ARG_OUT op = YY2ARG($1);
ParseNode opnew = gen_token(Term{ TokenMeta::OrOr, "!(%s)" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($2));
CLEAN_DELETE($1, $2);
}
| exp YY_GT exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::GT, "%s > %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp YY_GE exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::GE, "%s >= %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp YY_LE exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::LE, "%s <= %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
}
| exp YY_LT exp
{
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
ParseNode opnew = gen_token(Term{ TokenMeta::LT, "%s < %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| exp YY_OPERATOR exp
{
// TODO may have error priority
ARG_OUT exp1 = YY2ARG($1);
ARG_OUT op = YY2ARG($2);
ARG_OUT exp2 = YY2ARG($3);
const string & op_name = op.get_what();
auto keyword_iter = find_if(keywords.begin(), keywords.end(), [&](const auto & x) {return x.what == op_name; });
if (keyword_iter != keywords.end())
{
// this is a keyword
}
else {
fatal_error("self-defined operator is not supported", op);
}
ParseNode opnew = gen_token(Term{ keyword_iter->token, "%s " + op_name + " %s" });
$$ = RETURN_NT(gen_promote(opnew.get_what(), TokenMeta::NT_EXPRESSION, exp1, exp2, opnew));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($3));
CLEAN_DELETE($1, $2, $3);
}
| hidden_do
{
ARG_OUT hidden_do = YY2ARG($1);
//$$ = RETURN_NT(gen_token(Term{ TokenMeta::NT_EXPRESSION, hidden_do.get_what() }, hidden_do));
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| literal
{
/******************
* shouldn't promote literals to NT_EXPRESSION,
* because it can bring trouble to hardcoded dealt values
* e.g.
* when generating NT_SLICE, we can set a default lower bound UBOUND_DELTA_STR = `1`,
* and we hard code the UBOUND_DELTA_STR
* if we promote literals to NT_EXPRESSION, we should write
* `gen_token(Term{TokenMeta::NT_EXPRESSION, UBOUND_DELTA_STR}, gen_token(Term{TokenMeta::Int, UBOUND_DELTA_STR}))`
* it's not elegant
******************/
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
//| integer_promoted
// {
// $$ = $1;
// update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
// }
| variable
{
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
stmt : exp
{
/******************
* formerly, considering `stmt` are completed by `\n` or certain mark like `end do(enddo)`
* so `stmt` is used to have a list of children
* however, now,
******************/
$$ = RETURN_NT(gen_promote("%s;", TokenMeta::NT_STATEMENT, YY2ARG($1)));
insert_comments(YY2ARG($$));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| var_def
{
$$ = $1;
insert_comments(YY2ARG($$));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| compound_stmt
{
$$ = $1;
insert_comments(YY2ARG($$));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| io_stmt
{
$$ = $1;
insert_comments(YY2ARG($$));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| implicit_stmt
{
$$ = $1;
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| let_stmt
{
$$ = RETURN_NT(gen_promote("%s;", TokenMeta::NT_STATEMENT, YY2ARG($1)));
insert_comments(YY2ARG($$));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| common_stmt
{
$$ = $1;
insert_comments(YY2ARG($$));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| YY_FORMAT_STMT
{
ARG_OUT format = YY2ARG($1);
ParseNode newnode = gen_token(Term{ TokenMeta::NT_FORMAT, "\"" + format.to_string() + "\"" }, format);
$$ = RETURN_NT(newnode);
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_COMMENT
{
ARG_OUT comment = YY2ARG($1);
$$ = RETURN_NT(gen_comment(comment.get_what()));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| control_stmt
{
$$ = $1;
insert_comments(YY2ARG($$));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
| allocate_stmt
{
$$ = $1;
insert_comments(YY2ARG($$));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
}
|
{
$$ = RETURN_NT(gen_token(Term{ TokenMeta::NT_STATEMENT, "" }));
update_pos(YY2ARG($$));
}
control_stmt : pause_stmt
{
$$ = RETURN_NT(gen_promote("%s;", TokenMeta::NT_CONTROL_STMT, YY2ARG($1)));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| stop_stmt
{
$$ = RETURN_NT(gen_promote("%s;", TokenMeta::NT_CONTROL_STMT, YY2ARG($1)));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}
| YY_CONTINUE
{
$$ = RETURN_NT(gen_promote("nop();", TokenMeta::NT_CONTROL_STMT, YY2ARG($1)));
update_pos(YY2ARG($$), YY2ARG($1), YY2ARG($1));
CLEAN_DELETE($1);
}