1 # Torturing Bison. -*- 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([[Torture Tests.]])
22 # AT_DATA_STACK_TORTURE(C-PROLOGUE)
23 # ---------------------------------
24 # A parser specialized in torturing the stack size.
25 m4_define([AT_DATA_STACK_TORTURE],
26 [# A grammar of parens growing the stack thanks to right recursion.
34 static int yylex (void);
35 static void yyerror (const char *msg);
36 #define YYPRINT(File, Type, Value) \
37 fprintf (File, " (%d, stack size = %d, max = %d)", \
38 Value, yyssp - yyss + 1, yystacksize);
44 exp: WAIT_FOR_EOF exp | ;
47 yyerror (const char *msg)
49 fprintf (stderr, "%s\n", msg);
53 /* There are YYLVAL_MAX of WAIT_FOR_EOFs. */
54 unsigned int yylval_max;
66 main (int argc, const char **argv)
69 yylval = atoi (argv[1]);
74 AT_CHECK([bison input.y -o input.c])
75 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
79 ## -------------------------------------- ##
80 ## Exploding the Stack Size with Alloca. ##
81 ## -------------------------------------- ##
83 AT_SETUP([Exploding the Stack Size with Alloca])
87 # Below the limit of 200.
88 AT_CHECK([input 20], 0, [], [ignore])
89 # Two enlargements: 2 * 2 * 200.
90 AT_CHECK([input 900], 0, [], [ignore])
91 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
92 # multiply by two starting at 200 => 5120 is the last possible).
93 AT_CHECK([input 10000], 1, [], [ignore])
100 ## -------------------------------------- ##
101 ## Exploding the Stack Size with Malloc. ##
102 ## -------------------------------------- ##
104 AT_SETUP([Exploding the Stack Size with Malloc])
106 AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA 0]])
108 # Below the limit of 200.
109 AT_CHECK([input 20], 0, [], [ignore])
110 # Two enlargements: 2 * 2 * 200.
111 AT_CHECK([input 900], 0, [], [ignore])
112 # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
113 # multiply by two starting at 200 => 5120 is the possible).
114 AT_CHECK([input 10000], 1, [], [ignore])
119 ## ----------------- ##
120 ## GNU AWK Grammar. ##
121 ## ----------------- ##
123 AT_SETUP([GNU AWK Grammar])
125 # We have been careful to strip all the actions excepts the
126 # mid-rule actions. We rely on %expect to check that there are
127 # indeed 65 SR conflicts.
129 # Bison was once wrong, due to an incorrect computation of nullable.
130 # It reported 485 SR conflicts!
135 %token FUNC_CALL NAME REGEXP
137 %token YNUMBER YSTRING
138 %token RELOP APPEND_OP
139 %token ASSIGNOP MATCHOP NEWLINE CONCAT_OP
140 %token LEX_BEGIN LEX_END LEX_IF LEX_ELSE LEX_RETURN LEX_DELETE
141 %token LEX_WHILE LEX_DO LEX_FOR LEX_BREAK LEX_CONTINUE
142 %token LEX_PRINT LEX_PRINTF LEX_NEXT LEX_EXIT LEX_FUNCTION
143 %token LEX_GETLINE LEX_NEXTFILE
145 %token LEX_AND LEX_OR INCREMENT DECREMENT
146 %token LEX_BUILTIN LEX_LENGTH
148 /* Lowest to highest */
155 %left FUNC_CALL LEX_BUILTIN LEX_LENGTH
158 %nonassoc RELOP '<' '>' '|' APPEND_OP TWOWAYIO
160 %left YSTRING YNUMBER
165 %left INCREMENT DECREMENT
171 : opt_nls program opt_nls
183 : LEX_BEGIN {} action
185 | LEX_BEGIN statement_term
186 | LEX_END statement_term
189 | pattern statement_term
190 | function_prologue function_body
205 : LEX_FUNCTION {} func_name '(' opt_param_list r_paren opt_nls
209 : l_brace statements r_brace opt_semi opt_nls
210 | l_brace r_brace opt_semi opt_nls
221 * In this rule, want_regexp tells yylex that the next thing
222 * is a regexp so it should read up to the closing slash.
228 : l_brace statements r_brace opt_semi opt_nls
229 | l_brace r_brace opt_semi opt_nls
234 | statements statement
247 | l_brace statements r_brace
249 | LEX_WHILE '(' exp r_paren opt_nls statement
250 | LEX_DO opt_nls statement LEX_WHILE '(' exp r_paren opt_nls
251 | LEX_FOR '(' NAME LEX_IN NAME r_paren opt_nls statement
252 | LEX_FOR '(' opt_exp semi opt_nls exp semi opt_nls opt_exp r_paren opt_nls statement
253 | LEX_FOR '(' opt_exp semi opt_nls semi opt_nls opt_exp r_paren opt_nls statement
254 | LEX_BREAK statement_term
255 | LEX_CONTINUE statement_term
256 | print '(' expression_list r_paren output_redir statement_term
257 | print opt_rexpression_list output_redir statement_term
258 | LEX_NEXT statement_term
259 | LEX_NEXTFILE statement_term
260 | LEX_EXIT opt_exp statement_term
261 | LEX_RETURN {} opt_exp statement_term
262 | LEX_DELETE NAME '[' expression_list ']' statement_term
263 | LEX_DELETE NAME statement_term
273 : LEX_IF '(' exp r_paren opt_nls statement
274 | LEX_IF '(' exp r_paren opt_nls statement
275 LEX_ELSE opt_nls statement
308 | param_list comma NAME
311 | param_list comma error
314 /* optional expression, as in for loop */
327 | rexpression_list comma rexp
329 | rexpression_list error
330 | rexpression_list error rexp
331 | rexpression_list comma error
341 | expression_list comma exp
343 | expression_list error
344 | expression_list error exp
345 | expression_list comma error
348 /* Expressions, not including the comma operator. */
349 exp : variable ASSIGNOP {} exp
350 | '(' expression_list r_paren LEX_IN NAME
351 | exp '|' LEX_GETLINE opt_variable
352 | exp TWOWAYIO LEX_GETLINE opt_variable
353 | LEX_GETLINE opt_variable input_redir
358 | '!' regexp %prec UNARY
363 | exp '?' exp ':' exp
365 | exp simp_exp %prec CONCAT_OP
369 : variable ASSIGNOP {} rexp
372 | LEX_GETLINE opt_variable input_redir
374 | '!' regexp %prec UNARY
378 | rexp '?' rexp ':' rexp
380 | rexp simp_exp %prec CONCAT_OP
385 /* Binary operators in order of decreasing precedence. */
386 | simp_exp '^' simp_exp
387 | simp_exp '*' simp_exp
388 | simp_exp '/' simp_exp
389 | simp_exp '%' simp_exp
390 | simp_exp '+' simp_exp
391 | simp_exp '-' simp_exp
397 : '!' simp_exp %prec UNARY
400 '(' opt_expression_list r_paren
401 | LEX_LENGTH '(' opt_expression_list r_paren
403 | FUNC_CALL '(' opt_expression_list r_paren
409 | '-' simp_exp %prec UNARY
410 | '+' simp_exp %prec UNARY
420 | NAME '[' expression_list ']'
421 | '$' non_post_simp_exp
451 # Pass plenty of options, to exercise plenty of code, even if we
452 # don't actually check the output. But SEGV is watching us, and
453 # so might do dmalloc.
454 AT_CHECK([[bison --verbose --defines input.y]])