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_CXXTYPES(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_CXXTYPES],
27 [AT_DATA_GRAMMAR([types.y],
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); }
99 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 [[syntax 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_CXXTYPES([],
257 [%dprec 1], [%dprec 2])
258 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
259 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
262 AT_SETUP([GLR: Resolve ambiguity, impure, locations])
263 _AT_TEST_GLR_CXXTYPES([%locations],[%dprec 1],[%dprec 2])
264 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
265 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
268 AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
269 _AT_TEST_GLR_CXXTYPES([%pure-parser],
270 [%dprec 1], [%dprec 2])
271 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
272 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
275 AT_SETUP([GLR: Resolve ambiguity, pure, locations])
276 _AT_TEST_GLR_CXXTYPES([%pure-parser %locations],
277 [%dprec 1], [%dprec 2])
278 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
279 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
282 AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
283 _AT_TEST_GLR_CXXTYPES([],
284 [%merge <stmtMerge>], [%merge <stmtMerge>])
285 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
286 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
289 AT_SETUP([GLR: Merge conflicting parses, impure, locations])
290 _AT_TEST_GLR_CXXTYPES([%locations],
291 [%merge <stmtMerge>], [%merge <stmtMerge>])
292 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
293 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
296 AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
297 _AT_TEST_GLR_CXXTYPES([%pure-parser],
298 [%merge <stmtMerge>], [%merge <stmtMerge>])
299 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
300 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
302 AT_SETUP([GLR: Merge conflicting parses, pure, locations])
303 _AT_TEST_GLR_CXXTYPES([%pure-parser %locations],
304 [%merge <stmtMerge>],[%merge <stmtMerge>])
305 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
306 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
309 AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
310 _AT_TEST_GLR_CXXTYPES([%error-verbose],
311 [%merge <stmtMerge>], [%merge <stmtMerge>])
312 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
313 _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR)