]>
Commit | Line | Data |
---|---|---|
cb4956ee | 1 | # Exercising Bison Grammar Reduction. -*- Autotest -*- |
5523ac79 | 2 | # Copyright (C) 2001, 2002, 2007, 2008 Free Software Foundation, Inc. |
cb4956ee | 3 | |
f16b0819 | 4 | # This program is free software: you can redistribute it and/or modify |
cb4956ee | 5 | # it under the terms of the GNU General Public License as published by |
f16b0819 PE |
6 | # the Free Software Foundation, either version 3 of the License, or |
7 | # (at your option) any later version. | |
8 | # | |
cb4956ee AD |
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. | |
f16b0819 | 13 | # |
cb4956ee | 14 | # You should have received a copy of the GNU General Public License |
f16b0819 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
cb4956ee AD |
16 | |
17 | AT_BANNER([[Grammar Reduction.]]) | |
18 | ||
19 | ||
20 | ## ------------------- ## | |
21 | ## Useless Terminals. ## | |
22 | ## ------------------- ## | |
23 | ||
24 | AT_SETUP([Useless Terminals]) | |
25 | ||
26 | AT_DATA([[input.y]], | |
27 | [[%verbose | |
02975b9a | 28 | %output "input.c" |
cb4956ee AD |
29 | |
30 | %token useless1 | |
31 | %token useless2 | |
32 | %token useless3 | |
33 | %token useless4 | |
34 | %token useless5 | |
35 | %token useless6 | |
36 | %token useless7 | |
37 | %token useless8 | |
38 | %token useless9 | |
39 | ||
40 | %token useful | |
41 | %% | |
42 | exp: useful; | |
43 | ]]) | |
44 | ||
da730230 | 45 | AT_BISON_CHECK([[input.y]]) |
cb4956ee AD |
46 | |
47 | AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0, | |
d80fb37a | 48 | [[Terminals unused in grammar |
cb4956ee AD |
49 | useless1 |
50 | useless2 | |
51 | useless3 | |
52 | useless4 | |
53 | useless5 | |
54 | useless6 | |
55 | useless7 | |
56 | useless8 | |
57 | useless9 | |
58 | ]]) | |
59 | ||
60 | AT_CLEANUP | |
61 | ||
62 | ||
63 | ||
64 | ## ---------------------- ## | |
65 | ## Useless Nonterminals. ## | |
66 | ## ---------------------- ## | |
67 | ||
68 | AT_SETUP([Useless Nonterminals]) | |
69 | ||
70 | AT_DATA([[input.y]], | |
71 | [[%verbose | |
02975b9a | 72 | %output "input.c" |
cb4956ee AD |
73 | |
74 | %nterm useless1 | |
75 | %nterm useless2 | |
76 | %nterm useless3 | |
77 | %nterm useless4 | |
78 | %nterm useless5 | |
79 | %nterm useless6 | |
80 | %nterm useless7 | |
81 | %nterm useless8 | |
82 | %nterm useless9 | |
83 | ||
84 | %token useful | |
85 | %% | |
86 | exp: useful; | |
87 | ]]) | |
88 | ||
da730230 | 89 | AT_BISON_CHECK([[input.y]], 0, [], |
cff03fb2 JD |
90 | [[input.y: warning: 9 nonterminals useless in grammar |
91 | input.y:4.8-15: warning: nonterminal useless in grammar: useless1 | |
92 | input.y:5.8-15: warning: nonterminal useless in grammar: useless2 | |
93 | input.y:6.8-15: warning: nonterminal useless in grammar: useless3 | |
94 | input.y:7.8-15: warning: nonterminal useless in grammar: useless4 | |
95 | input.y:8.8-15: warning: nonterminal useless in grammar: useless5 | |
96 | input.y:9.8-15: warning: nonterminal useless in grammar: useless6 | |
97 | input.y:10.8-15: warning: nonterminal useless in grammar: useless7 | |
98 | input.y:11.8-15: warning: nonterminal useless in grammar: useless8 | |
99 | input.y:12.8-15: warning: nonterminal useless in grammar: useless9 | |
760b53a8 | 100 | ]]) |
cb4956ee AD |
101 | |
102 | AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0, | |
cff03fb2 | 103 | [[Nonterminals useless in grammar |
cb4956ee AD |
104 | useless1 |
105 | useless2 | |
106 | useless3 | |
107 | useless4 | |
108 | useless5 | |
109 | useless6 | |
110 | useless7 | |
111 | useless8 | |
112 | useless9 | |
113 | ]]) | |
114 | ||
115 | AT_CLEANUP | |
68f1e3ed AD |
116 | |
117 | ||
118 | ||
119 | ## --------------- ## | |
120 | ## Useless Rules. ## | |
121 | ## --------------- ## | |
122 | ||
123 | AT_SETUP([Useless Rules]) | |
124 | ||
9757c359 AD |
125 | AT_KEYWORDS([report]) |
126 | ||
68f1e3ed AD |
127 | AT_DATA([[input.y]], |
128 | [[%verbose | |
02975b9a | 129 | %output "input.c" |
68f1e3ed AD |
130 | %token useful |
131 | %% | |
132 | exp: useful; | |
133 | useless1: '1'; | |
134 | useless2: '2'; | |
135 | useless3: '3'; | |
136 | useless4: '4'; | |
137 | useless5: '5'; | |
138 | useless6: '6'; | |
139 | useless7: '7'; | |
140 | useless8: '8'; | |
141 | useless9: '9'; | |
142 | ]]) | |
143 | ||
da730230 | 144 | AT_BISON_CHECK([[input.y]], 0, [], |
bcf07cb7 JD |
145 | [[input.y: warning: 9 nonterminals useless in grammar |
146 | input.y: warning: 9 rules useless in grammar | |
cff03fb2 JD |
147 | input.y:6.1-8: warning: nonterminal useless in grammar: useless1 |
148 | input.y:7.1-8: warning: nonterminal useless in grammar: useless2 | |
149 | input.y:8.1-8: warning: nonterminal useless in grammar: useless3 | |
150 | input.y:9.1-8: warning: nonterminal useless in grammar: useless4 | |
151 | input.y:10.1-8: warning: nonterminal useless in grammar: useless5 | |
152 | input.y:11.1-8: warning: nonterminal useless in grammar: useless6 | |
153 | input.y:12.1-8: warning: nonterminal useless in grammar: useless7 | |
154 | input.y:13.1-8: warning: nonterminal useless in grammar: useless8 | |
155 | input.y:14.1-8: warning: nonterminal useless in grammar: useless9 | |
156 | input.y:6.11-13: warning: rule useless in grammar: useless1: '1' | |
157 | input.y:7.11-13: warning: rule useless in grammar: useless2: '2' | |
158 | input.y:8.11-13: warning: rule useless in grammar: useless3: '3' | |
159 | input.y:9.11-13: warning: rule useless in grammar: useless4: '4' | |
160 | input.y:10.11-13: warning: rule useless in grammar: useless5: '5' | |
161 | input.y:11.11-13: warning: rule useless in grammar: useless6: '6' | |
162 | input.y:12.11-13: warning: rule useless in grammar: useless7: '7' | |
163 | input.y:13.11-13: warning: rule useless in grammar: useless8: '8' | |
164 | input.y:14.11-13: warning: rule useless in grammar: useless9: '9' | |
68f1e3ed AD |
165 | ]]) |
166 | ||
167 | AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0, | |
cff03fb2 | 168 | [[Nonterminals useless in grammar |
68f1e3ed AD |
169 | useless1 |
170 | useless2 | |
171 | useless3 | |
172 | useless4 | |
173 | useless5 | |
174 | useless6 | |
175 | useless7 | |
176 | useless8 | |
177 | useless9 | |
d80fb37a | 178 | Terminals unused in grammar |
68f1e3ed AD |
179 | '1' |
180 | '2' | |
181 | '3' | |
182 | '4' | |
183 | '5' | |
184 | '6' | |
185 | '7' | |
186 | '8' | |
187 | '9' | |
cff03fb2 | 188 | Rules useless in grammar |
9757c359 AD |
189 | 2 useless1: '1' |
190 | 3 useless2: '2' | |
191 | 4 useless3: '3' | |
192 | 5 useless4: '4' | |
193 | 6 useless5: '5' | |
194 | 7 useless6: '6' | |
195 | 8 useless7: '7' | |
196 | 9 useless8: '8' | |
197 | 10 useless9: '9' | |
68f1e3ed AD |
198 | ]]) |
199 | ||
200 | AT_CLEANUP | |
201 | ||
202 | ||
203 | ||
c3b407f4 AD |
204 | ## ------------------- ## |
205 | ## Reduced Automaton. ## | |
206 | ## ------------------- ## | |
207 | ||
208 | # Check that the automaton is that as the for the grammar reduced by | |
209 | # hand. | |
210 | ||
211 | AT_SETUP([Reduced Automaton]) | |
212 | ||
9757c359 AD |
213 | AT_KEYWORDS([report]) |
214 | ||
c3b407f4 AD |
215 | # The non reduced grammar. |
216 | # ------------------------ | |
217 | AT_DATA([[not-reduced.y]], | |
218 | [[/* A useless token. */ | |
219 | %token useless_token | |
220 | /* A useful one. */ | |
221 | %token useful | |
222 | %verbose | |
02975b9a | 223 | %output "not-reduced.c" |
c3b407f4 AD |
224 | |
225 | %% | |
226 | ||
227 | exp: useful { /* A useful action. */ } | |
228 | | non_productive { /* A non productive action. */ } | |
229 | ; | |
230 | ||
231 | not_reachable: useful { /* A not reachable action. */ } | |
232 | ; | |
233 | ||
234 | non_productive: non_productive useless_token | |
235 | { /* Another non productive action. */ } | |
236 | ; | |
e9955c83 | 237 | %% |
c3b407f4 AD |
238 | ]]) |
239 | ||
da730230 | 240 | AT_BISON_CHECK([[not-reduced.y]], 0, [], |
bcf07cb7 JD |
241 | [[not-reduced.y: warning: 2 nonterminals useless in grammar |
242 | not-reduced.y: warning: 3 rules useless in grammar | |
cff03fb2 JD |
243 | not-reduced.y:14.1-13: warning: nonterminal useless in grammar: not_reachable |
244 | not-reduced.y:11.6-19: warning: nonterminal useless in grammar: non_productive | |
245 | not-reduced.y:11.6-57: warning: rule useless in grammar: exp: non_productive | |
246 | not-reduced.y:14.16-56: warning: rule useless in grammar: not_reachable: useful | |
247 | not-reduced.y:17.17-18.63: warning: rule useless in grammar: non_productive: non_productive useless_token | |
c3b407f4 AD |
248 | ]]) |
249 | ||
250 | AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0, | |
cff03fb2 | 251 | [[Nonterminals useless in grammar |
c3b407f4 AD |
252 | not_reachable |
253 | non_productive | |
d80fb37a | 254 | Terminals unused in grammar |
c3b407f4 | 255 | useless_token |
cff03fb2 | 256 | Rules useless in grammar |
9757c359 AD |
257 | 2 exp: non_productive |
258 | 3 not_reachable: useful | |
259 | 4 non_productive: non_productive useless_token | |
c3b407f4 AD |
260 | ]]) |
261 | ||
262 | # The reduced grammar. | |
263 | # -------------------- | |
264 | AT_DATA([[reduced.y]], | |
265 | [[/* A useless token. */ | |
266 | %token useless_token | |
267 | /* A useful one. */ | |
268 | %token useful | |
269 | %verbose | |
02975b9a | 270 | %output "reduced.c" |
c3b407f4 AD |
271 | |
272 | %% | |
273 | ||
274 | exp: useful { /* A useful action. */ } | |
275 | // | non_productive { /* A non productive action. */ } */ | |
276 | ; | |
277 | ||
278 | //not_reachable: useful { /* A not reachable action. */ } | |
279 | // ; | |
280 | ||
281 | //non_productive: non_productive useless_token | |
282 | // { /* Another non productive action. */ } | |
283 | // ; | |
e9955c83 | 284 | %% |
c3b407f4 AD |
285 | ]]) |
286 | ||
da730230 | 287 | AT_BISON_CHECK([[reduced.y]]) |
c3b407f4 AD |
288 | |
289 | # Comparing the parsers. | |
290 | cp reduced.c expout | |
291 | AT_CHECK([sed 's/not-reduced/reduced/g' not-reduced.c], 0, [expout]) | |
292 | ||
293 | AT_CLEANUP | |
294 | ||
295 | ||
296 | ||
68f1e3ed AD |
297 | ## ------------------- ## |
298 | ## Underivable Rules. ## | |
299 | ## ------------------- ## | |
300 | ||
301 | AT_SETUP([Underivable Rules]) | |
302 | ||
9757c359 AD |
303 | AT_KEYWORDS([report]) |
304 | ||
68f1e3ed AD |
305 | AT_DATA([[input.y]], |
306 | [[%verbose | |
02975b9a | 307 | %output "input.c" |
68f1e3ed AD |
308 | %token useful |
309 | %% | |
310 | exp: useful | underivable; | |
311 | underivable: indirection; | |
312 | indirection: underivable; | |
313 | ]]) | |
314 | ||
da730230 | 315 | AT_BISON_CHECK([[input.y]], 0, [], |
bcf07cb7 JD |
316 | [[input.y: warning: 2 nonterminals useless in grammar |
317 | input.y: warning: 3 rules useless in grammar | |
cff03fb2 JD |
318 | input.y:5.15-25: warning: nonterminal useless in grammar: underivable |
319 | input.y:6.14-24: warning: nonterminal useless in grammar: indirection | |
320 | input.y:5.15-25: warning: rule useless in grammar: exp: underivable | |
321 | input.y:6.14-24: warning: rule useless in grammar: underivable: indirection | |
322 | input.y:7.14-24: warning: rule useless in grammar: indirection: underivable | |
68f1e3ed AD |
323 | ]]) |
324 | ||
325 | AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0, | |
cff03fb2 | 326 | [[Nonterminals useless in grammar |
68f1e3ed AD |
327 | underivable |
328 | indirection | |
cff03fb2 | 329 | Rules useless in grammar |
9757c359 AD |
330 | 2 exp: underivable |
331 | 3 underivable: indirection | |
332 | 4 indirection: underivable | |
68f1e3ed AD |
333 | ]]) |
334 | ||
335 | AT_CLEANUP | |
1bfb97db AD |
336 | |
337 | ||
338 | ||
339 | ## ---------------- ## | |
340 | ## Empty Language. ## | |
341 | ## ---------------- ## | |
342 | ||
343 | AT_SETUP([Empty Language]) | |
344 | ||
345 | AT_DATA([[input.y]], | |
02975b9a | 346 | [[%output "input.c" |
1bfb97db AD |
347 | %% |
348 | exp: exp; | |
349 | ]]) | |
350 | ||
da730230 | 351 | AT_BISON_CHECK([[input.y]], 1, [], |
bcf07cb7 JD |
352 | [[input.y: warning: 2 nonterminals useless in grammar |
353 | input.y: warning: 2 rules useless in grammar | |
1bfb97db AD |
354 | input.y:3.1-3: fatal error: start symbol exp does not derive any sentence |
355 | ]]) | |
356 | ||
357 | AT_CLEANUP |