style: rename stmtMerge as stmt_merge
[bison.git] / tests / output.at
blobe2615161317048d7dc3a72279e9fa2f8a23eac7d
1 # Checking the output filenames.                    -*- Autotest -*-
3 # Copyright (C) 2000-2002, 2005-2015, 2018-2021 Free Software
4 # Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 AT_BANNER([[Output file names.]])
21 # AT_CHECK_FILES(EXPECTED-FILES, [IGNORED-FILES])
22 # -----------------------------------------------
23 # Check that the current directory contains FILE... (sorted).
24 m4_define([AT_CHECK_FILES],
25 [AT_REQUIRE([[find . -type f |
26            "$PERL" -ne '
27       s,\./,,; chomp;
28       push @file, $_ unless m{^($2|testsuite.log)$};
29       END { print join (" ", sort @file), "\n" }']],
30           [], [$1
31 ])])
33 # AT_CHECK_OUTPUT($1 = INPUT-FILE, $2 = [DIRECTIVES], $3 = [FLAGS],
34 #                 $4 = EXPECTED-FILES, $5 = [STATUS],
35 #                 $6 = [ADDITIONAL-TESTS], $7 = [PRE-TESTS])
36 # -----------------------------------------------------------------
37 m4_define([AT_CHECK_OUTPUT],
38 [AT_SETUP([[Output files: ]$2 $3])[
39 ]m4_bmatch([$3], [--html],
40            [AT_SKIP_IF([[test x"$XSLTPROC" = x]])])[
41 ]$7[
42 for file in ]$1 $4[; do
43   case $file in
44     */*) mkdir -p `echo "$file" | sed 's,/[^/]*,,'`;;
45   esac
46 done
47 ]AT_DATA([$1],
48 [$2[
50 foo: '0' {};
51 ]])
53 # There is no AT_DATA_UNQUOTED.
54 if $EGREP 'at_dir' $1 >/dev/null; then
55    AT_PERL_REQUIRE([-pi -e 's{\$at_dir}'"{$at_group_dir}g" $1])
56    # On Cygwin, up to Perl 5.28, 'perl -pi' left a foo.bak file.
57    AT_CHECK([rm -f $1.bak])
61 AT_BISON_CHECK([$3 $1], [$5], [], [ignore])[
62 # Ignore the files non-generated files
63 ]AT_CHECK_FILES([$4], [$1])[
64 ]$6[
65 ]AT_CLEANUP[
66 ]])
68 AT_CHECK_OUTPUT([foo.y], [], [-dv],
69                 [foo.output foo.tab.c foo.tab.h])
71 # Some versions of Valgrind (at least valgrind-3.6.0.SVN-Debian) report
72 # "fgrep: write error: Bad file descriptor" when stdout is closed, so we
73 # skip this test group during maintainer-check-valgrind.
74 AT_CHECK_OUTPUT([foo.y], [], [-dv >&-],
75                 [foo.output foo.tab.c foo.tab.h],
76                 [], [],
77                 [AT_CHECK([[case "$PREBISON" in *valgrind*) exit 77;; esac]])])
80 # Check how api.header.include.
81 AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.c],
82                 [foo.c foo.h foo.output], [],
83                 [AT_CHECK([grep '#include "foo.h"' foo.c], [0], [ignore])])
84 AT_CHECK_OUTPUT([foo.y], [], [-dv -y],
85                 [y.output y.tab.c y.tab.h], [],
86                 [AT_CHECK([grep '#include "y.tab.h"' y.tab.c], [1], [ignore])])
87 AT_CHECK_OUTPUT([foo.y], [%define api.header.include {"./foo.h"}], [-dv -y],
88                 [y.output y.tab.c y.tab.h], [],
89                 [AT_CHECK([grep '#include "./foo.h"' y.tab.c], [0], [ignore])])
92 AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.tab.c],
93                 [foo.output foo.tab.c foo.tab.h])
95 AT_CHECK_OUTPUT([foo.y], [], [--fixed-output-files -dv -g --html],
96                 [y.gv y.html y.output y.tab.c y.tab.h y.xml])
97 AT_CHECK_OUTPUT([foo.y], [], [-Hfoo.header -v -gfoo.gv --html=foo.html],
98                 [foo.gv foo.header foo.html foo.output foo.tab.c foo.xml])
100 AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml --fixed-output-files],
101                 [y.gv y.output y.tab.c y.tab.h y.xml])
102 AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -y],
103                 [y.gv y.output y.tab.c y.tab.h y.xml])
104 AT_CHECK_OUTPUT([foo.y], [%require "3.4"], [-dv -g --xml -y],
105                 [y.gv y.output y.tab.c y.tab.h y.xml])
106 # With '-o y.tab.c', we expect 'y.output' etc. (for compatibility with Yacc).
107 AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -o y.tab.c],
108                 [y.gv y.output y.tab.c y.tab.h y.xml])
110 AT_CHECK_OUTPUT([foo.y], [], [-dv -b bar],
111                 [bar.output bar.tab.c bar.tab.h])
112 AT_CHECK_OUTPUT([foo.y], [], [-dv -g -o foo.c],
113                 [foo.c foo.gv foo.h foo.output])
116 AT_CHECK_OUTPUT([foo.y], [%header %verbose],      [],
117                 [foo.output foo.tab.c foo.tab.h])
118 AT_CHECK_OUTPUT([foo.y], [%header %verbose %yacc],[],
119                 [y.output y.tab.c y.tab.h])
121 AT_CHECK_OUTPUT([foo.yy], [%header %verbose %yacc],[],
122                 [y.output y.tab.c y.tab.h])
124 # Exercise %output and %file-prefix including deprecated '='
125 AT_CHECK_OUTPUT([foo.y], [%file-prefix "bar" %header %verbose],      [],
126                 [bar.output bar.tab.c bar.tab.h])
127 AT_CHECK_OUTPUT([foo.y], [%output "bar.c" %header %verbose %yacc],[],
128                 [bar.c bar.h bar.output])
129 AT_CHECK_OUTPUT([foo.y],
130                 [%file-prefix "baz" %output "bar.c" %header %verbose %yacc],
131                 [],
132                 [bar.c bar.h bar.output])
135 # Check priorities of extension control.
136 AT_CHECK_OUTPUT([foo.yy], [%header %verbose], [],
137                 [foo.output foo.tab.cc foo.tab.hh])
139 AT_CHECK_OUTPUT([foo.yy], [%header %verbose ], [-o foo.c],
140                 [foo.c foo.h foo.output])
142 AT_CHECK_OUTPUT([foo.yy], [],
143                 [--header=foo.hpp -o foo.c++],
144                 [foo.c++ foo.hpp])
146 AT_CHECK_OUTPUT([foo.yy], [],
147                 [--header=foo.hpp -o foo.c++],
148                 [foo.c++ foo.hpp])
150 AT_CHECK_OUTPUT([foo.yy], [%header "foo.hpp"],
151                 [-o foo.c++],
152                 [foo.c++ foo.hpp])
154 AT_CHECK_OUTPUT([foo.yy], [],
155                 [-o foo.c++ --graph=foo.gph],
156                 [foo.c++ foo.gph])
158 # Do not generate code when there are early errors (even warnings as
159 # errors).
160 AT_CHECK_OUTPUT([foo.y], [%type <foo> useless],
161                 [--header --graph --xml --report=all -Wall -Werror],
162                 [foo.gv foo.output foo.xml],
163                 [1])
165 # Do not generate code when there are late errors (even warnings as
166 # errors).
167 AT_CHECK_OUTPUT([foo.y], [%define useless],
168                 [--header --graph --xml --report=all -Wall -Werror],
169                 [foo.gv foo.output foo.xml],
170                 [1])
172 # %header was spelled %defines before.
173 AT_CHECK_OUTPUT([foo.yy], [%defines],
174                 [-o foo.c++],
175                 [foo.c++ foo.h++])
176 AT_CHECK_OUTPUT([foo.yy], [%defines "foo.hpp"],
177                 [-o foo.c++],
178                 [foo.c++ foo.hpp])
181 ## ------------ ##
182 ## C++ output.  ##
183 ## ------------ ##
185 m4_define([AT_CHECK_NO_SUBDIR_PART],
186 [# Also make sure that the includes do not refer to the subdirectory.
187 AT_CHECK([grep 'include .subdir/' $1.cc], 1, [])
188 AT_CHECK([grep 'include .subdir/' $1.hh], 1, [])
191 AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc"], [],
192                 [foo.tab.cc])
194 AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %verbose], [],
195                 [foo.output foo.tab.cc])
197 AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %header %verbose], [],
198                 [foo.output foo.tab.cc foo.tab.hh stack.hh])
200 AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %verbose %locations], [],
201                 [foo.output foo.tab.cc])
203 AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %header %verbose %locations], [],
204                 [foo.output foo.tab.cc foo.tab.hh location.hh position.hh stack.hh])
206 AT_CHECK_OUTPUT([subdir/foo.yy], [%skeleton "lalr1.cc" %header %verbose], [],
207                 [foo.output foo.tab.cc foo.tab.hh stack.hh],
208                 [], [AT_CHECK_NO_SUBDIR_PART([foo.tab])])
210 AT_CHECK_OUTPUT([subdir/foo.yy], [%skeleton "lalr1.cc" %header %verbose %locations],
211                 [-o subdir/foo.cc],
212                 [subdir/foo.cc subdir/foo.hh subdir/foo.output subdir/location.hh subdir/position.hh subdir/stack.hh],
213                 [], [AT_CHECK_NO_SUBDIR_PART([subdir/foo])])
215 AT_CHECK_OUTPUT([gram_dir/foo.yy],
216                 [%skeleton "lalr1.cc" %header %verbose %file-prefix "output_dir/foo"],
217                 [],
218                 [output_dir/foo.output output_dir/foo.tab.cc output_dir/foo.tab.hh output_dir/stack.hh])
220 AT_CHECK_OUTPUT([gram_dir/foo.yy],
221                 [%skeleton "lalr1.cc" %header %locations %verbose %file-prefix "output_dir/foo"],
222                 [],
223                 [output_dir/foo.output output_dir/foo.tab.cc output_dir/foo.tab.hh output_dir/location.hh output_dir/position.hh output_dir/stack.hh])
225 # %require "3.2" => no position.hh not stack.hh.
226 AT_CHECK_OUTPUT([foo.yy],
227                 [%skeleton "lalr1.cc" %header %locations %define api.location.file none %require "3.2"],
228                 [],
229                 [foo.tab.cc foo.tab.hh])
231 AT_CHECK_OUTPUT([foo.yy],
232                 [%skeleton "lalr1.cc" %header %locations %define api.location.file "foo.loc.hh" %require "3.2"],
233                 [],
234                 [foo.loc.hh foo.tab.cc foo.tab.hh])
236 # Absolute paths.
237 AT_CHECK_OUTPUT([foo.yy],
238                 [%skeleton "lalr1.cc" %header %locations %define api.location.file "$at_dir/foo.loc.hh" %require "3.2"],
239                 [],
240                 [foo.loc.hh foo.tab.cc foo.tab.hh])
243 # AT_CHECK_CONFLICTING_OUTPUT(INPUT-FILE, DIRECTIVES, FLAGS, STDERR,
244 #                             [EXIT-STATUS])
245 # ------------------------------------------------------------------
246 m4_define([AT_CHECK_CONFLICTING_OUTPUT],
247 [AT_SETUP([Conflicting output files: $2 $3])
248 case "$1" in
249   */*) mkdir `echo "$1" | sed 's,/.*,,'`;;
250 esac
251 AT_DATA([$1],
252 [[$2
254 foo: {};
257 [cp ]$1[ expout]
258 # Because an output file name conflict is still a warning, Bison exits
259 # with status 0, so AT_BISON_CHECK does not realize that there may be no
260 # output file against which to check the XML.  AT_BISON_CHECK_NO_XML
261 # avoids that problem.
262 AT_BISON_CHECK_NO_XML([$3 $1], $5, [], [$4])
263 AT_CHECK([[cat $1]], [[0]], [expout])
264 AT_CLEANUP
267 AT_CHECK_CONFLICTING_OUTPUT([foo.y],
268 [], [--graph="foo.tab.c"],
269 [[foo.y: warning: conflicting outputs to file 'foo.tab.c' [-Wother]
272 AT_CHECK_CONFLICTING_OUTPUT([foo.y],
273 [%header "foo.output"], [-v],
274 [[foo.y: warning: conflicting outputs to file 'foo.output' [-Wother]
277 AT_CHECK_CONFLICTING_OUTPUT([foo.y],
278 [%skeleton "lalr1.cc" %header %locations], [--graph="location.hh"],
279 [[foo.y: warning: conflicting outputs to file 'location.hh' [-Wother]
282 AT_CHECK_CONFLICTING_OUTPUT([foo.y], [], [-o foo.y],
283 [[foo.y: error: refusing to overwrite the input file 'foo.y'
284 ]], 1)
287 # AT_CHECK_OUTPUT_FILE_NAME(FILE-NAME-PREFIX, [ADDITIONAL-TESTS])
288 # ---------------------------------------------------------------
289 m4_define([AT_CHECK_OUTPUT_FILE_NAME],
290 [AT_SETUP([Output file name: $1])
292 AT_BISON_OPTION_PUSHDEFS
293 # Skip if platform doesn't support file name.  For example, Cygwin
294 # doesn't support file names containing ":" or "\".
295 AT_REQUIRE([[touch "]AS_ESCAPE([$1[.tmp]])["]])
297 AT_DATA_GRAMMAR([glr.y],
298 [[%glr-parser
299 %code {
300 ]AT_YYERROR_DECLARE_EXTERN[
301 ]AT_YYLEX_DECLARE_EXTERN[
304 start: {};
306 AT_BISON_CHECK([-o "AS_ESCAPE([$1.c])" --header="AS_ESCAPE([$1.h])" glr.y])
307 AT_CHECK([ls "AS_ESCAPE([$1.c])" "AS_ESCAPE([$1.h])"], [], [ignore])
308 AT_COMPILE([glr.o], [-c "AS_ESCAPE([$1.c])"])
311 AT_DATA_GRAMMAR([cxx.y],
312 [[%skeleton "lalr1.cc"
313 %code { int yylex (yy::parser::semantic_type*); }
315 start: {};
317 AT_BISON_CHECK([-o "AS_ESCAPE([$1.cc])" --header="AS_ESCAPE([$1.hh])" cxx.y])
318 AT_CHECK([ls "AS_ESCAPE([$1.cc])" "AS_ESCAPE([$1.hh])"], [], [ignore])
319 AT_COMPILE_CXX([cxx.o], [-c "AS_ESCAPE([$1.cc])"])
322 AT_BISON_OPTION_POPDEFS
323 AT_CLEANUP
326 # Notice that the header file name here cannot contain
327 # '"' since FILENAME in '#include "FILENAME"' cannot.
328 AT_CHECK_OUTPUT_FILE_NAME([[`~!@#$%^&*()-=_+{}[]|\:;<>, .']])
329 dnl Work around a bug in m4_expand that broke AT_SETUP in autoconf 2.62,
330 dnl by using the definition from 2.63.
331 m4_version_prereq([2.63], [],
332 [m4_define([m4_expand], [_$0(-=<{($1)}>=-)])
333 m4_define([_m4_expand],
334 [m4_changequote([-=<{(], [)}>=-])$1m4_changequote([, ])])])
335 AT_CHECK_OUTPUT_FILE_NAME([[(]])
336 AT_CHECK_OUTPUT_FILE_NAME([[)]])
337 AT_CHECK_OUTPUT_FILE_NAME([[@%:@]])
338 AT_CHECK_OUTPUT_FILE_NAME([[@@]])
339 AT_CHECK_OUTPUT_FILE_NAME([[@{]])
340 AT_CHECK_OUTPUT_FILE_NAME([[@}]])
341 AT_CHECK_OUTPUT_FILE_NAME([[@<:@]])
342 AT_CHECK_OUTPUT_FILE_NAME([[@:>@]])
345 # AT_TEST(SETUP-NAME, GRAMMAR, DOT-BODY)
346 # --------------------------------------
347 # Check that the DOT graph for GRAMMAR is DOT-BODY.
348 m4_pushdef([AT_TEST],
349 [AT_SETUP([$1])
350 AT_KEYWORDS([[graph]])
351 AT_DATA([[input.y]], [$2])
352 AT_BISON_CHECK([[-rall --graph input.y]], [0], [[]], [[ignore]])
353 AT_CHECK([[grep -v // input.gv]], [0],
354 [$3])
355 AT_CLEANUP
359 ## ------------------------ ##
360 ## Graph with no conflicts. ##
361 ## ------------------------ ##
363 AT_TEST([Graph with no conflicts],
364 [[%%
365 exp: a '?' b;
366 a: ;
367 b: 'b';
370 digraph "input.y"
372   node [fontname = courier, shape = box, colorscheme = paired6]
373   edge [fontname = courier]
375   0 [label="State 0\n\l  0 $accept: • exp $end\l  1 exp: • a '?' b\l  2 a: • %empty\l"]
376   0 -> 1 [style=dashed label="exp"]
377   0 -> 2 [style=dashed label="a"]
378   0 -> "0R2" [style=solid]
379  "0R2" [label="R2", fillcolor=3, shape=diamond, style=filled]
380   1 [label="State 1\n\l  0 $accept: exp • $end\l"]
381   1 -> 3 [style=solid label="$end"]
382   2 [label="State 2\n\l  1 exp: a • '?' b\l"]
383   2 -> 4 [style=solid label="'?'"]
384   3 [label="State 3\n\l  0 $accept: exp $end •\l"]
385   3 -> "3R0" [style=solid]
386  "3R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
387   4 [label="State 4\n\l  1 exp: a '?' • b\l  3 b: • 'b'\l"]
388   4 -> 5 [style=solid label="'b'"]
389   4 -> 6 [style=dashed label="b"]
390   5 [label="State 5\n\l  3 b: 'b' •\l"]
391   5 -> "5R3" [style=solid]
392  "5R3" [label="R3", fillcolor=3, shape=diamond, style=filled]
393   6 [label="State 6\n\l  1 exp: a '?' b •\l"]
394   6 -> "6R1" [style=solid]
395  "6R1" [label="R1", fillcolor=3, shape=diamond, style=filled]
399 ## ------------------------ ##
400 ## Graph with unsolved S/R. ##
401 ## ------------------------ ##
403 AT_TEST([Graph with unsolved S/R],
404 [[%%
405 start:
406     'a'
407   | empty_a 'a'
408   | 'b'
409   | empty_b 'b'
410   | 'c'
411   | empty_c 'c'
412   ;
413 empty_a: %prec 'a';
414 empty_b: %prec 'b';
415 empty_c: %prec 'c';
418 digraph "input.y"
420   node [fontname = courier, shape = box, colorscheme = paired6]
421   edge [fontname = courier]
423   0 [label="State 0\n\l  0 $accept: • start $end\l  1 start: • 'a'\l  2      | • empty_a 'a'\l  3      | • 'b'\l  4      | • empty_b 'b'\l  5      | • 'c'\l  6      | • empty_c 'c'\l  7 empty_a: • %empty  ['a']\l  8 empty_b: • %empty  ['b']\l  9 empty_c: • %empty  ['c']\l"]
424   0 -> 1 [style=solid label="'a'"]
425   0 -> 2 [style=solid label="'b'"]
426   0 -> 3 [style=solid label="'c'"]
427   0 -> 4 [style=dashed label="start"]
428   0 -> 5 [style=dashed label="empty_a"]
429   0 -> 6 [style=dashed label="empty_b"]
430   0 -> 7 [style=dashed label="empty_c"]
431   0 -> "0R7d" [label="['a']", style=solid]
432  "0R7d" [label="R7", fillcolor=5, shape=diamond, style=filled]
433   0 -> "0R8d" [label="['b']", style=solid]
434  "0R8d" [label="R8", fillcolor=5, shape=diamond, style=filled]
435   0 -> "0R9d" [label="['c']", style=solid]
436  "0R9d" [label="R9", fillcolor=5, shape=diamond, style=filled]
437   1 [label="State 1\n\l  1 start: 'a' •\l"]
438   1 -> "1R1" [style=solid]
439  "1R1" [label="R1", fillcolor=3, shape=diamond, style=filled]
440   2 [label="State 2\n\l  3 start: 'b' •\l"]
441   2 -> "2R3" [style=solid]
442  "2R3" [label="R3", fillcolor=3, shape=diamond, style=filled]
443   3 [label="State 3\n\l  5 start: 'c' •\l"]
444   3 -> "3R5" [style=solid]
445  "3R5" [label="R5", fillcolor=3, shape=diamond, style=filled]
446   4 [label="State 4\n\l  0 $accept: start • $end\l"]
447   4 -> 8 [style=solid label="$end"]
448   5 [label="State 5\n\l  2 start: empty_a • 'a'\l"]
449   5 -> 9 [style=solid label="'a'"]
450   6 [label="State 6\n\l  4 start: empty_b • 'b'\l"]
451   6 -> 10 [style=solid label="'b'"]
452   7 [label="State 7\n\l  6 start: empty_c • 'c'\l"]
453   7 -> 11 [style=solid label="'c'"]
454   8 [label="State 8\n\l  0 $accept: start $end •\l"]
455   8 -> "8R0" [style=solid]
456  "8R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
457   9 [label="State 9\n\l  2 start: empty_a 'a' •\l"]
458   9 -> "9R2" [style=solid]
459  "9R2" [label="R2", fillcolor=3, shape=diamond, style=filled]
460   10 [label="State 10\n\l  4 start: empty_b 'b' •\l"]
461   10 -> "10R4" [style=solid]
462  "10R4" [label="R4", fillcolor=3, shape=diamond, style=filled]
463   11 [label="State 11\n\l  6 start: empty_c 'c' •\l"]
464   11 -> "11R6" [style=solid]
465  "11R6" [label="R6", fillcolor=3, shape=diamond, style=filled]
469 ## ---------------------- ##
470 ## Graph with solved S/R. ##
471 ## ---------------------- ##
473 AT_TEST([Graph with solved S/R],
474 [[%left 'a'
475 %right 'b'
476 %right 'c'
478 start:
479     'a'
480   | empty_a 'a'
481   | 'b'
482   | empty_b 'b'
483   | 'c'
484   | empty_c 'c'
485   ;
486 empty_a: %prec 'a';
487 empty_b: %prec 'b';
488 empty_c: %prec 'c';
491 digraph "input.y"
493   node [fontname = courier, shape = box, colorscheme = paired6]
494   edge [fontname = courier]
496   0 [label="State 0\n\l  0 $accept: • start $end\l  1 start: • 'a'\l  2      | • empty_a 'a'\l  3      | • 'b'\l  4      | • empty_b 'b'\l  5      | • 'c'\l  6      | • empty_c 'c'\l  7 empty_a: • %empty  ['a']\l  8 empty_b: • %empty  []\l  9 empty_c: • %empty  []\l"]
497   0 -> 1 [style=solid label="'b'"]
498   0 -> 2 [style=solid label="'c'"]
499   0 -> 3 [style=dashed label="start"]
500   0 -> 4 [style=dashed label="empty_a"]
501   0 -> 5 [style=dashed label="empty_b"]
502   0 -> 6 [style=dashed label="empty_c"]
503   0 -> "0R7" [style=solid]
504  "0R7" [label="R7", fillcolor=3, shape=diamond, style=filled]
505   1 [label="State 1\n\l  3 start: 'b' •\l"]
506   1 -> "1R3" [style=solid]
507  "1R3" [label="R3", fillcolor=3, shape=diamond, style=filled]
508   2 [label="State 2\n\l  5 start: 'c' •\l"]
509   2 -> "2R5" [style=solid]
510  "2R5" [label="R5", fillcolor=3, shape=diamond, style=filled]
511   3 [label="State 3\n\l  0 $accept: start • $end\l"]
512   3 -> 7 [style=solid label="$end"]
513   4 [label="State 4\n\l  2 start: empty_a • 'a'\l"]
514   4 -> 8 [style=solid label="'a'"]
515   5 [label="State 5\n\l  4 start: empty_b • 'b'\l"]
516   5 -> 9 [style=solid label="'b'"]
517   6 [label="State 6\n\l  6 start: empty_c • 'c'\l"]
518   6 -> 10 [style=solid label="'c'"]
519   7 [label="State 7\n\l  0 $accept: start $end •\l"]
520   7 -> "7R0" [style=solid]
521  "7R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
522   8 [label="State 8\n\l  2 start: empty_a 'a' •\l"]
523   8 -> "8R2" [style=solid]
524  "8R2" [label="R2", fillcolor=3, shape=diamond, style=filled]
525   9 [label="State 9\n\l  4 start: empty_b 'b' •\l"]
526   9 -> "9R4" [style=solid]
527  "9R4" [label="R4", fillcolor=3, shape=diamond, style=filled]
528   10 [label="State 10\n\l  6 start: empty_c 'c' •\l"]
529   10 -> "10R6" [style=solid]
530  "10R6" [label="R6", fillcolor=3, shape=diamond, style=filled]
534 ## ---------------- ##
535 ## Graph with  R/R. ##
536 ## ---------------- ##
538 AT_TEST([Graph with R/R],
539 [[%%
540 exp: a | b;
541 a: ;
542 b: ;
545 digraph "input.y"
547   node [fontname = courier, shape = box, colorscheme = paired6]
548   edge [fontname = courier]
550   0 [label="State 0\n\l  0 $accept: • exp $end\l  1 exp: • a\l  2    | • b\l  3 a: • %empty  [$end]\l  4 b: • %empty  [$end]\l"]
551   0 -> 1 [style=dashed label="exp"]
552   0 -> 2 [style=dashed label="a"]
553   0 -> 3 [style=dashed label="b"]
554   0 -> "0R3" [style=solid]
555  "0R3" [label="R3", fillcolor=3, shape=diamond, style=filled]
556   0 -> "0R4d" [label="[$end]", style=solid]
557  "0R4d" [label="R4", fillcolor=5, shape=diamond, style=filled]
558   1 [label="State 1\n\l  0 $accept: exp • $end\l"]
559   1 -> 4 [style=solid label="$end"]
560   2 [label="State 2\n\l  1 exp: a •\l"]
561   2 -> "2R1" [style=solid]
562  "2R1" [label="R1", fillcolor=3, shape=diamond, style=filled]
563   3 [label="State 3\n\l  2 exp: b •\l"]
564   3 -> "3R2" [style=solid]
565  "3R2" [label="R2", fillcolor=3, shape=diamond, style=filled]
566   4 [label="State 4\n\l  0 $accept: exp $end •\l"]
567   4 -> "4R0" [style=solid]
568  "4R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
572 ## ---------------------------------------- ##
573 ## Graph with reductions with multiple LAT. ##
574 ## ---------------------------------------- ##
576 AT_TEST([Graph with reductions with multiple LAT],
577 [[%%
578 exp: a ';' | a ';' | a '.' | b '?' | b '!' | c '?' | c ';';
579 a: ;
580 b: ;
581 c: ;
584 digraph "input.y"
586   node [fontname = courier, shape = box, colorscheme = paired6]
587   edge [fontname = courier]
589   0 [label="State 0\n\l  0 $accept: • exp $end\l  1 exp: • a ';'\l  2    | • a ';'\l  3    | • a '.'\l  4    | • b '?'\l  5    | • b '!'\l  6    | • c '?'\l  7    | • c ';'\l  8 a: • %empty  [';', '.']\l  9 b: • %empty  ['?', '!']\l 10 c: • %empty  [';', '?']\l"]
590   0 -> 1 [style=dashed label="exp"]
591   0 -> 2 [style=dashed label="a"]
592   0 -> 3 [style=dashed label="b"]
593   0 -> 4 [style=dashed label="c"]
594   0 -> "0R8" [style=solid]
595  "0R8" [label="R8", fillcolor=3, shape=diamond, style=filled]
596   0 -> "0R9" [label="['?', '!']", style=solid]
597  "0R9" [label="R9", fillcolor=3, shape=diamond, style=filled]
598   0 -> "0R10d" [label="[';', '?']", style=solid]
599  "0R10d" [label="R10", fillcolor=5, shape=diamond, style=filled]
600   1 [label="State 1\n\l  0 $accept: exp • $end\l"]
601   1 -> 5 [style=solid label="$end"]
602   2 [label="State 2\n\l  1 exp: a • ';'\l  2    | a • ';'\l  3    | a • '.'\l"]
603   2 -> 6 [style=solid label="';'"]
604   2 -> 7 [style=solid label="'.'"]
605   3 [label="State 3\n\l  4 exp: b • '?'\l  5    | b • '!'\l"]
606   3 -> 8 [style=solid label="'?'"]
607   3 -> 9 [style=solid label="'!'"]
608   4 [label="State 4\n\l  6 exp: c • '?'\l  7    | c • ';'\l"]
609   4 -> 10 [style=solid label="';'"]
610   4 -> 11 [style=solid label="'?'"]
611   5 [label="State 5\n\l  0 $accept: exp $end •\l"]
612   5 -> "5R0" [style=solid]
613  "5R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
614   6 [label="State 6\n\l  1 exp: a ';' •  [$end]\l  2    | a ';' •  [$end]\l"]
615   6 -> "6R1" [style=solid]
616  "6R1" [label="R1", fillcolor=3, shape=diamond, style=filled]
617   6 -> "6R2d" [label="[$end]", style=solid]
618  "6R2d" [label="R2", fillcolor=5, shape=diamond, style=filled]
619   7 [label="State 7\n\l  3 exp: a '.' •\l"]
620   7 -> "7R3" [style=solid]
621  "7R3" [label="R3", fillcolor=3, shape=diamond, style=filled]
622   8 [label="State 8\n\l  4 exp: b '?' •\l"]
623   8 -> "8R4" [style=solid]
624  "8R4" [label="R4", fillcolor=3, shape=diamond, style=filled]
625   9 [label="State 9\n\l  5 exp: b '!' •\l"]
626   9 -> "9R5" [style=solid]
627  "9R5" [label="R5", fillcolor=3, shape=diamond, style=filled]
628   10 [label="State 10\n\l  7 exp: c ';' •\l"]
629   10 -> "10R7" [style=solid]
630  "10R7" [label="R7", fillcolor=3, shape=diamond, style=filled]
631   11 [label="State 11\n\l  6 exp: c '?' •\l"]
632   11 -> "11R6" [style=solid]
633  "11R6" [label="R6", fillcolor=3, shape=diamond, style=filled]
637 ## ------------------------------------------------------ ##
638 ## Graph with a reduction rule both enabled and disabled. ##
639 ## ------------------------------------------------------ ##
641 AT_TEST([Graph with a reduction rule both enabled and disabled],
642 [[%%
643 exp: ifexp | opexp | imm;
644 ifexp: "if" exp "then" exp elseexp;
645 elseexp: "else" exp | ;
646 opexp: exp '+' exp;
647 imm: '0';
650 digraph "input.y"
652   node [fontname = courier, shape = box, colorscheme = paired6]
653   edge [fontname = courier]
655   0 [label="State 0\n\l  0 $accept: • exp $end\l  1 exp: • ifexp\l  2    | • opexp\l  3    | • imm\l  4 ifexp: • \"if\" exp \"then\" exp elseexp\l  7 opexp: • exp '+' exp\l  8 imm: • '0'\l"]
656   0 -> 1 [style=solid label="\"if\""]
657   0 -> 2 [style=solid label="'0'"]
658   0 -> 3 [style=dashed label="exp"]
659   0 -> 4 [style=dashed label="ifexp"]
660   0 -> 5 [style=dashed label="opexp"]
661   0 -> 6 [style=dashed label="imm"]
662   1 [label="State 1\n\l  1 exp: • ifexp\l  2    | • opexp\l  3    | • imm\l  4 ifexp: • \"if\" exp \"then\" exp elseexp\l  4      | \"if\" • exp \"then\" exp elseexp\l  7 opexp: • exp '+' exp\l  8 imm: • '0'\l"]
663   1 -> 1 [style=solid label="\"if\""]
664   1 -> 2 [style=solid label="'0'"]
665   1 -> 7 [style=dashed label="exp"]
666   1 -> 4 [style=dashed label="ifexp"]
667   1 -> 5 [style=dashed label="opexp"]
668   1 -> 6 [style=dashed label="imm"]
669   2 [label="State 2\n\l  8 imm: '0' •\l"]
670   2 -> "2R8" [style=solid]
671  "2R8" [label="R8", fillcolor=3, shape=diamond, style=filled]
672   3 [label="State 3\n\l  0 $accept: exp • $end\l  7 opexp: exp • '+' exp\l"]
673   3 -> 8 [style=solid label="$end"]
674   3 -> 9 [style=solid label="'+'"]
675   4 [label="State 4\n\l  1 exp: ifexp •\l"]
676   4 -> "4R1" [style=solid]
677  "4R1" [label="R1", fillcolor=3, shape=diamond, style=filled]
678   5 [label="State 5\n\l  2 exp: opexp •\l"]
679   5 -> "5R2" [style=solid]
680  "5R2" [label="R2", fillcolor=3, shape=diamond, style=filled]
681   6 [label="State 6\n\l  3 exp: imm •\l"]
682   6 -> "6R3" [style=solid]
683  "6R3" [label="R3", fillcolor=3, shape=diamond, style=filled]
684   7 [label="State 7\n\l  4 ifexp: \"if\" exp • \"then\" exp elseexp\l  7 opexp: exp • '+' exp\l"]
685   7 -> 10 [style=solid label="\"then\""]
686   7 -> 9 [style=solid label="'+'"]
687   8 [label="State 8\n\l  0 $accept: exp $end •\l"]
688   8 -> "8R0" [style=solid]
689  "8R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
690   9 [label="State 9\n\l  1 exp: • ifexp\l  2    | • opexp\l  3    | • imm\l  4 ifexp: • \"if\" exp \"then\" exp elseexp\l  7 opexp: • exp '+' exp\l  7      | exp '+' • exp\l  8 imm: • '0'\l"]
691   9 -> 1 [style=solid label="\"if\""]
692   9 -> 2 [style=solid label="'0'"]
693   9 -> 11 [style=dashed label="exp"]
694   9 -> 4 [style=dashed label="ifexp"]
695   9 -> 5 [style=dashed label="opexp"]
696   9 -> 6 [style=dashed label="imm"]
697   10 [label="State 10\n\l  1 exp: • ifexp\l  2    | • opexp\l  3    | • imm\l  4 ifexp: • \"if\" exp \"then\" exp elseexp\l  4      | \"if\" exp \"then\" • exp elseexp\l  7 opexp: • exp '+' exp\l  8 imm: • '0'\l"]
698   10 -> 1 [style=solid label="\"if\""]
699   10 -> 2 [style=solid label="'0'"]
700   10 -> 12 [style=dashed label="exp"]
701   10 -> 4 [style=dashed label="ifexp"]
702   10 -> 5 [style=dashed label="opexp"]
703   10 -> 6 [style=dashed label="imm"]
704   11 [label="State 11\n\l  7 opexp: exp • '+' exp\l  7      | exp '+' exp •  [$end, \"then\", \"else\", '+']\l"]
705   11 -> 9 [style=solid label="'+'"]
706   11 -> "11R7d" [label="['+']", style=solid]
707  "11R7d" [label="R7", fillcolor=5, shape=diamond, style=filled]
708   11 -> "11R7" [style=solid]
709  "11R7" [label="R7", fillcolor=3, shape=diamond, style=filled]
710   12 [label="State 12\n\l  4 ifexp: \"if\" exp \"then\" exp • elseexp\l  5 elseexp: • \"else\" exp\l  6        | • %empty  [$end, \"then\", \"else\", '+']\l  7 opexp: exp • '+' exp\l"]
711   12 -> 13 [style=solid label="\"else\""]
712   12 -> 9 [style=solid label="'+'"]
713   12 -> 14 [style=dashed label="elseexp"]
714   12 -> "12R6d" [label="[\"else\", '+']", style=solid]
715  "12R6d" [label="R6", fillcolor=5, shape=diamond, style=filled]
716   12 -> "12R6" [style=solid]
717  "12R6" [label="R6", fillcolor=3, shape=diamond, style=filled]
718   13 [label="State 13\n\l  1 exp: • ifexp\l  2    | • opexp\l  3    | • imm\l  4 ifexp: • \"if\" exp \"then\" exp elseexp\l  5 elseexp: \"else\" • exp\l  7 opexp: • exp '+' exp\l  8 imm: • '0'\l"]
719   13 -> 1 [style=solid label="\"if\""]
720   13 -> 2 [style=solid label="'0'"]
721   13 -> 15 [style=dashed label="exp"]
722   13 -> 4 [style=dashed label="ifexp"]
723   13 -> 5 [style=dashed label="opexp"]
724   13 -> 6 [style=dashed label="imm"]
725   14 [label="State 14\n\l  4 ifexp: \"if\" exp \"then\" exp elseexp •\l"]
726   14 -> "14R4" [style=solid]
727  "14R4" [label="R4", fillcolor=3, shape=diamond, style=filled]
728   15 [label="State 15\n\l  5 elseexp: \"else\" exp •  [$end, \"then\", \"else\", '+']\l  7 opexp: exp • '+' exp\l"]
729   15 -> 9 [style=solid label="'+'"]
730   15 -> "15R5d" [label="['+']", style=solid]
731  "15R5d" [label="R5", fillcolor=5, shape=diamond, style=filled]
732   15 -> "15R5" [style=solid]
733  "15R5" [label="R5", fillcolor=3, shape=diamond, style=filled]
737 m4_popdef([AT_TEST])
740 ## -------------------------------- ##
741 ## C++ Output File Prefix Mapping.  ##
742 ## -------------------------------- ##
744 AT_SETUP([C++ Output File Prefix Mapping])
746 # AT_TEST([PREFIX], [DIRECTIVES])
747 # -------------------------------
748 m4_pushdef([AT_TEST],
749 [AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" %define api.namespace {$1} $2])
750 AT_LOC_PUSHDEF([begin.line], [begin.column], [end.line], [end.column])
751 AT_DATA_GRAMMAR([$1.yy],
752 [[%skeleton "lalr1.cc"
753 %define api.namespace {$1}
755 %code {
756   ]AT_YYERROR_DECLARE[
757   ]AT_YYLEX_DECLARE[
760 exp: '0';
762 ]AT_YYERROR_DEFINE[
763 ]AT_YYLEX_DEFINE(["0"])[
766 AT_BISON_CHECK([-fcaret -o out/$1.cc -M out/=bar/ $1.yy])
767 AT_LANG_COMPILE([out/$1.o], [], [-Iout/include])
769 AT_LOC_POPDEF
770 AT_BISON_OPTION_POPDEFS
773 mkdir -p out/include/ast
775 AT_TEST([x1],
776         [%header
777          %locations
778          %define api.location.file "include/ast/loc.hh"
779          ])
781 # Check the CPP guard and Doxyen comments.
782 AT_CHECK([[sed -ne 's/#line [0-9][0-9]* "/#line "/p;/INCLUDED/p;/\\file/{p;n;p;}' out/include/ast/loc.hh]], [],
783 [[ ** \file bar/include/ast/loc.hh
784  ** Define the x1::location class.
785 #ifndef YY_YY_BAR_INCLUDE_AST_LOC_HH_INCLUDED
786 # define YY_YY_BAR_INCLUDE_AST_LOC_HH_INCLUDED
787 #line "x1.yy"
788 #line "bar/include/ast/loc.hh"
789 #line "x1.yy"
790 #line "bar/include/ast/loc.hh"
791 #endif // !YY_YY_BAR_INCLUDE_AST_LOC_HH_INCLUDED
794 AT_CHECK([[sed -ne 's/^#line [0-9][0-9]* "/#line "/p;/INCLUDED/p;/\\file/{p;n;p;}' out/x1.hh]], [],
795 [[ ** \file bar/x1.hh
796  ** Define the x1::parser class.
797 #ifndef YY_YY_BAR_X1_HH_INCLUDED
798 # define YY_YY_BAR_X1_HH_INCLUDED
799 #line "x1.yy"
800 #line "bar/x1.hh"
801 #line "x1.yy"
802 #line "bar/x1.hh"
803 #endif // !YY_YY_BAR_X1_HH_INCLUDED
806 AT_TEST([x2],
807         [%header
808          %locations
809          %code requires {#include "include/ast/loc.hh"}
810          %define api.location.type {x1::location}])
812 m4_popdef([AT_TEST])
814 AT_DATA([main.cc],
815 [AT_DATA_SOURCE_PROLOGUE
816 [#include "x1.hh"
817 #include "x2.hh"
819 #define RUN(S)                                  \
820   do {                                          \
821     S::parser parser;                           \
822     int res = parser.parse();                   \
823     if (res)                                    \
824       std::cerr << #S": " << res << '\n';       \
825   } while (false)
828 main (void)
830   RUN(x1);
831   RUN(x2);
833 ]])# main.cc
835 AT_COMPILE_CXX([parser], [[out/x[12].o main.cc]], [-Iout/])
836 AT_PARSER_CHECK([parser], [0])
838 AT_CLEANUP