]> git.saurik.com Git - bison.git/blame_incremental - tests/reduce.at
Instead of attaching lookaheads and duplicating the rules being
[bison.git] / tests / reduce.at
... / ...
CommitLineData
1# Exercising Bison Grammar Reduction. -*- Autotest -*-
2# Copyright 2001 Free Software Foundation, Inc.
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
8
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.
13
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17# 02111-1307, USA.
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_CHECK([[bison input.y]])
48
49AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
50[[Terminals which are not used:
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_CHECK([[bison input.y]], 0, [],
92[[input.y: warning: 9 useless nonterminals
93input.y:4.8-15: warning: useless nonterminal: useless1
94input.y:5.8-15: warning: useless nonterminal: useless2
95input.y:6.8-15: warning: useless nonterminal: useless3
96input.y:7.8-15: warning: useless nonterminal: useless4
97input.y:8.8-15: warning: useless nonterminal: useless5
98input.y:9.8-15: warning: useless nonterminal: useless6
99input.y:10.8-15: warning: useless nonterminal: useless7
100input.y:11.8-15: warning: useless nonterminal: useless8
101input.y:12.8-15: warning: useless nonterminal: useless9
102]])
103
104AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
105[[Useless nonterminals:
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_CHECK([[bison input.y]], 0, [],
147[[input.y: warning: 9 useless nonterminals and 9 useless rules
148input.y:6.1-8: warning: useless nonterminal: useless1
149input.y:7.1-8: warning: useless nonterminal: useless2
150input.y:8.1-8: warning: useless nonterminal: useless3
151input.y:9.1-8: warning: useless nonterminal: useless4
152input.y:10.1-8: warning: useless nonterminal: useless5
153input.y:11.1-8: warning: useless nonterminal: useless6
154input.y:12.1-8: warning: useless nonterminal: useless7
155input.y:13.1-8: warning: useless nonterminal: useless8
156input.y:14.1-8: warning: useless nonterminal: useless9
157input.y:6.9-13: warning: useless rule: useless1: '1'
158input.y:7.9-13: warning: useless rule: useless2: '2'
159input.y:8.9-13: warning: useless rule: useless3: '3'
160input.y:9.9-13: warning: useless rule: useless4: '4'
161input.y:10.9-13: warning: useless rule: useless5: '5'
162input.y:11.9-13: warning: useless rule: useless6: '6'
163input.y:12.9-13: warning: useless rule: useless7: '7'
164input.y:13.9-13: warning: useless rule: useless8: '8'
165input.y:14.9-13: warning: useless rule: useless9: '9'
166]])
167
168AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
169[[Useless nonterminals:
170 useless1
171 useless2
172 useless3
173 useless4
174 useless5
175 useless6
176 useless7
177 useless8
178 useless9
179Terminals which are not used:
180 '1'
181 '2'
182 '3'
183 '4'
184 '5'
185 '6'
186 '7'
187 '8'
188 '9'
189Useless rules
190 2 useless1: '1'
191 3 useless2: '2'
192 4 useless3: '3'
193 5 useless4: '4'
194 6 useless5: '5'
195 7 useless6: '6'
196 8 useless7: '7'
197 9 useless8: '8'
198 10 useless9: '9'
199]])
200
201AT_CLEANUP
202
203
204
205## ------------------- ##
206## Reduced Automaton. ##
207## ------------------- ##
208
209# Check that the automaton is that as the for the grammar reduced by
210# hand.
211
212AT_SETUP([Reduced Automaton])
213
214AT_KEYWORDS([report])
215
216# The non reduced grammar.
217# ------------------------
218AT_DATA([[not-reduced.y]],
219[[/* A useless token. */
220%token useless_token
221/* A useful one. */
222%token useful
223%verbose
224%output="not-reduced.c"
225
226%%
227
228exp: useful { /* A useful action. */ }
229 | non_productive { /* A non productive action. */ }
230 ;
231
232not_reachable: useful { /* A not reachable action. */ }
233 ;
234
235non_productive: non_productive useless_token
236 { /* Another non productive action. */ }
237 ;
238%%
239]])
240
241AT_CHECK([[bison not-reduced.y]], 0, [],
242[[not-reduced.y: warning: 2 useless nonterminals and 3 useless rules
243not-reduced.y:14.1-13: warning: useless nonterminal: not_reachable
244not-reduced.y:11.6-19: warning: useless nonterminal: non_productive
245not-reduced.y:11.4-57: warning: useless rule: exp: non_productive
246not-reduced.y:14.14-56: warning: useless rule: not_reachable: useful
247not-reduced.y:17.15-18.63: warning: useless rule: non_productive: non_productive useless_token
248]])
249
250AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
251[[Useless nonterminals:
252 not_reachable
253 non_productive
254Terminals which are not used:
255 useless_token
256Useless rules
257 2 exp: non_productive
258 3 not_reachable: useful
259 4 non_productive: non_productive useless_token
260]])
261
262# The reduced grammar.
263# --------------------
264AT_DATA([[reduced.y]],
265[[/* A useless token. */
266%token useless_token
267/* A useful one. */
268%token useful
269%verbose
270%output="reduced.c"
271
272%%
273
274exp: 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// ;
284%%
285]])
286
287AT_CHECK([[bison reduced.y]])
288
289# Comparing the parsers.
290cp reduced.c expout
291AT_CHECK([sed 's/not-reduced/reduced/g' not-reduced.c], 0, [expout])
292
293AT_CLEANUP
294
295
296
297## ------------------- ##
298## Underivable Rules. ##
299## ------------------- ##
300
301AT_SETUP([Underivable Rules])
302
303AT_KEYWORDS([report])
304
305AT_DATA([[input.y]],
306[[%verbose
307%output="input.c"
308%token useful
309%%
310exp: useful | underivable;
311underivable: indirection;
312indirection: underivable;
313]])
314
315AT_CHECK([[bison input.y]], 0, [],
316[[input.y: warning: 2 useless nonterminals and 3 useless rules
317input.y:5.15-25: warning: useless nonterminal: underivable
318input.y:6.14-24: warning: useless nonterminal: indirection
319input.y:5.13-25: warning: useless rule: exp: underivable
320input.y:6.12-24: warning: useless rule: underivable: indirection
321input.y:7.12-24: warning: useless rule: indirection: underivable
322]])
323
324AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
325[[Useless nonterminals:
326 underivable
327 indirection
328Useless rules
329 2 exp: underivable
330 3 underivable: indirection
331 4 indirection: underivable
332]])
333
334AT_CLEANUP
335
336
337
338## ---------------- ##
339## Empty Language. ##
340## ---------------- ##
341
342AT_SETUP([Empty Language])
343
344AT_DATA([[input.y]],
345[[%output="input.c"
346%%
347exp: exp;
348]])
349
350AT_CHECK([[bison input.y]], 1, [],
351[[input.y: warning: 2 useless nonterminals and 2 useless rules
352input.y:3.1-3: fatal error: start symbol exp does not derive any sentence
353]])
354
355AT_CLEANUP