-
Notifications
You must be signed in to change notification settings - Fork 74
/
cdgram.y
946 lines (854 loc) · 26.2 KB
/
cdgram.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
%{
/* Yacc grammar for ANSI and C++ cdecl. */
/* The output of this file is included */
/* into the C file cdecl.c. */
char cdgramsccsid[] = "@(#)cdgram.y 2.2 3/30/88";
%}
%union {
char *dynstr;
struct {
char *left;
char *right;
char *type;
} halves;
}
%token ARRAY AS CAST COMMA DECLARE DOUBLECOLON EXPLAIN FUNCTION BLOCK
%token HELP INTO OF MEMBER POINTER REFERENCE RETURNING SET TO
%token <dynstr> CHAR CLASS CONSTVOLATILE DOUBLE ENUM FLOAT INT LONG NAME
%token <dynstr> NUMBER SHORT SIGNED STRUCT UNION UNSIGNED VOID
%token <dynstr> AUTO EXTERN REGISTER STATIC
%type <dynstr> adecllist adims c_type cast castlist cdecl cdecl1 cdims
%type <dynstr> constvol_list ClassStruct mod_list mod_list1 modifier
%type <dynstr> opt_constvol_list optNAME opt_storage storage StrClaUniEnum
%type <dynstr> tname type
%type <halves> adecl
%start prog
%%
prog : /* empty */
| prog stmt
{
prompt();
prev = 0;
}
;
stmt : HELP NL
{
Debug((stderr, "stmt: help\n"));
dohelp();
}
| DECLARE NAME AS opt_storage adecl NL
{
Debug((stderr, "stmt: DECLARE NAME AS opt_storage adecl\n"));
Debug((stderr, "\tNAME='%s'\n", $2));
Debug((stderr, "\topt_storage='%s'\n", $4));
Debug((stderr, "\tacdecl.left='%s'\n", $5.left));
Debug((stderr, "\tacdecl.right='%s'\n", $5.right));
Debug((stderr, "\tacdecl.type='%s'\n", $5.type));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
dodeclare($2, $4, $5.left, $5.right, $5.type);
}
| DECLARE opt_storage adecl NL
{
Debug((stderr, "stmt: DECLARE opt_storage adecl\n"));
Debug((stderr, "\topt_storage='%s'\n", $2));
Debug((stderr, "\tacdecl.left='%s'\n", $3.left));
Debug((stderr, "\tacdecl.right='%s'\n", $3.right));
Debug((stderr, "\tacdecl.type='%s'\n", $3.type));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
dodeclare(NullCP, $2, $3.left, $3.right, $3.type);
}
| CAST NAME INTO adecl NL
{
Debug((stderr, "stmt: CAST NAME AS adecl\n"));
Debug((stderr, "\tNAME='%s'\n", $2));
Debug((stderr, "\tacdecl.left='%s'\n", $4.left));
Debug((stderr, "\tacdecl.right='%s'\n", $4.right));
Debug((stderr, "\tacdecl.type='%s'\n", $4.type));
docast($2, $4.left, $4.right, $4.type);
}
| CAST adecl NL
{
Debug((stderr, "stmt: CAST adecl\n"));
Debug((stderr, "\tacdecl.left='%s'\n", $2.left));
Debug((stderr, "\tacdecl.right='%s'\n", $2.right));
Debug((stderr, "\tacdecl.type='%s'\n", $2.type));
docast(NullCP, $2.left, $2.right, $2.type);
}
| EXPLAIN opt_storage opt_constvol_list type opt_constvol_list cdecl NL
{
Debug((stderr, "stmt: EXPLAIN opt_storage opt_constvol_list type cdecl\n"));
Debug((stderr, "\topt_storage='%s'\n", $2));
Debug((stderr, "\topt_constvol_list='%s'\n", $3));
Debug((stderr, "\ttype='%s'\n", $4));
Debug((stderr, "\tcdecl='%s'\n", $6));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
dodexplain($2, $3, $5, $4, $6);
}
| EXPLAIN storage opt_constvol_list cdecl NL
{
Debug((stderr, "stmt: EXPLAIN storage opt_constvol_list cdecl\n"));
Debug((stderr, "\tstorage='%s'\n", $2));
Debug((stderr, "\topt_constvol_list='%s'\n", $3));
Debug((stderr, "\tcdecl='%s'\n", $4));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
dodexplain($2, $3, NullCP, NullCP, $4);
}
| EXPLAIN opt_storage constvol_list cdecl NL
{
Debug((stderr, "stmt: EXPLAIN opt_storage constvol_list cdecl\n"));
Debug((stderr, "\topt_storage='%s'\n", $2));
Debug((stderr, "\tconstvol_list='%s'\n", $3));
Debug((stderr, "\tcdecl='%s'\n", $4));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
dodexplain($2, $3, NullCP, NullCP, $4);
}
| EXPLAIN '(' opt_constvol_list type cast ')' optNAME NL
{
Debug((stderr, "stmt: EXPLAIN ( opt_constvol_list type cast ) optNAME\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $3));
Debug((stderr, "\ttype='%s'\n", $4));
Debug((stderr, "\tcast='%s'\n", $5));
Debug((stderr, "\tNAME='%s'\n", $7));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
docexplain($3, $4, $5, $7);
}
| SET optNAME NL
{
Debug((stderr, "stmt: SET optNAME\n"));
Debug((stderr, "\toptNAME='%s'\n", $2));
doset($2);
}
| NL
| error NL
{
yyerrok;
}
;
NL : '\n'
{
doprompt();
}
| ';'
{
noprompt();
}
;
optNAME : NAME
{
Debug((stderr, "optNAME: NAME\n"));
Debug((stderr, "\tNAME='%s'\n", $1));
$$ = $1;
}
| /* empty */
{
Debug((stderr, "optNAME: EMPTY\n"));
$$ = ds(unknown_name);
}
;
cdecl : cdecl1
| '*' opt_constvol_list cdecl
{
Debug((stderr, "cdecl: * opt_constvol_list cdecl\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $2));
Debug((stderr, "\tcdecl='%s'\n", $3));
$$ = cat($3,$2,ds(strlen($2)?" pointer to ":"pointer to "),NullCP);
prev = 'p';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| NAME DOUBLECOLON '*' cdecl
{
Debug((stderr, "cdecl: NAME DOUBLECOLON '*' cdecl\n"));
Debug((stderr, "\tNAME='%s'\n", $1));
Debug((stderr, "\tcdecl='%s'\n", $4));
if (!CplusplusFlag)
unsupp("pointer to member of class", NullCP);
$$ = cat($4,ds("pointer to member of class "),$1,ds(" "),NullCP);
prev = 'p';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '&' opt_constvol_list cdecl
{
Debug((stderr, "cdecl: & opt_constvol_list cdecl\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $2));
Debug((stderr, "\tcdecl='%s'\n", $3));
if (!CplusplusFlag)
unsupp("reference", NullCP);
$$ = cat($3,$2,ds(strlen($2)?" reference to ":"reference to "),NullCP);
prev = 'r';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
;
cdecl1 : cdecl1 '(' ')'
{
Debug((stderr, "cdecl1: cdecl1()\n"));
Debug((stderr, "\tcdecl1='%s'\n", $1));
$$ = cat($1,ds("function returning "),NullCP);
prev = 'f';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '(' '^' opt_constvol_list cdecl ')' '(' ')'
{
char *sp = "";
Debug((stderr, "cdecl1: (^ opt_constvol_list cdecl)()\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $3));
Debug((stderr, "\tcdecl='%s'\n", $4));
if (strlen($3) > 0)
sp = " ";
$$ = cat($4, $3, ds(sp), ds("block returning "), NullCP);
prev = 'b';
}
| '(' '^' opt_constvol_list cdecl ')' '(' castlist ')'
{
char *sp = "";
Debug((stderr, "cdecl1: (^ opt_constvol_list cdecl)( castlist )\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $3));
Debug((stderr, "\tcdecl='%s'\n", $4));
Debug((stderr, "\tcastlist='%s'\n", $7));
if (strlen($3) > 0)
sp = " ";
$$ = cat($4, $3, ds(sp), ds("block ("),
$7, ds(") returning "), NullCP);
prev = 'b';
}
| cdecl1 '(' castlist ')'
{
Debug((stderr, "cdecl1: cdecl1(castlist)\n"));
Debug((stderr, "\tcdecl1='%s'\n", $1));
Debug((stderr, "\tcastlist='%s'\n", $3));
$$ = cat($1, ds("function ("),
$3, ds(") returning "), NullCP);
prev = 'f';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| cdecl1 cdims
{
Debug((stderr, "cdecl1: cdecl1 cdims\n"));
Debug((stderr, "\tcdecl1='%s'\n", $1));
Debug((stderr, "\tcdims='%s'\n", $2));
$$ = cat($1,ds("array "),$2,NullCP);
prev = 'a';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '(' cdecl ')'
{
Debug((stderr, "cdecl1: (cdecl)\n"));
Debug((stderr, "\tcdecl='%s'\n", $2));
$$ = $2;
/* prev = prev; */
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| NAME
{
Debug((stderr, "cdecl1: NAME\n"));
Debug((stderr, "\tNAME='%s'\n", $1));
savedname = $1;
$$ = ds("");
prev = 'n';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
;
castlist : castlist COMMA castlist
{
Debug((stderr, "castlist: castlist1, castlist2\n"));
Debug((stderr, "\tcastlist1='%s'\n", $1));
Debug((stderr, "\tcastlist2='%s'\n", $3));
$$ = cat($1, ds(", "), $3, NullCP);
}
| opt_constvol_list type cast
{
Debug((stderr, "castlist: opt_constvol_list type cast\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $1));
Debug((stderr, "\ttype='%s'\n", $2));
Debug((stderr, "\tcast='%s'\n", $3));
$$ = cat($3, $1, ds(strlen($1) ? " " : ""), $2, NullCP);
}
| NAME
{
$$ = $1;
}
;
adecllist : /* empty */
{
Debug((stderr, "adecllist: EMPTY\n"));
$$ = ds("");
}
| adecllist COMMA adecllist
{
Debug((stderr, "adecllist: adecllist1, adecllist2\n"));
Debug((stderr, "\tadecllist1='%s'\n", $1));
Debug((stderr, "\tadecllist2='%s'\n", $3));
$$ = cat($1, ds(", "), $3, NullCP);
}
| NAME
{
Debug((stderr, "adecllist: NAME\n"));
Debug((stderr, "\tNAME='%s'\n", $1));
$$ = $1;
}
| adecl
{
Debug((stderr, "adecllist: adecl\n"));
Debug((stderr, "\tadecl.left='%s'\n", $1.left));
Debug((stderr, "\tadecl.right='%s'\n", $1.right));
Debug((stderr, "\tadecl.type='%s'\n", $1.type));
$$ = cat($1.type, ds(strlen($1.left) || strlen($1.right) ? " " : ""), $1.left, $1.right, NullCP);
}
| NAME AS adecl
{
Debug((stderr, "adecllist: NAME AS adecl\n"));
Debug((stderr, "\tNAME='%s'\n", $1));
Debug((stderr, "\tadecl.left='%s'\n", $3.left));
Debug((stderr, "\tadecl.right='%s'\n", $3.right));
Debug((stderr, "\tadecl.type='%s'\n", $3.type));
$$ = cat($3.type, ds(" "), $3.left, $1, $3.right, NullCP);
}
;
cast : /* empty */
{
Debug((stderr, "cast: EMPTY\n"));
$$ = ds("");
/* prev = prev; */
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '(' ')'
{
Debug((stderr, "cast: ()\n"));
$$ = ds("function returning ");
prev = 'f';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '(' cast ')' '(' ')'
{
Debug((stderr, "cast: (cast)()\n"));
Debug((stderr, "\tcast='%s'\n", $2));
$$ = cat($2,ds("function returning "),NullCP);
prev = 'f';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '(' cast ')' '(' castlist ')'
{
Debug((stderr, "cast: (cast)(castlist)\n"));
Debug((stderr, "\tcast='%s'\n", $2));
Debug((stderr, "\tcastlist='%s'\n", $5));
$$ = cat($2,ds("function ("),$5,ds(") returning "),NullCP);
prev = 'f';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '(' '^' cast ')' '(' ')'
{
Debug((stderr, "cast: (^ cast)()\n"));
Debug((stderr, "\tcast='%s'\n", $3));
$$ = cat($3,ds("block returning "),NullCP);
prev = 'b';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '(' '^' cast ')' '(' castlist ')'
{
Debug((stderr, "cast: (^ cast)(castlist)\n"));
Debug((stderr, "\tcast='%s'\n", $3));
$$ = cat($3,ds("block ("), $6, ds(") returning "),NullCP);
prev = 'b';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '(' cast ')'
{
Debug((stderr, "cast: (cast)\n"));
Debug((stderr, "\tcast='%s'\n", $2));
$$ = $2;
/* prev = prev; */
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| NAME DOUBLECOLON '*' cast
{
Debug((stderr, "cast: NAME::*cast\n"));
Debug((stderr, "\tcast='%s'\n", $4));
if (!CplusplusFlag)
unsupp("pointer to member of class", NullCP);
$$ = cat($4,ds("pointer to member of class "),$1,ds(" "),NullCP);
prev = 'p';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '*' cast
{
Debug((stderr, "cast: *cast\n"));
Debug((stderr, "\tcast='%s'\n", $2));
$$ = cat($2,ds("pointer to "),NullCP);
prev = 'p';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| '&' cast
{
Debug((stderr, "cast: &cast\n"));
Debug((stderr, "\tcast='%s'\n", $2));
if (!CplusplusFlag)
unsupp("reference", NullCP);
$$ = cat($2,ds("reference to "),NullCP);
prev = 'r';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| cast cdims
{
Debug((stderr, "cast: cast cdims\n"));
Debug((stderr, "\tcast='%s'\n", $1));
Debug((stderr, "\tcdims='%s'\n", $2));
$$ = cat($1,ds("array "),$2,NullCP);
prev = 'a';
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
;
cdims : '[' ']'
{
Debug((stderr, "cdims: []\n"));
$$ = ds("of ");
}
| '[' NUMBER ']'
{
Debug((stderr, "cdims: [NUMBER]\n"));
Debug((stderr, "\tNUMBER='%s'\n", $2));
$$ = cat($2,ds(" of "),NullCP);
}
;
adecl : FUNCTION RETURNING adecl
{
Debug((stderr, "adecl: FUNCTION RETURNING adecl\n"));
Debug((stderr, "\tadecl.left='%s'\n", $3.left));
Debug((stderr, "\tadecl.right='%s'\n", $3.right));
Debug((stderr, "\tadecl.type='%s'\n", $3.type));
if (prev == 'f')
unsupp("Function returning function",
"function returning pointer to function");
else if (prev=='A' || prev=='a')
unsupp("Function returning array",
"function returning pointer");
$$.left = $3.left;
$$.right = cat(ds("()"),$3.right,NullCP);
$$.type = $3.type;
prev = 'f';
Debug((stderr, "\n\tadecl now =\n"));
Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| FUNCTION '(' adecllist ')' RETURNING adecl
{
Debug((stderr, "adecl: FUNCTION (adecllist) RETURNING adecl\n"));
Debug((stderr, "\tadecllist='%s'\n", $3));
Debug((stderr, "\tadecl.left='%s'\n", $6.left));
Debug((stderr, "\tadecl.right='%s'\n", $6.right));
Debug((stderr, "\tadecl.type='%s'\n", $6.type));
if (prev == 'f')
unsupp("Function returning function",
"function returning pointer to function");
else if (prev=='A' || prev=='a')
unsupp("Function returning array",
"function returning pointer");
$$.left = $6.left;
$$.right = cat(ds("("),$3,ds(")"),$6.right,NullCP);
$$.type = $6.type;
prev = 'f';
Debug((stderr, "\n\tadecl now =\n"));
Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| opt_constvol_list BLOCK RETURNING adecl
{
char *sp = "";
Debug((stderr, "adecl: opt_constvol_list BLOCK RETURNING adecl\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $1));
Debug((stderr, "\tadecl.left='%s'\n", $4.left));
Debug((stderr, "\tadecl.right='%s'\n", $4.right));
Debug((stderr, "\tadecl.type='%s'\n", $4.type));
if (prev == 'f')
unsupp("Block returning function",
"block returning pointer to function");
else if (prev=='A' || prev=='a')
unsupp("Block returning array",
"block returning pointer");
if (strlen($1) != 0)
sp = " ";
$$.left = cat($4.left, ds("(^"), ds(sp), $1, ds(sp), NullCP);
$$.right = cat(ds(")()"),$4.right,NullCP);
$$.type = $4.type;
prev = 'b';
}
| opt_constvol_list BLOCK '(' adecllist ')' RETURNING adecl
{
char *sp = "";
Debug((stderr, "adecl: opt_constvol_list BLOCK RETURNING adecl\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $1));
Debug((stderr, "\tadecllist='%s'\n", $4));
Debug((stderr, "\tadecl.left='%s'\n", $7.left));
Debug((stderr, "\tadecl.right='%s'\n", $7.right));
Debug((stderr, "\tadecl.type='%s'\n", $7.type));
if (prev == 'f')
unsupp("Block returning function",
"block returning pointer to function");
else if (prev=='A' || prev=='a')
unsupp("Block returning array",
"block returning pointer");
if (strlen($1) != 0)
sp = " ";
$$.left = cat($7.left, ds("(^"), ds(sp), $1, ds(sp), NullCP);
$$.right = cat(ds(")("), $4, ds(")"), $7.right, NullCP);
$$.type = $7.type;
prev = 'b';
}
| ARRAY adims OF adecl
{
Debug((stderr, "adecl: ARRAY adims OF adecl\n"));
Debug((stderr, "\tadims='%s'\n", $2));
Debug((stderr, "\tadecl.left='%s'\n", $4.left));
Debug((stderr, "\tadecl.right='%s'\n", $4.right));
Debug((stderr, "\tadecl.type='%s'\n", $4.type));
if (prev == 'f')
unsupp("Array of function",
"array of pointer to function");
else if (prev == 'a')
unsupp("Inner array of unspecified size",
"array of pointer");
else if (prev == 'v')
unsupp("Array of void",
"pointer to void");
if (arbdims)
prev = 'a';
else
prev = 'A';
$$.left = $4.left;
$$.right = cat($2,$4.right,NullCP);
$$.type = $4.type;
Debug((stderr, "\n\tadecl now =\n"));
Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| opt_constvol_list POINTER TO adecl
{
char *op = "", *cp = "", *sp = "";
Debug((stderr, "adecl: opt_constvol_list POINTER TO adecl\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $1));
Debug((stderr, "\tadecl.left='%s'\n", $4.left));
Debug((stderr, "\tadecl.right='%s'\n", $4.right));
Debug((stderr, "\tadecl.type='%s'\n", $4.type));
if (prev == 'a')
unsupp("Pointer to array of unspecified dimension",
"pointer to object");
if (prev=='a' || prev=='A' || prev=='f') {
op = "(";
cp = ")";
}
if (strlen($1) != 0)
sp = " ";
$$.left = cat($4.left,ds(op),ds("*"),
ds(sp),$1,ds(sp),NullCP);
$$.right = cat(ds(cp),$4.right,NullCP);
$$.type = $4.type;
prev = 'p';
Debug((stderr, "\n\tadecl now =\n"));
Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| opt_constvol_list POINTER TO MEMBER OF ClassStruct NAME adecl
{
char *op = "", *cp = "", *sp = "";
Debug((stderr, "adecl: opt_constvol_list POINTER TO MEMBER OF ClassStruct NAME adecl\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $1));
Debug((stderr, "\tClassStruct='%s'\n", $6));
Debug((stderr, "\tNAME='%s'\n", $7));
Debug((stderr, "\tadecl.left='%s'\n", $8.left));
Debug((stderr, "\tadecl.right='%s'\n", $8.right));
Debug((stderr, "\tadecl.type='%s'\n", $8.type));
if (!CplusplusFlag)
unsupp("pointer to member of class", NullCP);
if (prev == 'a')
unsupp("Pointer to array of unspecified dimension",
"pointer to object");
if (prev=='a' || prev=='A' || prev=='f') {
op = "(";
cp = ")";
}
if (strlen($1) != 0)
sp = " ";
$$.left = cat($8.left,ds(op),$7,ds("::*"),
ds(sp),$1,ds(sp),NullCP);
$$.right = cat(ds(cp),$8.right,NullCP);
$$.type = $8.type;
prev = 'p';
Debug((stderr, "\n\tadecl now =\n"));
Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| opt_constvol_list REFERENCE TO adecl
{
char *op = "", *cp = "", *sp = "";
Debug((stderr, "adecl: opt_constvol_list REFERENCE TO adecl\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $1));
Debug((stderr, "\tadecl.left='%s'\n", $4.left));
Debug((stderr, "\tadecl.right='%s'\n", $4.right));
Debug((stderr, "\tadecl.type='%s'\n", $4.type));
if (!CplusplusFlag)
unsupp("reference", NullCP);
if (prev == 'v')
unsupp("Reference to void",
"pointer to void");
else if (prev == 'a')
unsupp("Reference to array of unspecified dimension",
"reference to object");
if (prev=='a' || prev=='A' || prev=='f') {
op = "(";
cp = ")";
}
if (strlen($1) != 0)
sp = " ";
$$.left = cat($4.left,ds(op),ds("&"),
ds(sp),$1,ds(sp),NullCP);
$$.right = cat(ds(cp),$4.right,NullCP);
$$.type = $4.type;
prev = 'r';
Debug((stderr, "\n\tadecl now =\n"));
Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
| opt_constvol_list type
{
Debug((stderr, "adecl: opt_constvol_list type\n"));
Debug((stderr, "\topt_constvol_list='%s'\n", $1));
Debug((stderr, "\ttype='%s'\n", $2));
$$.left = ds("");
$$.right = ds("");
$$.type = cat($1,ds(strlen($1)?" ":""),$2,NullCP);
if (strcmp($2, "void") == 0)
prev = 'v';
else if ((strncmp($2, "struct", 6) == 0) ||
(strncmp($2, "class", 5) == 0))
prev = 's';
else
prev = 't';
Debug((stderr, "\n\tadecl now =\n"));
Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
Debug((stderr, "\tprev = '%s'\n", visible(prev)));
}
;
adims : /* empty */
{
Debug((stderr, "adims: EMPTY\n"));
arbdims = 1;
$$ = ds("[]");
}
| NUMBER
{
Debug((stderr, "adims: NUMBER\n"));
Debug((stderr, "\tNUMBER='%s'\n", $1));
arbdims = 0;
$$ = cat(ds("["),$1,ds("]"),NullCP);
}
;
type : tinit c_type
{
Debug((stderr, "type: tinit c_type\n"));
Debug((stderr, "\ttinit=''\n"));
Debug((stderr, "\tc_type='%s'\n", $2));
mbcheck();
$$ = $2;
}
;
tinit : /* empty */
{
Debug((stderr, "tinit: EMPTY\n"));
modbits = 0;
}
;
c_type : mod_list
{
Debug((stderr, "c_type: mod_list\n"));
Debug((stderr, "\tmod_list='%s'\n", $1));
$$ = $1;
}
| tname
{
Debug((stderr, "c_type: tname\n"));
Debug((stderr, "\ttname='%s'\n", $1));
$$ = $1;
}
| mod_list tname
{
Debug((stderr, "c_type: mod_list tname\n"));
Debug((stderr, "\tmod_list='%s'\n", $1));
Debug((stderr, "\ttname='%s'\n", $2));
$$ = cat($1,ds(" "),$2,NullCP);
}
| StrClaUniEnum NAME
{
Debug((stderr, "c_type: StrClaUniEnum NAME\n"));
Debug((stderr, "\tStrClaUniEnum='%s'\n", $1));
Debug((stderr, "\tNAME='%s'\n", $2));
$$ = cat($1,ds(" "),$2,NullCP);
}
;
StrClaUniEnum : ClassStruct
| ENUM
| UNION
{
$$ = $1;
}
;
ClassStruct : STRUCT
| CLASS
{
$$ = $1;
}
;
tname : INT
{
Debug((stderr, "tname: INT\n"));
Debug((stderr, "\tINT='%s'\n", $1));
modbits |= MB_INT; $$ = $1;
}
| CHAR
{
Debug((stderr, "tname: CHAR\n"));
Debug((stderr, "\tCHAR='%s'\n", $1));
modbits |= MB_CHAR; $$ = $1;
}
| FLOAT
{
Debug((stderr, "tname: FLOAT\n"));
Debug((stderr, "\tFLOAT='%s'\n", $1));
modbits |= MB_FLOAT; $$ = $1;
}
| DOUBLE
{
Debug((stderr, "tname: DOUBLE\n"));
Debug((stderr, "\tDOUBLE='%s'\n", $1));
modbits |= MB_DOUBLE; $$ = $1;
}
| VOID
{
Debug((stderr, "tname: VOID\n"));
Debug((stderr, "\tVOID='%s'\n", $1));
modbits |= MB_VOID; $$ = $1;
}
;
mod_list : modifier mod_list1
{
Debug((stderr, "mod_list: modifier mod_list1\n"));
Debug((stderr, "\tmodifier='%s'\n", $1));
Debug((stderr, "\tmod_list1='%s'\n", $2));
$$ = cat($1,ds(" "),$2,NullCP);
}
| modifier
{
Debug((stderr, "mod_list: modifier\n"));
Debug((stderr, "\tmodifier='%s'\n", $1));
$$ = $1;
}
;
mod_list1 : mod_list
{
Debug((stderr, "mod_list1: mod_list\n"));
Debug((stderr, "\tmod_list='%s'\n", $1));
$$ = $1;
}
| CONSTVOLATILE
{
Debug((stderr, "mod_list1: CONSTVOLATILE\n"));
Debug((stderr, "\tCONSTVOLATILE='%s'\n", $1));
if (PreANSIFlag)
notsupported(" (Pre-ANSI Compiler)", $1, NullCP);
else if (RitchieFlag)
notsupported(" (Ritchie Compiler)", $1, NullCP);
else if ((strcmp($1, "noalias") == 0) && CplusplusFlag)
unsupp($1, NullCP);
$$ = $1;
}
;
modifier : UNSIGNED
{
Debug((stderr, "modifier: UNSIGNED\n"));
Debug((stderr, "\tUNSIGNED='%s'\n", $1));
modbits |= MB_UNSIGNED; $$ = $1;
}
| SIGNED
{
Debug((stderr, "modifier: SIGNED\n"));
Debug((stderr, "\tSIGNED='%s'\n", $1));
modbits |= MB_SIGNED; $$ = $1;
}
| LONG
{
Debug((stderr, "modifier: LONG\n"));
Debug((stderr, "\tLONG='%s'\n", $1));
modbits |= MB_LONG; $$ = $1;
}
| SHORT
{
Debug((stderr, "modifier: SHORT\n"));
Debug((stderr, "\tSHORT='%s'\n", $1));
modbits |= MB_SHORT; $$ = $1;
}
;
opt_constvol_list: CONSTVOLATILE opt_constvol_list
{
Debug((stderr, "opt_constvol_list: CONSTVOLATILE opt_constvol_list\n"));
Debug((stderr, "\tCONSTVOLATILE='%s'\n", $1));
Debug((stderr, "\topt_constvol_list='%s'\n", $2));
if (PreANSIFlag)
notsupported(" (Pre-ANSI Compiler)", $1, NullCP);
else if (RitchieFlag)
notsupported(" (Ritchie Compiler)", $1, NullCP);
else if ((strcmp($1, "noalias") == 0) && CplusplusFlag)
unsupp($1, NullCP);
$$ = cat($1,ds(strlen($2) ? " " : ""),$2,NullCP);
}
| /* empty */
{
Debug((stderr, "opt_constvol_list: EMPTY\n"));
$$ = ds("");
}
;
constvol_list: CONSTVOLATILE opt_constvol_list
{
Debug((stderr, "constvol_list: CONSTVOLATILE opt_constvol_list\n"));
Debug((stderr, "\tCONSTVOLATILE='%s'\n", $1));
Debug((stderr, "\topt_constvol_list='%s'\n", $2));
if (PreANSIFlag)
notsupported(" (Pre-ANSI Compiler)", $1, NullCP);
else if (RitchieFlag)
notsupported(" (Ritchie Compiler)", $1, NullCP);
else if ((strcmp($1, "noalias") == 0) && CplusplusFlag)
unsupp($1, NullCP);
$$ = cat($1,ds(strlen($2) ? " " : ""),$2,NullCP);
}
;
storage : AUTO
| EXTERN
| REGISTER
| STATIC
{
Debug((stderr, "storage: AUTO,EXTERN,STATIC,REGISTER (%s)\n", $1));
$$ = $1;
}
;
opt_storage : storage
{
Debug((stderr, "opt_storage: storage=%s\n", $1));
$$ = $1;
}
| /* empty */
{
Debug((stderr, "opt_storage: EMPTY\n"));
$$ = ds("");
}
;
%%