1 # Checking the Bison scanner. -*- Autotest -*-
2 # Copyright (C) 2002, 2003, 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA
19 AT_BANNER([[Input Processing.]])
21 # Mostly test that we are robust to mistakes.
28 AT_SETUP([Invalid dollar-n])
35 AT_CHECK([bison input.y], [1], [],
36 [[input.y:2.13-14: integer out of range: `$1'
46 AT_SETUP([Invalid @n])
53 AT_CHECK([bison input.y], [1], [],
54 [[input.y:2.13-14: integer out of range: `@1'
64 AT_SETUP([Type Clashes])
76 AT_CHECK([bison input.y], [], [],
77 [[input.y:4.6-15: warning: type clash on default action: <bar> != <>
78 input.y:5.6-8: warning: type clash on default action: <bar> != <>
79 input.y:6.5: warning: empty rule for typed nonterminal, and no action
89 m4_define([AT_CHECK_UNUSED_VALUES],
90 [AT_SETUP([Unused values])
93 [[%token <integer> INT
102 AT_CHECK([bison input.y], [], [],
108 AT_CHECK_UNUSED_VALUES([INT { } INT { } INT { }],
109 [input.y:5.3-25: warning: unset value: $$
110 input.y:5.3-25: warning: unused value: $1
111 input.y:5.3-25: warning: unused value: $3
112 input.y:5.3-25: warning: unused value: $5
115 AT_CHECK_UNUSED_VALUES([INT { $1 } INT { } INT { }],
116 [input.y:5.3-28: warning: unset value: $$
117 input.y:5.3-28: warning: unused value: $3
118 input.y:5.3-28: warning: unused value: $5
121 AT_CHECK_UNUSED_VALUES([INT { } INT { $1 } INT { }],
122 [input.y:5.3-28: warning: unset value: $$
123 input.y:5.3-28: warning: unused value: $3
124 input.y:5.3-28: warning: unused value: $5
127 AT_CHECK_UNUSED_VALUES([INT { } INT { } INT { $1 }],
128 [input.y:5.3-29: warning: unset value: $$
129 input.y:5.3-29: warning: unused value: $3
130 input.y:5.3-29: warning: unused value: $5
133 AT_CHECK_UNUSED_VALUES([INT { } INT { } INT { $$ = $1 + $3 + $5; }])
135 # Checking mid-rule values.
136 AT_CHECK_UNUSED_VALUES([INT { $$ } INT { $$ } INT { }],
137 [input.y:5.3-31: warning: unset value: $$
138 input.y:5.3-31: warning: unused value: $1
139 input.y:5.3-31: warning: unused value: $2
140 input.y:5.3-31: warning: unused value: $3
141 input.y:5.3-31: warning: unused value: $4
142 input.y:5.3-31: warning: unused value: $5
145 AT_CHECK_UNUSED_VALUES([INT { $$ } INT { $$ = $2 } INT { }],
146 [input.y:5.3-36: warning: unset value: $$
147 input.y:5.3-36: warning: unused value: $1
148 input.y:5.3-36: warning: unused value: $3
149 input.y:5.3-36: warning: unused value: $4
150 input.y:5.3-36: warning: unused value: $5
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
161 AT_CHECK_UNUSED_VALUES([INT { $$ = $1 } INT { $$ = $2 + $3 } INT { $$ = $4 + $5 }])
165 ## ---------------------- ##
166 ## Incompatible Aliases. ##
167 ## ---------------------- ##
169 AT_SETUP([Incompatible Aliases])
176 %destructor {bar} foo
181 %destructor {baz} "foo"
188 AT_CHECK([bison input.y], [1], [],
189 [[input.y:8.7-11: %type redeclaration for foo
190 input.y:3.7-11: first declaration
191 input.y:10.13-17: %destructor redeclaration for foo
192 input.y:5.13-17: first declaration
193 input.y:9.19-23: %printer redeclaration for foo
194 input.y:10.13-17: first declaration
195 input.y:11.1-5: %left redeclaration for foo
196 input.y:6.1-5: first declaration
203 ## ----------------------- ##
204 ## Torturing the Scanner. ##
205 ## ----------------------- ##
207 # Be sure to compile and run, so that the C compiler checks what
210 AT_SETUP([Torturing the Scanner])
213 AT_DATA([input.y], [])
214 AT_CHECK([bison input.y], [1], [],
215 [[input.y:1.1: syntax error, unexpected end of file
219 AT_DATA_GRAMMAR([input.y],
221 /* This is seen in GCC: a %{ and %} in middle of a comment. */
222 const char *foo = "So %{ and %} can be here too.";
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
231 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
234 The Apple Darwin compiler (as of late 2002) mishandles
235 \\[newline]' within a character constant.
240 * A comment with backslash-newlines in it. %} *\
243 /* { Close the above comment, if the C compiler mishandled it. */
246 " A string with backslash-newlines in it %{ %} \\
250 char apostrophe = '\'';
255 /* %{ and %} can be here too. */
258 /* Exercise pre-prologue dependency to %union. */
262 /* Exercise M4 quoting: '@:>@@:>@', 0. */
264 /* Also exercise %union. */
267 value ival; /* A comment to exercise an old bug. */
271 /* Exercise post-prologue dependency to %union. */
273 static YYSTYPE value_as_yystype (value val);
275 /* Exercise quotes in declarations. */
276 char quote[] = "@:>@@:>@,";
280 static void yyerror (const char *s);
281 static int yylex (void);
286 /* Exercise quotes in strings. */
287 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
290 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
291 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
293 /* Exercise quotes in braces. */
294 char tmp[] = "@<:@%c@:>@,\n";
299 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
300 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
301 output.or.oline.opt: ;|oline;;|output;;;
302 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
304 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
307 value_as_yystype (value val)
317 static const char *input = "@<:@\1\2$@{@oline@__@&t@oline__\
320 yylval = value_as_yystype (*input);
325 yyerror (const char *msg)
327 fprintf (stderr, "%s\n", msg);
331 # Pacify Emacs'font-lock-mode: "
346 AT_CHECK([bison -d -v -o input.c input.y])
347 AT_COMPILE([input.o], [-c input.c])
348 AT_COMPILE([main.o], [-c main.c])
349 AT_COMPILE([input], [input.o main.o])
350 AT_PARSER_CHECK([./input], 0,
357 ## ---------------------- ##
358 ## Typed symbol aliases. ##
359 ## ---------------------- ##
361 AT_SETUP([Typed symbol aliases])
363 # Bison 2.0 broke typed symbol aliases - ensure they work.
365 AT_DATA_GRAMMAR([input.y],
370 %token <val> MY_TOKEN "MY TOKEN"
377 AT_CHECK([bison -o input.c input.y])
386 m4_define([AT_CHECK_REQUIRE],
387 [AT_SETUP([Require $1])
388 AT_DATA_GRAMMAR([input.y],
393 AT_CHECK([bison -o input.c input.y], $2, [], ignore)
397 AT_CHECK_REQUIRE(1.0, 0)
398 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
399 ## FIXME: Some day augment this version number.
400 AT_CHECK_REQUIRE(100.0, 63)