1 # Checking the output filenames. -*- Autotest -*-
2 # Copyright 2000, 2001 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(`$1',DECL, RESOLVE1, RESOLVE2)
22 # (first argument is a literal $1; it's a trick).
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*
35 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
36 #define YYINITDEPTH 10
49 | prog stmt { printf ("\n"); }
58 expr : ID { printf ("%s ", $$); }
59 | TYPENAME '(' expr ')'
60 { printf ("%s <cast> ", $1); }
61 | expr '+' expr { printf ("+ "); }
62 | expr '=' expr { printf ("= "); }
65 decl : TYPENAME declarator ';'
66 { printf ("%s <declare> ", $1); }
67 | TYPENAME declarator '=' expr ';'
68 { printf ("%s <init-declare> ", $1); }
71 declarator : ID { printf ("\"%s\" ", $1); }
80 main (int argc, char** argv)
82 freopen (argv[1], "r", stdin);
87 int yylex (YYSTYPE *lvalp)
88 #define yylval (*lvalp)
100 case ' ': case '\t': case '\n': case '\f':
105 scanf ("%[A-Za-z0-9_]", buffer);
106 yylval = strdup (buffer);
107 return isupper (buffer[0]) ? TYPENAME : ID;
115 yyerror (const char *s)
117 fprintf (stderr, "%s\n", s);
121 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1)
128 AT_DATA([test-input],
151 This is total garbage, but it should be ignored.
154 AT_CHECK([bison types.y], 0, [], ignore)
155 AT_CHECK([gcc -o types types.tab.c], 0, [], ignore)
158 m4_define([_AT_RESOLVED_GLR_OUTPUT],
161 "x" y T <init-declare>
165 "y" z q + T <init-declare>
170 m4_define([_AT_AMBIG_GLR_OUTPUT],
173 "x" y T <init-declare>
176 "x" T <declare> x T <cast> <OR>
177 "y" z q + T <init-declare> y T <cast> z q + = <OR>
182 m4_define([_AT_GLR_STDERR],
186 m4_define([_AT_VERBOSE_GLR_STDERR],
187 [[parse error, unexpected ID, expecting '=' or '+' or ')'
190 ## ---------------------------------------------------- ##
191 ## Compile the grammar described in the documentation. ##
192 ## ---------------------------------------------------- ##
194 AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
195 _AT_TEST_GLR_CALC([$1],[],[%dprec 1],[%dprec 2])
196 AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
200 AT_SETUP([GLR: Resolve ambiguity, impure, locations])
201 _AT_TEST_GLR_CALC([$1],[%locations],[%dprec 1],[%dprec 2])
202 AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
206 AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
207 _AT_TEST_GLR_CALC([$1],[%pure-parser],[%dprec 1],[%dprec 2])
208 AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
212 AT_SETUP([GLR: Resolve ambiguity, pure, locations])
213 _AT_TEST_GLR_CALC([$1],[%pure-parser
214 %locations],[%dprec 1],[%dprec 2])
215 AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
219 AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
220 _AT_TEST_GLR_CALC([$1],[],[%merge <stmtMerge>],[%merge <stmtMerge>])
221 AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT,
225 AT_SETUP([GLR: Merge conflicting parses, impure, locations])
226 _AT_TEST_GLR_CALC([$1],[%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
227 AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT,
231 AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
232 _AT_TEST_GLR_CALC([$1],[%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])
233 AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT,
236 AT_SETUP([GLR: Merge conflicting parses, pure, locations])
237 _AT_TEST_GLR_CALC([$1],[%pure-parser
238 %locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
239 AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT,
243 AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
244 _AT_TEST_GLR_CALC([$1],[%error-verbose],
245 [%merge <stmtMerge>],[%merge <stmtMerge>])
246 AT_CHECK([[./types test-input | sed 's/ *$//']], 0,
247 _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR)