-
Notifications
You must be signed in to change notification settings - Fork 85
/
input.at
3100 lines (2549 loc) · 83.5 KB
/
input.at
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
# Checking the Bison reader. -*- Autotest -*-
# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
# 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 3 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, see <http://www.gnu.org/licenses/>.
AT_BANNER([[Input Processing.]])
# Mostly test that we are robust to mistakes.
## ----------------------------- ##
## Invalid number of arguments. ##
## ----------------------------- ##
AT_SETUP([Invalid number of arguments])
AT_BISON_CHECK([], [1], [],
[[bison: missing operand
Try 'bison --help' for more information.
]])
AT_BISON_CHECK([1.y 2.y], [1], [],
[[bison: extra operand '2.y'
Try 'bison --help' for more information.
]])
# For some reason, on some systems we use the system's getopt, not the
# one we ship in gnulib. So we can get two different error messages.
# See https://lists.gnu.org/archive/html/bison-patches/2018-10/msg00154.html
AT_BISON_CHECK([--skeleton], [1], [], [stderr])
AT_CHECK([[sed -e \
"s/requires an argument -- skeleton/'--skeleton' requires an argument/" \
stderr]], 0,
[[bison: option '--skeleton' requires an argument
Try 'bison --help' for more information.
]])
AT_CLEANUP
## ----------------- ##
## Invalid options. ##
## ----------------- ##
AT_SETUP([Invalid options])
AT_DATA([input.y],
[[%%
exp: '0'
]])
# We used to accept these, as -f, --report and others were sharing
# their code with -W.
AT_BISON_CHECK([-ferror=caret input.y], [1], [], [ignore])
AT_BISON_CHECK([--report=error=itemsets input.y], [1], [], [ignore])
# We used to accept any character after "-Werror", instead of ensuring
# this is "=".
AT_BISON_CHECK([-Werror?all input.y], [1], [], [ignore])
AT_CLEANUP
## ---------------- ##
## Invalid inputs. ##
## ---------------- ##
# The truly bad guys no human would write, but easily uncovered by
# fuzzers.
AT_SETUP([Invalid inputs])
AT_DATA([input.y],
[[\000\001\002\377?
"\000"
%%
?
default: 'a' }
%&
%a-does-not-exist
%-
%{
]])
AT_PERL_REQUIRE([[-pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y]])
AT_BISON_CHECK([-fcaret input.y], [1], [], [stderr])
# Autotest's diffing, when there are NUL bytes, just reports "binary
# files differ". So don't leave NUL bytes.
AT_PERL_CHECK([[-p -e 's{([\0\377])}{sprintf "\\x%02x", ord($1)}ge' stderr]], [],
[[input.y:1.1-2: error: invalid characters: '\0\001\002\377?'
1 | \x00\xff?
| ^~
input.y:2.2: error: invalid null character
2 | "\x00"
| ^
input.y:4.1: error: invalid character: '?'
4 | ?
| ^
input.y:5.14: error: invalid character: '}'
5 | default: 'a' }
| ^
input.y:6.1: error: invalid character: '%'
6 | %&
| ^
input.y:6.2: error: invalid character: '&'
6 | %&
| ^
input.y:7.1-17: error: invalid directive: '%a-does-not-exist'
7 | %a-does-not-exist
| ^~~~~~~~~~~~~~~~~
input.y:8.1: error: invalid character: '%'
8 | %-
| ^
input.y:8.2: error: invalid character: '-'
8 | %-
| ^
input.y:9.1-10.0: error: missing '%}' at end of file
9 | %{
| ^~
]])
AT_CLEANUP
## ------------------------ ##
## Invalid inputs with {}. ##
## ------------------------ ##
AT_SETUP([Invalid inputs with {}])
# We used to SEGV here. See
# http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
AT_DATA([input.y],
[[
%destructor
%initial-action
%lex-param
%parse-param
%printer
%union
]])
AT_BISON_CHECK([input.y], [1], [],
[[input.y:3.1-15: error: expected {...} before %initial-action
]])
AT_CLEANUP
## -------------------------- ##
## Yacc warnings on symbols. ##
## -------------------------- ##
AT_SETUP([Yacc warnings on symbols])
AT_DATA([input.y],
[[%nterm exp
%token NUM 0x40 "number"
%%
exp: "number";
]])
AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
[[input.y:1.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
1 | %nterm exp
| ^~~~~~
input.y:2.12-15: warning: POSIX Yacc does not support hexadecimal literals [-Wyacc]
2 | %token NUM 0x40 "number"
| ^~~~
input.y:2.17-24: warning: POSIX Yacc does not support string literals [-Wyacc]
2 | %token NUM 0x40 "number"
| ^~~~~~~~
input.y:4.6-13: warning: POSIX Yacc does not support string literals [-Wyacc]
4 | exp: "number";
| ^~~~~~~~
]])
AT_CLEANUP
## --------------- ##
## Yacc warnings. ##
## --------------- ##
AT_SETUP([Yacc warnings])
AT_DATA([input.y],
[[%destructor {} <int>
%printer {} <int>
%type <int> exp a b
%%
exp: a b { $$ = $1 + $2; };
a: <int>{ $$ = 42; } { $$ = $1; };
b: %empty { $$ = 42; };
]])
AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
[[input.y:1.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
1 | %destructor {} <int>
| ^~~~~~~~~~~
input.y:2.1-8: warning: POSIX Yacc does not support %printer [-Wyacc]
2 | %printer {} <int>
| ^~~~~~~~
input.y:6.9-20: warning: POSIX Yacc does not support typed midrule actions [-Wyacc]
6 | a: <int>{ $$ = 42; } { $$ = $1; };
| ^~~~~~~~~~~~
input.y:7.4-9: warning: POSIX Yacc does not support %empty [-Wyacc]
7 | b: %empty { $$ = 42; };
| ^~~~~~
]])
AT_CLEANUP
## -------------- ##
## Yacc's %type. ##
## -------------- ##
AT_SETUP([Yacc's %type])
AT_DATA([input.y],
[[%token TOKEN1
%nterm nterm1
%type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
%token TOKEN2
%nterm nterm2
%%
expr: nterm1 nterm2 nterm3
nterm1: TOKEN1
nterm2: TOKEN2
nterm3: "TOKEN3"
]])
AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
[[input.y:2.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
2 | %nterm nterm1
| ^~~~~~
input.y:3.14-19: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~~~~
input.y:3.28-35: warning: POSIX Yacc does not support string literals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~~~~~~
input.y:3.28-35: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~~~~~~
input.y:3.58-60: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~
input.y:5.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
5 | %nterm nterm2
| ^~~~~~
input.y:3.21-26: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~~~~
input.y:10.9-16: warning: POSIX Yacc does not support string literals [-Wyacc]
10 | nterm3: "TOKEN3"
| ^~~~~~~~
]])
AT_CLEANUP
## ----------------------------- ##
## Invalid symbol declarations. ##
## ----------------------------- ##
AT_SETUP([Invalid symbol declarations])
AT_DATA([input.y],
[[%nterm expr "expression";
%nterm term 123;
%nterm fact 124 "factor";
%nterm '+' '*';
%nterm "number";
%token "tok1" 1;
%left "tok2" 2;
%type "tok3" 3;
%%
expr: expr '+' term | term;
term: term '*' fact | fact;
fact: "number";
]])
AT_BISON_CHECK([-fcaret input.y], [1], [],
[[input.y:1.13-24: error: nonterminals cannot be given a string alias
1 | %nterm expr "expression";
| ^~~~~~~~~~~~
input.y:2.13-15: error: nonterminals cannot be given a token code
2 | %nterm term 123;
| ^~~
input.y:3.13-15: error: nonterminals cannot be given a token code
3 | %nterm fact 124 "factor";
| ^~~
input.y:3.17-24: error: nonterminals cannot be given a string alias
3 | %nterm fact 124 "factor";
| ^~~~~~~~
input.y:4.8-10: error: character literals cannot be nonterminals
4 | %nterm '+' '*';
| ^~~
input.y:5.8-15: error: expected character literal or identifier or <tag> before string
5 | %nterm "number";
| ^~~~~~~~
input.y:6.8-13: error: expected character literal or identifier or <tag> before string
6 | %token "tok1" 1;
| ^~~~~~
input.y:7.14: error: unexpected integer literal
7 | %left "tok2" 2;
| ^
input.y:8.14: error: unexpected integer literal
8 | %type "tok3" 3;
| ^
]])
AT_CLEANUP
## ---------------------------- ##
## Redefining the error token. ##
## ---------------------------- ##
AT_SETUP([Redefining the error token])
# We used to crash when trying to display the original definition of
# "error", which is a builtin without any location.
AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.y],
[[%token error 123
%token error 124
%%
exp:
]])
AT_BISON_CHECK([-fcaret input.y], [1], [],
[[input.y:2.8-12: warning: symbol error redeclared [-Wother]
2 | %token error 124
| ^~~~~
input.y:1.8-12: note: previous declaration
1 | %token error 123
| ^~~~~
input.y:2.14-16: error: redefining code of token error
2 | %token error 124
| ^~~
]])
# While at it, make sure we properly used the user's number for
# "error". I don't see what it buys us, but...
AT_DATA([input.y],
[[%{
#include <assert.h>
#include <stdio.h>
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
%}
%token error 123
%%
exp:
%%
int main (void)
{
assert (YYerror == 123);
assert (YYTRANSLATE (YYEOF) == YYSYMBOL_YYEOF);
assert (YYTRANSLATE (YYerror) == YYSYMBOL_YYerror);
assert (YYTRANSLATE (YYUNDEF) == YYSYMBOL_YYUNDEF);
return 0;
}
]])
AT_FULL_COMPILE([input])
AT_PARSER_CHECK([input], 0)
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
## ------------------ ##
## Dangling aliases. ##
## ------------------ ##
AT_SETUP([Dangling aliases])
AT_DATA([input.y],
[[%token FOO "foo"
%type <val> "bar"
%%
expr: "foo" "bar" "baz"
]])
AT_BISON_CHECK([-fcaret -Wdangling input.y], [0], [],
[[input.y:2.13-17: warning: string literal "bar" not attached to a symbol [-Wdangling-alias]
2 | %type <val> "bar"
| ^~~~~
input.y:4.19-23: warning: string literal "baz" not attached to a symbol [-Wdangling-alias]
4 | expr: "foo" "bar" "baz"
| ^~~~~
]])
AT_CLEANUP
## --------------------- ##
## Symbol declarations. ##
## --------------------- ##
# Check the parsing of %token, %nterm, %type and %left...
AT_SETUP([Symbol declarations])
AT_DATA([dump-symbols.m4],
[[m4@&t@_define([b4_api_PREFIX], [YY])
m4@&t@_define([b4_symbol_dump],
[$1, d@&t@nl
b4_symbol_if([$1], [is_token], [Token], [Nonterminal]), d@&t@nl
b4_symbol([$1], [tag]), d@&t@nl
b4_symbol([$1], [id]), d@&t@nl
b4_symbol([$1], [code]), d@&t@nl
b4_symbol([$1], [type]),
])
b4_output_begin([symbols.csv])
number, class, tag, id, code, type,
b4_symbol_foreach([b4_symbol_dump])d@&t@nl
b4_output_end
]])
AT_DATA([input.y],
[[%token 'a' A1 1 "A1" A2 A3 "A3" A4 4
<type_b> 'b' B5 5 "B5" B6 B7 "B8" B9 9
<type_c> 'c' C10 10 "C10" C11 C12 "C12" C13 13
%left 'd' D20 20 "D20" D21 D22 "D22" D23 23
<type_e> 'e' E25 25 "E25" E26 E27 "E28" E29 29
<type_f> 'f' F30 30 "F30" F31 F32 "F32" F33 33
%type 'g' G40 "D40" G21 G22 G23
<type_h> 'h' H25 "H25" H26 H27 "H28" H29
<type_i> 'i' I30 "I30" I31 I32 "I32" I33
%nterm j60 j61 j62 j63
<type_k> k75 k76 k77 k79
<type_l> l80 l81 l82 l83
%%
exp:;
]])
AT_BISON_CHECK([-Wno-other -S./dump-symbols.m4 input.y])
AT_CHECK([cat symbols.csv], [],
[[number, class, tag, id, code, type,
0, Token, "end of file", YYEOF, 0, ,
1, Token, error, YYerror, 256, ,
2, Token, "invalid token", YYUNDEF, 257, ,
3, Token, 'a', , 97, ,
4, Token, "A1", A1, 1, ,
5, Token, A2, A2, 258, ,
6, Token, "A3", A3, 259, ,
7, Token, A4, A4, 4, ,
8, Token, 'b', , 98, type_b,
9, Token, "B5", B5, 5, type_b,
10, Token, B6, B6, 260, type_b,
11, Token, "B8", B7, 261, type_b,
12, Token, B9, B9, 9, type_b,
13, Token, 'c', , 99, type_c,
14, Token, "C10", C10, 10, type_c,
15, Token, C11, C11, 262, type_c,
16, Token, "C12", C12, 263, type_c,
17, Token, C13, C13, 13, type_c,
18, Token, 'd', , 100, ,
19, Token, D20, D20, 20, ,
20, Token, "D20", , 264, ,
21, Token, D21, D21, 265, ,
22, Token, D22, D22, 266, ,
23, Token, "D22", , 267, ,
24, Token, D23, D23, 23, ,
25, Token, 'e', , 101, type_e,
26, Token, E25, E25, 25, type_e,
27, Token, "E25", , 268, type_e,
28, Token, E26, E26, 269, type_e,
29, Token, E27, E27, 270, type_e,
30, Token, "E28", , 271, type_e,
31, Token, E29, E29, 29, type_e,
32, Token, 'f', , 102, type_f,
33, Token, F30, F30, 30, type_f,
34, Token, "F30", , 272, type_f,
35, Token, F31, F31, 273, type_f,
36, Token, F32, F32, 274, type_f,
37, Token, "F32", , 275, type_f,
38, Token, F33, F33, 33, type_f,
39, Token, 'g', , 103, ,
40, Token, "D40", , 276, ,
41, Token, 'h', , 104, type_h,
42, Token, "H25", , 277, type_h,
43, Token, "H28", , 278, type_h,
44, Token, 'i', , 105, type_i,
45, Token, "I30", , 279, type_i,
46, Token, "I32", , 280, type_i,
47, Nonterminal, $accept, , -1, ,
48, Nonterminal, exp, exp, -1, ,
]])
AT_CLEANUP
## ------------ ##
## Invalid $n. ##
## ------------ ##
AT_SETUP([Invalid $n and @n])
AT_DATA([input.y],
[[%%
exp: %empty { $$ = $1 ; };
exp: %empty { @$ = @1 ; };
]])
AT_BISON_CHECK([-fcaret input.y], [1], [],
[[input.y:2.20-21: error: integer out of range: '$1'
2 | exp: %empty { $$ = $1 ; };
| ^~
input.y:3.20-21: error: integer out of range: '@1'
3 | exp: %empty { @$ = @1 ; };
| ^~
]])
AT_CLEANUP
## -------------- ##
## Type Clashes. ##
## -------------- ##
AT_SETUP([Type Clashes])
AT_DATA([input.y],
[[%union { int bar; }
%token foo
%type <bar> exp
%%
exp: foo { $$; } foo { $2; } foo
| foo
| %empty
;
]])
AT_BISON_CHECK([-fcaret input.y], [1], [],
[[input.y:5.12-13: error: $$ for the midrule at $2 of 'exp' has no declared type
5 | exp: foo { $$; } foo { $2; } foo
| ^~
input.y:5.24-25: error: $2 of 'exp' has no declared type
5 | exp: foo { $$; } foo { $2; } foo
| ^~
input.y:5.6-32: warning: type clash on default action: <bar> != <> [-Wother]
5 | exp: foo { $$; } foo { $2; } foo
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
input.y:6.6-8: warning: type clash on default action: <bar> != <> [-Wother]
6 | | foo
| ^~~
input.y:7.6-11: warning: empty rule for typed nonterminal, and no action [-Wother]
7 | | %empty
| ^~~~~~
]])
AT_CLEANUP
# _AT_UNUSED_VALUES_DECLARATIONS()
# --------------------------------
# Generate the token, type, and destructor
# declarations for the unused values tests.
m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
[[[%token <integer> INT;
%type <integer> a b c d e f g h i j k l m n o;
%destructor { destroy ($$); } <integer>;]]])
# AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
# ----------------------------------------------------------------
# Generate a grammar to test unused values, and compile it. If
# DECLARATIONS_AFTER is set, then the token, type, and destructor
# declarations are generated after the rules rather than before. If
# CHECK_MIDRULE_VALUES is set, then --warnings=midrule-values is set.
m4_define([AT_CHECK_UNUSED_VALUES],
[AT_DATA([input.y],
m4_ifval([$1], [
], [_AT_UNUSED_VALUES_DECLARATIONS
])[[%%
start:
'a' a { $][2; } | 'b' b { $][2; } | 'c' c { $][2; } | 'd' d { $][2; }
| 'e' e { $][2; } | 'f' f { $][2; } | 'g' g { $][2; } | 'h' h { $][2; }
| 'i' i { $][2; } | 'j' j { $][2; } | 'k' k { $][2; } | 'l' l { $][2; }
| 'm' m { $][2; } | 'n' n { $][2; } | 'o' o { $][2; }
;
a: INT | INT { } INT { } INT { };
b: INT | %empty;
c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
d: INT | INT { } INT { $][1; } INT { $<integer>2; };
e: INT | INT { } INT { } INT { $][1; };
f: INT | INT { } INT { } INT { $][$ = $][1 + $][3 + $][5; };
g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
i: INT | INT INT { } { $][$ = $][1 + $][2; };
j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; };
k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };
m: INT | INT <integer>{ $][$ = $][1; } INT <integer>{ $][$ = $][2 + $][3; } INT { $][$ = $][4 + $][5; };
n: INT | INT <integer>{ } INT <integer>{ } INT { };
o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
]]m4_ifval([$1], [
_AT_UNUSED_VALUES_DECLARATIONS])
)
AT_BISON_CHECK(m4_ifval([$2], [--warnings=midrule-values ])[-fcaret input.y],
[0], [],
[[input.y:12.10-32: warning: unset value: $][$ [-Wother]
12 | a: INT | INT { } INT { } INT { };
| ^~~~~~~~~~~~~~~~~~~~~~~
input.y:12.10-12: warning: unused value: $][1 [-Wother]
12 | a: INT | INT { } INT { } INT { };
| ^~~
input.y:12.18-20: warning: unused value: $][3 [-Wother]
12 | a: INT | INT { } INT { } INT { };
| ^~~
input.y:12.26-28: warning: unused value: $][5 [-Wother]
12 | a: INT | INT { } INT { } INT { };
| ^~~
input.y:13.10-15: warning: empty rule for typed nonterminal, and no action [-Wother]
13 | b: INT | %empty;
| ^~~~~~
]]m4_ifval([$2], [[[input.y:14.14-20: warning: unset value: $][$ [-Wmidrule-values]
14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
| ^~~~~~~
input.y:14.26-41: warning: unset value: $][$ [-Wmidrule-values]
14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
| ^~~~~~~~~~~~~~~~
]]])[[input.y:14.10-62: warning: unset value: $][$ [-Wother]
14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input.y:14.22-24: warning: unused value: $][3 [-Wother]
14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
| ^~~
input.y:14.43-45: warning: unused value: $][5 [-Wother]
14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
| ^~~
]]m4_ifval([$2], [[[input.y:15.14-16: warning: unset value: $][$ [-Wmidrule-values]
15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
| ^~~
]]])[[input.y:15.10-49: warning: unset value: $][$ [-Wother]
15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input.y:15.18-20: warning: unused value: $][3 [-Wother]
15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
| ^~~
input.y:15.30-32: warning: unused value: $][5 [-Wother]
15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
| ^~~
input.y:16.10-37: warning: unset value: $][$ [-Wother]
16 | e: INT | INT { } INT { } INT { $][1; };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
input.y:16.18-20: warning: unused value: $][3 [-Wother]
16 | e: INT | INT { } INT { } INT { $][1; };
| ^~~
input.y:16.27-29: warning: unused value: $][5 [-Wother]
16 | e: INT | INT { } INT { } INT { $][1; };
| ^~~
input.y:18.10-58: warning: unset value: $][$ [-Wother]
18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input.y:18.10-12: warning: unused value: $][1 [-Wother]
18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
| ^~~
]]m4_ifval([$2], [[[input.y:18.14-29: warning: unused value: $][2 [-Wmidrule-values]
18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
| ^~~~~~~~~~~~~~~~
]]])[[input.y:18.31-33: warning: unused value: $][3 [-Wother]
18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
| ^~~
]]m4_ifval([$2], [[[input.y:18.35-50: warning: unused value: $][4 [-Wmidrule-values]
18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
| ^~~~~~~~~~~~~~~~
]]])[[input.y:18.52-54: warning: unused value: $][5 [-Wother]
18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
| ^~~
input.y:19.10-72: warning: unset value: $][$ [-Wother]
19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input.y:19.10-12: warning: unused value: $][1 [-Wother]
19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
| ^~~
input.y:19.31-33: warning: unused value: $][3 [-Wother]
19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
| ^~~
]]m4_ifval([$2], [[[input.y:19.35-64: warning: unused value: $][4 [-Wmidrule-values]
19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
]]])[[input.y:19.66-68: warning: unused value: $][5 [-Wother]
19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
| ^~~
]]m4_ifval([$2], [[[input.y:21.18-37: warning: unused value: $][3 [-Wmidrule-values]
21 | j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; };
| ^~~~~~~~~~~~~~~~~~~~
]]])[[input.y:22.10-68: warning: unset value: $][$ [-Wother]
22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input.y:22.10-12: warning: unused value: $][1 [-Wother]
22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
| ^~~
input.y:22.14-16: warning: unused value: $][2 [-Wother]
22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
| ^~~
]]m4_ifval([$2], [[[input.y:22.35-64: warning: unused value: $][4 [-Wmidrule-values]
22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
]]])[[input.y:25.23-25: warning: unset value: $][$ [-Wother]
25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
| ^~~
input.y:25.40-42: warning: unset value: $][$ [-Wother]
25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
| ^~~
input.y:25.10-50: warning: unset value: $][$ [-Wother]
25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input.y:25.10-12: warning: unused value: $][1 [-Wother]
25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
| ^~~
input.y:25.23-25: warning: unused value: $][2 [-Wother]
25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
| ^~~
input.y:25.27-29: warning: unused value: $][3 [-Wother]
25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
| ^~~
input.y:25.40-42: warning: unused value: $][4 [-Wother]
25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
| ^~~
input.y:25.44-46: warning: unused value: $][5 [-Wother]
25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
| ^~~
input.y:26.23-25: warning: unset value: $][$ [-Wother]
26 | o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
| ^~~
input.y:26.40-42: warning: unset value: $][$ [-Wother]
26 | o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
| ^~~
]])
])
## --------------- ##
## Unused values. ##
## --------------- ##
AT_SETUP([Unused values])
AT_CHECK_UNUSED_VALUES
AT_CHECK_UNUSED_VALUES(, [1])
AT_CLEANUP
## ------------------------------------------ ##
## Unused values before symbol declarations. ##
## ------------------------------------------ ##
AT_SETUP([Unused values before symbol declarations])
AT_CHECK_UNUSED_VALUES([1])
AT_CHECK_UNUSED_VALUES([1], [1])
AT_CLEANUP
## ------------------- ##
## Symbol redeclared. ##
## ------------------- ##
AT_SETUP([Symbol redeclared])
AT_DATA([[input.y]],
[[%token FOO FOO
%token BAR 12 BAR 12
%token EOF 0 EOF 0
%%
exp: FOO BAR
]])
AT_BISON_CHECK([-fcaret input.y], [0], [],
[[input.y:1.12-14: warning: symbol FOO redeclared [-Wother]
1 | %token FOO FOO
| ^~~
input.y:1.8-10: note: previous declaration
1 | %token FOO FOO
| ^~~
input.y:2.15-17: warning: symbol BAR redeclared [-Wother]
2 | %token BAR 12 BAR 12
| ^~~
input.y:2.8-10: note: previous declaration
2 | %token BAR 12 BAR 12
| ^~~
input.y:3.14-16: warning: symbol EOF redeclared [-Wother]
3 | %token EOF 0 EOF 0
| ^~~
input.y:3.8-10: note: previous declaration
3 | %token EOF 0 EOF 0
| ^~~
]])
AT_CLEANUP
## ---------------- ##
## EOF redeclared. ##
## ---------------- ##
AT_SETUP([EOF redeclared])
# We used to crash when redefining a token after having defined EOF.
# See https://lists.gnu.org/r/bug-bison/2020-08/msg00008.html.
AT_DATA([[input.y]],
[[%token FOO BAR FOO 0
%%
input: %empty
]])
AT_BISON_CHECK([-fcaret input.y], [0], [],
[[input.y:1.16-18: warning: symbol FOO redeclared [-Wother]
1 | %token FOO BAR FOO 0
| ^~~
input.y:1.8-10: note: previous declaration
1 | %token FOO BAR FOO 0
| ^~~
]])
AT_CLEANUP
## --------------------------- ##
## Symbol class redefinition. ##
## --------------------------- ##
AT_SETUP([Symbol class redefinition])
AT_DATA([[input.y]],
[[%token FOO
%nterm FOO BAR
%token BAR
%nterm error // The token error cannot be redefined as an nterm.
%%
FOO: BAR
BAR:
]])
AT_BISON_CHECK([-fcaret input.y], [1], [],
[[input.y:2.8-10: error: symbol FOO redeclared as a nonterminal
2 | %nterm FOO BAR
| ^~~
input.y:1.8-10: note: previous definition
1 | %token FOO
| ^~~
input.y:3.8-10: error: symbol BAR redeclared as a token
3 | %token BAR
| ^~~
input.y:2.12-14: note: previous definition
2 | %nterm FOO BAR
| ^~~
input.y:4.8-12: error: symbol error redeclared as a nonterminal
4 | %nterm error // The token error cannot be redefined as an nterm.
| ^~~~~
input.y:6.1-3: error: rule given for FOO, which is a token
6 | FOO: BAR
| ^~~
]])
AT_CLEANUP
## --------------------------------------------- ##
## Default %printer and %destructor redeclared. ##
## --------------------------------------------- ##
AT_SETUP([Default %printer and %destructor redeclared])
# AT_TEST([*])
# ------------
m4_pushdef([AT_TEST],
[AT_DATA([[input.y]],
[[%destructor { destroy ($$); } <$1> <$1>
%printer { print ($$); } <$1> <$1>
%destructor { destroy ($$); } <$1>
%printer { print ($$); } <$1>
%%
start: %empty;
%destructor { destroy ($$); } <$1>;
%printer { print ($$); } <$1>;
]])
AT_BISON_CHECK([-fcaret input.y], [1], [],
[[input.y:1.13-29: error: %destructor redeclaration for <>
1 | %destructor { destroy ($$); } <> <>
| ^~~~~~~~~~~~~~~~~
input.y:1.13-29: note: previous declaration
1 | %destructor { destroy ($$); } <> <>
| ^~~~~~~~~~~~~~~~~
input.y:2.10-24: error: %printer redeclaration for <>
2 | %printer { print ($$); } <> <>
| ^~~~~~~~~~~~~~~
input.y:2.10-24: note: previous declaration
2 | %printer { print ($$); } <> <>
| ^~~~~~~~~~~~~~~
input.y:4.13-29: error: %destructor redeclaration for <>
4 | %destructor { destroy ($$); } <>
| ^~~~~~~~~~~~~~~~~
input.y:1.13-29: note: previous declaration
1 | %destructor { destroy ($$); } <> <>
| ^~~~~~~~~~~~~~~~~
input.y:5.10-24: error: %printer redeclaration for <>
5 | %printer { print ($$); } <>
| ^~~~~~~~~~~~~~~
input.y:2.10-24: note: previous declaration
2 | %printer { print ($$); } <> <>
| ^~~~~~~~~~~~~~~
input.y:11.13-29: error: %destructor redeclaration for <>
11 | %destructor { destroy ($$); } <>;
| ^~~~~~~~~~~~~~~~~
input.y:1.13-29: note: previous declaration
1 | %destructor { destroy ($$); } <> <>
| ^~~~~~~~~~~~~~~~~
input.y:12.10-24: error: %printer redeclaration for <>
12 | %printer { print ($$); } <>;
| ^~~~~~~~~~~~~~~
input.y:2.10-24: note: previous declaration
2 | %printer { print ($$); } <> <>
| ^~~~~~~~~~~~~~~
]])
])
AT_TEST([], [], [])
AT_TEST([], [*], [*])
m4_popdef([AT_TEST])
AT_CLEANUP
## ---------------------------------------------- ##
## Per-type %printer and %destructor redeclared. ##
## ---------------------------------------------- ##
AT_SETUP([Per-type %printer and %destructor redeclared])
AT_DATA([[input.y]],
[[%destructor { destroy ($$); } <field1> <field2>
%printer { print ($$); } <field1> <field2>
%destructor { destroy ($$); } <field1> <field1>
%printer { print ($$); } <field2> <field2>
%%
start: %empty;
%destructor { destroy ($$); } <field2> <field1>;
%printer { print ($$); } <field2> <field1>;
]])
AT_BISON_CHECK([input.y], [1], [],
[[input.y:4.13-29: error: %destructor redeclaration for <field1>
input.y:1.13-29: note: previous declaration
input.y:4.13-29: error: %destructor redeclaration for <field1>
input.y:1.13-29: note: previous declaration
input.y:5.10-24: error: %printer redeclaration for <field2>
input.y:2.10-24: note: previous declaration
input.y:5.10-24: error: %printer redeclaration for <field2>
input.y:2.10-24: note: previous declaration
input.y:11.13-29: error: %destructor redeclaration for <field2>
input.y:1.13-29: note: previous declaration
input.y:11.13-29: error: %destructor redeclaration for <field1>
input.y:1.13-29: note: previous declaration
input.y:12.10-24: error: %printer redeclaration for <field2>
input.y:2.10-24: note: previous declaration
input.y:12.10-24: error: %printer redeclaration for <field1>
input.y:2.10-24: note: previous declaration
]])