From 83ccf991a6b09a2f93e97dab936f6d3574e27d68 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 3 May 2002 08:42:48 +0000 Subject: [PATCH] * data/bison.simple (b4_token_enum): New. (b4_token_defines): Use it to output tokens both as #define and enums. Suggested by Paul Eggert. * src/output.c (token_definitions_output): Don't output spurious white spaces. --- ChangeLog | 9 +++++++++ TODO | 20 -------------------- data/bison.c++ | 4 ++-- data/bison.simple | 26 +++++++++++++++++++++++--- src/output.c | 2 +- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 147125c2..8083bc8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2002-05-03 Akim Demaille + + * data/bison.simple (b4_token_enum): New. + (b4_token_defines): Use it to output tokens both as #define and + enums. + Suggested by Paul Eggert. + * src/output.c (token_definitions_output): Don't output spurious + white spaces. + 2002-05-03 Akim Demaille * data/m4sugar/m4sugar.m4: Update from CVS Autoconf. diff --git a/TODO b/TODO index e94652cd..a43659b4 100644 --- a/TODO +++ b/TODO @@ -34,26 +34,6 @@ Paul notes: PDP-10 ports :-) but they should probably be documented somewhere. -* Using enums instead of int for tokens. -Paul suggests: - - #ifndef YYTOKENTYPE - # if defined (__STDC__) || defined (__cplusplus) - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - FOO = 256, - BAR, - ... - }; - /* POSIX requires `int' for tokens in interfaces. */ - # define YYTOKENTYPE int - # endif - #endif - #define FOO 256 - #define BAR 257 - ... - * Output directory Akim: diff --git a/data/bison.c++ b/data/bison.c++ index b0ba32f4..f5c39f41 100644 --- a/data/bison.c++ +++ b/data/bison.c++ @@ -50,8 +50,8 @@ m4_define([b4_rhs_location], [location_stack_@<:@m4_eval([$1 - $2])@:>@]) -# b4_token_defines(TOKEN-NAME, TOKEN-NUMBER) -# ------------------------------------------ +# b4_token_define(TOKEN-NAME, TOKEN-NUMBER) +# ----------------------------------------- # Output the definition of this token as #define. m4_define([b4_token_define], [#define $1 $2 diff --git a/data/bison.simple b/data/bison.simple index 0a7804dc..1c153a0a 100644 --- a/data/bison.simple +++ b/data/bison.simple @@ -70,19 +70,39 @@ m4_define_default([b4_header_guard], [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])]) -# b4_token_defines(TOKEN-NAME, TOKEN-NUMBER) -# ------------------------------------------ +# b4_token_define(TOKEN-NAME, TOKEN-NUMBER) +# ----------------------------------------- # Output the definition of this token as #define. m4_define([b4_token_define], [#define $1 $2 ]) +# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) +# --------------------------------------- +# Output the definition of this token as an enum. +m4_define([b4_token_enum], +[enum $1 = $2]) + + # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) # ------------------------------------------------------- # Output the definition of the tokens as #define. m4_define([b4_token_defines], -[m4_map([b4_token_define], [$@])]) +[#ifndef YYTOKENTYPE +# if defined (__STDC__) || defined (__cplusplus) + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { +m4_map_sep([ b4_token_enum], [, +], + [$@]) + }; + /* POSIX requires `int' for tokens in interfaces. */ +# define YYTOKENTYPE int +# endif +#endif +m4_map([b4_token_define], [$@])]) m4_divert(0)dnl diff --git a/src/output.c b/src/output.c index 676328fb..f92b6646 100644 --- a/src/output.c +++ b/src/output.c @@ -603,7 +603,7 @@ token_definitions_output (FILE *out) if (strchr (symbol->tag, '.') || strchr (symbol->tag, '$')) continue; - fprintf (out, "%s [[[%s]], [%d]]", + fprintf (out, "%s[[[%s]], [%d]]", first ? "" : ",\n", symbol->tag, number); first = 0; } -- 2.45.2