1 # Checking GLR Parsing. -*- Autotest -*-
2 # Copyright 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 assert (freopen (argv[1], "r", stdin));
103 ]m4_bmatch([$1], [location],
104 [yylex (YYSTYPE *lvalp, YYLTYPE *llocp)],
105 [yylex (YYSTYPE *lvalp)])[
115 # define yylval (*lvalp)
116 ]m4_bmatch([$1], [location],[ (void) llocp;])[
124 case ' ': case '\t': case '\n': case '\f':
129 scanf ("%[A-Za-z0-9_]", buffer);
130 yylval = strdup (buffer);
131 return isupper (buffer[0]) ? TYPENAME : ID;
139 yyerror (const char *s)
141 fprintf (stderr, "%s\n", s);
146 m4_bmatch([$2], [stmtMerge],
148 stmtMerge (YYSTYPE x0, YYSTYPE x1)
150 /* Use the arguments. */
159 AT_DATA([test-input],
182 This is total garbage, but it should be ignored.
185 AT_CHECK([bison types.y -o types.c], 0, [], ignore)
189 m4_define([_AT_RESOLVED_GLR_OUTPUT],
192 "x" y T <init-declare>
196 "y" z q + T <init-declare>
201 m4_define([_AT_AMBIG_GLR_OUTPUT],
204 "x" y T <init-declare>
207 "x" T <declare> x T <cast> <OR>
208 "y" z q + T <init-declare> y T <cast> z q + = <OR>
213 m4_define([_AT_GLR_STDERR],
217 m4_define([_AT_VERBOSE_GLR_STDERR],
218 [[parse error, unexpected ID, expecting '=' or '+' or ')'
221 ## ---------------------------------------------------- ##
222 ## Compile the grammar described in the documentation. ##
223 ## ---------------------------------------------------- ##
225 AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
226 _AT_TEST_GLR_CALC([],[%dprec 1],[%dprec 2])
227 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
231 AT_SETUP([GLR: Resolve ambiguity, impure, locations])
232 _AT_TEST_GLR_CALC([%locations],[%dprec 1],[%dprec 2])
233 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
237 AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
238 _AT_TEST_GLR_CALC([%pure-parser],[%dprec 1],[%dprec 2])
239 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
243 AT_SETUP([GLR: Resolve ambiguity, pure, locations])
244 _AT_TEST_GLR_CALC([%pure-parser
245 %locations],[%dprec 1],[%dprec 2])
246 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
247 _AT_RESOLVED_GLR_OUTPUT,
251 AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
252 _AT_TEST_GLR_CALC([],[%merge <stmtMerge>],[%merge <stmtMerge>])
253 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
254 _AT_AMBIG_GLR_OUTPUT,
258 AT_SETUP([GLR: Merge conflicting parses, impure, locations])
259 _AT_TEST_GLR_CALC([%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
260 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
261 _AT_AMBIG_GLR_OUTPUT,
265 AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
266 _AT_TEST_GLR_CALC([%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])
267 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
268 _AT_AMBIG_GLR_OUTPUT,
271 AT_SETUP([GLR: Merge conflicting parses, pure, locations])
272 _AT_TEST_GLR_CALC([%pure-parser
273 %locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
274 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
275 _AT_AMBIG_GLR_OUTPUT,
279 AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
280 _AT_TEST_GLR_CALC([%error-verbose],
281 [%merge <stmtMerge>],[%merge <stmtMerge>])
282 AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
283 _AT_AMBIG_GLR_OUTPUT,
284 _AT_VERBOSE_GLR_STDERR)