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