From 46cce832fd797e7cd8e4124bd35c7ea4435d3b90 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 11 Jan 2020 11:43:13 +0100 Subject: [PATCH] yacc.c: introduce yysymbol_name Provide the users with a public API to get the name of the tokens. A thin wrapper around yytname. * data/skeletons/yacc.c (yysymbol_name): New. Use it. --- data/skeletons/yacc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c index 6143f96d..6093ee79 100644 --- a/data/skeletons/yacc.c +++ b/data/skeletons/yacc.c @@ -609,6 +609,15 @@ static const char *const yytname[] = { ]b4_tname[ }; + +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (int yysymbol) YY_ATTRIBUTE_UNUSED; +static const char * +yysymbol_name (int yysymbol) +{ + return yytname[yysymbol]; +} #endif # ifdef YYPRINT @@ -885,7 +894,7 @@ do { \ { \ YYDPRINTF ((stderr, \ "LAC: initial context established for %s\n", \ - yytname[yytoken])); \ + yysymbol_name(yytoken))); \ yy_lac_established = 1; \ { \ int yy_lac_status = \ @@ -937,7 +946,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes, { yy_state_t *yyes_prev = yyssp; yy_state_t *yyesp = yyes_prev; - YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken])); + YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yysymbol_name(yytoken))); if (yytoken == YYUNDEFTOK) { YYDPRINTF ((stderr, " Always Err\n"));