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
39 int yyerror (const char *s
40 #if YYPURE && YYLSP_NEEDED
46 ]m4_bmatch([$1], [location],
47 [ int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);],
48 [ int yylex (YYSTYPE *lvalp);])[
65 | prog stmt { printf ("\n"); }
74 expr : ID { printf ("%s ", $$); }
75 | TYPENAME '(' expr ')'
76 { printf ("%s <cast> ", ]$[1); }
77 | expr '+' expr { printf ("+ "); }
78 | expr '=' expr { printf ("= "); }
81 decl : TYPENAME declarator ';'
82 { printf ("%s <declare> ", ]$[1); }
83 | TYPENAME declarator '=' expr ';'
84 { printf ("%s <init-declare> ", ]$[1); }
87 declarator : ID { printf ("\"%s\" ", ]$[1); }
99 main (int argc, char** argv)
102 if (!freopen (argv[1], "r", stdin))
109 ]m4_bmatch([$1], [location],
110 [yylex (YYSTYPE *lvalp, YYLTYPE *llocp)],
111 [yylex (YYSTYPE *lvalp)])[
122 # define yylval (*lvalp)
123 ]m4_bmatch([$1], [location],[ (void) llocp;])[
133 case ' ': case '\t': case '\n': case '\f':
143 if (i == sizeof buffer - 1)
147 while (isalnum (c) || c == '_');
151 yylval = strcpy (malloc (i), buffer);
152 return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
160 yyerror (const char *s
161 #if YYPURE && YYLSP_NEEDED
162 , YYLTYPE *yylocation
166 #if YYPURE && YYLSP_NEEDED
169 fprintf (stderr, "%s\n", s);
174 m4_bmatch([$2], [stmtMerge],
176 stmtMerge (YYSTYPE x0, YYSTYPE x1)
178 /* Use the arguments. */
187 AT_DATA([test-input],
210 This is total garbage, but it should be ignored.
213 AT_CHECK([bison -o types.c types.y], 0, [], ignore)
217 m4_define([_AT_RESOLVED_GLR_OUTPUT],
220 "x" y T <init-declare>
224 "y" z q + T <init-declare>
229 m4_define([_AT_AMBIG_GLR_OUTPUT],
232 "x" y T <init-declare>
235 "x" T <declare> x T <cast> <OR>
236 "y" z q + T <init-declare> y T <cast> z q + = <OR>
241 m4_define([_AT_GLR_STDERR],
245 m4_define([_AT_VERBOSE_GLR_STDERR],
246 [[parse error, unexpected ID, expecting '=' or '+' or ')'
249 ## ---------------------------------------------------- ##
250 ## Compile the grammar described in the documentation. ##
251 ## ---------------------------------------------------- ##
253 AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
254 _AT_TEST_GLR_CALC([],[%dprec 1],[%dprec 2])
255 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
256 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
259 AT_SETUP([GLR: Resolve ambiguity, impure, locations])
260 _AT_TEST_GLR_CALC([%locations],[%dprec 1],[%dprec 2])
261 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
262 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
265 AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
266 _AT_TEST_GLR_CALC([%pure-parser],[%dprec 1],[%dprec 2])
267 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
268 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
271 AT_SETUP([GLR: Resolve ambiguity, pure, locations])
272 _AT_TEST_GLR_CALC([%pure-parser
273 %locations],[%dprec 1],[%dprec 2])
274 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
275 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
278 AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
279 _AT_TEST_GLR_CALC([],[%merge <stmtMerge>],[%merge <stmtMerge>])
280 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
281 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
284 AT_SETUP([GLR: Merge conflicting parses, impure, locations])
285 _AT_TEST_GLR_CALC([%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
286 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
287 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
290 AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
291 _AT_TEST_GLR_CALC([%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])
292 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
293 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
295 AT_SETUP([GLR: Merge conflicting parses, pure, locations])
296 _AT_TEST_GLR_CALC([%pure-parser
297 %locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
298 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
299 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
302 AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
303 _AT_TEST_GLR_CALC([%error-verbose],
304 [%merge <stmtMerge>],[%merge <stmtMerge>])
305 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
306 _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR)