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