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