-
Notifications
You must be signed in to change notification settings - Fork 4
/
parser.y
1456 lines (1210 loc) · 28.7 KB
/
parser.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
/**************Parser for ADA*************/
%{
#include <stdio.h>
#include "util.h"
#include "errormsg.h"
#include "table.h"
#include "symbol.h"
#include "absyn.h"
#include "prabsyn.h"
int yylex(void); /* function prototype */
A_exp absyn_root;
int yydebug = 0;
S_table table;
void yyerror(char *s)
{
EM_error(EM_tokPos, "%s", s);
}
%}
%union {
int pos;
int ival;
float fval;
string sval;
A_var var;
A_exp exp;
A_dec dec;
A_oper oper;
A_unaryOper unaryop;
A_expList expList;
}
%type <expList> statement_s goal_symbol compilation c_name_list
cond_clause_s else_opt enum_id_s index_s iter_index_constraint
iter_discrete_range_s choice_s alternative_s pragma_arg_s pragma_s
basic_loop handled_stmt_s block_body value_s context_spec with_clause
name_s use_clause_opt formal_part formal_part_opt param_s def_id_s
discrim_part_opt discrim_spec_s discrim_part
%type <exp> expression relation simple_expression term factor primary
literal name allocator qualified parenthesized_primary
statement simple_stmt compound_stmt unlabeled null_stmt condition
range range_constraint simple_name pragma assign_stmt exit_stmt
return_stmt goto_stmt raise_stmt
code_stmt if_stmt case_stmt loop_stmt block pragma_arg comp_unit
compound_name unit subprog_body case_hdr
cond_part cond_clause subtype_ind when_opt
name_opt operator_symbol selected_comp used_char enum_id
range_spec range_spec_opt index component_subtype_def
discrete_range choice discrete_with_range alternative iter_part
iteration reverse_opt designator id_opt label_opt procedure_call
indexed_comp value comp_assoc private_opt use_clause subprog_spec
param decimal_digits_constraint object_subtype_def constraint
init_opt unconstr_array_type constr_array_type array_type range_constr_opt
discrim_spec type_completion type_def enumeration_type integer_type
float_type real_type fixed_type record_def def_id
%type <oper> logical short_circuit relational adding multiplying membership
%type <unaryop> unary
/*******************************************************************************
%type <dec> decl object_decl number_decl type_decl subtype_decl subprog_decl
pkg_decl task_decl prot_decl exception_decl rename_decl generic_decl
body_stub
*******************************************************************************/
%type <sval> object_qualifier_opt
%token <oper> LT_EQ EXPON NE GE AND OR XOR MOD REM TICK DOT_DOT
%token <unaryop> NOT ABS
%token <sval> IDENTIFIER CHARACTER STRING NuLL REVERSE PRIVATE TYPE NUMBER
%token LT_LT
%token BOX
%token GT_GT
%token IS_ASSIGNED
%token RIGHT_SHAFT
%token ABORT
%token ABSTRACT
%token ACCEPT
%token ACCESS
%token ALIASED
%token ALL
%token ARRAY
%token AT
%token BegiN
%token BODY
%token CASE
%token CONSTANT
%token DECLARE
%token DELAY
%token DELTA
%token DIGITS
%token DO
%token ELSE
%token ELSIF
%token END
%token ENTRY
%token EXCEPTION
%token EXIT
%token FOR
%token FUNCTION
%token GENERIC
%token GOTO
%token IF
%token IN
%token IS
%token LIMITED
%token LOOP
%token NEW
%token OF
%token OTHERS
%token OUT
%token PACKAGE
%token PRAGMA
%token PROCEDURE
%token PROTECTED
%token RAISE
%token RANGE
%token RECORD
%token RENAMES
%token REQUEUE
%token RETURN
%token SELECT
%token SEPARATE
%token SUBTYPE
%token TAGGED
%token TASK
%token TERMINATE
%token THEN
%token UNTIL
%token USE
%token WHEN
%token WHILE
%token WITH
%{
%}
%%
goal_symbol : compilation
{absyn_root = A_SeqExp(EM_tokPos,$1);}
;
pragma : PRAGMA IDENTIFIER ';'
{ $$ = A_Pragma(EM_tokPos,$2);}
| PRAGMA simple_name '(' pragma_arg_s ')' ';'
{ $$ = A_Pragmalist(EM_tokPos,$2,$4);}
;
pragma_arg_s : pragma_arg
{$$ = A_ExpList($1,NULL);}
| pragma_arg_s ',' pragma_arg
{$$ = A_ExpList($3,$1);}
;
pragma_arg : expression
{$$ = $1;}
| simple_name RIGHT_SHAFT expression
{$$ = $1;}
;
pragma_s :
{$$ = A_ExpList(A_NilExp(EM_tokPos),NULL);}
| pragma_s pragma
{$$ = A_ExpList($2,$1);}
;
decl : object_decl
| number_decl
| type_decl
| subtype_decl
| subprog_decl
| pkg_decl
| task_decl
| prot_decl
| exception_decl
| rename_decl
| generic_decl
| body_stub
| error ';'
{EM_error(EM_tokPos,"Illegal Declaration.");}
;
object_decl : def_id_s ':' object_qualifier_opt object_subtype_def init_opt ';'
{
A_expList e = $1;
while(e!=NULL)
{
if(S_look(table,S_Symbol(e->head->u.stringg))!=NULL)
{
EM_error(EM_tokPos,"Re-declaration of %s",e->head->u.stringg);
}
else
{
S_enter(table,S_Symbol(e->head->u.stringg),A_ObjectTy(EM_tokPos,$3,$4,$5));
}
e = e->tail;
}
}
;
def_id_s : def_id
{$$ = A_ExpList($1,NULL);}
| def_id_s ',' def_id
{$$ = A_ExpList($3,$1);}
;
def_id : IDENTIFIER
{$$ = A_StringExp(EM_tokPos,table,$1);}
;
object_qualifier_opt :
{$$ = String("");}
| ALIASED
{$$ = String("");}
| CONSTANT
{$$ = String("CONSTANT");}
| ALIASED CONSTANT
{$$ = String("");}
;
object_subtype_def : subtype_ind
{$$ = $1;}
| array_type
{$$ = $1;}
;
init_opt :
{$$ = A_NilExp(EM_tokPos);}
| IS_ASSIGNED expression
{$$ = $2;}
;
number_decl : def_id_s ':' CONSTANT IS_ASSIGNED expression ';'
{
A_expList e = $1;
while(e!=NULL)
{
if(S_look(table,S_Symbol(e->head->u.stringg))!=NULL)
{
EM_error(EM_tokPos,"Re-declaration of %s",e->head->u.stringg);
}
else
{
S_enter(table,S_Symbol(e->head->u.stringg),A_NumTy(EM_tokPos,$5));
}
e = e->tail;
}
}
;
type_decl : TYPE IDENTIFIER discrim_part_opt type_completion ';'
{
if(S_look(table,S_Symbol($2))!=NULL)
{
EM_error(EM_tokPos,"Re-declaration of %s",$2);
}
else
{
S_enter(table,S_Symbol($2),A_TypeDecTy(EM_tokPos,$3,$4));
}
}
;
discrim_part_opt :
{$$ = A_ExpList(A_NilExp(EM_tokPos),NULL);}
| discrim_part
{$$ = $1;}
| '(' BOX ')'
{$$ = A_ExpList(A_StringExp(EM_tokPos,table,"BOX"),NULL);}
;
type_completion :
{$$ = A_NilExp(EM_tokPos);}
| IS type_def
{$$ = $2;}
;
type_def : enumeration_type
{$$ = $1;}
| integer_type
{$$ = $1;}
| real_type
{$$ = $1;}
| array_type
{$$ = $1;}
| record_type
{$$ = A_NotImplemented(EM_tokPos,"record type not implemented yet");}
| access_type
{$$ = A_NotImplemented(EM_tokPos,"access type not implemented yet");}
| derived_type
{$$ = A_NotImplemented(EM_tokPos,"derived type not implemented");}
| private_type
{$$ = A_NotImplemented(EM_tokPos,"private type not implemented");}
;
subtype_decl : SUBTYPE IDENTIFIER IS subtype_ind ';'
;
subtype_ind : name constraint
{$$ = A_NameConstr(EM_tokPos,$1,$2);}
| name
{$$ = $1;}
;
constraint : range_constraint
{$$ = $1;}
| decimal_digits_constraint
{$$ = $1;}
;
decimal_digits_constraint : DIGITS expression range_constr_opt
{$$ = A_DecimalConstr(EM_tokPos,$2,$3);}
;
derived_type : NEW subtype_ind
| NEW subtype_ind WITH PRIVATE
| NEW subtype_ind WITH record_def
| ABSTRACT NEW subtype_ind WITH PRIVATE
| ABSTRACT NEW subtype_ind WITH record_def
;
range_constraint : RANGE range
{$$ = $2;}
;
range : simple_expression DOT_DOT simple_expression
{$$ = A_OpExp(EM_tokPos,A_rangeOp,$1,$3);}
| name TICK RANGE
{$$ = $1;}
| name TICK RANGE '(' expression ')'
{$$ = $1;}
;
enumeration_type : '(' enum_id_s ')'
{$$ = A_EnumExp(EM_tokPos,$2);}
enum_id_s : enum_id
{$$ = A_ExpList($1,NULL);}
| enum_id_s ',' enum_id
{$$ = A_ExpList($3,$1);}
;
enum_id : IDENTIFIER
{$$ = A_StringExp(EM_tokPos,table,$1);}
| CHARACTER
{$$ = A_StringExp(EM_tokPos,table,$1);}
;
integer_type : range_spec
{$$ = A_IntdefExp(EM_tokPos,$1);}
| MOD expression
{$$ = A_IntdefExp(EM_tokPos,$2);}
;
range_spec : range_constraint
{$$ = $1;}
;
range_spec_opt :
{$$ = A_NilExp(EM_tokPos);}
| range_spec
{$$ = $1;}
;
real_type : float_type
{$$ = $1;}
| fixed_type
{$$ = $1;}
;
float_type : DIGITS expression range_spec_opt
{$$ = A_FloatdefExp(EM_tokPos,$2,$3);}
;
fixed_type : DELTA expression range_spec
{$$ = A_FixeddefExp(EM_tokPos,$2,$3);}
| DELTA expression DIGITS expression range_spec_opt
{$$ = A_FixeddefdigitExp(EM_tokPos,$2,$4,$5);}
;
array_type : unconstr_array_type
{$$ = $1;}
| constr_array_type
{$$ = $1;}
;
unconstr_array_type : ARRAY '(' index_s ')' OF component_subtype_def
{$$ = A_UnconarraydefExp(EM_tokPos,$3,$6);}
;
constr_array_type : ARRAY iter_index_constraint OF component_subtype_def
{$$ = A_ConarraydefExp(EM_tokPos,$2,$4);}
;
component_subtype_def : aliased_opt subtype_ind
{$$ = $2;}
;
aliased_opt :
| ALIASED
;
index_s : index
{$$ = A_ExpList($1,NULL);}
| index_s ',' index
{$$ = A_ExpList($3,$1);}
;
index : name RANGE BOX
{$$ = $1;}
;
iter_index_constraint : '(' iter_discrete_range_s ')'
{$$ = $2;}
;
iter_discrete_range_s : discrete_range
{$$ = A_ExpList($1,NULL);}
| iter_discrete_range_s ',' discrete_range
{$$ = A_ExpList($3,$1);}
;
discrete_range : name range_constr_opt
{$$ = $1;}
| range
{$$ = $1;}
;
range_constr_opt :
{$$ = A_NilExp(EM_tokPos);}
| range_constraint
{$$ = $1;}
;
record_type : tagged_opt limited_opt record_def
;
record_def : RECORD pragma_s comp_list END RECORD
{$$ = A_RecorddefExp(EM_tokPos,$2,A_NotImplemented(EM_tokPos,"comp list not implemented"));}
| NuLL RECORD
{$$ = A_NullrecorddefExp(EM_tokPos);}
;
tagged_opt :
| TAGGED
| ABSTRACT TAGGED
;
comp_list : comp_decl_s variant_part_opt
| variant_part pragma_s
| NuLL ';' pragma_s
;
comp_decl_s : comp_decl
| comp_decl_s pragma_s comp_decl
;
variant_part_opt : pragma_s
| pragma_s variant_part pragma_s
;
comp_decl : def_id_s ':' component_subtype_def init_opt ';'
| error ';'
{EM_error(EM_tokPos,"Error in comp decl");}
;
discrim_part : '(' discrim_spec_s ')'
{$$ = $2;}
;
discrim_spec_s : discrim_spec
{$$ = A_ExpList($1,NULL);}
| discrim_spec_s ';' discrim_spec
{$$ = A_ExpList($3,$1);}
;
discrim_spec : def_id_s ':' access_opt mark init_opt
{$$ = A_NotImplemented(EM_tokPos,"discrim_spec not implemented");}
| error
{EM_error(EM_tokPos,"Error in discrim_spec");}
;
access_opt :
| ACCESS
;
variant_part : CASE simple_name IS pragma_s variant_s END CASE ';'
;
variant_s : variant
| variant_s variant
;
variant : WHEN choice_s RIGHT_SHAFT pragma_s comp_list
;
choice_s : choice
{$$ = A_ExpList($1,NULL);}
| choice_s '|' choice
{$$ = A_ExpList($3,$1);}
;
choice : expression
{$$ = $1;}
| discrete_with_range
{$$ = $1;}
| OTHERS
{$$ = A_StringExp(EM_tokPos,table,"OTHERS");}
;
discrete_with_range : name range_constraint
{$$ = $2;}
| range
{$$ = $1;}
;
access_type : ACCESS subtype_ind
| ACCESS CONSTANT subtype_ind
| ACCESS ALL subtype_ind
| ACCESS prot_opt PROCEDURE formal_part_opt
| ACCESS prot_opt FUNCTION formal_part_opt RETURN mark
;
prot_opt :
| PROTECTED
;
decl_part :
| decl_item_or_body_s1
;
decl_item_s :
| decl_item_s1
;
decl_item_s1 : decl_item
| decl_item_s1 decl_item
;
decl_item : decl
| use_clause
| rep_spec
| pragma
;
decl_item_or_body_s1 : decl_item_or_body
| decl_item_or_body_s1 decl_item_or_body
;
decl_item_or_body : body
| decl_item
;
body : subprog_body
| pkg_body
| task_body
| prot_body
;
name : simple_name
{$$ = $1;}
| indexed_comp
{$$ = $1;}
| selected_comp
{$$ = $1;}
| attribute
{$$ = A_NotImplemented(EM_tokPos,"attribute not implemented");}
| operator_symbol
{$$ = $1;}
;
mark : simple_name
| mark TICK attribute_id
| mark '.' simple_name
;
simple_name : IDENTIFIER
{$$ = A_StringExp(EM_tokPos,table,$1);}
;
compound_name : simple_name
{ $$ = $1;}
| compound_name '.' simple_name
{ $$ = A_OpExp(EM_tokPos,A_dotOp,$1,$3);}
;
c_name_list : compound_name
{ $$ = A_ExpList($1,NULL);}
| c_name_list ',' compound_name
{ $$ = A_ExpList($3,$1);}
;
used_char : CHARACTER
{ $$ = A_StringExp(EM_tokPos,table,$1);}
;
operator_symbol : STRING
{ $$ = A_StringExp(EM_tokPos,table,$1);}
;
indexed_comp : name '(' value_s ')'
{$$ = A_FunctionUse(EM_tokPos,$1,$3);}
;
value_s : value
{$$ = A_ExpList($1,NULL);}
| value_s ',' value
{$$ = A_ExpList($3,$1);}
;
value : expression
{$$ = $1;}
| comp_assoc
{$$ = $1;}
| discrete_with_range
{$$ = $1;}
| error
{EM_error(EM_tokPos,"Error in statement.");}
;
selected_comp : name '.' simple_name
{$$ = A_OpExp(EM_tokPos,A_dotOp,$1,$3);}
| name '.' used_char
{$$ = A_OpExp(EM_tokPos,A_dotOp,$1,$3);}
| name '.' operator_symbol
{$$ = A_OpExp(EM_tokPos,A_dotOp,$1,$3);}
| name '.' ALL
{$$ = A_OpExp(EM_tokPos,A_dotOp,$1,A_StringExp(EM_tokPos,table,"ALL"));}
;
attribute : name TICK attribute_id
;
attribute_id : IDENTIFIER
| DIGITS
| DELTA
| ACCESS
;
literal : NUMBER
{$$ = A_NumberExp(EM_tokPos,$1);}
| used_char
{$$ = $1;}
| NuLL
{$$ = A_NilExp(EM_tokPos);}
;
aggregate : '(' comp_assoc ')'
| '(' value_s_2 ')'
| '(' expression WITH value_s ')'
| '(' expression WITH NuLL RECORD ')'
| '(' NuLL RECORD ')'
;
value_s_2 : value ',' value
| value_s_2 ',' value
;
comp_assoc : choice_s RIGHT_SHAFT expression
{$$ = A_CompAssoc(EM_tokPos,$1,$3);}
;
expression : relation
{$$ = $1;}
| expression logical relation
{$$ = A_OpExp(EM_tokPos,$2,$1,$3);}
| expression short_circuit relation
{$$ = A_OpExp(EM_tokPos,$2,$1,$3);}
;
logical : AND
{$$ = A_andOp;}
| OR
{$$ = A_orOp;}
| XOR
{$$ = A_xorOp;}
;
short_circuit : AND THEN
{$$ = $1;}
| OR ELSE
{$$ = $1;}
;
relation : simple_expression
{$$ = $1;}
| simple_expression relational simple_expression
{$$ = A_OpExp(EM_tokPos,$2,$1,$3);}
| simple_expression membership range
{$$ = A_OpExp(EM_tokPos,$2,$1,$3);}
| simple_expression membership name
{$$ = A_OpExp(EM_tokPos,$2,$1,$3);}
;
relational : '='
{$$ = A_eqOp;}
| NE
{$$ = A_neqOp;}
| '<'
{$$ = A_ltOp;}
| LT_EQ
{$$ = A_leOp;}
| '>'
{$$ = A_gtOp;}
| GE
{$$ = A_geOp;}
;
membership : IN
{$$ = A_inOp;}
| NOT IN
{$$ = A_notInOp;}
;
simple_expression : unary term
{$$ = A_UnaryOpExp(EM_tokPos,$1,$2);}
| term
{$$ = $1;}
| simple_expression adding term
{$$ = A_OpExp(EM_tokPos,$2,$1,$3);}
;
unary : '+'
{$$ = A_unaryplusOp;}
| '-'
{$$ = A_unaryminusOp;}
;
adding : '+'
{$$ = A_plusOp;}
| '-'
{$$ = A_minusOp;}
| '&'
{$$ = A_binAndOp;}
;
term : factor
{$$ = $1;}
| term multiplying factor
{$$ = A_OpExp(EM_tokPos,$2,$1,$3);}
;
multiplying : '*'
{$$ = A_timesOp;}
| '/'
{$$ = A_divideOp;}
| MOD
{$$ = A_modOp;}
| REM
{$$ = A_remOp;}
;
factor : primary
{$$ = $1;}
| NOT primary
{$$ = A_UnaryOpExp(EM_tokPos,A_notOp,$2);}
| ABS primary
{$$ = A_UnaryOpExp(EM_tokPos,A_absOp,$2);}
| primary EXPON primary
{$$ = A_OpExp(EM_tokPos,A_expOp,$1,$3);}
;
primary : literal
{$$ = $1;}
| name
{$$ = $1;}
| allocator
{$$ = $1;}
| qualified
{$$ = $1;}
| parenthesized_primary
{$$ = $1;}
;
parenthesized_primary : aggregate
{$$ = A_NotImplemented(EM_tokPos,"aggregate not implemented");}
| '(' expression ')'
{$$ = $2;}
;
qualified : name TICK parenthesized_primary
{$$ = A_OpExp(EM_tokPos,A_tickOp,$1,$3);}
;
allocator : NEW name
{$$ = $2;}
| NEW qualified
{$$ = $2;}
;
statement_s : statement
{$$ = A_ExpList($1,NULL);}
| statement_s statement
{$$ = A_ExpList($2,$1);}
;
statement : unlabeled
{$$ = $1;}
| label statement
{$$ = $2;}
;
unlabeled : simple_stmt
{$$ = $1;}
| compound_stmt
{$$ = $1;}
| pragma
{$$ = $1;}
;
simple_stmt : null_stmt
{$$ = $1;}
| assign_stmt
{$$ = $1;}
| exit_stmt
{$$ = $1;}
| return_stmt
{$$ = $1;}
| goto_stmt
{$$ = $1;}
| procedure_call
{$$ = $1;}
| delay_stmt
{$$ = A_NotImplemented(EM_tokPos,"delay not implemented");}
| abort_stmt
{$$ = A_NotImplemented(EM_tokPos,"abort not implemented");}
| raise_stmt
{$$ = $1;}
| code_stmt
{$$ = $1;}
| requeue_stmt
{$$ = A_NotImplemented(EM_tokPos,"requeue not implemented");}
| error ';'
{EM_error(EM_tokPos,"Error in statement.");}
;
compound_stmt : if_stmt
{$$ = $1;}
| case_stmt
{$$ = $1;}
| loop_stmt
{$$ = $1;}
| block
{$$ = $1;}
| accept_stmt
{$$ = A_NotImplemented(EM_tokPos,"accept stmt not implemented");}
| select_stmt
{$$ = A_NotImplemented(EM_tokPos,"select stmt not implemented");}
;
label : LT_LT IDENTIFIER GT_GT
;
null_stmt : NuLL ';'
{$$ = A_NilExp(EM_tokPos);}
;
assign_stmt : name IS_ASSIGNED expression ';'
{$$ = A_AssignExp(EM_tokPos,$1,$3);}
;
if_stmt : IF cond_clause_s else_opt END IF ';'
{$$ = A_IfExp(EM_tokPos,$2,$3);}
;
cond_clause_s : cond_clause
{$$ = A_ExpList($1,NULL);}
| cond_clause_s ELSIF cond_clause
{$$ = A_ExpList($3,$1);}
;
cond_clause : cond_part statement_s
{$$ = A_CondExp(EM_tokPos,$1,$2);}
;
cond_part : condition THEN
{$$ = $1;}
;
condition : expression
{$$ = $1;}
;
else_opt :
{$$ = A_ExpList(A_NilExp(EM_tokPos),NULL);}
| ELSE statement_s
{$$ = $2;}
;
case_stmt : case_hdr pragma_s alternative_s END CASE ';'
{$$ = A_Case(EM_tokPos,$1,$2,$3);}
;
case_hdr : CASE expression IS
{$$ = $2;}
;
alternative_s :
{$$ = A_ExpList(A_NilExp(EM_tokPos),NULL);}
| alternative_s alternative
{$$ = A_ExpList($2,$1);}
;
alternative : WHEN choice_s RIGHT_SHAFT statement_s
{$$ = A_Alternative(EM_tokPos,$2,$4);}
;
loop_stmt : label_opt iteration basic_loop id_opt ';'
{$$ = A_LoopExp(EM_tokPos,$1,$2,$3,$4);}
;
label_opt :
{$$ = A_NilExp(EM_tokPos);}
| IDENTIFIER ':'
{$$ = A_StringExp(EM_tokPos,table,$1);}
;
iteration :
{$$ = A_NilExp(EM_tokPos);}
| WHILE condition
{$$ = A_WhileExp(EM_tokPos,$2);}
| iter_part reverse_opt discrete_range
{$$ = A_ForExp(EM_tokPos,$1,$2,$3);}
;
iter_part : FOR IDENTIFIER IN
{$$ = A_StringExp(EM_tokPos,table,$2);}
;
reverse_opt :
{$$ = A_NilExp(EM_tokPos);}
| REVERSE
{$$ = A_StringExp(EM_tokPos,table,$1);}
;
basic_loop : LOOP statement_s END LOOP
{$$ = $2;}
;
id_opt :
{$$ = A_NilExp(EM_tokPos);}
| designator
{$$ = $1;}
;
block : label_opt
{S_beginScope(table);S_enter(table,S_Symbol($1->u.stringg),$1);}
block_decl
block_body END
id_opt
{
if($1->kind == A_stringExp)
{
if(S_look(table,S_Symbol($6->u.stringg)) == NULL)
EM_error(EM_tokPos,"Wrong block id");
}
}
';'
{S_endScope(table);}
;
block_decl :
| DECLARE decl_part
;
block_body : BegiN handled_stmt_s
{$$ = $2;}
;
handled_stmt_s : statement_s except_handler_part_opt
{$$ = $1;}
;
except_handler_part_opt :
| except_handler_part
;
exit_stmt : EXIT name_opt when_opt ';'
{$$ = A_ExitExp(EM_tokPos,$2,$3);}
;
name_opt :
{$$ = A_NilExp(EM_tokPos);}
| name
{$$ = $1;}
;
when_opt :
{$$ = A_NilExp(EM_tokPos);}
| WHEN condition
{$$ = $2;}
;
return_stmt : RETURN ';'
{$$ = A_ReturnExp(EM_tokPos,A_NilExp(EM_tokPos));}
| RETURN expression ';'
{$$ = A_ReturnExp(EM_tokPos,$2);}