forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.yy
More file actions
2422 lines (2142 loc) · 79.6 KB
/
parser.yy
File metadata and controls
2422 lines (2142 loc) · 79.6 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
%require "3.0"
%define api.pure
%define api.value.type {LFortran::YYSTYPE}
%param {LFortran::Parser &p}
%locations
%glr-parser
%expect 197 // shift/reduce conflicts
%expect-rr 171 // reduce/reduce conflicts
// Uncomment this to get verbose error messages
//%define parse.error verbose
/*
// Uncomment this to enable parser tracing. Then in the main code, set
// extern int yydebug;
// yydebug=1;
%define parse.trace
%printer { fprintf(yyo, "%s", $$.str().c_str()); } <string>
%printer { fprintf(yyo, "%d", $$); } <n>
%printer { std::cerr << "AST TYPE: " << $$->type; } <ast>
*/
%code requires // *.h
{
#include <lpython/parser/parser.h>
}
%code // *.cpp
{
#include <lpython/parser/parser.h>
#include <lpython/parser/tokenizer.h>
#include <lpython/parser/semantics.h>
int yylex(LFortran::YYSTYPE *yylval, YYLTYPE *yyloc, LFortran::Parser &p)
{
return p.m_tokenizer.lex(p.m_a, *yylval, *yyloc, p.diag);
} // ylex
void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg)
{
p.handle_yyerror(*yyloc, msg);
}
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).first = YYRHSLOC (Rhs, 1).first; \
(Current).last = YYRHSLOC (Rhs, N).last; \
} \
else \
{ \
(Current).first = (Current).last = \
YYRHSLOC (Rhs, 0).last; \
} \
while (0)
} // code
// -----------------------------------------------------------------------------
// List of tokens
// All tokens that we use (including "+" and such) are declared here first
// using the %token line. Each token will end up a member of the "enum
// yytokentype" in parser.tab.hh. Tokens can have a string equivalent (such as
// "+" for TK_PLUS) that is used later in the file to simplify reading it, but
// it is equivalent to TK_PLUS. Bison also allows so called "character token
// type" which are specified using single quotes (and that bypass the %token
// definitions), and those are not used here, and we test that the whole file
// does not contain any single quotes to ensure that.
//
// If this list is updated, update also token2text() in parser.cpp.
// Terminal tokens
%token END_OF_FILE 0
%token TK_NEWLINE
%token <string> TK_NAME
%token <string> TK_DEF_OP
%token <int_suffix> TK_INTEGER
%token <n> TK_LABEL
%token <string> TK_REAL
%token <string> TK_BOZ_CONSTANT
%token TK_PLUS "+"
%token TK_MINUS "-"
%token TK_STAR "*"
%token TK_SLASH "/"
%token TK_COLON ":"
%token TK_SEMICOLON ";"
%token TK_COMMA ","
%token TK_EQUAL "="
%token TK_LPAREN "("
%token TK_RPAREN ")"
%token TK_LBRACKET "["
%token TK_RBRACKET "]"
%token TK_RBRACKET_OLD "/)"
%token TK_PERCENT "%"
%token TK_VBAR "|"
%token <string> TK_STRING
%token <string> TK_COMMENT
%token <string> TK_EOLCOMMENT
%token TK_DBL_DOT ".."
%token TK_DBL_COLON "::"
%token TK_POW "**"
%token TK_CONCAT "//"
%token TK_ARROW "=>"
%token TK_EQ "=="
%token TK_NE "/="
%token TK_LT "<"
%token TK_LE "<="
%token TK_GT ">"
%token TK_GE ">="
%token TK_NOT ".not."
%token TK_AND ".and."
%token TK_OR ".or."
%token TK_XOR ".xor."
%token TK_EQV ".eqv."
%token TK_NEQV ".neqv."
%token TK_TRUE ".true."
%token TK_FALSE ".false."
%token <string> TK_FORMAT
// Terminal tokens: semi-reserved keywords
%token <string> KW_ABSTRACT
%token <string> KW_ALL
%token <string> KW_ALLOCATABLE
%token <string> KW_ALLOCATE
%token <string> KW_ASSIGN
%token <string> KW_ASSIGNMENT
%token <string> KW_ASSOCIATE
%token <string> KW_ASYNCHRONOUS
%token <string> KW_BACKSPACE
%token <string> KW_BIND
%token <string> KW_BLOCK
%token <string> KW_CALL
%token <string> KW_CASE
%token <string> KW_CHANGE
%token <string> KW_CHANGE_TEAM
%token <string> KW_CHARACTER
%token <string> KW_CLASS
%token <string> KW_CLOSE
%token <string> KW_CODIMENSION
%token <string> KW_COMMON
%token <string> KW_COMPLEX
%token <string> KW_CONCURRENT
%token <string> KW_CONTAINS
%token <string> KW_CONTIGUOUS
%token <string> KW_CONTINUE
%token <string> KW_CRITICAL
%token <string> KW_CYCLE
%token <string> KW_DATA
%token <string> KW_DEALLOCATE
%token <string> KW_DEFAULT
%token <string> KW_DEFERRED
%token <string> KW_DIMENSION
%token <string> KW_DO
%token <string> KW_DOWHILE
%token <string> KW_DOUBLE
%token <string> KW_DOUBLE_PRECISION
%token <string> KW_ELEMENTAL
%token <string> KW_ELSE
%token <string> KW_ELSEIF
%token <string> KW_ELSEWHERE
%token <string> KW_END
%token <string> KW_END_PROGRAM
%token <string> KW_ENDPROGRAM
%token <string> KW_END_MODULE
%token <string> KW_ENDMODULE
%token <string> KW_END_SUBMODULE
%token <string> KW_ENDSUBMODULE
%token <string> KW_END_BLOCK
%token <string> KW_ENDBLOCK
%token <string> KW_END_BLOCK_DATA
%token <string> KW_ENDBLOCKDATA
%token <string> KW_END_SUBROUTINE
%token <string> KW_ENDSUBROUTINE
%token <string> KW_END_FUNCTION
%token <string> KW_ENDFUNCTION
%token <string> KW_END_PROCEDURE
%token <string> KW_ENDPROCEDURE
%token <string> KW_END_ENUM
%token <string> KW_ENDENUM
%token <string> KW_END_SELECT
%token <string> KW_ENDSELECT
%token <string> KW_END_IF
%token <string> KW_ENDIF
%token <string> KW_END_INTERFACE
%token <string> KW_ENDINTERFACE
%token <string> KW_END_TYPE
%token <string> KW_ENDTYPE
%token <string> KW_END_ASSOCIATE
%token <string> KW_ENDASSOCIATE
%token <string> KW_END_FORALL
%token <string> KW_ENDFORALL
%token <string> KW_END_DO
%token <string> KW_ENDDO
%token <string> KW_END_WHERE
%token <string> KW_ENDWHERE
%token <string> KW_END_CRITICAL
%token <string> KW_ENDCRITICAL
%token <string> KW_END_FILE
%token <string> KW_ENDFILE
%token <string> KW_END_TEAM
%token <string> KW_ENDTEAM
%token <string> KW_ENTRY
%token <string> KW_ENUM
%token <string> KW_ENUMERATOR
%token <string> KW_EQUIVALENCE
%token <string> KW_ERRMSG
%token <string> KW_ERROR
%token <string> KW_EVENT
%token <string> KW_EXIT
%token <string> KW_EXTENDS
%token <string> KW_EXTERNAL
%token <string> KW_FILE
%token <string> KW_FINAL
%token <string> KW_FLUSH
%token <string> KW_FORALL
%token <string> KW_FORMATTED
%token <string> KW_FORM
%token <string> KW_FORM_TEAM
%token <string> KW_FUNCTION
%token <string> KW_GENERIC
%token <string> KW_GO
%token <string> KW_GOTO
%token <string> KW_IF
%token <string> KW_IMAGES
%token <string> KW_IMPLICIT
%token <string> KW_IMPORT
%token <string> KW_IMPURE
%token <string> KW_IN
%token <string> KW_INCLUDE
%token <string> KW_INOUT
%token <string> KW_IN_OUT
%token <string> KW_INQUIRE
%token <string> KW_INTEGER
%token <string> KW_INTENT
%token <string> KW_INTERFACE
%token <string> KW_INTRINSIC
%token <string> KW_IS
%token <string> KW_KIND
%token <string> KW_LEN
%token <string> KW_LOCAL
%token <string> KW_LOCAL_INIT
%token <string> KW_LOGICAL
%token <string> KW_MEMORY
%token <string> KW_MODULE
%token <string> KW_MOLD
%token <string> KW_NAME
%token <string> KW_NAMELIST
%token <string> KW_NEW_INDEX
%token <string> KW_NOPASS
%token <string> KW_NON_INTRINSIC
%token <string> KW_NON_OVERRIDABLE
%token <string> KW_NON_RECURSIVE
%token <string> KW_NONE
%token <string> KW_NULLIFY
%token <string> KW_ONLY
%token <string> KW_OPEN
%token <string> KW_OPERATOR
%token <string> KW_OPTIONAL
%token <string> KW_OUT
%token <string> KW_PARAMETER
%token <string> KW_PASS
%token <string> KW_POINTER
%token <string> KW_POST
%token <string> KW_PRECISION
%token <string> KW_PRINT
%token <string> KW_PRIVATE
%token <string> KW_PROCEDURE
%token <string> KW_PROGRAM
%token <string> KW_PROTECTED
%token <string> KW_PUBLIC
%token <string> KW_PURE
%token <string> KW_QUIET
%token <string> KW_RANK
%token <string> KW_READ
%token <string> KW_REAL
%token <string> KW_RECURSIVE
%token <string> KW_REDUCE
%token <string> KW_RESULT
%token <string> KW_RETURN
%token <string> KW_REWIND
%token <string> KW_SAVE
%token <string> KW_SELECT
%token <string> KW_SELECT_CASE
%token <string> KW_SELECT_RANK
%token <string> KW_SELECT_TYPE
%token <string> KW_SEQUENCE
%token <string> KW_SHARED
%token <string> KW_SOURCE
%token <string> KW_STAT
%token <string> KW_STOP
%token <string> KW_SUBMODULE
%token <string> KW_SUBROUTINE
%token <string> KW_SYNC
%token <string> KW_SYNC_ALL
%token <string> KW_SYNC_IMAGES
%token <string> KW_SYNC_MEMORY
%token <string> KW_SYNC_TEAM
%token <string> KW_TARGET
%token <string> KW_TEAM
%token <string> KW_TEAM_NUMBER
%token <string> KW_THEN
%token <string> KW_TO
%token <string> KW_TYPE
%token <string> KW_UNFORMATTED
%token <string> KW_USE
%token <string> KW_VALUE
%token <string> KW_VOLATILE
%token <string> KW_WAIT
%token <string> KW_WHERE
%token <string> KW_WHILE
%token <string> KW_WRITE
// Nonterminal tokens
%type <ast> expr
%type <vec_ast> expr_list
%type <vec_ast> expr_list_opt
%type <ast> id
%type <vec_ast> id_list
%type <vec_ast> id_list_opt
%type <ast> script_unit
%type <ast> module
%type <ast> submodule
%type <ast> block_data
%type <ast> decl
%type <vec_ast> decl_star
%type <ast> interface_decl
%type <ast> interface_stmt
%type <ast> derived_type_decl
%type <ast> enum_decl
%type <ast> program
%type <ast> subroutine
%type <ast> procedure
%type <ast> sub_or_func
%type <vec_ast> sub_args
%type <ast> function
%type <ast> use_statement
%type <ast> use_statement1
%type <vec_ast> use_statement_star
%type <ast> use_symbol
%type <vec_ast> use_symbol_list
%type <ast> use_modifier
%type <vec_ast> use_modifiers
%type <vec_ast> use_modifier_list
%type <vec_ast> var_decl_star
%type <vec_var_sym> var_sym_decl_list
%type <ast> var_decl
%type <ast> decl_spec
%type <var_sym> var_sym_decl
%type <vec_dim> array_comp_decl_list
%type <vec_codim> coarray_comp_decl_list
%type <fnarg> fnarray_arg
%type <vec_fnarg> fnarray_arg_list_opt
%type <coarrayarg> coarray_arg
%type <vec_coarrayarg> coarray_arg_list
%type <dim> array_comp_decl
%type <codim> coarray_comp_decl
%type <ast> var_type
%type <ast> fn_mod
%type <vec_ast> fn_mod_plus
%type <vec_ast> var_modifiers
%type <vec_ast> enum_var_modifiers
%type <vec_ast> var_modifier_list
%type <ast> var_modifier
%type <ast> statement
%type <ast> statement1
%type <ast> single_line_statement
%type <ast> multi_line_statement
%type <ast> multi_line_statement0
%type <ast> assign_statement
%type <ast> assignment_statement
%type <ast> goto_statement
%type <ast> associate_statement
%type <ast> associate_block
%type <ast> block_statement
%type <ast> subroutine_call
%type <ast> allocate_statement
%type <ast> deallocate_statement
%type <ast> nullify_statement
%type <ast> print_statement
%type <ast> format
%type <ast> open_statement
%type <ast> flush_statement
%type <ast> close_statement
%type <ast> write_statement
%type <ast> read_statement
%type <ast> inquire_statement
%type <ast> rewind_statement
%type <ast> backspace_statement
%type <ast> endfile_statement
%type <ast> if_statement
%type <ast> if_statement_single
%type <ast> if_block
%type <ast> elseif_block
%type <ast> where_statement
%type <ast> where_statement_single
%type <ast> where_block
%type <ast> select_statement
%type <ast> select_type_statement
%type <vec_ast> select_type_body_statements
%type <ast> select_type_body_statement
%type <ast> select_rank_statement
%type <vec_ast> select_rank_case_stmts
%type <ast> select_rank_case_stmt
%type <vec_ast> case_statements
%type <ast> case_statement
%type <vec_ast> case_conditions
%type <ast> case_condition
%type <ast> while_statement
%type <ast> critical_statement
%type <ast> change_team_statement
%type <vec_ast> coarray_association_list
%type <ast> coarray_association
%type <ast> do_statement
%type <ast> forall_statement
%type <ast> forall_statement_single
%type <vec_ast> concurrent_locality_star
%type <ast> concurrent_locality
%type <reduce_op_type> reduce_op
%type <ast> exit_statement
%type <ast> return_statement
%type <ast> cycle_statement
%type <ast> continue_statement
%type <ast> stop_statement
%type <ast> entry_statement
%type <ast> error_stop_statement
%type <ast> event_post_statement
%type <ast> event_wait_statement
%type <ast> sync_all_statement
%type <ast> sync_images_statement
%type <ast> sync_memory_statement
%type <ast> sync_team_statement
%type <vec_ast> event_wait_spec_list
%type <ast> event_wait_spec
%type <vec_ast> sync_stat_list
%type <vec_ast> event_post_stat_list
%type <ast> sync_stat
%type <ast> format_statement
%type <ast> form_team_statement
%type <ast> decl_statement
%type <vec_ast> statements
%type <vec_ast> decl_statements
%type <vec_ast> contains_block_opt
%type <vec_ast> sub_or_func_plus
%type <ast> result_opt
%type <ast> result
%type <string> inout
%type <vec_ast> concurrent_control_list
%type <ast> concurrent_control
%type <vec_var_sym> named_constant_def_list
%type <var_sym> named_constant_def
%type <vec_var_sym> common_block_list
%type <var_sym> common_block
%type <vec_ast> data_set_list
%type <ast> data_set
%type <vec_ast> data_object_list
%type <vec_ast> data_stmt_value_list
%type <ast> data_stmt_value
%type <ast> data_stmt_repeat
%type <ast> data_stmt_constant
%type <ast> data_object
%type <ast> integer_type
%type <vec_kind_arg> kind_arg_list
%type <kind_arg> kind_arg2
%type <vec_ast> interface_body
%type <ast> interface_item
%type <interface_op_type> operator_type
%type <ast> write_arg
%type <argstarkw> write_arg2
%type <vec_argstarkw> write_arg_list
%type <struct_member> struct_member
%type <vec_struct_member> struct_member_star
%type <ast> bind
%type <ast> bind_opt
%type <vec_ast> import_statement_star
%type <ast> import_statement
%type <ast> implicit_statement
%type <vec_ast> implicit_statement_star
%type <ast> implicit_none_spec
%type <vec_ast> implicit_none_spec_list
%type <ast> letter_spec
%type <vec_ast> letter_spec_list
%type <ast> procedure_decl
%type <vec_ast> access_spec_list
%type <ast> access_spec
%type <ast> proc_modifier
%type <vec_ast> procedure_list
%type <vec_ast> derived_type_contains_opt
%type <vec_ast> proc_modifiers
%type <vec_ast> proc_modifier_list
%type <equi> equivalence_set
%type <vec_equi> equivalence_set_list
%type <ast> sep_one
%type <vec_ast> sep
// Precedence
%left TK_DEF_OP
%left ".eqv." ".neqv."
%left ".or." ".xor."
%left ".and."
%precedence ".not."
%left "==" "/=" "<" "<=" ">" ">="
%left "//"
%left "-" "+"
%left "*" "/"
%precedence UMINUS
%right "**"
%start units
%%
// The order of rules does not matter in Bison (unlike in ANTLR). The
// precedence is specified not by the order but by %left and %right directives
// as well as with %dprec.
// ----------------------------------------------------------------------------
// Top level rules to be used for parsing.
// Higher %dprec means higher precedence
units
: units script_unit %dprec 9 { RESULT($2); }
| script_unit %dprec 10 { RESULT($1); }
| sep
;
script_unit
: module
| submodule
| block_data
| program
| subroutine
| procedure
| function
| use_statement
| implicit_statement
| var_decl
| statement %dprec 7
| expr sep %dprec 8
;
// ----------------------------------------------------------------------------
// Module definitions
//
// * private/public blocks
// * interface blocks
//
module
: KW_MODULE id sep use_statement_star implicit_statement_star
decl_star contains_block_opt end_module sep {
$$ = MODULE($2, TRIVIA($3, $9, @$), $4, $5, $6, $7, @$); }
;
submodule
: KW_SUBMODULE "(" id ")" id sep use_statement_star implicit_statement_star
decl_star contains_block_opt end_submodule sep {
$$ = SUBMODULE($3, $5, TRIVIA($6, $12, @$), $7, $8, $9, $10, @$); }
| KW_SUBMODULE "(" id ":" id ")" id sep use_statement_star
implicit_statement_star decl_star
contains_block_opt end_submodule sep {
$$ = SUBMODULE1($3, $5, $7, TRIVIA($8, $14, @$), $9, $10, $11, $12, @$); }
;
block_data
: KW_BLOCK KW_DATA sep use_statement_star implicit_statement_star
decl_star end_blockdata sep {
$$ = BLOCKDATA(TRIVIA($3, $8, @$), $4, $5, $6, @$); }
| KW_BLOCK KW_DATA id sep use_statement_star implicit_statement_star
decl_star end_blockdata sep {
$$ = BLOCKDATA1($3, TRIVIA($4, $9, @$), $5, $6, $7, @$); }
;
interface_decl
: interface_stmt sep interface_body endinterface sep {
$$ = INTERFACE($1, TRIVIA($2, $5, @$), $3, @$); }
;
interface_stmt
: KW_INTERFACE { $$ = INTERFACE_HEADER(@$); }
| KW_INTERFACE id { $$ = INTERFACE_HEADER_NAME($2, @$); }
| KW_INTERFACE KW_ASSIGNMENT "(" "=" ")" {
$$ = INTERFACE_HEADER_ASSIGNMENT(@$); }
| KW_INTERFACE KW_OPERATOR "(" operator_type ")" {
$$ = INTERFACE_HEADER_OPERATOR($4, @$); }
| KW_INTERFACE KW_OPERATOR "(" "/)" {
$$ = INTERFACE_HEADER_OPERATOR(OPERATOR(DIV, @$), @$); }
| KW_INTERFACE KW_OPERATOR "(" TK_DEF_OP ")" {
$$ = INTERFACE_HEADER_DEFOP($4, @$); }
| KW_ABSTRACT KW_INTERFACE { $$ = ABSTRACT_INTERFACE_HEADER(@$); }
| KW_INTERFACE KW_WRITE "(" id ")" { $$ = INTERFACE_HEADER_WRITE($4, @$); }
| KW_INTERFACE KW_READ "(" id ")" { $$ = INTERFACE_HEADER_READ($4, @$); }
;
endinterface
: endinterface0
| endinterface0 id
| endinterface0 KW_ASSIGNMENT "(" "=" ")"
| endinterface0 KW_OPERATOR "(" operator_type ")"
| endinterface0 KW_OPERATOR "(" "/)"
| endinterface0 KW_OPERATOR "(" TK_DEF_OP ")"
;
endinterface0
: KW_END_INTERFACE
| KW_ENDINTERFACE
;
interface_body
: interface_body interface_item { $$ = $1; LIST_ADD($$, $2); }
| %empty { LIST_NEW($$); }
;
interface_item
: fn_mod_plus KW_PROCEDURE id_list sep {
$$ = INTERFACE_MODULE_PROC1($1, $3, TRIVIA_AFTER($4, @$), @$); }
| fn_mod_plus KW_PROCEDURE "::" id_list sep {
$$ = INTERFACE_MODULE_PROC1($1, $4, TRIVIA_AFTER($5, @$), @$); }
| KW_PROCEDURE id_list sep {
$$ = INTERFACE_MODULE_PROC($2, TRIVIA_AFTER($3, @$), @$); }
| KW_PROCEDURE "::" id_list sep {
$$ = INTERFACE_MODULE_PROC($3, TRIVIA_AFTER($4, @$), @$); }
| subroutine {
$$ = INTERFACE_PROC($1, @$); }
| function {
$$ = INTERFACE_PROC($1, @$); }
;
enum_decl
: KW_ENUM enum_var_modifiers sep var_decl_star endenum sep {
$$ = ENUM($2, TRIVIA($3, $6, @$), $4, @$); }
;
endenum
: KW_END_ENUM
| KW_ENDENUM
;
enum_var_modifiers
: %empty { LIST_NEW($$); }
| var_modifier_list { $$ = $1; }
;
derived_type_decl
: KW_TYPE var_modifiers id sep var_decl_star
derived_type_contains_opt end_type sep {
$$ = DERIVED_TYPE($2, $3, TRIVIA($4, $8, @$), $5, $6, @$); }
| KW_TYPE var_modifiers id "(" id_list ")" sep var_decl_star
derived_type_contains_opt end_type sep {
$$ = DERIVED_TYPE1($2, $3, $5, TRIVIA($7, $11, @$), $8, $9, @$); }
;
end_type
: KW_END_TYPE id_opt
| KW_ENDTYPE id_opt
;
derived_type_contains_opt
: KW_CONTAINS sep procedure_list { $$ = $3; }
| %empty { LIST_NEW($$); }
;
procedure_list
: procedure_list procedure_decl { $$ = $1; LIST_ADD($$, $2); }
| procedure_decl { LIST_NEW($$); LIST_ADD($$, $1); }
;
procedure_decl
: KW_PROCEDURE proc_modifiers use_symbol_list sep {
$$ = DERIVED_TYPE_PROC($2, $3, TRIVIA_AFTER($4, @$), @$); }
| KW_PROCEDURE "(" id ")" proc_modifiers use_symbol_list sep {
$$ = DERIVED_TYPE_PROC1($3, $5, $6, TRIVIA_AFTER($7, @$), @$); }
| KW_GENERIC access_spec_list KW_OPERATOR "(" operator_type ")" "=>" id_list sep {
$$ = GENERIC_OPERATOR($2, $5, $8, TRIVIA_AFTER($9, @$), @$); }
| KW_GENERIC access_spec_list KW_OPERATOR "(" "/)" "=>" id_list sep {
$$ = GENERIC_OPERATOR($2, OPERATOR(DIV, @$), $7, TRIVIA_AFTER($8, @$), @$); }
| KW_GENERIC access_spec_list KW_OPERATOR "(" TK_DEF_OP ")" "=>" id_list sep {
$$ = GENERIC_DEFOP($2, $5, $8, TRIVIA_AFTER($9, @$), @$); }
| KW_GENERIC access_spec_list KW_ASSIGNMENT "(" "=" ")" "=>" id_list sep {
$$ = GENERIC_ASSIGNMENT($2, $8, TRIVIA_AFTER($9, @$), @$); }
| KW_GENERIC access_spec_list id "=>" id_list sep {
$$ = GENERIC_NAME($2, $3, $5, TRIVIA_AFTER($6, @$), @$); }
| KW_GENERIC access_spec_list KW_WRITE "(" id ")" "=>" id_list sep {
$$ = GENERIC_WRITE($2, $5, $8, TRIVIA_AFTER($9, @$), @$); }
| KW_GENERIC access_spec_list KW_READ "(" id ")" "=>" id_list sep {
$$ = GENERIC_READ($2, $5, $8, TRIVIA_AFTER($9, @$), @$); }
| KW_FINAL "::" id sep { $$ = FINAL_NAME($3, TRIVIA_AFTER($4, @$), @$); }
| KW_PRIVATE sep { $$ = PRIVATE(Private, TRIVIA_AFTER($2, @$), @$); }
;
access_spec_list
: "::" { LIST_NEW($$); }
| access_spec "::" { LIST_NEW($$); LIST_ADD($$, $1); }
;
access_spec
: "," KW_PRIVATE { $$ = SIMPLE_ATTR(Private, @$); }
| "," KW_PUBLIC { $$ = SIMPLE_ATTR(Public, @$); }
;
operator_type
: "+" { $$ = OPERATOR(PLUS, @$); }
| "-" { $$ = OPERATOR(MINUS, @$); }
| "*" { $$ = OPERATOR(STAR, @$); }
| "/" { $$ = OPERATOR(DIV, @$); }
| "**" { $$ = OPERATOR(POW, @$); }
| "==" { $$ = OPERATOR(EQ, @$); }
| "/=" { $$ = OPERATOR(NOTEQ, @$); }
| ">" { $$ = OPERATOR(GT, @$); }
| ">=" { $$ = OPERATOR(GTE, @$); }
| "<" { $$ = OPERATOR(LT, @$); }
| "<=" { $$ = OPERATOR(LTE, @$); }
| "//" { $$ = OPERATOR(CONCAT, @$); }
| ".not." { $$ = OPERATOR(NOT, @$); }
| ".and." { $$ = OPERATOR(AND, @$); }
| ".or." { $$ = OPERATOR(OR, @$); }
| ".xor." { $$ = OPERATOR(XOR, @$); }
| ".eqv." { $$ = OPERATOR(EQV, @$); }
| ".neqv." { $$ = OPERATOR(NEQV, @$); }
;
proc_modifiers
: %empty { LIST_NEW($$); }
| "::" { LIST_NEW($$); }
| proc_modifier_list "::" { $$ = $1; }
;
proc_modifier_list
: proc_modifier_list "," proc_modifier { $$ = $1; LIST_ADD($$, $3); }
| "," proc_modifier { LIST_NEW($$); LIST_ADD($$, $2); }
;
proc_modifier
: KW_PRIVATE { $$ = SIMPLE_ATTR(Private, @$); }
| KW_PUBLIC { $$ = SIMPLE_ATTR(Public, @$); }
| KW_PASS { $$ = PASS(nullptr, @$); }
| KW_PASS "(" id ")" { $$ = PASS($3, @$); }
| KW_NOPASS { $$ = SIMPLE_ATTR(NoPass, @$); }
| KW_DEFERRED { $$ = SIMPLE_ATTR(Deferred, @$); }
| KW_NON_OVERRIDABLE { $$ = SIMPLE_ATTR(NonDeferred, @$); }
;
// ----------------------------------------------------------------------------
// Subroutine/Procedure/functions/program definitions
program
: KW_PROGRAM id sep use_statement_star implicit_statement_star decl_statements
contains_block_opt end_program sep {
LLOC(@$, @9); $$ = PROGRAM($2, TRIVIA($3, $9, @$), $4, $5, $6, $7, @$); }
;
end_program
: KW_END_PROGRAM id_opt
| KW_ENDPROGRAM id_opt
| KW_END
;
end_module
: KW_END_MODULE id_opt
| KW_ENDMODULE id_opt
| KW_END
;
end_submodule
: KW_END_SUBMODULE id_opt
| KW_ENDSUBMODULE id_opt
| KW_END
;
end_blockdata
: KW_END_BLOCK_DATA id_opt
| KW_ENDBLOCKDATA id_opt
| KW_END
;
end_subroutine
: KW_END_SUBROUTINE id_opt
| KW_ENDSUBROUTINE id_opt
| KW_END
;
end_procedure
: KW_END_PROCEDURE id_opt
| KW_ENDPROCEDURE id_opt
| KW_END
;
end_function
: KW_END_FUNCTION id_opt
| KW_ENDFUNCTION id_opt
| KW_END
;
end_associate
: KW_END_ASSOCIATE
| KW_ENDASSOCIATE
;
end_block
: KW_END_BLOCK
| KW_ENDBLOCK
;
end_select
: KW_END_SELECT
| KW_ENDSELECT
;
end_critical
: KW_END_CRITICAL
| KW_ENDCRITICAL
;
end_team
: KW_END_TEAM
| KW_ENDTEAM
;
subroutine
: KW_SUBROUTINE id sub_args bind_opt sep use_statement_star
import_statement_star implicit_statement_star decl_statements
contains_block_opt
end_subroutine sep {
LLOC(@$, @12); $$ = SUBROUTINE($2, $3, $4, TRIVIA($5, $12, @$), $6,
$7, $8, SPLIT_DECL(p.m_a, $9), SPLIT_STMT(p.m_a, $9), $10, @$); }
| fn_mod_plus KW_SUBROUTINE id sub_args bind_opt sep use_statement_star
import_statement_star implicit_statement_star decl_statements
contains_block_opt
end_subroutine sep {
LLOC(@$, @13); $$ = SUBROUTINE1($1, $3, $4, $5, TRIVIA($6, $13, @$),
$7, $8, $9, SPLIT_DECL(p.m_a, $10), SPLIT_STMT(p.m_a, $10), $11, @$); }
;
procedure
: fn_mod_plus KW_PROCEDURE id sub_args sep use_statement_star
import_statement_star implicit_statement_star decl_statements
contains_block_opt
end_procedure sep {
LLOC(@$, @12); $$ = PROCEDURE($1, $3, $4, TRIVIA($5, $12, @$), $6,
$7, $8, SPLIT_DECL(p.m_a, $9), SPLIT_STMT(p.m_a, $9), $10, @$); }
;
function
: KW_FUNCTION id "(" id_list_opt ")"
sep use_statement_star import_statement_star implicit_statement_star decl_statements
contains_block_opt
end_function sep {
LLOC(@$, @13); $$ = FUNCTION0($2, $4, nullptr, nullptr,
TRIVIA($6, $13, @$), $7, $8, $9, SPLIT_DECL(p.m_a, $10),
SPLIT_STMT(p.m_a, $10), $11, @$); }
| KW_FUNCTION id "(" id_list_opt ")"
bind
result_opt
sep use_statement_star import_statement_star implicit_statement_star decl_statements
contains_block_opt
end_function sep {
LLOC(@$, @15); $$ = FUNCTION0($2, $4, $7, $6, TRIVIA($8, $15, @$),
$9, $10, $11, SPLIT_DECL(p.m_a, $12), SPLIT_STMT(p.m_a, $12), $13, @$); }
| KW_FUNCTION id "(" id_list_opt ")"
result
bind_opt
sep use_statement_star import_statement_star implicit_statement_star decl_statements
contains_block_opt
end_function sep {
LLOC(@$, @15); $$ = FUNCTION0($2, $4, $6, $7, TRIVIA($8, $15, @$),
$9, $10, $11, SPLIT_DECL(p.m_a, $12), SPLIT_STMT(p.m_a, $12), $13, @$); }
| fn_mod_plus KW_FUNCTION id "(" id_list_opt ")"
sep use_statement_star import_statement_star implicit_statement_star decl_statements
contains_block_opt
end_function sep {
LLOC(@$, @14); $$ = FUNCTION($1, $3, $5, nullptr, nullptr,
TRIVIA($7, $14, @$), $8, $9, $10, SPLIT_DECL(p.m_a, $11),
SPLIT_STMT(p.m_a, $11), $12, @$); }
| fn_mod_plus KW_FUNCTION id "(" id_list_opt ")"
bind
result_opt
sep use_statement_star import_statement_star implicit_statement_star decl_statements
contains_block_opt
end_function sep {
LLOC(@$, @16); $$ = FUNCTION($1, $3, $5, $8, $7, TRIVIA($9, $16, @$),
$10, $11, $12, SPLIT_DECL(p.m_a, $13), SPLIT_STMT(p.m_a, $13), $14, @$); }
| fn_mod_plus KW_FUNCTION id "(" id_list_opt ")"
result
bind_opt
sep use_statement_star import_statement_star implicit_statement_star decl_statements
contains_block_opt
end_function sep {
LLOC(@$, @16); $$ = FUNCTION($1, $3, $5, $7, $8, TRIVIA($9, $16, @$),
$10, $11, $12, SPLIT_DECL(p.m_a, $13), SPLIT_STMT(p.m_a, $13), $14, @$); }
;
fn_mod_plus
: fn_mod_plus fn_mod { $$ = $1; LIST_ADD($$, $2); }
| fn_mod { LIST_NEW($$); LIST_ADD($$, $1); }
;
fn_mod
: var_type { $$ = $1; }
| KW_ELEMENTAL { $$ = SIMPLE_ATTR(Elemental, @$); }
| KW_IMPURE { $$ = SIMPLE_ATTR(Impure, @$); }
| KW_MODULE { $$ = SIMPLE_ATTR(Module, @$); }
| KW_PURE { $$ = SIMPLE_ATTR(Pure, @$); }
| KW_RECURSIVE { $$ = SIMPLE_ATTR(Recursive, @$); }
;
decl_star
: decl_star decl { $$ = $1; LIST_ADD($$, $2); }
| %empty { LIST_NEW($$); }
decl
: var_decl
| interface_decl
| derived_type_decl
| enum_decl
;
contains_block_opt
: KW_CONTAINS sep sub_or_func_plus { $$ = $3; }
| KW_CONTAINS sep { LIST_NEW($$); }
| %empty { LIST_NEW($$); }
;
sub_or_func_plus
: sub_or_func_plus sub_or_func { LIST_ADD($$, $2); }
| sub_or_func { LIST_NEW($$); LIST_ADD($$, $1); }
;
sub_or_func
: subroutine
| function
| procedure
;
sub_args
: "(" id_list_opt ")" { $$ = $2; }
| %empty { LIST_NEW($$); }
;
bind_opt
: bind { $$ = $1; }
| %empty { $$ = nullptr; }
;
bind
: KW_BIND "(" write_arg_list ")" { $$ = BIND2($3, @$); }
;
result_opt
: result { $$ = $1; }
| %empty { $$ = nullptr; }
;
result
: KW_RESULT "(" id ")" { $$ = $3; }
;
implicit_statement_star
: implicit_statement_star implicit_statement { $$ = $1; LIST_ADD($$, $2); }
| %empty { LIST_NEW($$); }
;