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); }
94 main (int argc, char** argv)
97 if (!freopen (argv[1], "r", stdin))
104 ]m4_bmatch([$1], [location],
105 [yylex (YYSTYPE *lvalp, YYLTYPE *llocp)],
106 [yylex (YYSTYPE *lvalp)])[
116 # define yylval (*lvalp)
117 ]m4_bmatch([$1], [location],[ (void) llocp;])[
125 case ' ': case '\t': case '\n': case '\f':
130 scanf ("%[A-Za-z0-9_]", buffer);
131 yylval = strdup (buffer);
132 return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
140 yyerror (const char *s)
142 fprintf (stderr, "%s\n", s);
147 m4_bmatch([$2], [stmtMerge],
149 stmtMerge (YYSTYPE x0, YYSTYPE x1)
151 /* Use the arguments. */
160 AT_DATA([test-input],
183 This is total garbage, but it should be ignored.
186 AT_CHECK([bison -o types.c types.y], 0, [], ignore)
190 m4_define([_AT_RESOLVED_GLR_OUTPUT],
193 "x" y T <init-declare>
197 "y" z q + T <init-declare>
202 m4_define([_AT_AMBIG_GLR_OUTPUT],
205 "x" y T <init-declare>
208 "x" T <declare> x T <cast> <OR>
209 "y" z q + T <init-declare> y T <cast> z q + = <OR>
214 m4_define([_AT_GLR_STDERR],
218 m4_define([_AT_VERBOSE_GLR_STDERR],
219 [[parse error, unexpected ID, expecting '=' or '+' or ')'
222 ## ---------------------------------------------------- ##
223 ## Compile the grammar described in the documentation. ##
224 ## ---------------------------------------------------- ##
226 AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
227 _AT_TEST_GLR_CALC([],[%dprec 1],[%dprec 2])
228 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
232 AT_SETUP([GLR: Resolve ambiguity, impure, locations])
233 _AT_TEST_GLR_CALC([%locations],[%dprec 1],[%dprec 2])
234 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
238 AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
239 _AT_TEST_GLR_CALC([%pure-parser],[%dprec 1],[%dprec 2])
240 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
244 AT_SETUP([GLR: Resolve ambiguity, pure, locations])
245 _AT_TEST_GLR_CALC([%pure-parser
246 %locations],[%dprec 1],[%dprec 2])
247 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
248 _AT_RESOLVED_GLR_OUTPUT,
252 AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
253 _AT_TEST_GLR_CALC([],[%merge <stmtMerge>],[%merge <stmtMerge>])
254 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
255 _AT_AMBIG_GLR_OUTPUT,
259 AT_SETUP([GLR: Merge conflicting parses, impure, locations])
260 _AT_TEST_GLR_CALC([%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
261 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
262 _AT_AMBIG_GLR_OUTPUT,
266 AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
267 _AT_TEST_GLR_CALC([%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])
268 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
269 _AT_AMBIG_GLR_OUTPUT,
272 AT_SETUP([GLR: Merge conflicting parses, pure, locations])
273 _AT_TEST_GLR_CALC([%pure-parser
274 %locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
275 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
276 _AT_AMBIG_GLR_OUTPUT,
280 AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
281 _AT_TEST_GLR_CALC([%error-verbose],
282 [%merge <stmtMerge>],[%merge <stmtMerge>])
283 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
284 _AT_AMBIG_GLR_OUTPUT,
285 _AT_VERBOSE_GLR_STDERR)