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
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
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 }
102 a: INT | INT { } INT { } INT { };
103 b: INT | /* empty */;
104 c: INT | INT { $1 } INT { } INT { };
105 d: INT | INT { } INT { $1 } INT { };
106 e: INT | INT { } INT { } INT { $1 };
107 f: INT | INT { } INT { } INT { $$ = $1 + $3 + $5; };
108 g: INT | INT { $$ } INT { $$ } INT { };
109 h: INT | INT { $$ } INT { $$ = $2 } INT { };
110 i: INT | INT INT { } { $$ = $1 + $2; };
111 j: INT | INT INT { $<integer>$ = 1; } { $$ = $1 + $2; };
112 k: INT | INT INT { $$; } { $$ = $3; } { };
113 l: INT | INT { $$ = $1; } INT { $$ = $2 + $3; } INT { $$ = $4 + $5; };
117 AT_CHECK([bison input.y], [], [],
118 [[input.y:11.10-32: warning: unset value: $$
119 input.y:11.10-32: warning: unused value: $1
120 input.y:11.10-32: warning: unused value: $3
121 input.y:11.10-32: warning: unused value: $5
122 input.y:12.9: warning: empty rule for typed nonterminal, and no action
123 input.y:13.10-35: warning: unset value: $$
124 input.y:13.10-35: warning: unused value: $3
125 input.y:13.10-35: warning: unused value: $5
126 input.y:14.10-35: warning: unset value: $$
127 input.y:14.10-35: warning: unused value: $3
128 input.y:14.10-35: warning: unused value: $5
129 input.y:15.10-36: warning: unset value: $$
130 input.y:15.10-36: warning: unused value: $3
131 input.y:15.10-36: warning: unused value: $5
132 input.y:17.10-38: warning: unset value: $$
133 input.y:17.10-38: warning: unused value: $1
134 input.y:17.10-38: warning: unused value: $2
135 input.y:17.10-38: warning: unused value: $3
136 input.y:17.10-38: warning: unused value: $4
137 input.y:17.10-38: warning: unused value: $5
138 input.y:18.10-43: warning: unset value: $$
139 input.y:18.10-43: warning: unused value: $1
140 input.y:18.10-43: warning: unused value: $3
141 input.y:18.10-43: warning: unused value: $4
142 input.y:18.10-43: warning: unused value: $5
143 input.y:20.10-55: warning: unused value: $3
144 input.y:21.10-41: warning: unset value: $$
145 input.y:21.10-41: warning: unused value: $1
146 input.y:21.10-41: warning: unused value: $2
147 input.y:21.10-41: warning: unused value: $4
153 ## ---------------------- ##
154 ## Incompatible Aliases. ##
155 ## ---------------------- ##
157 AT_SETUP([Incompatible Aliases])
164 %destructor {bar} foo
169 %destructor {baz} "foo"
176 AT_CHECK([bison input.y], [1], [],
177 [[input.y:8.7-11: %type redeclaration for foo
178 input.y:3.7-11: first declaration
179 input.y:10.13-17: %destructor redeclaration for foo
180 input.y:5.13-17: first declaration
181 input.y:9.10-14: %printer redeclaration for foo
182 input.y:10.13-17: first declaration
183 input.y:11.1-5: %left redeclaration for foo
184 input.y:6.1-5: first declaration
191 ## ----------------------- ##
192 ## Torturing the Scanner. ##
193 ## ----------------------- ##
195 # Be sure to compile and run, so that the C compiler checks what
198 AT_SETUP([Torturing the Scanner])
201 AT_DATA([input.y], [])
202 AT_CHECK([bison input.y], [1], [],
203 [[input.y:1.1: syntax error, unexpected end of file
210 AT_CHECK([bison input.y], [1], [],
211 [[input.y:1.1-2: syntax error, unexpected {...}
215 AT_DATA_GRAMMAR([input.y],
217 /* This is seen in GCC: a %{ and %} in middle of a comment. */
218 const char *foo = "So %{ and %} can be here too.";
221 /* These examples test Bison while not stressing C compilers too much.
222 Many C compilers mishandle backslash-newlines, so this part of the
223 test is inside "#if 0". The comment and string are written so that
224 the "#endif" will be seen regardless of the C compiler bugs that we
227 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
230 The Apple Darwin compiler (as of late 2002) mishandles
231 \\[newline]' within a character constant.
236 * A comment with backslash-newlines in it. %} *\
239 /* { Close the above comment, if the C compiler mishandled it. */
242 " A string with backslash-newlines in it %{ %} \\
246 char apostrophe = '\'';
251 /* %{ and %} can be here too. */
254 /* Exercise pre-prologue dependency to %union. */
258 /* Exercise M4 quoting: '@:>@@:>@', 0. */
260 /* Also exercise %union. */
263 value ival; /* A comment to exercise an old bug. */
267 /* Exercise post-prologue dependency to %union. */
269 static YYSTYPE value_as_yystype (value val);
271 /* Exercise quotes in declarations. */
272 char quote[] = "@:>@@:>@,";
276 static void yyerror (const char *s);
277 static int yylex (void);
282 /* Exercise quotes in strings. */
283 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
286 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
287 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
289 /* Exercise quotes in braces. */
290 char tmp[] = "@<:@%c@:>@,\n";
295 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
296 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
297 output.or.oline.opt: ;|oline;;|output;;;
298 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
300 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
303 value_as_yystype (value val)
313 static const char *input = "@<:@\1\2$@{@oline@__@&t@oline__\
316 yylval = value_as_yystype (*input);
321 yyerror (const char *msg)
323 fprintf (stderr, "%s\n", msg);
327 # Pacify Emacs'font-lock-mode: "
342 AT_CHECK([bison -d -v -o input.c input.y])
343 AT_COMPILE([input.o], [-c input.c])
344 AT_COMPILE([main.o], [-c main.c])
345 AT_COMPILE([input], [input.o main.o])
346 AT_PARSER_CHECK([./input], 0,
353 ## ---------------------- ##
354 ## Typed symbol aliases. ##
355 ## ---------------------- ##
357 AT_SETUP([Typed symbol aliases])
359 # Bison 2.0 broke typed symbol aliases - ensure they work.
361 AT_DATA_GRAMMAR([input.y],
366 %token <val> MY_TOKEN "MY TOKEN"
373 AT_CHECK([bison -o input.c input.y])
382 m4_define([AT_CHECK_REQUIRE],
383 [AT_SETUP([Require $1])
384 AT_DATA_GRAMMAR([input.y],
389 AT_CHECK([bison -o input.c input.y], $2, [], ignore)
393 AT_CHECK_REQUIRE(1.0, 0)
394 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
395 ## FIXME: Some day augment this version number.
396 AT_CHECK_REQUIRE(100.0, 63)