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);
42 ]m4_bmatch([$1], [location],
43 [ int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);],
44 [ int yylex (YYSTYPE *lvalp);])[
61 | prog stmt { printf ("\n"); }
70 expr : ID { printf ("%s ", $$); }
71 | TYPENAME '(' expr ')'
72 { printf ("%s <cast> ", ]$[1); }
73 | expr '+' expr { printf ("+ "); }
74 | expr '=' expr { printf ("= "); }
77 decl : TYPENAME declarator ';'
78 { printf ("%s <declare> ", ]$[1); }
79 | TYPENAME declarator '=' expr ';'
80 { printf ("%s <init-declare> ", ]$[1); }
83 declarator : ID { printf ("\"%s\" ", ]$[1); }
95 main (int argc, char** argv)
98 if (!freopen (argv[1], "r", stdin))
105 ]m4_bmatch([$1], [location],
106 [yylex (YYSTYPE *lvalp, YYLTYPE *llocp)],
107 [yylex (YYSTYPE *lvalp)])[
118 # define yylval (*lvalp)
119 ]m4_bmatch([$1], [location],[ (void) llocp;])[
129 case ' ': case '\t': case '\n': case '\f':
139 if (i == sizeof buffer - 1)
143 while (isalnum (c) || c == '_');
147 yylval = strcpy (malloc (i), buffer);
148 return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
156 yyerror (const char *s)
158 fprintf (stderr, "%s\n", s);
163 m4_bmatch([$2], [stmtMerge],
165 stmtMerge (YYSTYPE x0, YYSTYPE x1)
167 /* Use the arguments. */
176 AT_DATA([test-input],
199 This is total garbage, but it should be ignored.
202 AT_CHECK([bison -o types.c types.y], 0, [], ignore)
206 m4_define([_AT_RESOLVED_GLR_OUTPUT],
209 "x" y T <init-declare>
213 "y" z q + T <init-declare>
218 m4_define([_AT_AMBIG_GLR_OUTPUT],
221 "x" y T <init-declare>
224 "x" T <declare> x T <cast> <OR>
225 "y" z q + T <init-declare> y T <cast> z q + = <OR>
230 m4_define([_AT_GLR_STDERR],
234 m4_define([_AT_VERBOSE_GLR_STDERR],
235 [[parse error, unexpected ID, expecting '=' or '+' or ')'
238 ## ---------------------------------------------------- ##
239 ## Compile the grammar described in the documentation. ##
240 ## ---------------------------------------------------- ##
242 AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
243 _AT_TEST_GLR_CALC([],[%dprec 1],[%dprec 2])
244 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
245 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
248 AT_SETUP([GLR: Resolve ambiguity, impure, locations])
249 _AT_TEST_GLR_CALC([%locations],[%dprec 1],[%dprec 2])
250 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
251 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
254 AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
255 _AT_TEST_GLR_CALC([%pure-parser],[%dprec 1],[%dprec 2])
256 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
257 _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR)
260 AT_SETUP([GLR: Resolve ambiguity, pure, locations])
261 _AT_TEST_GLR_CALC([%pure-parser
262 %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: Merge conflicting parses, impure, no locations])
268 _AT_TEST_GLR_CALC([],[%merge <stmtMerge>],[%merge <stmtMerge>])
269 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
270 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
273 AT_SETUP([GLR: Merge conflicting parses, impure, locations])
274 _AT_TEST_GLR_CALC([%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
275 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
276 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
279 AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
280 _AT_TEST_GLR_CALC([%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])
281 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
282 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
284 AT_SETUP([GLR: Merge conflicting parses, pure, locations])
285 _AT_TEST_GLR_CALC([%pure-parser
286 %locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
287 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
288 _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR)
291 AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
292 _AT_TEST_GLR_CALC([%error-verbose],
293 [%merge <stmtMerge>],[%merge <stmtMerge>])
294 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
295 _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR)