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 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])
127 AT_KEYWORDS([report])
146 AT_CHECK([[bison input.y]], 0, [],
147 [[input.y: warning: 9 useless nonterminals and 9 useless rules
148 input.y:6.1-8: warning: useless nonterminal: useless1
149 input.y:7.1-8: warning: useless nonterminal: useless2
150 input.y:8.1-8: warning: useless nonterminal: useless3
151 input.y:9.1-8: warning: useless nonterminal: useless4
152 input.y:10.1-8: warning: useless nonterminal: useless5
153 input.y:11.1-8: warning: useless nonterminal: useless6
154 input.y:12.1-8: warning: useless nonterminal: useless7
155 input.y:13.1-8: warning: useless nonterminal: useless8
156 input.y:14.1-8: warning: useless nonterminal: useless9
157 input.y:6.11-13: warning: useless rule: useless1: '1'
158 input.y:7.11-13: warning: useless rule: useless2: '2'
159 input.y:8.11-13: warning: useless rule: useless3: '3'
160 input.y:9.11-13: warning: useless rule: useless4: '4'
161 input.y:10.11-13: warning: useless rule: useless5: '5'
162 input.y:11.11-13: warning: useless rule: useless6: '6'
163 input.y:12.11-13: warning: useless rule: useless7: '7'
164 input.y:13.11-13: warning: useless rule: useless8: '8'
165 input.y:14.11-13: warning: useless rule: useless9: '9'
168 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
169 [[Useless nonterminals
179 Terminals which are not used
205 ## ------------------- ##
206 ## Reduced Automaton. ##
207 ## ------------------- ##
209 # Check that the automaton is that as the for the grammar reduced by
212 AT_SETUP([Reduced Automaton])
214 AT_KEYWORDS([report])
216 # The non reduced grammar.
217 # ------------------------
218 AT_DATA([[not-reduced.y]],
219 [[/* A useless token. */
224 %output="not-reduced.c"
228 exp: useful { /* A useful action. */ }
229 | non_productive { /* A non productive action. */ }
232 not_reachable: useful { /* A not reachable action. */ }
235 non_productive: non_productive useless_token
236 { /* Another non productive action. */ }
241 AT_CHECK([[bison not-reduced.y]], 0, [],
242 [[not-reduced.y: warning: 2 useless nonterminals and 3 useless rules
243 not-reduced.y:14.1-13: warning: useless nonterminal: not_reachable
244 not-reduced.y:11.6-19: warning: useless nonterminal: non_productive
245 not-reduced.y:11.6-57: warning: useless rule: exp: non_productive
246 not-reduced.y:14.16-56: warning: useless rule: not_reachable: useful
247 not-reduced.y:17.17-18.63: warning: useless rule: non_productive: non_productive useless_token
250 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
251 [[Useless nonterminals
254 Terminals which are not used
257 2 exp: non_productive
258 3 not_reachable: useful
259 4 non_productive: non_productive useless_token
262 # The reduced grammar.
263 # --------------------
264 AT_DATA([[reduced.y]],
265 [[/* A useless token. */
274 exp: useful { /* A useful action. */ }
275 // | non_productive { /* A non productive action. */ } */
278 //not_reachable: useful { /* A not reachable action. */ }
281 //non_productive: non_productive useless_token
282 // { /* Another non productive action. */ }
287 AT_CHECK([[bison reduced.y]])
289 # Comparing the parsers.
291 AT_CHECK([sed 's/not-reduced/reduced/g' not-reduced.c], 0, [expout])
297 ## ------------------- ##
298 ## Underivable Rules. ##
299 ## ------------------- ##
301 AT_SETUP([Underivable Rules])
303 AT_KEYWORDS([report])
310 exp: useful | underivable;
311 underivable: indirection;
312 indirection: underivable;
315 AT_CHECK([[bison input.y]], 0, [],
316 [[input.y: warning: 2 useless nonterminals and 3 useless rules
317 input.y:5.15-25: warning: useless nonterminal: underivable
318 input.y:6.14-24: warning: useless nonterminal: indirection
319 input.y:5.15-25: warning: useless rule: exp: underivable
320 input.y:6.14-24: warning: useless rule: underivable: indirection
321 input.y:7.14-24: warning: useless rule: indirection: underivable
324 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
325 [[Useless nonterminals
330 3 underivable: indirection
331 4 indirection: underivable
338 ## ---------------- ##
339 ## Empty Language. ##
340 ## ---------------- ##
342 AT_SETUP([Empty Language])
350 AT_CHECK([[bison input.y]], 1, [],
351 [[input.y: warning: 2 useless nonterminals and 2 useless rules
352 input.y:3.1-3: fatal error: start symbol exp does not derive any sentence