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