]> git.saurik.com Git - bison.git/blame - tests/reduce.at
maint: use announce-gen's new --mail-headers.
[bison.git] / tests / reduce.at
CommitLineData
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
19AT_BANNER([[Grammar Reduction.]])
20
21
22## ------------------- ##
23## Useless Terminals. ##
24## ------------------- ##
25
26AT_SETUP([Useless Terminals])
27
28AT_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%%
44exp: useful;
45]])
46
da730230 47AT_BISON_CHECK([[input.y]])
cb4956ee
AD
48
49AT_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
62AT_CLEANUP
63
64
65
66## ---------------------- ##
67## Useless Nonterminals. ##
68## ---------------------- ##
69
70AT_SETUP([Useless Nonterminals])
71
72AT_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%%
88exp: useful;
89]])
90
da730230 91AT_BISON_CHECK([[input.y]], 0, [],
cff03fb2
JD
92[[input.y: warning: 9 nonterminals useless in grammar
93input.y:4.8-15: warning: nonterminal useless in grammar: useless1
94input.y:5.8-15: warning: nonterminal useless in grammar: useless2
95input.y:6.8-15: warning: nonterminal useless in grammar: useless3
96input.y:7.8-15: warning: nonterminal useless in grammar: useless4
97input.y:8.8-15: warning: nonterminal useless in grammar: useless5
98input.y:9.8-15: warning: nonterminal useless in grammar: useless6
99input.y:10.8-15: warning: nonterminal useless in grammar: useless7
100input.y:11.8-15: warning: nonterminal useless in grammar: useless8
101input.y:12.8-15: warning: nonterminal useless in grammar: useless9
760b53a8 102]])
cb4956ee
AD
103
104AT_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
117AT_CLEANUP
68f1e3ed
AD
118
119
120
121## --------------- ##
122## Useless Rules. ##
123## --------------- ##
124
125AT_SETUP([Useless Rules])
126
9757c359
AD
127AT_KEYWORDS([report])
128
68f1e3ed
AD
129AT_DATA([[input.y]],
130[[%verbose
02975b9a 131%output "input.c"
68f1e3ed
AD
132%token useful
133%%
134exp: useful;
135useless1: '1';
136useless2: '2';
137useless3: '3';
138useless4: '4';
139useless5: '5';
140useless6: '6';
141useless7: '7';
142useless8: '8';
143useless9: '9';
144]])
145
da730230 146AT_BISON_CHECK([[input.y]], 0, [],
bcf07cb7
JD
147[[input.y: warning: 9 nonterminals useless in grammar
148input.y: warning: 9 rules useless in grammar
cff03fb2
JD
149input.y:6.1-8: warning: nonterminal useless in grammar: useless1
150input.y:7.1-8: warning: nonterminal useless in grammar: useless2
151input.y:8.1-8: warning: nonterminal useless in grammar: useless3
152input.y:9.1-8: warning: nonterminal useless in grammar: useless4
153input.y:10.1-8: warning: nonterminal useless in grammar: useless5
154input.y:11.1-8: warning: nonterminal useless in grammar: useless6
155input.y:12.1-8: warning: nonterminal useless in grammar: useless7
156input.y:13.1-8: warning: nonterminal useless in grammar: useless8
157input.y:14.1-8: warning: nonterminal useless in grammar: useless9
158input.y:6.11-13: warning: rule useless in grammar: useless1: '1'
159input.y:7.11-13: warning: rule useless in grammar: useless2: '2'
160input.y:8.11-13: warning: rule useless in grammar: useless3: '3'
161input.y:9.11-13: warning: rule useless in grammar: useless4: '4'
162input.y:10.11-13: warning: rule useless in grammar: useless5: '5'
163input.y:11.11-13: warning: rule useless in grammar: useless6: '6'
164input.y:12.11-13: warning: rule useless in grammar: useless7: '7'
165input.y:13.11-13: warning: rule useless in grammar: useless8: '8'
166input.y:14.11-13: warning: rule useless in grammar: useless9: '9'
68f1e3ed
AD
167]])
168
169AT_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 180Terminals unused in grammar
68f1e3ed
AD
181 '1'
182 '2'
183 '3'
184 '4'
185 '5'
186 '6'
187 '7'
188 '8'
189 '9'
cff03fb2 190Rules 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
202AT_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
213AT_SETUP([Reduced Automaton])
214
9757c359
AD
215AT_KEYWORDS([report])
216
c3b407f4
AD
217# The non reduced grammar.
218# ------------------------
219AT_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
229exp: useful { /* A useful action. */ }
230 | non_productive { /* A non productive action. */ }
231 ;
232
233not_reachable: useful { /* A not reachable action. */ }
234 ;
235
236non_productive: non_productive useless_token
237 { /* Another non productive action. */ }
238 ;
e9955c83 239%%
c3b407f4
AD
240]])
241
da730230 242AT_BISON_CHECK([[not-reduced.y]], 0, [],
bcf07cb7
JD
243[[not-reduced.y: warning: 2 nonterminals useless in grammar
244not-reduced.y: warning: 3 rules useless in grammar
cff03fb2
JD
245not-reduced.y:14.1-13: warning: nonterminal useless in grammar: not_reachable
246not-reduced.y:11.6-19: warning: nonterminal useless in grammar: non_productive
247not-reduced.y:11.6-57: warning: rule useless in grammar: exp: non_productive
248not-reduced.y:14.16-56: warning: rule useless in grammar: not_reachable: useful
249not-reduced.y:17.17-18.63: warning: rule useless in grammar: non_productive: non_productive useless_token
c3b407f4
AD
250]])
251
252AT_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 256Terminals unused in grammar
c3b407f4 257 useless_token
cff03fb2 258Rules 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# --------------------
266AT_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
276exp: 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 289AT_BISON_CHECK([[reduced.y]])
c3b407f4
AD
290
291# Comparing the parsers.
292cp reduced.c expout
293AT_CHECK([sed 's/not-reduced/reduced/g' not-reduced.c], 0, [expout])
294
295AT_CLEANUP
296
297
298
68f1e3ed
AD
299## ------------------- ##
300## Underivable Rules. ##
301## ------------------- ##
302
303AT_SETUP([Underivable Rules])
304
9757c359
AD
305AT_KEYWORDS([report])
306
68f1e3ed
AD
307AT_DATA([[input.y]],
308[[%verbose
02975b9a 309%output "input.c"
68f1e3ed
AD
310%token useful
311%%
312exp: useful | underivable;
313underivable: indirection;
314indirection: underivable;
315]])
316
da730230 317AT_BISON_CHECK([[input.y]], 0, [],
bcf07cb7
JD
318[[input.y: warning: 2 nonterminals useless in grammar
319input.y: warning: 3 rules useless in grammar
cff03fb2
JD
320input.y:5.15-25: warning: nonterminal useless in grammar: underivable
321input.y:6.14-24: warning: nonterminal useless in grammar: indirection
322input.y:5.15-25: warning: rule useless in grammar: exp: underivable
323input.y:6.14-24: warning: rule useless in grammar: underivable: indirection
324input.y:7.14-24: warning: rule useless in grammar: indirection: underivable
68f1e3ed
AD
325]])
326
327AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
cff03fb2 328[[Nonterminals useless in grammar
68f1e3ed
AD
329 underivable
330 indirection
cff03fb2 331Rules useless in grammar
9757c359
AD
332 2 exp: underivable
333 3 underivable: indirection
334 4 indirection: underivable
68f1e3ed
AD
335]])
336
337AT_CLEANUP
1bfb97db
AD
338
339
340
341## ---------------- ##
342## Empty Language. ##
343## ---------------- ##
344
345AT_SETUP([Empty Language])
346
347AT_DATA([[input.y]],
02975b9a 348[[%output "input.c"
1bfb97db
AD
349%%
350exp: exp;
351]])
352
da730230 353AT_BISON_CHECK([[input.y]], 1, [],
bcf07cb7
JD
354[[input.y: warning: 2 nonterminals useless in grammar
355input.y: warning: 2 rules useless in grammar
1bfb97db
AD
356input.y:3.1-3: fatal error: start symbol exp does not derive any sentence
357]])
358
359AT_CLEANUP