1 # Checking GLR Parsing: Regression Tests -*- Autotest -*-
2 # Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 AT_BANNER([[GLR Regression Tests]])
21 ## --------------------------- ##
22 ## Badly Collapsed GLR States. ##
23 ## --------------------------- ##
25 AT_SETUP([Badly Collapsed GLR States])
27 AT_DATA_GRAMMAR([glr-regr1.y],
28 [[/* Regression Test: Improper state compression */
29 /* Reported by Scott McPeak */
35 static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
37 void yyerror (char const *msg);
44 /* -------- productions ------ */
47 StartSymbol: E { $$=0; } %merge <exprMerge>
50 E: E 'P' E { $$=1; printf("E -> E 'P' E\n"); } %merge <exprMerge>
51 | 'B' { $$=2; printf("E -> 'B'\n"); } %merge <exprMerge>
56 /* ---------- C code ----------- */
59 static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1)
74 yyerror (char const *msg)
76 fprintf (stderr, "%s\n", msg);
88 else if (ch == 'B' || ch == 'P')
94 AT_CHECK([[bison -o glr-regr1.c glr-regr1.y]], 0, [],
95 [glr-regr1.y: conflicts: 1 shift/reduce
97 AT_COMPILE([glr-regr1])
98 AT_CHECK([[echo BPBPB | ./glr-regr1]], 0,
112 ## ------------------------------------------------------------ ##
113 ## Improper handling of embedded actions and $-N in GLR parsers ##
114 ## ------------------------------------------------------------ ##
116 AT_SETUP([Improper handling of embedded actions and dollar(-N) in GLR parsers])
118 AT_DATA_GRAMMAR([glr-regr2a.y],
119 [[/* Regression Test: Improper handling of embedded actions and $-N */
120 /* Reported by S. Eken */
123 #define YYSTYPE char *
130 void yyerror (char const *);
139 { printf ("Variable: '%s'\n", $2); }
142 | 's' var_list 't' 'e'
143 { printf ("Varlist: '%s'\n", $2); free ($2); }
144 | 's' var 't' var_printer 'x'
158 char *s = (char *) realloc ($1, strlen ($1) + 1 + strlen ($3) + 1);
167 { printf ("Variable: '%s'\n", $-1); }
178 switch (fscanf (input, " %1[a-z,]", buf)) {
186 if (fscanf (input, "%49s", buf) != 1)
188 if (sizeof buf - 1 <= strlen (buf))
190 s = (char *) malloc (strlen (buf) + 1);
197 yyerror (char const *s)
198 { printf ("%s\n", s);
202 main (int argc, char **argv)
205 if (argc == 2 && !(input = fopen (argv[1], "r"))) return 3;
210 AT_CHECK([[bison -o glr-regr2a.c glr-regr2a.y]], 0, [],
211 [glr-regr2a.y: conflicts: 2 shift/reduce
213 AT_COMPILE([glr-regr2a])
215 AT_CHECK([[echo s VARIABLE_1 t v x q | ./glr-regr2a]], 0,
216 [[Variable: 'VARIABLE_1'
218 AT_CHECK([[echo s VARIABLE_1 , ANOTHER_VARIABLE_2 t e | ./glr-regr2a]], 0,
219 [[Varlist: 'VARIABLE_1,ANOTHER_VARIABLE_2'
221 AT_CHECK([[echo s VARIABLE_3 t v x | ./glr-regr2a]], 0,
222 [[Variable: 'VARIABLE_3'
228 ## ------------------------------------------------------------ ##
229 ## Improper merging of GLR delayed action sets ##
230 ## ------------------------------------------------------------ ##
232 AT_SETUP([Improper merging of GLR delayed action sets])
234 AT_DATA_GRAMMAR([glr-regr3.y],
235 [[/* Regression Test: Improper merging of GLR delayed action sets. */
236 /* Reported by M. Rosien */
242 static int MergeRule (int x0, int x1);
243 static void yyerror (char const * s);
246 #define RULE(x) (1 << (x))
253 %token P1 P2 T1 T2 T3 T4 O1 O2
257 S : P1 T4 O2 NT6 P2 { printf ("Result: %x\n", $4); }
260 NT1 : P1 T1 O1 T2 P2 { $$ = RULE(2); } %merge<MergeRule>
263 NT2 : NT1 { $$ = RULE(3); } %merge<MergeRule>
264 | P1 NT1 O1 T3 P2 { $$ = RULE(4); } %merge<MergeRule>
267 NT3 : T3 { $$ = RULE(5); } %merge<MergeRule>
268 | P1 NT1 O1 T3 P2 { $$ = RULE(6); } %merge<MergeRule>
271 NT4 : NT3 { $$ = RULE(7); } %merge<MergeRule>
272 | NT2 { $$ = RULE(8); } %merge<MergeRule>
273 | P1 NT2 O1 NT3 P2 { $$ = RULE(9); } %merge<MergeRule>
276 NT5 : NT4 { $$ = RULE(10); } %merge<MergeRule>
279 NT6 : P1 NT1 O1 T3 P2 { $$ = RULE(11) | $2; } %merge<MergeRule>
280 | NT5 { $$ = RULE(12) | $1; } %merge<MergeRule>
285 static int MergeRule (int x0, int x1) {
289 static void yyerror(char const * s) {
290 fprintf(stderr,"error: %s\n",s);
295 int P[] = { P1, P2 };
296 int O[] = { O1, O2 };
297 int T[] = { T1, T2, T3, T4 };
302 if (fscanf (input, "%2s", inp) == EOF)
306 case 'p': return P[inp[1] - '1'];
307 case 't': return T[inp[1] - '1'];
308 case 'o': return O[inp[1] - '1'];
313 int main(int argc, char* argv[]) {
315 if (argc == 2 && !(input = fopen (argv[1], "r"))) return 3;
320 AT_CHECK([[bison -o glr-regr3.c glr-regr3.y]], 0, [],
321 [glr-regr3.y: conflicts: 1 shift/reduce, 1 reduce/reduce
323 AT_COMPILE([glr-regr3])
325 AT_CHECK([[echo p1 t4 o2 p1 p1 t1 o1 t2 p2 o1 t3 p2 p2 | ./glr-regr3]], 0,
332 ## ------------------------------------------------------------------------- ##
333 ## Duplicate representation of merged trees. See ##
334 ## <http://lists.gnu.org/archive/html/help-bison/2005-07/msg00013.html>. ##
335 ## ------------------------------------------------------------------------- ##
337 AT_SETUP([Duplicate representation of merged trees])
339 AT_DATA_GRAMMAR([glr-regr4.y],
341 %union { char *ptr; }
342 %type <ptr> S A A1 A2 B
349 static char *merge (YYSTYPE, YYSTYPE);
350 static char *make_value (char const *, char const *);
351 static void yyerror (char const *);
352 static int yylex (void);
357 tree: S { printf ("%s\n", $1); } ;
360 A %merge<merge> { $$ = make_value ("S", $1); }
361 | B %merge<merge> { $$ = make_value ("S", $1); }
365 A1 %merge<merge> { $$ = make_value ("A", $1); }
366 | A2 %merge<merge> { $$ = make_value ("A", $1); }
369 A1: 'a' { $$ = make_value ("A1", "'a'"); } ;
370 A2: 'a' { $$ = make_value ("A2", "'a'"); } ;
371 B: 'a' { $$ = make_value ("B", "'a'"); } ;
378 static char const *input = "a";
389 make_value (char const *parent, char const *child)
391 char const format[] = "%s <- %s";
393 (char *) malloc (strlen (parent) + strlen (child) + sizeof format);
394 sprintf (value, format, parent, child);
399 merge (YYSTYPE s1, YYSTYPE s2)
401 char const format[] = "merge{ %s and %s }";
403 (char *) malloc (strlen (s1.ptr) + strlen (s2.ptr) + sizeof format);
404 sprintf (value, format, s1.ptr, s2.ptr);
409 yyerror (char const *msg)
411 fprintf (stderr, "%s\n", msg);
415 AT_CHECK([[bison -o glr-regr4.c glr-regr4.y]], 0, [],
416 [glr-regr4.y: conflicts: 1 reduce/reduce
418 AT_COMPILE([glr-regr4])
420 AT_CHECK([[./glr-regr4]], 0,
421 [[merge{ S <- merge{ A <- A1 <- 'a' and A <- A2 <- 'a' } and S <- B <- 'a' }
427 ## -------------------------------------------------------------------------- ##
428 ## User destructor for unresolved GLR semantic value. See ##
429 ## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00016.html>. ##
430 ## -------------------------------------------------------------------------- ##
432 AT_SETUP([User destructor for unresolved GLR semantic value])
434 AT_DATA_GRAMMAR([glr-regr5.y],
439 static void yyerror (char const *);
440 static int yylex (void);
441 enum { MAGIC_VALUE = -1057808125 }; /* originally chosen at random */
445 %union { int value; }
449 if ($$ != MAGIC_VALUE)
451 fprintf (stderr, "Bad destructor call.\n");
459 'a' { $$ = MAGIC_VALUE; }
460 | 'a' { $$ = MAGIC_VALUE; }
468 static char const *input = "a";
473 yyerror (char const *msg)
475 fprintf (stderr, "%s\n", msg);
481 return yyparse () != 1;
485 AT_CHECK([[bison -o glr-regr5.c glr-regr5.y]], 0, [],
486 [glr-regr5.y: conflicts: 1 reduce/reduce
488 AT_COMPILE([glr-regr5])
490 AT_CHECK([[./glr-regr5]], 0, [],
497 ## -------------------------------------------------------------------------- ##
498 ## User destructor after an error during a split parse. See ##
499 ## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00029.html>. ##
500 ## -------------------------------------------------------------------------- ##
502 AT_SETUP([User destructor after an error during a split parse])
504 AT_DATA_GRAMMAR([glr-regr6.y],
509 static void yyerror (char const *);
510 static int yylex (void);
514 %union { int value; }
518 printf ("Destructor called.\n");
530 static char const *input = "a";
535 yyerror (char const *msg)
537 fprintf (stderr, "%s\n", msg);
543 return yyparse () != 1;
547 AT_CHECK([[bison -o glr-regr6.c glr-regr6.y]], 0, [],
548 [glr-regr6.y: conflicts: 1 reduce/reduce
550 AT_COMPILE([glr-regr6])
552 AT_CHECK([[./glr-regr6]], 0,
561 ## ------------------------------------------------------------------------- ##
562 ## Duplicated user destructor for lookahead. See ##
563 ## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00035.html>. ##
564 ## ------------------------------------------------------------------------- ##
566 AT_SETUP([Duplicated user destructor for lookahead])
568 AT_DATA_GRAMMAR([glr-regr7.y],
573 static void yyerror (char const *);
574 static int yylex (void);
575 #define YYSTACKEXPANDABLE 0
579 %union { int *count; }
584 fprintf (stderr, "Destructor called on same value twice.\n");
602 yylval.count = (int *) malloc (sizeof (int));
605 fprintf (stderr, "Test inconclusive.\n");
613 yyerror (char const *msg)
615 fprintf (stderr, "%s\n", msg);
625 AT_CHECK([[bison -o glr-regr7.c glr-regr7.y]], 0, [],
626 [glr-regr7.y: conflicts: 2 reduce/reduce
628 AT_COMPILE([glr-regr7])
630 AT_CHECK([[./glr-regr7]], 2, [],
637 ## ------------------------------------------------------------------------- ##
638 ## Incorrect default location for empty right-hand sides. Adapted from bug ##
639 ## report by Claudia Hermann. ##
640 ## See http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00069.html and ##
641 ## http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00072.html ##
642 ## ------------------------------------------------------------------------- ##
644 AT_SETUP([Incorrectly initialized location for empty right-hand side in GLR])
646 AT_DATA_GRAMMAR([glr-regr8.y],
651 static void yyerror (char const *);
652 static int yylex (void);
653 static void yyerror (char const *msg);
665 PortClause : T_PORT InterfaceDeclaration T_PORT
666 { printf("%d/%d - %d/%d - %d/%d\n",
667 @1.first_column, @1.last_column,
668 @2.first_column, @2.last_column,
669 @3.first_column, @3.last_column); }
672 InterfaceDeclaration : OptConstantWord %dprec 1
673 | OptSignalWord %dprec 2
676 OptConstantWord : /* empty */
680 OptSignalWord : /* empty */
681 { printf("empty: %d/%d\n", @$.first_column, @$.last_column); }
688 yyerror (char const *msg)
690 fprintf (stderr, "%s\n", msg);
701 yylloc.first_column = 1;
702 yylloc.last_column = 9;
705 yylloc.first_column = 13;
706 yylloc.last_column = 17;
721 AT_CHECK([[bison -o glr-regr8.c glr-regr8.y]], 0, [],
722 [glr-regr8.y: conflicts: 1 reduce/reduce
724 AT_COMPILE([glr-regr8])
726 AT_CHECK([[./glr-regr8]], 0,
735 ## ------------------------------------------------------------------------- ##
736 ## No users destructors if stack 0 deleted. See ##
737 ## <http://lists.gnu.org/archive/html/bison-patches/2005-09/msg00109.html>. ##
738 ## ------------------------------------------------------------------------- ##
740 AT_SETUP([No users destructors if stack 0 deleted])
742 AT_DATA_GRAMMAR([glr-regr9.y],
747 static void yyerror (char const *);
748 static int yylex (void);
749 # define YYSTACKEXPANDABLE 0
750 static int tokens = 0;
751 static int destructors = 0;
756 %union { int dummy; }
766 ambig0 'a' { destructors += 2; USE ($2); }
767 | ambig1 start { destructors += 1; }
768 | ambig2 start { destructors += 1; }
785 yyerror (char const *msg)
787 fprintf (stderr, "%s\n", msg);
794 exit_status = yyparse ();
795 if (tokens != destructors)
797 fprintf (stderr, "Tokens = %d, Destructors = %d\n", tokens, destructors);
804 AT_CHECK([[bison -o glr-regr9.c glr-regr9.y]], 0, [],
805 [glr-regr9.y: conflicts: 1 reduce/reduce
807 AT_COMPILE([glr-regr9])
809 AT_CHECK([[./glr-regr9]], 0, [],
816 ## ------------------------------------------------------------------------- ##
817 ## Corrupted semantic options if user action cuts parse. ##
818 ## ------------------------------------------------------------------------- ##
820 AT_SETUP([Corrupted semantic options if user action cuts parse])
822 AT_DATA_GRAMMAR([glr-regr10.y],
826 static void yyerror (char const *);
827 static int yylex (void);
828 #define GARBAGE_SIZE 50
829 static char garbage[GARBAGE_SIZE];
833 %union { char *ptr; }
839 %dprec 2 { $$ = garbage; YYACCEPT; }
840 | %dprec 1 { $$ = garbage; YYACCEPT; }
846 yyerror (char const *msg)
848 fprintf (stderr, "%s\n", msg);
861 for (i = 0; i < GARBAGE_SIZE; i+=1)
867 AT_CHECK([[bison -o glr-regr10.c glr-regr10.y]], 0, [],
868 [glr-regr10.y: conflicts: 1 reduce/reduce
870 AT_COMPILE([glr-regr10])
872 AT_CHECK([[./glr-regr10]], 0, [], [])
877 ## ------------------------------------------------------------------------- ##
878 ## Undesirable destructors if user action cuts parse. ##
879 ## ------------------------------------------------------------------------- ##
881 AT_SETUP([Undesirable destructors if user action cuts parse])
883 AT_DATA_GRAMMAR([glr-regr11.y],
887 static void yyerror (char const *);
888 static int yylex (void);
889 static int destructors = 0;
894 %union { int dummy; }
896 %destructor { destructors += 1; } 'a'
901 'a' %dprec 2 { USE ($1); destructors += 1; YYACCEPT; }
902 | 'a' %dprec 1 { USE ($1); destructors += 1; YYACCEPT; }
908 yyerror (char const *msg)
910 fprintf (stderr, "%s\n", msg);
916 static char const *input = "a";
923 int exit_status = yyparse ();
924 if (destructors != 1)
926 fprintf (stderr, "Destructor calls: %d\n", destructors);
933 AT_CHECK([[bison -o glr-regr11.c glr-regr11.y]], 0, [],
934 [glr-regr11.y: conflicts: 1 reduce/reduce
936 AT_COMPILE([glr-regr11])
938 AT_CHECK([[./glr-regr11]], 0, [], [])
943 ## ------------------------------------------------------------------------- ##
944 ## Leaked semantic values if user action cuts parse. ##
945 ## ------------------------------------------------------------------------- ##
947 AT_SETUP([Leaked semantic values if user action cuts parse])
949 AT_DATA_GRAMMAR([glr-regr12.y],
952 %union { int dummy; }
953 %token PARENT_RHS_AFTER
954 %type <dummy> parent_rhs_before merged PARENT_RHS_AFTER
955 %destructor { parent_rhs_before_value = 0; } parent_rhs_before
956 %destructor { merged_value = 0; } merged
957 %destructor { parent_rhs_after_value = 0; } PARENT_RHS_AFTER
961 static int merge (YYSTYPE, YYSTYPE);
962 static void yyerror (char const *);
963 static int yylex (void);
964 static int parent_rhs_before_value = 0;
965 static int merged_value = 0;
966 static int parent_rhs_after_value = 0;
980 parent_rhs_after_value = 0;
985 parent_rhs_before merged PARENT_RHS_AFTER {
987 parent_rhs_before_value = 0;
989 parent_rhs_after_value = 0;
996 parent_rhs_before_value = 1;
1005 | cut %merge<merge> {
1011 cut: { YYACCEPT; } ;
1016 merge (YYSTYPE s1, YYSTYPE s2)
1019 char dummy = s1.dummy + s2.dummy;
1024 yyerror (char const *msg)
1026 fprintf (stderr, "%s\n", msg);
1032 static int const input[] = { PARENT_RHS_AFTER, 0 };
1033 static const int *inputp = input;
1034 if (*inputp == PARENT_RHS_AFTER)
1035 parent_rhs_after_value = 1;
1042 int exit_status = yyparse ();
1043 if (parent_rhs_before_value)
1045 fprintf (stderr, "`parent_rhs_before' destructor not called.\n");
1050 fprintf (stderr, "`merged' destructor not called.\n");
1053 if (parent_rhs_after_value)
1055 fprintf (stderr, "`PARENT_RHS_AFTER' destructor not called.\n");
1062 AT_CHECK([[bison -o glr-regr12.c glr-regr12.y]], 0, [],
1063 [glr-regr12.y: conflicts: 1 shift/reduce, 1 reduce/reduce
1065 AT_COMPILE([glr-regr12])
1067 AT_CHECK([[./glr-regr12]], 0, [], [])
1072 ## ------------------------------------------------------------------------- ##
1073 ## Incorrect lookahead during deterministic GLR. See ##
1074 ## <http://lists.gnu.org/archive/html/help-bison/2005-07/msg00017.html> and ##
1075 ## <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00060.html>. ##
1076 ## ------------------------------------------------------------------------- ##
1078 AT_SETUP([Incorrect lookahead during deterministic GLR])
1080 AT_DATA_GRAMMAR([glr-regr13.y],
1083 - Defaulted state with initial yychar: yychar == YYEMPTY.
1084 - Nondefaulted state: yychar != YYEMPTY.
1085 - Defaulted state after lookahead: yychar != YYEMPTY.
1086 - Defaulted state after shift: yychar == YYEMPTY.
1087 - User action changing the lookahead. */
1091 static void yyerror (char const *);
1092 static int yylex (void);
1093 static void print_lookahead (char const *);
1097 %union { char value; }
1098 %type <value> 'a' 'b'
1105 defstate_init defstate_shift 'b' change_lookahead 'a' {
1107 print_lookahead ("start <- defstate_init defstate_shift 'b'");
1112 print_lookahead ("defstate_init <- empty string");
1116 nondefstate defstate_look 'a' {
1118 print_lookahead ("defstate_shift <- nondefstate defstate_look 'a'");
1123 print_lookahead ("defstate_look <- empty string");
1128 print_lookahead ("nondefstate <- empty string");
1132 print_lookahead ("nondefstate <- 'b'");
1144 yyerror (char const *msg)
1146 fprintf (stderr, "%s\n", msg);
1152 static char const *input = "ab";
1154 yylloc.first_line = yylloc.last_line = 1;
1155 yylloc.first_column = yylloc.last_column = i + 1;
1156 yylval.value = input[i] + 'A' - 'a';
1161 print_lookahead (char const *reduction)
1163 printf ("%s:\n yychar=", reduction);
1164 if (yychar == YYEMPTY)
1166 else if (yychar == YYEOF)
1170 printf ("'%c', yylval='", yychar);
1171 if (yylval.value > ' ')
1172 printf ("%c", yylval.value);
1173 printf ("', yylloc=(%d,%d),(%d,%d)",
1174 yylloc.first_line, yylloc.first_column,
1175 yylloc.last_line, yylloc.last_column);
1183 yychar = '#'; /* Not a token in the grammar. */
1189 AT_CHECK([[bison -o glr-regr13.c glr-regr13.y]], 0, [], [])
1190 AT_COMPILE([glr-regr13])
1192 AT_CHECK([[./glr-regr13]], 0,
1193 [defstate_init <- empty string:
1195 nondefstate <- empty string:
1196 yychar='a', yylval='A', yylloc=(1,1),(1,1)
1197 defstate_look <- empty string:
1198 yychar='a', yylval='A', yylloc=(1,1),(1,1)
1199 defstate_shift <- nondefstate defstate_look 'a':
1201 start <- defstate_init defstate_shift 'b':
1208 ## ------------------------------------------------------------------------- ##
1209 ## Incorrect lookahead during nondeterministic GLR. ##
1210 ## ------------------------------------------------------------------------- ##
1212 AT_SETUP([Incorrect lookahead during nondeterministic GLR])
1214 AT_DATA_GRAMMAR([glr-regr14.y],
1217 - Conflicting actions (split-off parse, which copies lookahead need,
1218 which is necessarily yytrue) and nonconflicting actions (non-split-off
1219 parse) for nondefaulted state: yychar != YYEMPTY.
1220 - Merged deferred actions (lookahead need and RHS from different stack
1221 than the target state) and nonmerged deferred actions (same stack).
1222 - Defaulted state after lookahead: yychar != YYEMPTY.
1223 - Defaulted state after shift: yychar == YYEMPTY.
1224 - yychar != YYEMPTY but lookahead need is yyfalse (a previous stack has
1225 seen the lookahead but current stack has not).
1226 - Exceeding stack capacity (stack explosion), and thus reallocating
1227 lookahead need array.
1228 Note that it does not seem possible to see the initial yychar value during
1229 nondeterministic operation since:
1230 - In order to preserve the initial yychar, only defaulted states may be
1232 - If only defaulted states are entered, there are no conflicts, so
1233 nondeterministic operation does not start. */
1235 %union { char value; }
1239 static void yyerror (char const *);
1240 static int yylex (void);
1241 static void print_lookahead (char const *);
1242 static char merge (union YYSTYPE, union YYSTYPE);
1246 %type <value> 'a' 'b' 'c' 'd' stack_explosion
1253 merge 'c' stack_explosion {
1255 print_lookahead ("start <- merge 'c' stack_explosion");
1259 /* When merging the 2 deferred actions, the lookahead needs are different. */
1261 nonconflict1 'a' 'b' nonconflict2 %dprec 1 {
1263 print_lookahead ("merge <- nonconflict1 'a' 'b' nonconflict2");
1265 | conflict defstate_look 'a' nonconflict2 'b' defstate_shift %dprec 2 {
1267 print_lookahead ("merge <- conflict defstate_look 'a' nonconflict2 'b'"
1274 print_lookahead ("nonconflict1 <- empty string");
1279 print_lookahead ("nonconflict2 <- empty string");
1283 print_lookahead ("nonconflict2 <- 'a'");
1288 print_lookahead ("conflict <- empty string");
1293 print_lookahead ("defstate_look <- empty string");
1297 /* yychar != YYEMPTY but lookahead need is yyfalse. */
1300 print_lookahead ("defstate_shift <- empty string");
1306 | alt1 stack_explosion %merge<merge> { $$ = $2; }
1307 | alt2 stack_explosion %merge<merge> { $$ = $2; }
1308 | alt3 stack_explosion %merge<merge> { $$ = $2; }
1313 if (yychar != 'd' && yychar != YYEOF)
1315 fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
1322 if (yychar != 'd' && yychar != YYEOF)
1324 fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
1331 if (yychar != 'd' && yychar != YYEOF)
1333 fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
1339 if (yychar != YYEMPTY)
1342 "Found lookahead where shouldn't during stack explosion.\n");
1350 yyerror (char const *msg)
1352 fprintf (stderr, "%s\n", msg);
1358 static char const *input = "abcdddd";
1360 yylloc.first_line = yylloc.last_line = 1;
1361 yylloc.first_column = yylloc.last_column = i + 1;
1362 yylval.value = input[i] + 'A' - 'a';
1367 print_lookahead (char const *reduction)
1369 printf ("%s:\n yychar=", reduction);
1370 if (yychar == YYEMPTY)
1372 else if (yychar == YYEOF)
1376 printf ("'%c', yylval='", yychar);
1377 if (yylval.value > ' ')
1378 printf ("%c", yylval.value);
1379 printf ("', yylloc=(%d,%d),(%d,%d)",
1380 yylloc.first_line, yylloc.first_column,
1381 yylloc.last_line, yylloc.last_column);
1387 merge (union YYSTYPE s1, union YYSTYPE s2)
1389 char dummy = s1.value + s2.value;
1396 yychar = '#'; /* Not a token in the grammar. */
1402 AT_CHECK([[bison -o glr-regr14.c glr-regr14.y]], 0, [],
1403 [glr-regr14.y: conflicts: 3 reduce/reduce
1405 AT_COMPILE([glr-regr14])
1407 AT_CHECK([[./glr-regr14]], 0,
1408 [conflict <- empty string:
1409 yychar='a', yylval='A', yylloc=(1,1),(1,1)
1410 defstate_look <- empty string:
1411 yychar='a', yylval='A', yylloc=(1,1),(1,1)
1412 nonconflict2 <- empty string:
1413 yychar='b', yylval='B', yylloc=(1,2),(1,2)
1414 defstate_shift <- empty string:
1416 merge <- conflict defstate_look 'a' nonconflict2 'b' defstate_shift:
1418 start <- merge 'c' stack_explosion:
1425 ## ------------------------------------------------------------------------- ##
1426 ## Leaked semantic values when reporting ambiguity. ##
1427 ## ------------------------------------------------------------------------- ##
1429 AT_SETUP([Leaked semantic values when reporting ambiguity])
1431 AT_DATA_GRAMMAR([glr-regr15.y],
1434 %destructor { parent_rhs_before_value = 0; } parent_rhs_before
1437 # include <stdlib.h>
1438 static void yyerror (char const *);
1439 static int yylex (void);
1440 static int parent_rhs_before_value = 0;
1451 /* This stack must be merged into the other stacks *last* (added at the
1452 beginning of the semantic options list) so that yyparse will choose to clean
1453 it up rather than the tree for which some semantic actions have been
1454 performed. Thus, if yyreportAmbiguity longjmp's to yyparse, the values from
1455 those other trees are not cleaned up. */
1459 parent_rhs_before ambiguity {
1461 parent_rhs_before_value = 0;
1468 parent_rhs_before_value = 1;
1472 ambiguity: ambiguity1 | ambiguity2 ;
1479 yyerror (char const *msg)
1481 fprintf (stderr, "%s\n", msg);
1493 int exit_status = yyparse () != 1;
1494 if (parent_rhs_before_value)
1496 fprintf (stderr, "`parent_rhs_before' destructor not called.\n");
1503 AT_CHECK([[bison -o glr-regr15.c glr-regr15.y]], 0, [],
1504 [glr-regr15.y: conflicts: 2 reduce/reduce
1506 AT_COMPILE([glr-regr15])
1508 AT_CHECK([[./glr-regr15]], 0, [],
1509 [syntax is ambiguous
1515 ## ------------------------------------------------------------------------- ##
1516 ## Leaked lookahead after nondeterministic parse syntax error. ##
1517 ## ------------------------------------------------------------------------- ##
1519 AT_SETUP([Leaked lookahead after nondeterministic parse syntax error])
1520 AT_DATA_GRAMMAR([glr-regr16.y],
1523 %destructor { lookahead_value = 0; } 'b'
1526 # include <stdlib.h>
1527 static void yyerror (char const *);
1528 static int yylex (void);
1529 static int lookahead_value = 0;
1535 start: alt1 'a' | alt2 'a' ;
1542 yyerror (char const *msg)
1544 fprintf (stderr, "%s\n", msg);
1550 static char const *input = "ab";
1552 lookahead_value = 1;
1559 int exit_status = yyparse () != 1;
1560 if (lookahead_value)
1562 fprintf (stderr, "Lookahead destructor not called.\n");
1569 AT_CHECK([[bison -o glr-regr16.c glr-regr16.y]], 0, [],
1570 [glr-regr16.y: conflicts: 1 reduce/reduce
1572 AT_COMPILE([glr-regr16])
1574 AT_CHECK([[./glr-regr16]], 0, [],
1581 ## ------------------------------------------------------------------------- ##
1582 ## Uninitialized location when reporting ambiguity. ##
1583 ## ------------------------------------------------------------------------- ##
1585 AT_SETUP([Uninitialized location when reporting ambiguity])
1586 AT_DATA_GRAMMAR([glr-regr17.y],
1593 %union { int dummy; }
1596 static void yyerror (YYLTYPE *, char const *);
1597 static int yylex (YYSTYPE *, YYLTYPE *);
1602 @$.first_column = 1;
1609 /* Tests the case of an empty RHS that has inherited the location of the
1610 previous nonterminal, which is unresolved. That location is reported as the
1611 last position of the ambiguity. */
1612 start: ambig1 empty1 | ambig2 empty2 ;
1614 /* Tests multiple levels of yyresolveLocations recursion. */
1615 ambig1: sub_ambig1 | sub_ambig2 ;
1616 ambig2: sub_ambig1 | sub_ambig2 ;
1618 /* Tests the case of a non-empty RHS as well as the case of an empty RHS that
1619 has inherited the initial location. The empty RHS's location is reported as
1620 the first position in the ambiguity. */
1621 sub_ambig1: empty1 'a' 'b' ;
1622 sub_ambig2: empty2 'a' 'b' ;
1629 yyerror (YYLTYPE *locp, char const *msg)
1631 fprintf (stderr, "Error at %d.%d-%d.%d: %s.\n", locp->first_line,
1632 locp->first_column, locp->last_line, locp->last_column, msg);
1636 yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
1638 static char const input[] = "ab";
1639 static char const *inputp = input;
1641 llocp->first_line = llocp->last_line = 2;
1642 llocp->first_column = inputp - input + 1;
1643 llocp->last_column = llocp->first_column + 1;
1650 return yyparse () != 1;
1654 AT_CHECK([[bison -o glr-regr17.c glr-regr17.y]], 0, [],
1655 [glr-regr17.y: conflicts: 3 reduce/reduce
1657 AT_COMPILE([glr-regr17])
1659 AT_CHECK([[./glr-regr17]], 0, [],
1660 [Error at 1.1-2.3: syntax is ambiguous.
1666 ## -------------------------------------------------------------##
1667 ## Missed %merge type warnings when LHS type is declared later. ##
1668 ## -------------------------------------------------------------##
1670 AT_SETUP([Missed %merge type warnings when LHS type is declared later])
1671 AT_DATA_GRAMMAR([glr-regr18.y],
1675 static void yyerror (char const *);
1676 static int yylex ();
1687 sym1: sym2 %merge<merge> { $$ = $1; } ;
1688 sym2: sym3 %merge<merge> { $$ = $1; } ;
1689 sym3: %merge<merge> { $$ = 0; } ;
1698 yyerror (char const *msg)
1700 fprintf (stderr, "%s\n", msg);
1716 AT_CHECK([[bison -o glr-regr18.c glr-regr18.y]], 0, [],
1717 [glr-regr18.y:27.18-24: warning: result type clash on merge function `merge': <type2> != <type1>
1718 glr-regr18.y:26.18-24: warning: previous declaration
1719 glr-regr18.y:28.13-19: warning: result type clash on merge function `merge': <type3> != <type2>
1720 glr-regr18.y:27.18-24: warning: previous declaration