1 # Exercising Bison Grammar Reduction. -*- Autotest -*-
2 # Copyright (C) 2001, 2002, 2007, 2008 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_BISON_CHECK([[input.y]])
47 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
48 [[Terminals unused in grammar
64 ## ---------------------- ##
65 ## Useless Nonterminals. ##
66 ## ---------------------- ##
68 AT_SETUP([Useless Nonterminals])
89 AT_BISON_CHECK([[input.y]], 0, [],
90 [[input.y: warning: 9 nonterminals useless in grammar
91 input.y:4.8-15: warning: nonterminal useless in grammar: useless1
92 input.y:5.8-15: warning: nonterminal useless in grammar: useless2
93 input.y:6.8-15: warning: nonterminal useless in grammar: useless3
94 input.y:7.8-15: warning: nonterminal useless in grammar: useless4
95 input.y:8.8-15: warning: nonterminal useless in grammar: useless5
96 input.y:9.8-15: warning: nonterminal useless in grammar: useless6
97 input.y:10.8-15: warning: nonterminal useless in grammar: useless7
98 input.y:11.8-15: warning: nonterminal useless in grammar: useless8
99 input.y:12.8-15: warning: nonterminal useless in grammar: useless9
102 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
103 [[Nonterminals useless in grammar
119 ## --------------- ##
121 ## --------------- ##
123 AT_SETUP([Useless Rules])
125 AT_KEYWORDS([report])
144 AT_BISON_CHECK([[input.y]], 0, [],
145 [[input.y: warning: 9 nonterminals useless in grammar
146 input.y: warning: 9 rules useless in grammar
147 input.y:6.1-8: warning: nonterminal useless in grammar: useless1
148 input.y:7.1-8: warning: nonterminal useless in grammar: useless2
149 input.y:8.1-8: warning: nonterminal useless in grammar: useless3
150 input.y:9.1-8: warning: nonterminal useless in grammar: useless4
151 input.y:10.1-8: warning: nonterminal useless in grammar: useless5
152 input.y:11.1-8: warning: nonterminal useless in grammar: useless6
153 input.y:12.1-8: warning: nonterminal useless in grammar: useless7
154 input.y:13.1-8: warning: nonterminal useless in grammar: useless8
155 input.y:14.1-8: warning: nonterminal useless in grammar: useless9
156 input.y:6.11-13: warning: rule useless in grammar: useless1: '1'
157 input.y:7.11-13: warning: rule useless in grammar: useless2: '2'
158 input.y:8.11-13: warning: rule useless in grammar: useless3: '3'
159 input.y:9.11-13: warning: rule useless in grammar: useless4: '4'
160 input.y:10.11-13: warning: rule useless in grammar: useless5: '5'
161 input.y:11.11-13: warning: rule useless in grammar: useless6: '6'
162 input.y:12.11-13: warning: rule useless in grammar: useless7: '7'
163 input.y:13.11-13: warning: rule useless in grammar: useless8: '8'
164 input.y:14.11-13: warning: rule useless in grammar: useless9: '9'
167 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
168 [[Nonterminals useless in grammar
178 Terminals unused in grammar
188 Rules useless in grammar
204 ## ------------------- ##
205 ## Reduced Automaton. ##
206 ## ------------------- ##
208 # Check that the automaton is that as the for the grammar reduced by
211 AT_SETUP([Reduced Automaton])
213 AT_KEYWORDS([report])
215 # The non reduced grammar.
216 # ------------------------
217 AT_DATA([[not-reduced.y]],
218 [[/* A useless token. */
223 %output "not-reduced.c"
227 exp: useful { /* A useful action. */ }
228 | non_productive { /* A non productive action. */ }
231 not_reachable: useful { /* A not reachable action. */ }
234 non_productive: non_productive useless_token
235 { /* Another non productive action. */ }
240 AT_BISON_CHECK([[not-reduced.y]], 0, [],
241 [[not-reduced.y: warning: 2 nonterminals useless in grammar
242 not-reduced.y: warning: 3 rules useless in grammar
243 not-reduced.y:14.1-13: warning: nonterminal useless in grammar: not_reachable
244 not-reduced.y:11.6-19: warning: nonterminal useless in grammar: non_productive
245 not-reduced.y:11.6-57: warning: rule useless in grammar: exp: non_productive
246 not-reduced.y:14.16-56: warning: rule useless in grammar: not_reachable: useful
247 not-reduced.y:17.17-18.63: warning: rule useless in grammar: non_productive: non_productive useless_token
250 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
251 [[Nonterminals useless in grammar
254 Terminals unused in grammar
256 Rules useless in grammar
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_BISON_CHECK([[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_BISON_CHECK([[input.y]], 0, [],
316 [[input.y: warning: 2 nonterminals useless in grammar
317 input.y: warning: 3 rules useless in grammar
318 input.y:5.15-25: warning: nonterminal useless in grammar: underivable
319 input.y:6.14-24: warning: nonterminal useless in grammar: indirection
320 input.y:5.15-25: warning: rule useless in grammar: exp: underivable
321 input.y:6.14-24: warning: rule useless in grammar: underivable: indirection
322 input.y:7.14-24: warning: rule useless in grammar: indirection: underivable
325 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
326 [[Nonterminals useless in grammar
329 Rules useless in grammar
331 3 underivable: indirection
332 4 indirection: underivable
339 ## ---------------- ##
340 ## Empty Language. ##
341 ## ---------------- ##
343 AT_SETUP([Empty Language])
351 AT_BISON_CHECK([[input.y]], 1, [],
352 [[input.y: warning: 2 nonterminals useless in grammar
353 input.y: warning: 2 rules useless in grammar
354 input.y:3.1-3: fatal error: start symbol exp does not derive any sentence