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