]> git.saurik.com Git - bison.git/blame_incremental - tests/input.at
* tests/input.at (AT_CHECK_UNUSED_VALUES): Remove. Instead, do
[bison.git] / tests / input.at
... / ...
CommitLineData
1# Checking the Bison scanner. -*- Autotest -*-
2# Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3
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)
7# any later version.
8
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.
13
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., 51 Franklin Street, Fifth Floor, Boston, MA
17# 02110-1301, USA.
18
19AT_BANNER([[Input Processing.]])
20
21# Mostly test that we are robust to mistakes.
22
23
24## ------------ ##
25## Invalid $n. ##
26## ------------ ##
27
28AT_SETUP([Invalid dollar-n])
29
30AT_DATA([input.y],
31[[%%
32exp: { $$ = $1 ; };
33]])
34
35AT_CHECK([bison input.y], [1], [],
36[[input.y:2.13-14: integer out of range: `$1'
37]])
38
39AT_CLEANUP
40
41
42## ------------ ##
43## Invalid @n. ##
44## ------------ ##
45
46AT_SETUP([Invalid @n])
47
48AT_DATA([input.y],
49[[%%
50exp: { @$ = @1 ; };
51]])
52
53AT_CHECK([bison input.y], [1], [],
54[[input.y:2.13-14: integer out of range: `@1'
55]])
56
57AT_CLEANUP
58
59
60## -------------- ##
61## Type Clashes. ##
62## -------------- ##
63
64AT_SETUP([Type Clashes])
65
66AT_DATA([input.y],
67[[%token foo
68%type <bar> exp
69%%
70exp: foo {} foo
71 | foo
72 | /* Empty. */
73 ;
74]])
75
76AT_CHECK([bison input.y], [], [],
77[[input.y:4.6-15: warning: type clash on default action: <bar> != <>
78input.y:5.6-8: warning: type clash on default action: <bar> != <>
79input.y:6.5: warning: empty rule for typed nonterminal, and no action
80]])
81
82AT_CLEANUP
83
84
85## --------------- ##
86## Unused values. ##
87## --------------- ##
88
89AT_SETUP([Unused values])
90
91AT_DATA([input.y],
92[[%token <integer> INT
93%type <integer> a b c d e f g h i j k l
94%destructor { destroy ($$); } INT a b c d e f g h i j k l
95%%
96start:
97 'a' a { $2 } | 'b' b { $2 } | 'c' c { $2 } | 'd' d { $2 } | 'e' e { $2 }
98| 'f' f { $2 } | 'g' g { $2 } | 'h' h { $2 } | 'i' i { $2 } | 'j' j { $2 }
99| 'k' k { $2 } | 'l' l { $2 }
100;
101
102a: INT | INT { } INT { } INT { };
103b: INT | /* empty */;
104c: INT | INT { $1 } INT { } INT { };
105d: INT | INT { } INT { $1 } INT { };
106e: INT | INT { } INT { } INT { $1 };
107f: INT | INT { } INT { } INT { $$ = $1 + $3 + $5; };
108g: INT | INT { $$ } INT { $$ } INT { };
109h: INT | INT { $$ } INT { $$ = $2 } INT { };
110i: INT | INT INT { } { $$ = $1 + $2; };
111j: INT | INT INT { $<integer>$ = 1; } { $$ = $1 + $2; };
112k: INT | INT INT { $$; } { $$ = $3; } { };
113l: INT | INT { $$ = $1; } INT { $$ = $2 + $3; } INT { $$ = $4 + $5; };
114
115]])
116
117AT_CHECK([bison input.y], [], [],
118[[input.y:11.10-32: warning: unset value: $$
119input.y:11.10-32: warning: unused value: $1
120input.y:11.10-32: warning: unused value: $3
121input.y:11.10-32: warning: unused value: $5
122input.y:12.9: warning: empty rule for typed nonterminal, and no action
123input.y:13.10-35: warning: unset value: $$
124input.y:13.10-35: warning: unused value: $3
125input.y:13.10-35: warning: unused value: $5
126input.y:14.10-35: warning: unset value: $$
127input.y:14.10-35: warning: unused value: $3
128input.y:14.10-35: warning: unused value: $5
129input.y:15.10-36: warning: unset value: $$
130input.y:15.10-36: warning: unused value: $3
131input.y:15.10-36: warning: unused value: $5
132input.y:17.10-38: warning: unset value: $$
133input.y:17.10-38: warning: unused value: $1
134input.y:17.10-38: warning: unused value: $2
135input.y:17.10-38: warning: unused value: $3
136input.y:17.10-38: warning: unused value: $4
137input.y:17.10-38: warning: unused value: $5
138input.y:18.10-43: warning: unset value: $$
139input.y:18.10-43: warning: unused value: $1
140input.y:18.10-43: warning: unused value: $3
141input.y:18.10-43: warning: unused value: $4
142input.y:18.10-43: warning: unused value: $5
143input.y:20.10-55: warning: unused value: $3
144input.y:21.10-41: warning: unset value: $$
145input.y:21.10-41: warning: unused value: $1
146input.y:21.10-41: warning: unused value: $2
147input.y:21.10-41: warning: unused value: $4
148]])
149
150AT_CLEANUP
151
152
153## ---------------------- ##
154## Incompatible Aliases. ##
155## ---------------------- ##
156
157AT_SETUP([Incompatible Aliases])
158
159AT_DATA([input.y],
160[[%token foo "foo"
161
162%type <bar> foo
163%printer {bar} foo
164%destructor {bar} foo
165%left foo
166
167%type <baz> "foo"
168%printer {baz} "foo"
169%destructor {baz} "foo"
170%left "foo"
171
172%%
173exp: foo;
174]])
175
176AT_CHECK([bison input.y], [1], [],
177[[input.y:8.7-11: %type redeclaration for foo
178input.y:3.7-11: first declaration
179input.y:10.13-17: %destructor redeclaration for foo
180input.y:5.13-17: first declaration
181input.y:9.19-23: %printer redeclaration for foo
182input.y:10.13-17: first declaration
183input.y:11.1-5: %left redeclaration for foo
184input.y:6.1-5: first declaration
185]])
186
187AT_CLEANUP
188
189
190
191## ----------------------- ##
192## Torturing the Scanner. ##
193## ----------------------- ##
194
195# Be sure to compile and run, so that the C compiler checks what
196# we do.
197
198AT_SETUP([Torturing the Scanner])
199
200
201AT_DATA([input.y], [])
202AT_CHECK([bison input.y], [1], [],
203[[input.y:1.1: syntax error, unexpected end of file
204]])
205
206
207AT_DATA_GRAMMAR([input.y],
208[[%{
209/* This is seen in GCC: a %{ and %} in middle of a comment. */
210const char *foo = "So %{ and %} can be here too.";
211
212#if 0
213/* These examples test Bison while not stressing C compilers too much.
214 Many C compilers mishandle backslash-newlines, so this part of the
215 test is inside "#if 0". The comment and string are written so that
216 the "#endif" will be seen regardless of the C compiler bugs that we
217 know about, namely:
218
219 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
220 comment.
221
222 The Apple Darwin compiler (as of late 2002) mishandles
223 \\[newline]' within a character constant.
224
225 */
226
227/\
228* A comment with backslash-newlines in it. %} *\
229\
230/
231/* { Close the above comment, if the C compiler mishandled it. */
232
233char str[] = "\\
234" A string with backslash-newlines in it %{ %} \\
235\
236"";
237
238char apostrophe = '\'';
239#endif
240
241#include <stdio.h>
242%}
243/* %{ and %} can be here too. */
244
245%{
246/* Exercise pre-prologue dependency to %union. */
247typedef int value;
248%}
249
250/* Exercise M4 quoting: '@:>@@:>@', 0. */
251
252/* Also exercise %union. */
253%union
254{
255 value ival; /* A comment to exercise an old bug. */
256};
257
258
259/* Exercise post-prologue dependency to %union. */
260%{
261static YYSTYPE value_as_yystype (value val);
262
263/* Exercise quotes in declarations. */
264char quote[] = "@:>@@:>@,";
265%}
266
267%{
268static void yyerror (const char *s);
269static int yylex (void);
270%}
271
272%type <ival> '@<:@'
273
274/* Exercise quotes in strings. */
275%token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
276
277%%
278/* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
279exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
280 {
281 /* Exercise quotes in braces. */
282 char tmp[] = "@<:@%c@:>@,\n";
283 printf (tmp, $1);
284 }
285;
286
287two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
288oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
289output.or.oline.opt: ;|oline;;|output;;;
290output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
291%%
292/* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
293
294static YYSTYPE
295value_as_yystype (value val)
296{
297 YYSTYPE res;
298 res.ival = val;
299 return res;
300}
301
302static int
303yylex (void)
304{
305 static const char *input = "@<:@\1\2$@{@oline@__@&t@oline__\
306#output "; /* "
307 */
308 yylval = value_as_yystype (*input);
309 return *input++;
310}
311
312static void
313yyerror (const char *msg)
314{
315 fprintf (stderr, "%s\n", msg);
316}
317]])
318
319# Pacify Emacs'font-lock-mode: "
320
321AT_DATA([main.c],
322[[typedef int value;
323#include "input.h"
324
325int yyparse (void);
326
327int
328main (void)
329{
330 return yyparse ();
331}
332]])
333
334AT_CHECK([bison -d -v -o input.c input.y])
335AT_COMPILE([input.o], [-c input.c])
336AT_COMPILE([main.o], [-c main.c])
337AT_COMPILE([input], [input.o main.o])
338AT_PARSER_CHECK([./input], 0,
339[[[@<:@],
340]])
341
342AT_CLEANUP
343
344
345## ---------------------- ##
346## Typed symbol aliases. ##
347## ---------------------- ##
348
349AT_SETUP([Typed symbol aliases])
350
351# Bison 2.0 broke typed symbol aliases - ensure they work.
352
353AT_DATA_GRAMMAR([input.y],
354[[%union
355{
356 int val;
357};
358%token <val> MY_TOKEN "MY TOKEN"
359%type <val> exp
360%%
361exp: "MY TOKEN";
362%%
363]])
364
365AT_CHECK([bison -o input.c input.y])
366
367AT_CLEANUP
368
369
370## --------- ##
371## Require. ##
372## --------- ##
373
374m4_define([AT_CHECK_REQUIRE],
375[AT_SETUP([Require $1])
376AT_DATA_GRAMMAR([input.y],
377[[%require "$1";
378%%
379empty_file:;
380]])
381AT_CHECK([bison -o input.c input.y], $2, [], ignore)
382AT_CLEANUP
383])
384
385AT_CHECK_REQUIRE(1.0, 0)
386AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
387## FIXME: Some day augment this version number.
388AT_CHECK_REQUIRE(100.0, 63)