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