From 0d8bed5636c07f932fdcb6ef04df749ab1c162d7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 19 Mar 2002 07:48:47 +0000 Subject: [PATCH] * data/m4sugar/m4sugar.m4: Update from CVS Autoconf. * data/bison.simple, data/bison.c++: Handle the `#define' part, so that we can move to enums for instance. * src/output.c (token_definitions_output): Output a list of `token-name, token-number' instead of the #define. (output_skeleton): Name this list `b4_tokens', not `b4_tokendefs'. --- ChangeLog | 9 ++++++ data/bison.c++ | 24 ++++++++++----- data/bison.simple | 26 +++++++++++----- data/m4sugar/m4sugar.m4 | 67 +++++++++++++++++++++-------------------- src/output.c | 10 +++--- 5 files changed, 83 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96155784..5a6844aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2002-03-19 Akim Demaille + + * data/m4sugar/m4sugar.m4: Update from CVS Autoconf. + * data/bison.simple, data/bison.c++: Handle the `#define' part, so + that we can move to enums for instance. + * src/output.c (token_definitions_output): Output a list of + `token-name, token-number' instead of the #define. + (output_skeleton): Name this list `b4_tokens', not `b4_tokendefs'. + 2002-03-14 Akim Demaille Use Gettext 0.11.1. diff --git a/data/bison.c++ b/data/bison.c++ index 71cd6d98..d081ee01 100644 --- a/data/bison.c++ +++ b/data/bison.c++ @@ -1,10 +1,18 @@ m4_divert(-1) -# m4_define_default(MACRO, VALUE) -# ------------------------------- -# Define MACRO to VALUE, unless already defined. -m4_define([m4_define_default], -[m4_ifdef([$1], [], [m4_define($@)])]) +# b4_token_defines(TOKEN-NAME, TOKEN-NUMBER) +# ------------------------------------------ +# Output the definition of this token as #define. +m4_define([b4_token_define], +[#define $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], [$@])]) m4_define_default([b4_input_suffix], [.y]) @@ -26,7 +34,7 @@ m4_define_default([b4_header_guard], [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])]) m4_define([b4_inherit], - [m4_ifdef([b4_root], + [m4_ifdef([b4_root], [: public b4_root ], [])]) @@ -88,7 +96,7 @@ b4_copyright b4_prologue /* Tokens. */ -b4_tokendef +b4_token_defines /* Enabling traces. */ #ifndef YYDEBUG @@ -158,7 +166,7 @@ namespace yy #if YYLSP_NEEDED b4_name (bool debug, - LocationType initlocation[]b4_param) : + LocationType initlocation[]b4_param) : b4_constructor[]debug_ (debug), initlocation_ (initlocation) #else diff --git a/data/bison.simple b/data/bison.simple index a493ad2e..87f4188d 100644 --- a/data/bison.simple +++ b/data/bison.simple @@ -1,11 +1,5 @@ m4_divert(-1) -# m4_define_default(MACRO, VALUE) -# ------------------------------- -# Define MACRO to VALUE, unless already defined. -m4_define([m4_define_default], -[m4_ifdef([$1], [], [m4_define($@)])]) - m4_define_default([b4_input_suffix], [.y]) m4_define_default([b4_output_parser_suffix], @@ -25,6 +19,22 @@ m4_define_default([b4_header_guard], [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name), [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])]) + +# b4_token_defines(TOKEN-NAME, TOKEN-NUMBER) +# ------------------------------------------ +# Output the definition of this token as #define. +m4_define([b4_token_define], +[#define $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], [$@])]) + + m4_divert(0)dnl #output "b4_output_parser_name" /* A Bison parser, made from b4_filename @@ -200,7 +210,7 @@ union yyalloc #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ /* Tokens. */ -b4_tokendef +b4_token_defines(b4_tokens) /* YYFINAL -- State number of the termination state. */ #define YYFINAL b4_final @@ -1148,7 +1158,7 @@ m4_if(b4_defines_flag, 0, [], #ifndef b4_header_guard # define b4_header_guard -b4_tokendef +b4_token_defines(b4_tokens) #ifndef YYSTYPE typedef b4_stype diff --git a/data/m4sugar/m4sugar.m4 b/data/m4sugar/m4sugar.m4 index 834a2056..bc965229 100644 --- a/data/m4sugar/m4sugar.m4 +++ b/data/m4sugar/m4sugar.m4 @@ -2,7 +2,7 @@ divert(-1)# -*- Autoconf -*- # This file is part of Autoconf. # Base M4 layer. # Requires GNU M4. -# Copyright 1999, 2000, 2001 Free Software Foundation, Inc. +# Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -426,6 +426,16 @@ m4_define([m4_bmatch], [$3])]) +# m4_map(MACRO, LIST) +# ------------------- +# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements +# of LIST (which can be lists themselves, for multiple arguments MACROs). +m4_define([m4_fst], [$1]) +m4_define([m4_map], +[m4_if([$2], [[]], [], + [$1(m4_fst($2))[]dnl +m4_map([$1], m4_cdr($2))])]) + ## ---------------------------------------- ## ## 6. Enhanced version of some primitives. ## @@ -466,6 +476,13 @@ m4_define([m4_do], [$1[]m4_do(m4_shift($@))])]) +# m4_define_default(MACRO, VALUE) +# ------------------------------- +# If MACRO is undefined, set it to VALUE. +m4_define([m4_define_default], +[m4_ifndef([$1], [m4_define($@)])]) + + # m4_default(EXP1, EXP2) # ---------------------- # Returns EXP1 if non empty, otherwise EXP2. @@ -521,16 +538,16 @@ m4_define([m4_popdef], m4_builtin([popdef], $@)]) -# m4_quote(STRING) -# ---------------- -# Return STRING quoted. +# m4_quote(ARGS) +# -------------- +# Return ARGS as a single arguments. # # It is important to realize the difference between `m4_quote(exp)' and # `[exp]': in the first case you obtain the quoted *result* of the # expansion of EXP, while in the latter you just obtain the string # `exp'. -m4_define([m4_quote], [[$*]]) -m4_define([m4_dquote], [[[$*]]]) +m4_define([m4_quote], [[$*]]) +m4_define([m4_dquote], [[$@]]) # m4_noquote(STRING) @@ -696,12 +713,12 @@ m4_define([m4_foreach], # Low level macros used to define m4_foreach. m4_define([m4_car], [[$1]]) -m4_define([m4_car2], [[$@]]) +m4_define([m4_cdr], [m4_dquote(m4_shift($@))]) m4_define([_m4_foreach], -[m4_if(m4_quote($2), [], [], - [m4_define([$1], [m4_car($2)])$3[]_m4_foreach([$1], - m4_car2(m4_shift($2)), - [$3])])]) +[m4_if([$2], [[]], [], + [m4_define([$1], m4_car($2))$3[]_m4_foreach([$1], + m4_cdr($2), + [$3])])]) @@ -1375,7 +1392,7 @@ m4_define([m4_re_escape], # ------------ # Regexp for `[a-zA-Z_0-9]*' m4_define([m4_re_string], -m4_dquote(m4_defn([m4_cr_symbols2]))dnl +m4_defn([m4_cr_symbols2])dnl [*]dnl ) @@ -1384,7 +1401,7 @@ m4_dquote(m4_defn([m4_cr_symbols2]))dnl # ---------- # Regexp for `[a-zA-Z_][a-zA-Z_0-9]*' m4_define([m4_re_word], -m4_dquote(m4_defn([m4_cr_symbols1]))dnl +m4_defn([m4_cr_symbols1])dnl m4_defn([m4_re_string])dnl ) @@ -1554,22 +1571,6 @@ m4_define([m4_append_uniq], [m4_append($@)])]) -# m4_foreach_quoted(VARIABLE, LIST, EXPRESSION) -# --------------------------------------------- -# FIXME: This macro should not exists. Currently it's used only in -# m4_wrap, which needs to be rewritten. But it's godam hard. -m4_define([m4_foreach_quoted], -[m4_pushdef([$1], [])_m4_foreach_quoted($@)m4_popdef([$1])]) - -# Low level macros used to define m4_foreach. -m4_define([m4_car_quoted], [[$1]]) -m4_define([_m4_foreach_quoted], -[m4_if($2, [()], , - [m4_define([$1], [m4_car_quoted$2])$3[]_m4_foreach_quoted([$1], - [(m4_shift$2)], - [$3])])]) - - # m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH]) # ------------------------------------------------------- # Expands into STRING wrapped to hold in WIDTH columns (default = 79). @@ -1617,16 +1618,16 @@ m4_Prefix1[]dnl m4_if(m4_eval(m4_Cursor > m4_len(m4_Prefix)), 1, [m4_define([m4_Cursor], m4_len(m4_Prefix)) m4_Prefix])[]dnl -m4_foreach_quoted([m4_Word], (m4_split(m4_normalize([$1]))), -[m4_define([m4_Cursor], m4_eval(m4_Cursor + m4_len(m4_Word) + 1))dnl +m4_foreach([m4_Word], m4_quote(m4_split(m4_normalize([$1]))), +[m4_define([m4_Cursor], m4_eval(m4_Cursor + m4_len(m4_defn([m4_Word])) + 1))dnl dnl New line if too long, else insert a space unless it is the first dnl of the words. m4_if(m4_eval(m4_Cursor > m4_Width), 1, [m4_define([m4_Cursor], - m4_eval(m4_len(m4_Prefix) + m4_len(m4_Word) + 1))] + m4_eval(m4_len(m4_Prefix) + m4_len(m4_defn([m4_Word])) + 1))] m4_Prefix, [m4_Separator])[]dnl -m4_Word[]dnl +m4_defn([m4_Word])[]dnl m4_define([m4_Separator], [ ])])dnl m4_popdef([m4_Separator])dnl m4_popdef([m4_Cursor])dnl diff --git a/src/output.c b/src/output.c index 140f220b..573eb0ca 100644 --- a/src/output.c +++ b/src/output.c @@ -568,6 +568,7 @@ void token_definitions_output (FILE *out) { int i; + int first = 1; for (i = 0; i < ntokens; ++i) { bucket *symbol = symbols[i]; @@ -594,12 +595,13 @@ token_definitions_output (FILE *out) if (strchr (symbol->tag, '.') || strchr (symbol->tag, '$')) continue; - fprintf (out, "# define %s\t%d\n", - symbol->tag, number); + fprintf (out, "%s [[[%s]], [%d]]", + first ? "" : ",\n", symbol->tag, number); if (semantic_parser) /* FIXME: This is probably wrong, and should be just as above. --akim. */ fprintf (out, "# define T%s\t%d\n", symbol->tag, symbol->value); + first = 0; } } @@ -988,9 +990,9 @@ output_skeleton (void) guards_output (out); fputs ("]])\n\n", out); - fputs ("m4_define([b4_tokendef], \n[[", out); + fputs ("m4_define([b4_tokens], \n[", out); token_definitions_output (out); - fputs ("]])\n\n", out); + fputs ("])\n\n", out); muscles_m4_output (out); -- 2.47.2