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 AT_SETUP([Unused values])
92 [[%token <integer> INT
96 INT { } INT { } INT { }
97 /* Ideally we would like to complain also about $2 and $4 here, but
98 it's hard to implement. */
99 | INT { $$ } INT { $$ } INT { }
100 | INT { $1 } INT { } INT { }
101 | INT { } INT { $1 } INT { }
102 | INT { } INT { } INT { $1 }
103 | INT { } INT { } INT { $$ = $1 + $3 + $5; }
107 AT_CHECK([bison input.y], [], [],
108 [[input.y:5.3-25: warning: unset value: $$
109 input.y:5.3-25: warning: unused value: $1
110 input.y:5.3-25: warning: unused value: $3
111 input.y:5.3-25: warning: unused value: $5
112 input.y:8.3-31: warning: unset value: $$
113 input.y:8.3-31: warning: unused value: $1
114 input.y:8.3-31: warning: unused value: $3
115 input.y:8.3-31: warning: unused value: $5
116 input.y:9.3-28: warning: unset value: $$
117 input.y:9.3-28: warning: unused value: $3
118 input.y:9.3-28: warning: unused value: $5
119 input.y:10.3-28: warning: unset value: $$
120 input.y:10.3-28: warning: unused value: $3
121 input.y:10.3-28: warning: unused value: $5
122 input.y:11.3-29: warning: unset value: $$
123 input.y:11.3-29: warning: unused value: $3
124 input.y:11.3-29: warning: unused value: $5
125 input.y: conflicts: 1 reduce/reduce
126 input.y:8.7-12: warning: rule never reduced because of conflicts: @3: /* empty */
127 input.y:9.7-12: warning: rule never reduced because of conflicts: @5: /* empty */
128 input.y:10.7-9: warning: rule never reduced because of conflicts: @7: /* empty */
129 input.y:11.7-9: warning: rule never reduced because of conflicts: @9: /* empty */
130 input.y:12.7-9: warning: rule never reduced because of conflicts: @11: /* empty */
136 ## ---------------------- ##
137 ## Incompatible Aliases. ##
138 ## ---------------------- ##
140 AT_SETUP([Incompatible Aliases])
147 %destructor {bar} foo
152 %destructor {baz} "foo"
159 AT_CHECK([bison input.y], [1], [],
160 [[input.y:8.7-11: %type redeclaration for foo
161 input.y:3.7-11: first declaration
162 input.y:10.13-17: %destructor redeclaration for foo
163 input.y:5.13-17: first declaration
164 input.y:9.19-23: %printer redeclaration for foo
165 input.y:10.13-17: first declaration
166 input.y:11.1-5: %left redeclaration for foo
167 input.y:6.1-5: first declaration
174 ## ----------------------- ##
175 ## Torturing the Scanner. ##
176 ## ----------------------- ##
178 # Be sure to compile and run, so that the C compiler checks what
181 AT_SETUP([Torturing the Scanner])
184 AT_DATA([input.y], [])
185 AT_CHECK([bison input.y], [1], [],
186 [[input.y:1.1: syntax error, unexpected end of file
190 AT_DATA_GRAMMAR([input.y],
192 /* This is seen in GCC: a %{ and %} in middle of a comment. */
193 const char *foo = "So %{ and %} can be here too.";
196 /* These examples test Bison while not stressing C compilers too much.
197 Many C compilers mishandle backslash-newlines, so this part of the
198 test is inside "#if 0". The comment and string are written so that
199 the "#endif" will be seen regardless of the C compiler bugs that we
202 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
205 The Apple Darwin compiler (as of late 2002) mishandles
206 \\[newline]' within a character constant.
211 * A comment with backslash-newlines in it. %} *\
214 /* { Close the above comment, if the C compiler mishandled it. */
217 " A string with backslash-newlines in it %{ %} \\
221 char apostrophe = '\'';
226 /* %{ and %} can be here too. */
229 /* Exercise pre-prologue dependency to %union. */
233 /* Exercise M4 quoting: '@:>@@:>@', 0. */
235 /* Also exercise %union. */
238 value ival; /* A comment to exercise an old bug. */
242 /* Exercise post-prologue dependency to %union. */
244 static YYSTYPE value_as_yystype (value val);
246 /* Exercise quotes in declarations. */
247 char quote[] = "@:>@@:>@,";
251 static void yyerror (const char *s);
252 static int yylex (void);
257 /* Exercise quotes in strings. */
258 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
261 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
262 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
264 /* Exercise quotes in braces. */
265 char tmp[] = "@<:@%c@:>@,\n";
270 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
271 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
272 output.or.oline.opt: ;|oline;;|output;;;
273 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
275 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
278 value_as_yystype (value val)
288 static const char *input = "@<:@\1\2$@{@oline@__@&t@oline__\
291 yylval = value_as_yystype (*input);
296 yyerror (const char *msg)
298 fprintf (stderr, "%s\n", msg);
302 # Pacify Emacs'font-lock-mode: "
317 AT_CHECK([bison -d -v -o input.c input.y])
318 AT_COMPILE([input.o], [-c input.c])
319 AT_COMPILE([main.o], [-c main.c])
320 AT_COMPILE([input], [input.o main.o])
321 AT_PARSER_CHECK([./input], 0,
328 ## ---------------------- ##
329 ## Typed symbol aliases. ##
330 ## ---------------------- ##
332 AT_SETUP([Typed symbol aliases])
334 # Bison 2.0 broke typed symbol aliases - ensure they work.
336 AT_DATA_GRAMMAR([input.y],
341 %token <val> MY_TOKEN "MY TOKEN"
348 AT_CHECK([bison -o input.c input.y])
357 m4_define([AT_CHECK_REQUIRE],
358 [AT_SETUP([Require $1])
359 AT_DATA_GRAMMAR([input.y],
364 AT_CHECK([bison -o input.c input.y], $2, [], ignore)
368 AT_CHECK_REQUIRE(1.0, 0)
369 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
370 ## FIXME: Some day augment this version number.
371 AT_CHECK_REQUIRE(100.0, 63)