1 # Exercising Bison Grammar Reduction. -*- Autotest -*-
2 # Copyright 2001 Free Software Foundation, Inc.
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)
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.
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
19 AT_BANNER([[Grammar Reduction.]])
22 ## ------------------- ##
23 ## Useless Terminals. ##
24 ## ------------------- ##
26 AT_SETUP([Useless Terminals])
47 AT_CHECK([[bison input.y]])
49 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
50 [[Terminals which are not used:
66 ## ---------------------- ##
67 ## Useless Nonterminals. ##
68 ## ---------------------- ##
70 AT_SETUP([Useless Nonterminals])
91 AT_CHECK([[bison input.y]], 0, [],
92 [[input.y: warning: 9 useless nonterminals
93 input.y:4.8-15: warning: useless nonterminal: useless1
94 input.y:5.8-15: warning: useless nonterminal: useless2
95 input.y:6.8-15: warning: useless nonterminal: useless3
96 input.y:7.8-15: warning: useless nonterminal: useless4
97 input.y:8.8-15: warning: useless nonterminal: useless5
98 input.y:9.8-15: warning: useless nonterminal: useless6
99 input.y:10.8-15: warning: useless nonterminal: useless7
100 input.y:11.8-15: warning: useless nonterminal: useless8
101 input.y:12.8-15: warning: useless nonterminal: useless9
104 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
105 [[Useless nonterminals:
121 ## --------------- ##
123 ## --------------- ##
125 AT_SETUP([Useless Rules])
144 AT_CHECK([[bison input.y]], 0, [],
145 [[input.y: warning: 9 useless nonterminals and 9 useless rules
146 input.y:6.1-8: warning: useless nonterminal: useless1
147 input.y:7.1-8: warning: useless nonterminal: useless2
148 input.y:8.1-8: warning: useless nonterminal: useless3
149 input.y:9.1-8: warning: useless nonterminal: useless4
150 input.y:10.1-8: warning: useless nonterminal: useless5
151 input.y:11.1-8: warning: useless nonterminal: useless6
152 input.y:12.1-8: warning: useless nonterminal: useless7
153 input.y:13.1-8: warning: useless nonterminal: useless8
154 input.y:14.1-8: warning: useless nonterminal: useless9
155 input.y:6.9-13: warning: useless rule: useless1: '1'
156 input.y:7.9-13: warning: useless rule: useless2: '2'
157 input.y:8.9-13: warning: useless rule: useless3: '3'
158 input.y:9.9-13: warning: useless rule: useless4: '4'
159 input.y:10.9-13: warning: useless rule: useless5: '5'
160 input.y:11.9-13: warning: useless rule: useless6: '6'
161 input.y:12.9-13: warning: useless rule: useless7: '7'
162 input.y:13.9-13: warning: useless rule: useless8: '8'
163 input.y:14.9-13: warning: useless rule: useless9: '9'
166 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
167 [[Useless nonterminals:
177 Terminals which are not used:
203 ## ------------------- ##
204 ## Reduced Automaton. ##
205 ## ------------------- ##
207 # Check that the automaton is that as the for the grammar reduced by
210 AT_SETUP([Reduced Automaton])
212 # The non reduced grammar.
213 # ------------------------
214 AT_DATA([[not-reduced.y]],
215 [[/* A useless token. */
220 %output="not-reduced.c"
224 exp: useful { /* A useful action. */ }
225 | non_productive { /* A non productive action. */ }
228 not_reachable: useful { /* A not reachable action. */ }
231 non_productive: non_productive useless_token
232 { /* Another non productive action. */ }
237 AT_CHECK([[bison not-reduced.y]], 0, [],
238 [[not-reduced.y: warning: 2 useless nonterminals and 3 useless rules
239 not-reduced.y:14.1-13: warning: useless nonterminal: not_reachable
240 not-reduced.y:11.6-19: warning: useless nonterminal: non_productive
241 not-reduced.y:11.4-57: warning: useless rule: exp: non_productive
242 not-reduced.y:14.14-56: warning: useless rule: not_reachable: useful
243 not-reduced.y:17.15-18.63: warning: useless rule: non_productive: non_productive useless_token
246 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
247 [[Useless nonterminals:
250 Terminals which are not used:
253 #2 exp: non_productive;
254 #3 not_reachable: useful;
255 #4 non_productive: non_productive useless_token;
258 # The reduced grammar.
259 # --------------------
260 AT_DATA([[reduced.y]],
261 [[/* A useless token. */
270 exp: useful { /* A useful action. */ }
271 // | non_productive { /* A non productive action. */ } */
274 //not_reachable: useful { /* A not reachable action. */ }
277 //non_productive: non_productive useless_token
278 // { /* Another non productive action. */ }
283 AT_CHECK([[bison reduced.y]])
285 # Comparing the parsers.
287 AT_CHECK([sed 's/not-reduced/reduced/g' not-reduced.c], 0, [expout])
293 ## ------------------- ##
294 ## Underivable Rules. ##
295 ## ------------------- ##
297 AT_SETUP([Underivable Rules])
304 exp: useful | underivable;
305 underivable: indirection;
306 indirection: underivable;
309 AT_CHECK([[bison input.y]], 0, [],
310 [[input.y: warning: 2 useless nonterminals and 3 useless rules
311 input.y:5.15-25: warning: useless nonterminal: underivable
312 input.y:6.14-24: warning: useless nonterminal: indirection
313 input.y:5.13-25: warning: useless rule: exp: underivable
314 input.y:6.12-24: warning: useless rule: underivable: indirection
315 input.y:7.12-24: warning: useless rule: indirection: underivable
318 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
319 [[Useless nonterminals:
324 #3 underivable: indirection;
325 #4 indirection: underivable;