1 # Checking GLR Parsing. -*- Autotest -*-
2 # Copyright (C) 2002 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([[C++ Type Syntax (GLR).]])
21 # _AT_TEST_GLR_CALC(DECL, RESOLVE1, RESOLVE2)
22 # -------------------------------------------
23 # Store into types.y the calc program, with DECL inserted as a declaration,
24 # and with RESOLVE1 and RESOLVE2 as annotations on the conflicted rule for
25 # stmt. Then compile the result.
26 m4_define([_AT_TEST_GLR_CALC],
28 [[/* Simplified C++ Type and Expression Grammar. */
34 #define YYSTYPE const char*
36 ]m4_bmatch([$2], [stmtMerge],
37 [ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[
38 #define YYINITDEPTH 10
40 #if YYPURE && YYLSP_NEEDED
47 ]m4_bmatch([$1], [location],
48 [ int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);],
49 [ int yylex (YYSTYPE *lvalp);])[
66 | prog stmt { printf ("\n"); }
75 expr : ID { printf ("%s ", $$); }
76 | TYPENAME '(' expr ')'
77 { printf ("%s <cast> ", ]$[1); }
78 | expr '+' expr { printf ("+ "); }
79 | expr '=' expr { printf ("= "); }
82 decl : TYPENAME declarator ';'
83 { printf ("%s <declare> ", ]$[1); }
84 | TYPENAME declarator '=' expr ';'
85 { printf ("%s <init-declare> ", ]$[1); }
88 declarator : ID { printf ("\"%s\" ", ]$[1); }
100 main (int argc, char** argv)
103 if (!freopen (argv[1], "r", stdin))
110 ]m4_bmatch([$1], [location],
111 [yylex (YYSTYPE *lvalp, YYLTYPE *llocp)],
112 [yylex (YYSTYPE *lvalp)])[
123 # define yylval (*lvalp)
124 ]m4_bmatch([$1], [location],[ (void) llocp;])[
134 case ' ': case '\t': case '\n': case '\f':
144 if (i == sizeof buffer - 1)
148 while (isalnum (c) || c == '_');
152 yylval = strcpy (malloc (i), buffer);
153 return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
162 #if YYPURE && YYLSP_NEEDED
168 #if YYPURE && YYLSP_NEEDED
171 fprintf (stderr, "%s\n", s);
176 m4_bmatch([$2], [stmtMerge],
178 stmtMerge (YYSTYPE x0, YYSTYPE x1)
180 /* Use the arguments. */
189 AT_DATA([test-input],
212 This is total garbage, but it should be ignored.
215 AT_CHECK([bison -o types.c types.y], 0, [], ignore)
219 m4_define([_AT_RESOLVED_GLR_OUTPUT],
222 "x" y T <init-declare>
226 "y" z q + T <init-declare>
231 m4_define([_AT_AMBIG_GLR_OUTPUT],
234 "x" y T <init-declare>
237 "x" T <declare> x T <cast> <OR>
238 "y" z q + T <init-declare> y T <cast> z q + = <OR>
243 m4_define([_AT_GLR_STDERR],
247 m4_define([_AT_VERBOSE_GLR_STDERR],
248 [[parse error, unexpected ID, expecting '=' or '+' or ')'
251 ## ---------------------------------------------------- ##
252 ## Compile the grammar described in the documentation. ##
253 ## ---------------------------------------------------- ##
255 AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
256 _AT_TEST_GLR_CALC([],[%dprec 1],[%dprec 2])
257 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
258 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
261 AT_SETUP([GLR: Resolve ambiguity, impure, locations])
262 _AT_TEST_GLR_CALC([%locations],[%dprec 1],[%dprec 2])
263 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
264 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
267 AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
268 _AT_TEST_GLR_CALC([%pure-parser],[%dprec 1],[%dprec 2])
269 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
270 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
273 AT_SETUP([GLR: Resolve ambiguity, pure, locations])
274 _AT_TEST_GLR_CALC([%pure-parser
275 %locations],[%dprec 1],[%dprec 2])
276 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
277 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
280 AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
281 _AT_TEST_GLR_CALC([],[%merge <stmtMerge>],[%merge <stmtMerge>])
282 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
283 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
286 AT_SETUP([GLR: Merge conflicting parses, impure, locations])
287 _AT_TEST_GLR_CALC([%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
288 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
289 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
292 AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
293 _AT_TEST_GLR_CALC([%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])
294 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
295 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
297 AT_SETUP([GLR: Merge conflicting parses, pure, locations])
298 _AT_TEST_GLR_CALC([%pure-parser
299 %locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
300 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
301 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
304 AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
305 _AT_TEST_GLR_CALC([%error-verbose],
306 [%merge <stmtMerge>],[%merge <stmtMerge>])
307 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
308 _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR)