]>
Commit | Line | Data |
---|---|---|
087b9fdf | 1 | # Checking the Bison scanner. -*- Autotest -*- |
4a99c664 | 2 | # Copyright (C) 2002, 2003 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 | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
17 | # 02111-1307, USA. | |
18 | ||
19 | AT_BANNER([[Input Processing.]]) | |
20 | ||
21 | # Mostly test that we are robust to mistakes. | |
22 | ||
6c35d22c | 23 | |
9b2d0677 AD |
24 | ## ------------ ## |
25 | ## Invalid $n. ## | |
26 | ## ------------ ## | |
27 | ||
9b2d0677 AD |
28 | AT_SETUP([Invalid $n]) |
29 | ||
30 | AT_DATA([input.y], | |
31 | [[%% | |
bfcf1f3a | 32 | exp: { $$ = $1 ; }; |
9b2d0677 AD |
33 | ]]) |
34 | ||
35 | AT_CHECK([bison input.y], [1], [], | |
b06af56f | 36 | [[input.y:2.13-14: integer out of range: `$1' |
9b2d0677 AD |
37 | ]]) |
38 | ||
39 | AT_CLEANUP | |
40 | ||
41 | ||
42 | ## ------------ ## | |
43 | ## Invalid @n. ## | |
44 | ## ------------ ## | |
45 | ||
9b2d0677 AD |
46 | AT_SETUP([Invalid @n]) |
47 | ||
48 | AT_DATA([input.y], | |
49 | [[%% | |
bfcf1f3a | 50 | exp: { @$ = @1 ; }; |
9b2d0677 AD |
51 | ]]) |
52 | ||
53 | AT_CHECK([bison input.y], [1], [], | |
b06af56f | 54 | [[input.y:2.13-14: integer out of range: `@1' |
9b2d0677 AD |
55 | ]]) |
56 | ||
57 | AT_CLEANUP | |
9af3fbce AD |
58 | |
59 | ||
60 | ## -------------- ## | |
e776192e | 61 | ## Type Clashes. ## |
9af3fbce AD |
62 | ## -------------- ## |
63 | ||
e776192e | 64 | AT_SETUP([Type Clashes]) |
9af3fbce AD |
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 | ||
38e71ff8 | 76 | AT_CHECK([bison input.y], [], [], |
b06af56f PE |
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 | |
9af3fbce AD |
80 | ]]) |
81 | ||
82 | AT_CLEANUP | |
5a08f1ce AD |
83 | |
84 | ||
85 | ||
86 | ## ----------------------- ## | |
87 | ## Torturing the Scanner. ## | |
88 | ## ----------------------- ## | |
89 | ||
90 | # Be sure to compile and run, so that the C compiler checks what | |
91 | # we do. | |
92 | ||
93 | AT_SETUP([Torturing the Scanner]) | |
94 | ||
0baf7c50 PE |
95 | |
96 | AT_DATA([input.y], []) | |
97 | AT_CHECK([bison input.y], [1], [], | |
98 | [[input.y:1.1: syntax error, unexpected "end of file" | |
99 | ]]) | |
100 | ||
101 | ||
9501dc6e | 102 | AT_DATA_GRAMMAR([input.y], |
5a08f1ce AD |
103 | [[%{ |
104 | /* This is seen in GCC: a %{ and %} in middle of a comment. */ | |
105 | const char *foo = "So %{ and %} can be here too."; | |
106 | ||
dda7a53e PE |
107 | #if 0 |
108 | /* These examples test Bison while not stressing C compilers too much. | |
109 | Many C compilers mishandle backslash-newlines, so this part of the | |
110 | test is inside "#if 0". The comment and string are written so that | |
111 | the "#endif" will be seen regardless of the C compiler bugs that we | |
112 | know about, namely: | |
113 | ||
114 | HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a | |
115 | comment. | |
116 | ||
117 | The Apple Darwin compiler (as of late 2002) mishandles | |
118 | \\[newline]' within a character constant. | |
119 | ||
120 | */ | |
121 | ||
206fe6a5 | 122 | /\ |
dda7a53e PE |
123 | * A comment with backslash-newlines in it. %} *\ |
124 | \ | |
206fe6a5 | 125 | / |
dda7a53e | 126 | /* { Close the above comment, if the C compiler mishandled it. */ |
206fe6a5 PE |
127 | |
128 | char str[] = "\\ | |
129 | " A string with backslash-newlines in it %{ %} \\ | |
dda7a53e | 130 | \ |
206fe6a5 PE |
131 | ""; |
132 | ||
dda7a53e | 133 | char apostrophe = '\''; |
206fe6a5 PE |
134 | #endif |
135 | ||
5a08f1ce AD |
136 | #include <stdio.h> |
137 | %} | |
138 | /* %{ and %} can be here too. */ | |
139 | ||
140 | %{ | |
141 | /* Exercise pre-prologue dependency to %union. */ | |
051ade83 | 142 | typedef int value; |
5a08f1ce AD |
143 | %} |
144 | ||
145 | /* Exercise M4 quoting: '@:>@@:>@', 0. */ | |
146 | ||
147 | /* Also exercise %union. */ | |
148 | %union | |
149 | { | |
051ade83 | 150 | value ival; /* A comment to exercise an old bug. */ |
5a08f1ce AD |
151 | }; |
152 | ||
153 | ||
154 | /* Exercise post-prologue dependency to %union. */ | |
155 | %{ | |
051ade83 | 156 | static YYSTYPE value_as_yystype (value val); |
5a08f1ce AD |
157 | |
158 | /* Exercise quotes in declarations. */ | |
159 | char quote[] = "@:>@@:>@,"; | |
160 | %} | |
161 | ||
162 | %{ | |
163 | static void yyerror (const char *s); | |
164 | static int yylex (void); | |
165 | %} | |
166 | ||
206fe6a5 | 167 | %type <ival> '@<:@' |
5a08f1ce AD |
168 | |
169 | /* Exercise quotes in strings. */ | |
206fe6a5 | 170 | %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x0\0" |
5a08f1ce AD |
171 | |
172 | %% | |
206fe6a5 | 173 | /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */ |
087b9fdf | 174 | exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt |
5a08f1ce AD |
175 | { |
176 | /* Exercise quotes in braces. */ | |
177 | char tmp[] = "@<:@%c@:>@,\n"; | |
178 | printf (tmp, $1); | |
179 | } | |
180 | ; | |
5b7f88c7 PE |
181 | |
182 | two: '\x000000000000000000000000000000000000000000000000000000000000000000002'; | |
183 | oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_'; | |
087b9fdf | 184 | output.or.oline.opt: ;|oline;;|output;;; |
5b7f88c7 | 185 | output: '#' 'o' 'u' 't' 'p' 'u' 't' ' '; |
5a08f1ce | 186 | %% |
206fe6a5 | 187 | /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */ |
5a08f1ce AD |
188 | |
189 | static YYSTYPE | |
051ade83 | 190 | value_as_yystype (value val) |
5a08f1ce AD |
191 | { |
192 | YYSTYPE res; | |
193 | res.ival = val; | |
194 | return res; | |
195 | } | |
196 | ||
197 | static int | |
198 | yylex (void) | |
199 | { | |
5b7f88c7 PE |
200 | static const char *input = "@<:@\1\2$@{@oline@__@&t@oline__\ |
201 | #output "; /* " | |
202 | */ | |
051ade83 | 203 | yylval = value_as_yystype (*input); |
5a08f1ce AD |
204 | return *input++; |
205 | } | |
206 | ||
207 | static void | |
208 | yyerror (const char *msg) | |
209 | { | |
210 | fprintf (stderr, "%s\n", msg); | |
211 | } | |
212 | ]]) | |
213 | ||
9501dc6e AD |
214 | # Pacify Emacs'font-lock-mode: " |
215 | ||
5a08f1ce | 216 | AT_DATA([main.c], |
051ade83 | 217 | [[typedef int value; |
5a08f1ce AD |
218 | #include "input.h" |
219 | ||
220 | int yyparse (void); | |
221 | ||
222 | int | |
223 | main (void) | |
224 | { | |
225 | return yyparse (); | |
226 | } | |
227 | ]]) | |
228 | ||
b56471a6 | 229 | AT_CHECK([bison -d -v -o input.c input.y]) |
efc6bf1b PE |
230 | AT_COMPILE([input.o], [-c input.c]) |
231 | AT_COMPILE([main.o], [-c main.c]) | |
232 | AT_COMPILE([input], [input.o main.o]) | |
1154cced | 233 | AT_PARSER_CHECK([./input], 0, |
206fe6a5 | 234 | [[[@<:@], |
5a08f1ce AD |
235 | ]]) |
236 | ||
237 | AT_CLEANUP |