Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/byacc/dist Add support for %token-table, yytnam...



details:   https://anonhg.NetBSD.org/src/rev/65796cfba027
branches:  trunk
changeset: 325592:65796cfba027
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Dec 30 19:08:55 2013 +0000

description:
Add support for %token-table, yytname[] and YYTRANSLATE(). ntpd(8) needs them.

diffstat:

 external/bsd/byacc/dist/defs.h     |   4 +++-
 external/bsd/byacc/dist/main.c     |   5 +++--
 external/bsd/byacc/dist/output.c   |  24 +++++++++++++++---------
 external/bsd/byacc/dist/reader.c   |  10 ++++++++--
 external/bsd/byacc/dist/skeleton.c |  18 ++++++------------
 5 files changed, 35 insertions(+), 26 deletions(-)

diffs (213 lines):

diff -r 135320ffd501 -r 65796cfba027 external/bsd/byacc/dist/defs.h
--- a/external/bsd/byacc/dist/defs.h    Mon Dec 30 19:06:45 2013 +0000
+++ b/external/bsd/byacc/dist/defs.h    Mon Dec 30 19:08:55 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.6 2013/04/06 14:52:24 christos Exp $        */
+/*     $NetBSD: defs.h,v 1.7 2013/12/30 19:08:55 christos Exp $        */
 
 #if HAVE_NBTOOL_CONFIG_H
 #include "nbtool_config.h"
@@ -109,6 +109,7 @@
 #define PARSE_PARAM 13
 #define LEX_PARAM 14
 #define POSIX_YACC 15
+#define TOKEN_TABLE 16
 
 /*  symbol classes  */
 
@@ -253,6 +254,7 @@
 extern int outline;
 extern int exit_code;
 extern int pure_parser;
+extern int token_table;
 
 extern const char *const banner[];
 extern const char *const xdecls[];
diff -r 135320ffd501 -r 65796cfba027 external/bsd/byacc/dist/main.c
--- a/external/bsd/byacc/dist/main.c    Mon Dec 30 19:06:45 2013 +0000
+++ b/external/bsd/byacc/dist/main.c    Mon Dec 30 19:08:55 2013 +0000
@@ -1,9 +1,9 @@
-/*     $NetBSD: main.c,v 1.8 2013/04/06 14:52:24 christos Exp $        */
+/*     $NetBSD: main.c,v 1.9 2013/12/30 19:08:55 christos Exp $        */
 
 #include "defs.h"
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: main.c,v 1.8 2013/04/06 14:52:24 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.9 2013/12/30 19:08:55 christos Exp $");
 /* Id: main.c,v 1.40 2012/09/29 13:11:00 Adrian.Bunk Exp  */
 
 #include <signal.h>
@@ -93,6 +93,7 @@
 char *symbol_assoc;
 
 int pure_parser;
+int token_table;
 int exit_code;
 
 Value_t *ritem;
diff -r 135320ffd501 -r 65796cfba027 external/bsd/byacc/dist/output.c
--- a/external/bsd/byacc/dist/output.c  Mon Dec 30 19:06:45 2013 +0000
+++ b/external/bsd/byacc/dist/output.c  Mon Dec 30 19:08:55 2013 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: output.c,v 1.9 2013/04/06 14:52:24 christos Exp $      */
+/*     $NetBSD: output.c,v 1.10 2013/12/30 19:08:55 christos Exp $     */
 
 /* Id: output.c,v 1.45 2013/03/05 00:29:17 tom Exp  */
 
 #include "defs.h"
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: output.c,v 1.9 2013/04/06 14:52:24 christos Exp $");
+__RCSID("$NetBSD: output.c,v 1.10 2013/12/30 19:08:55 christos Exp $");
 
 #define StaticOrR      (rflag ? "" : "static ")
 #define CountLine(fp)   (!rflag || ((fp) == code_file))
@@ -116,7 +116,7 @@
        define_prefixed(fp, "yygindex");
        define_prefixed(fp, "yytable");
        define_prefixed(fp, "yycheck");
-       define_prefixed(fp, "yyname");
+       define_prefixed(fp, "yytname");
        define_prefixed(fp, "yyrule");
     }
     if (CountLine(fp))
@@ -926,23 +926,27 @@
 
     ++outline;
     fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
+    fprintf(code_file, "#define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? "
+       "(YYMAXTOKEN + 1) : (a))\n");
 
-    symnam = TMALLOC(const char *, max + 1);
+    symnam = TMALLOC(const char *, max + 2);
     NO_SPACE(symnam);
 
     /* Note that it is  not necessary to initialize the element         */
     /* symnam[max].                                                     */
-    for (i = 0; i < max; ++i)
+    for (i = 0; i <= max; ++i)
        symnam[i] = 0;
     for (i = ntokens - 1; i >= 2; --i)
        symnam[symbol_value[i]] = symbol_name[i];
     symnam[0] = "end-of-file";
-
-    output_line("#if YYDEBUG");
+    symnam[max + 1] = "illegal-token";
 
-    start_str_table("name");
+    if (!token_table)
+       output_line("#if YYDEBUG");
+
+    start_str_table("tname");
     j = 80;
-    for (i = 0; i <= max; ++i)
+    for (i = 0; i <= max + 1; ++i)
     {
        if ((s = symnam[i]) != 0)
        {
@@ -1063,6 +1067,8 @@
     end_table();
     FREE(symnam);
 
+    if (token_table)
+       output_line("#if YYDEBUG");
     start_str_table("rule");
     for (i = 2; i < nrules; ++i)
     {
diff -r 135320ffd501 -r 65796cfba027 external/bsd/byacc/dist/reader.c
--- a/external/bsd/byacc/dist/reader.c  Mon Dec 30 19:06:45 2013 +0000
+++ b/external/bsd/byacc/dist/reader.c  Mon Dec 30 19:08:55 2013 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: reader.c,v 1.8 2013/04/06 14:52:24 christos Exp $      */
+/*     $NetBSD: reader.c,v 1.9 2013/12/30 19:08:55 christos Exp $      */
 
 /* Id: reader.c,v 1.36 2012/05/26 16:05:41 tom Exp  */
 
 #include "defs.h"
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: reader.c,v 1.8 2013/04/06 14:52:24 christos Exp $");
+__RCSID("$NetBSD: reader.c,v 1.9 2013/12/30 19:08:55 christos Exp $");
 
 /*  The line size must be a positive integer.  One hundred was chosen  */
 /*  because few lines in Yacc input grammars exceed 100 characters.    */
@@ -322,6 +322,8 @@
            return (PARSE_PARAM);
        if (matchec("lex-param"))
            return (LEX_PARAM);
+       if (matchec("token-table"))
+           return (TOKEN_TABLE);
        if (matchec("yacc"))
            return (POSIX_YACC);
     }
@@ -1307,6 +1309,10 @@
            copy_param(k);
            break;
 
+       case TOKEN_TABLE:
+           token_table = 1;
+           break;
+
        case POSIX_YACC:
            /* noop for bison compatibility. byacc is already designed to be posix
             * yacc compatible. */
diff -r 135320ffd501 -r 65796cfba027 external/bsd/byacc/dist/skeleton.c
--- a/external/bsd/byacc/dist/skeleton.c        Mon Dec 30 19:06:45 2013 +0000
+++ b/external/bsd/byacc/dist/skeleton.c        Mon Dec 30 19:08:55 2013 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: skeleton.c,v 1.13 2013/09/13 18:53:29 joerg Exp $      */
+/*     $NetBSD: skeleton.c,v 1.14 2013/12/30 19:08:55 christos Exp $   */
 
 /* Id: skeleton.c,v 1.32 2013/03/04 23:19:39 tom Exp  */
 
 #include "defs.h"
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: skeleton.c,v 1.13 2013/09/13 18:53:29 joerg Exp $");
+__RCSID("$NetBSD: skeleton.c,v 1.14 2013/12/30 19:08:55 christos Exp $");
 
 /*  The definition of yysccsid in the banner should be replaced with   */
 /*  a #pragma ident directive if the target C compiler supports                */
@@ -73,7 +73,7 @@
     "extern short yycheck[];",
     "",
     "#if YYDEBUG",
-    "extern char *yyname[];",
+    "extern char *yytname[];",
     "extern char *yyrule[];",
     "#endif",
     0
@@ -249,9 +249,7 @@
     "#if YYDEBUG",
     "        if (yydebug)",
     "        {",
-    "            yys = 0;",
-    "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
-    "            if (!yys) yys = \"illegal-symbol\";",
+    "            yys = yytname[YYTRANSLATE(yychar)];",
     "            printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
     "                    YYPREFIX, yystate, yychar, yys);",
     "        }",
@@ -338,9 +336,7 @@
     "#if YYDEBUG",
     "        if (yydebug)",
     "        {",
-    "            yys = 0;",
-    "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
-    "            if (!yys) yys = \"illegal-symbol\";",
+    "            yys = yytname[YYTRANSLATE(yychar)];",
     "            printf(\"%sdebug: state %d, error recovery discards token %d\
  (%s)\\n\",",
     "                    YYPREFIX, yystate, yychar, yys);",
@@ -389,9 +385,7 @@
     "#if YYDEBUG",
     "            if (yydebug)",
     "            {",
-    "                yys = 0;",
-    "                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
-    "                if (!yys) yys = \"illegal-symbol\";",
+    "                yys = yytname[YYTRANSLATE(yychar)];",
     "                printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
     "                        YYPREFIX, YYFINAL, yychar, yys);",
     "            }",



Home | Main Index | Thread Index | Old Index