1 # Checking GLR Parsing: Regression Tests -*- Autotest -*-
2 # Copyright (C) 2002, 2003 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., 59 Temple Place - Suite 330, 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 int 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);
89 else if (ch == 'B' || ch == 'P')
95 AT_CHECK([[bison -o glr-regr1.c glr-regr1.y]], 0, [],
96 [glr-regr1.y: conflicts: 1 shift/reduce
98 AT_COMPILE([glr-regr1])
99 AT_CHECK([[echo BPBPB | ./glr-regr1]], 0,
113 ## ------------------------------------------------------------ ##
114 ## Improper handling of embedded actions and $-N in GLR parsers ##
115 ## ------------------------------------------------------------ ##
117 AT_SETUP([Improper handling of embedded actions and $-N in GLR parsers])
119 AT_DATA_GRAMMAR([glr-regr2a.y],
120 [[/* Regression Test: Improper handling of embedded actions and $-N */
121 /* Reported by S. Eken */
124 #define YYSTYPE char const *
132 void yyerror (char const *);
141 { printf ("Variable: '%s'\n", $2); }
143 | 's' var_list 't' 'e'
144 { printf ("Varlist: '%s'\n", $2); }
145 | 's' var 't' var_printer 'x'
160 strcat (buffer, ",");
162 $$ = strdup (buffer);
167 { printf ("Variable: '%s'\n", $-1); }
178 switch (fscanf (yyin, " %1[a-z,]", buf)) {
186 fscanf (yyin, "%s", buf);
187 yylval = strdup (buf);
192 yyerror (char const *s)
193 { printf ("%s\n", s);
197 main (int argc, char **argv)
200 if (argc == 2 && !(yyin = fopen (argv[1], "r"))) return 1;
205 AT_CHECK([[bison -o glr-regr2a.c glr-regr2a.y]], 0, [],
206 [glr-regr2a.y: conflicts: 2 shift/reduce
208 AT_COMPILE([glr-regr2a])
210 AT_CHECK([[echo s VARIABLE_1 t v x q | ./glr-regr2a]], 0,
211 [[Variable: 'VARIABLE_1'
213 AT_CHECK([[echo s VARIABLE_1 , ANOTHER_VARIABLE_2 t e | ./glr-regr2a]], 0,
214 [[Varlist: 'VARIABLE_1,ANOTHER_VARIABLE_2'
216 AT_CHECK([[echo s VARIABLE_3 t v x | ./glr-regr2a]], 0,
217 [[Variable: 'VARIABLE_3'