diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2014-01-08 08:08:22 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2014-01-08 08:08:22 +0000 |
commit | 4b4a8fca3197fe6fbf074ac74d28269725ba2113 (patch) | |
tree | 7189f7105b1efabeb09c64eb720325c61af35a91 /contrib/byacc/output.c | |
parent | 5945b5f5abd64b943fd59e8bd264b84186883ed1 (diff) | |
parent | 88deb182c9a4d68ca0007518fb97e95668b156fe (diff) | |
download | src-4b4a8fca3197fe6fbf074ac74d28269725ba2113.tar.gz src-4b4a8fca3197fe6fbf074ac74d28269725ba2113.zip |
Notes
Diffstat (limited to 'contrib/byacc/output.c')
-rw-r--r-- | contrib/byacc/output.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/contrib/byacc/output.c b/contrib/byacc/output.c index 05c35d8292e4..f57c7e9f047b 100644 --- a/contrib/byacc/output.c +++ b/contrib/byacc/output.c @@ -1,4 +1,4 @@ -/* $Id: output.c,v 1.45 2013/03/05 00:29:17 tom Exp $ */ +/* $Id: output.c,v 1.47 2014/01/01 17:22:38 tom Exp $ */ #include "defs.h" @@ -921,23 +921,42 @@ output_debug(void) ++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-symbol"; + + /* + * bison's yytname[] array is roughly the same as byacc's yyname[] array. + * The difference is that byacc does not predefine "$end", "$error" or + * "$undefined". + * + * If the grammar declares "%token-table", define symbol "yytname" so + * an application such as ntpd can build. + */ + if (token_table) + { + output_line("#undef yytname"); + output_line("#define yytname yyname"); + } + else + { + output_line("#if YYDEBUG"); + } start_str_table("name"); j = 80; - for (i = 0; i <= max; ++i) + for (i = 0; i <= max + 1; ++i) { if ((s = symnam[i]) != 0) { @@ -1058,6 +1077,8 @@ output_debug(void) end_table(); FREE(symnam); + if (token_table) + output_line("#if YYDEBUG"); start_str_table("rule"); for (i = 2; i < nrules; ++i) { |