From: Paul Eggert Date: Sat, 16 Nov 2002 07:31:35 +0000 (+0000) Subject: (Actions after errors): New test case. X-Git-Tag: BISON-1_875~244 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/5dac0025f6cef52c95cf1b8d04c5047980a73160?ds=inline (Actions after errors): New test case. --- diff --git a/tests/actions.at b/tests/actions.at index 366c3d33..18140cec 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -82,6 +82,153 @@ AT_CLEANUP +## ---------------------- ## +## Actions after errors. ## +## ---------------------- ## + +AT_SETUP([Actions after errors]) + + + +AT_DATA_GRAMMAR([[input.y]], +[[%{ +#include +#include + +static int yylex (void); +static void yyerror (char const *); + +#define YYDEBUG 1 +%} +%union { int ival; } +%type 'x' ';' thing line input + +%% +input: + /* Nothing. */ + { + $$ = 0; + printf ("input(%d): /* Nothing */\n", $$); + } +| line input /* Right recursive to load the stack so that popping at + EOF can be exercised. */ + { + $$ = 2; + printf ("input(%d): line(%d) input(%d)\n", $$, $1, $2); + } +; + +line: + thing thing thing ';' + { + $$ = $1; + printf ("line(%d): thing(%d) thing(%d) thing(%d) ';'(%d)\n", + $$, $1, $2, $3, $4); + } +| thing thing ';' + { + $$ = $1; + printf ("line(%d): thing(%d) thing(%d) ';'(%d)\n", $$, $1, $2, $3); + } +| thing ';' + { + $$ = $1; + printf ("line(%d): thing(%d) ';'(%d)\n", $$, $1, $2); + } +| error ';' + { + $$ = -1; + printf ("line(%d): error ';'(%d)\n", $$, $2); + } +; + +thing: + 'x' + { + $$ = $1; + printf ("thing(%d): 'x'(%d)\n", $$, $1); + } +; +%% +static size_t counter; + +static int +yylex (void) +{ + static char const input[] = + { + /* Exericise the discarding of stack top and input until `error' + can be reduced. */ + 'x', 'x', 'x', 'x', 'x', 'x', ';', + + /* Load the stack and provoke an error that cannot be caught by + the grammar, to check that the stack is cleared. */ + 'x', 'x', ';', + 'x', ';', + 'y' + }; + + if (counter < sizeof input) + { + yylval.ival = counter; + printf ("sending: '%c' (value = %d)\n", input[counter], yylval.ival); + return input[counter++]; + } + else + { + printf ("sending: EOF\n"); + return EOF; + } +} + +static void +yyerror (char const *msg) +{ + printf ("%lu: %s\n", (unsigned long int) counter, msg); +} + +int +main (void) +{ + yydebug = !!getenv ("YYDEBUG"); + return yyparse (); +} +]]) + +AT_CHECK([bison -o input.c input.y]) +AT_COMPILE([input]) +AT_PARSER_CHECK([./input], 1, +[[sending: 'x' (value = 0) +thing(0): 'x'(0) +sending: 'x' (value = 1) +thing(1): 'x'(1) +sending: 'x' (value = 2) +thing(2): 'x'(2) +sending: 'x' (value = 3) +4: syntax error +sending: 'x' (value = 4) +sending: 'x' (value = 5) +sending: ';' (value = 6) +line(-1): error ';'(6) +sending: 'x' (value = 7) +thing(7): 'x'(7) +sending: 'x' (value = 8) +thing(8): 'x'(8) +sending: ';' (value = 9) +line(7): thing(7) thing(8) ';'(9) +sending: 'x' (value = 10) +thing(10): 'x'(10) +sending: ';' (value = 11) +line(10): thing(10) ';'(11) +sending: 'y' (value = 12) +13: syntax error +sending: EOF +]]) + +AT_CLEANUP + + + ## ---------------- ## ## Exotic Dollars. ## ## ---------------- ##