From: Akim Demaille Date: Thu, 20 Jun 2002 09:47:44 +0000 (+0000) Subject: * data/bison.simple (yysymprint): Don't print the token number, X-Git-Tag: BISON-1_49b~142 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/e317006080af0dcd45a78af6fb365a67f71daf82 * data/bison.simple (yysymprint): Don't print the token number, just its name. * tests/actions.at (Destructors): Rename as... (Printers and Destructors): this. Also exercise %printer. --- diff --git a/ChangeLog b/ChangeLog index b0fde66a..4a48d21e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-06-20 Akim Demaille + + * data/bison.simple (yysymprint): Don't print the token number, + just its name. + * tests/actions.at (Destructors): Rename as... + (Printers and Destructors): this. + Also exercise %printer. + 2002-06-20 Akim Demaille * data/bison.simple (YYDSYMPRINT): New. diff --git a/data/bison.simple b/data/bison.simple index b56c0e16..c5ce1386 100644 --- a/data/bison.simple +++ b/data/bison.simple @@ -1250,9 +1250,9 @@ m4_map([b4_symbol_destructor], m4_defn([b4_symbol_destructors]))dnl #if YYDEBUG -/*---------------------------. -| Print this symbol on OUT. | -`---------------------------*/ +/*-----------------------------. +| Print this symbol on YYOUT. | +`-----------------------------*/ m4_divert_push([KILL])# M4 code. # b4_symbol_printer(SYMBOL-NUMBER, PRINTER, TYPE-NAME) @@ -1270,15 +1270,15 @@ m4_popdef([b4_dollar_dollar])]) m4_divert_pop([KILL])dnl# End of M4 code. static void -yysymprint (FILE* out, int yytype, +yysymprint (FILE* yyout, int yytype, YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation])) { if (yytype < YYNTOKENS) - YYFPRINTF (out, "token %d (%s ", yytoknum[[yytype]], yytname[[yytype]]); + YYFPRINTF (yyout, "token %s (", yytname[[yytype]]); else - YYFPRINTF (out, "nterm %s (", yytname[[yytype]]); + YYFPRINTF (yyout, "nterm %s (", yytname[[yytype]]); # ifdef YYPRINT - YYPRINT (out, yytype, yyvalue); + YYPRINT (yyout, yytype, yyvalue); # else switch (yytype) { @@ -1287,7 +1287,7 @@ m4_map([b4_symbol_printer], m4_defn([b4_symbol_printers]))dnl break; } # endif /* !defined YYPRINT. */ - YYFPRINTF (out, ")"); + YYFPRINTF (yyout, ")"); } #endif /* YYDEBUG. */ diff --git a/tests/actions.at b/tests/actions.at index 990b72bd..7b285d13 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -169,7 +169,6 @@ AT_DATA([[input.y]], #define YYERROR_VERBOSE 1 #define YYDEBUG 1 -#define YYPRINT yyprint %} %verbose %union @@ -177,10 +176,19 @@ AT_DATA([[input.y]], int ival; } %type 'x' thing line input -%destructor { printf ("Freeing input %d from %d\n", $$, @$.first_line); } input -%destructor { printf ("Freeing line %d from %d\n", $$, @$.first_line); } line -%destructor { printf ("Freeing thing %d from %d\n", $$, @$.first_line); } thing -%destructor { printf ("Freeing 'x' %d from %d\n", $$, @$.first_line); } 'x' + +%printer { fprintf (yyout, "%d from %d", $$, @$.first_line); } + input line thing 'x' + +%destructor + { + fprintf (stdout, "Freeing "); + /* FIXME: Ouch: INTERNAL DETAILS EXPOSED HERE. */ + /* Cannot use $$ which is the union member, not the union itself. */ + yysymprint (stdout, yytype, yyvalue, @$); + fprintf (stdout, "\n"); + } + input line thing 'x' %{ static int yylex (void); @@ -255,7 +263,7 @@ yylex (void) if (counter < (sizeof(input) / sizeof (input[0]))) { yylval.ival = counter; - printf ("sending: '%c'(%d)\n", input[counter], counter); + printf ("sending: '%c' (line %d)\n", input[counter], counter); /* As in BASIC, line numbers go from 10 to 10. */ yylloc.first_line = 10 * counter; return input[counter++]; @@ -273,12 +281,6 @@ yyerror (const char *msg) fprintf (stdout, "%d: %s\n", yylloc.first_line, msg); } -static void -yyprint (FILE *out, int num, YYSTYPE val) -{ - fprintf (out, " = %d", val.ival); -} - int main (void) { @@ -296,40 +298,40 @@ main (void) AT_CHECK([bison input.y --location -d -v -o input.c]) AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) AT_CHECK([./input], 1, -[[sending: 'x'(0) +[[sending: 'x' (line 0) thing(0): 'x'(0) -sending: 'x'(1) +sending: 'x' (line 1) thing(1): 'x'(1) -sending: 'x'(2) +sending: 'x' (line 2) thing(2): 'x'(2) -sending: 'x'(3) +sending: 'x' (line 3) 30: parse error, unexpected 'x', expecting ';' -Freeing thing 2 from 20 -Freeing thing 1 from 10 -Freeing thing 0 from 0 -Freeing 'x' 3 from 30 -sending: 'x'(4) -Freeing 'x' 4 from 40 -sending: 'x'(5) -Freeing 'x' 5 from 50 -sending: ';'(6) +Freeing nterm thing (2 from 20) +Freeing nterm thing (1 from 10) +Freeing nterm thing (0 from 0) +Freeing token 'x' (3 from 30) +sending: 'x' (line 4) +Freeing token 'x' (4 from 40) +sending: 'x' (line 5) +Freeing token 'x' (5 from 50) +sending: ';' (line 6) line(-1): error ';' -sending: 'x'(7) +sending: 'x' (line 7) thing(7): 'x'(7) -sending: 'x'(8) +sending: 'x' (line 8) thing(8): 'x'(8) -sending: ';'(9) +sending: ';' (line 9) line(7): thing(7) thing(8) ';' -sending: 'x'(10) +sending: 'x' (line 10) thing(10): 'x'(10) -sending: ';'(11) +sending: ';' (line 11) line(10): thing(10) ';' -sending: 'y'(12) +sending: 'y' (line 12) 120: parse error, unexpected $undefined., expecting $ or error or 'x' sending: EOF -Freeing line 10 from 100 -Freeing line 7 from 70 -Freeing line -1 from 50 +Freeing nterm line (10 from 100) +Freeing nterm line (7 from 70) +Freeing nterm line (-1 from 50) Parsing FAILED. ]])