]> git.saurik.com Git - bison.git/blame_incremental - tests/reduce.at
maint: use announce-gen's new --mail-headers.
[bison.git] / tests / reduce.at
... / ...
CommitLineData
1# Exercising Bison Grammar Reduction. -*- Autotest -*-
2
3# Copyright (C) 2001, 2002, 2007, 2008, 2009, 2010 Free Software
4# Foundation, Inc.
5
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
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.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19AT_BANNER([[Grammar Reduction.]])
20
21
22## ------------------- ##
23## Useless Terminals. ##
24## ------------------- ##
25
26AT_SETUP([Useless Terminals])
27
28AT_DATA([[input.y]],
29[[%verbose
30%output "input.c"
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
47AT_BISON_CHECK([[input.y]])
48
49AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
50[[Terminals unused in grammar
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
74%output "input.c"
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
91AT_BISON_CHECK([[input.y]], 0, [],
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
102]])
103
104AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
105[[Nonterminals useless in grammar
106 useless1
107 useless2
108 useless3
109 useless4
110 useless5
111 useless6
112 useless7
113 useless8
114 useless9
115]])
116
117AT_CLEANUP
118
119
120
121## --------------- ##
122## Useless Rules. ##
123## --------------- ##
124
125AT_SETUP([Useless Rules])
126
127AT_KEYWORDS([report])
128
129AT_DATA([[input.y]],
130[[%verbose
131%output "input.c"
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
146AT_BISON_CHECK([[input.y]], 0, [],
147[[input.y: warning: 9 nonterminals useless in grammar
148input.y: warning: 9 rules useless in grammar
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'
167]])
168
169AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
170[[Nonterminals useless in grammar
171 useless1
172 useless2
173 useless3
174 useless4
175 useless5
176 useless6
177 useless7
178 useless8
179 useless9
180Terminals unused in grammar
181 '1'
182 '2'
183 '3'
184 '4'
185 '5'
186 '6'
187 '7'
188 '8'
189 '9'
190Rules useless in grammar
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'
200]])
201
202AT_CLEANUP
203
204
205
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
215AT_KEYWORDS([report])
216
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
225%output "not-reduced.c"
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 ;
239%%
240]])
241
242AT_BISON_CHECK([[not-reduced.y]], 0, [],
243[[not-reduced.y: warning: 2 nonterminals useless in grammar
244not-reduced.y: warning: 3 rules useless in grammar
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
250]])
251
252AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
253[[Nonterminals useless in grammar
254 not_reachable
255 non_productive
256Terminals unused in grammar
257 useless_token
258Rules useless in grammar
259 2 exp: non_productive
260 3 not_reachable: useful
261 4 non_productive: non_productive useless_token
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
272%output "reduced.c"
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// ;
286%%
287]])
288
289AT_BISON_CHECK([[reduced.y]])
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
299## ------------------- ##
300## Underivable Rules. ##
301## ------------------- ##
302
303AT_SETUP([Underivable Rules])
304
305AT_KEYWORDS([report])
306
307AT_DATA([[input.y]],
308[[%verbose
309%output "input.c"
310%token useful
311%%
312exp: useful | underivable;
313underivable: indirection;
314indirection: underivable;
315]])
316
317AT_BISON_CHECK([[input.y]], 0, [],
318[[input.y: warning: 2 nonterminals useless in grammar
319input.y: warning: 3 rules useless in grammar
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
325]])
326
327AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
328[[Nonterminals useless in grammar
329 underivable
330 indirection
331Rules useless in grammar
332 2 exp: underivable
333 3 underivable: indirection
334 4 indirection: underivable
335]])
336
337AT_CLEANUP
338
339
340
341## ---------------- ##
342## Empty Language. ##
343## ---------------- ##
344
345AT_SETUP([Empty Language])
346
347AT_DATA([[input.y]],
348[[%output "input.c"
349%%
350exp: exp;
351]])
352
353AT_BISON_CHECK([[input.y]], 1, [],
354[[input.y: warning: 2 nonterminals useless in grammar
355input.y: warning: 2 rules useless in grammar
356input.y:3.1-3: fatal error: start symbol exp does not derive any sentence
357]])
358
359AT_CLEANUP