1 # Exercising Bison Grammar Reduction. -*- Autotest -*-
2 # Copyright (C) 2001, 2002 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 3 of the License, or
7 # (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
17 AT_BANNER([[Grammar Reduction.]])
20 ## ------------------- ##
21 ## Useless Terminals. ##
22 ## ------------------- ##
24 AT_SETUP([Useless Terminals])
45 AT_CHECK([[bison input.y]])
47 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
48 [[Terminals which are not used
64 ## ---------------------- ##
65 ## Useless Nonterminals. ##
66 ## ---------------------- ##
68 AT_SETUP([Useless Nonterminals])
89 AT_CHECK([[bison input.y]], 0, [],
90 [[input.y: warning: 9 useless nonterminals
91 input.y:4.8-15: warning: useless nonterminal: useless1
92 input.y:5.8-15: warning: useless nonterminal: useless2
93 input.y:6.8-15: warning: useless nonterminal: useless3
94 input.y:7.8-15: warning: useless nonterminal: useless4
95 input.y:8.8-15: warning: useless nonterminal: useless5
96 input.y:9.8-15: warning: useless nonterminal: useless6
97 input.y:10.8-15: warning: useless nonterminal: useless7
98 input.y:11.8-15: warning: useless nonterminal: useless8
99 input.y:12.8-15: warning: useless nonterminal: useless9
102 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
103 [[Useless nonterminals
119 ## --------------- ##
121 ## --------------- ##
123 AT_SETUP([Useless Rules])
125 AT_KEYWORDS([report])
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.11-13: warning: useless rule: useless1: '1'
156 input.y:7.11-13: warning: useless rule: useless2: '2'
157 input.y:8.11-13: warning: useless rule: useless3: '3'
158 input.y:9.11-13: warning: useless rule: useless4: '4'
159 input.y:10.11-13: warning: useless rule: useless5: '5'
160 input.y:11.11-13: warning: useless rule: useless6: '6'
161 input.y:12.11-13: warning: useless rule: useless7: '7'
162 input.y:13.11-13: warning: useless rule: useless8: '8'
163 input.y:14.11-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 AT_KEYWORDS([report])
214 # The non reduced grammar.
215 # ------------------------
216 AT_DATA([[not-reduced.y]],
217 [[/* A useless token. */
222 %output "not-reduced.c"
226 exp: useful { /* A useful action. */ }
227 | non_productive { /* A non productive action. */ }
230 not_reachable: useful { /* A not reachable action. */ }
233 non_productive: non_productive useless_token
234 { /* Another non productive action. */ }
239 AT_CHECK([[bison not-reduced.y]], 0, [],
240 [[not-reduced.y: warning: 2 useless nonterminals and 3 useless rules
241 not-reduced.y:14.1-13: warning: useless nonterminal: not_reachable
242 not-reduced.y:11.6-19: warning: useless nonterminal: non_productive
243 not-reduced.y:11.6-57: warning: useless rule: exp: non_productive
244 not-reduced.y:14.16-56: warning: useless rule: not_reachable: useful
245 not-reduced.y:17.17-18.63: warning: useless rule: non_productive: non_productive useless_token
248 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
249 [[Useless nonterminals
252 Terminals which are not used
255 2 exp: non_productive
256 3 not_reachable: useful
257 4 non_productive: non_productive useless_token
260 # The reduced grammar.
261 # --------------------
262 AT_DATA([[reduced.y]],
263 [[/* A useless token. */
272 exp: useful { /* A useful action. */ }
273 // | non_productive { /* A non productive action. */ } */
276 //not_reachable: useful { /* A not reachable action. */ }
279 //non_productive: non_productive useless_token
280 // { /* Another non productive action. */ }
285 AT_CHECK([[bison reduced.y]])
287 # Comparing the parsers.
289 AT_CHECK([sed 's/not-reduced/reduced/g' not-reduced.c], 0, [expout])
295 ## ------------------- ##
296 ## Underivable Rules. ##
297 ## ------------------- ##
299 AT_SETUP([Underivable Rules])
301 AT_KEYWORDS([report])
308 exp: useful | underivable;
309 underivable: indirection;
310 indirection: underivable;
313 AT_CHECK([[bison input.y]], 0, [],
314 [[input.y: warning: 2 useless nonterminals and 3 useless rules
315 input.y:5.15-25: warning: useless nonterminal: underivable
316 input.y:6.14-24: warning: useless nonterminal: indirection
317 input.y:5.15-25: warning: useless rule: exp: underivable
318 input.y:6.14-24: warning: useless rule: underivable: indirection
319 input.y:7.14-24: warning: useless rule: indirection: underivable
322 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
323 [[Useless nonterminals
328 3 underivable: indirection
329 4 indirection: underivable
336 ## ---------------- ##
337 ## Empty Language. ##
338 ## ---------------- ##
340 AT_SETUP([Empty Language])
348 AT_CHECK([[bison input.y]], 1, [],
349 [[input.y: warning: 2 useless nonterminals and 2 useless rules
350 input.y:3.1-3: fatal error: start symbol exp does not derive any sentence