Remove `translations' as it is always set to true.

* src/gram.h: Adjust.
* src/reader.c (packsymbols, parse_token_decl): Adjust
* src/print.c (print_grammar): Adjust.
* src/output.c (output_token_translations): Adjust.
* src/lex.c (lex): Adjust.
* src/gram.c: Be sure the set pointers to NULL.
(dummy): Rename as...
(gram_free): this.
This commit is contained in:
Akim Demaille
2001-09-22 17:43:26 +00:00
parent f2632e420f
commit ab6fbb02ad
7 changed files with 77 additions and 120 deletions

View File

@@ -1,3 +1,16 @@
2001-09-22 Akim Demaille <akim@epita.fr>
Remove `translations' as it is always set to true.
* src/gram.h: Adjust.
* src/reader.c (packsymbols, parse_token_decl): Adjust
* src/print.c (print_grammar): Adjust.
* src/output.c (output_token_translations): Adjust.
* src/lex.c (lex): Adjust.
* src/gram.c: Be sure the set pointers to NULL.
(dummy): Rename as...
(gram_free): this.
2001-09-22 Akim Demaille <akim@epita.fr> 2001-09-22 Akim Demaille <akim@epita.fr>
* configure.in: Invoke AM_LIB_DMALLOC. * configure.in: Invoke AM_LIB_DMALLOC.

View File

@@ -31,21 +31,19 @@ int nsyms;
int ntokens; int ntokens;
int nvars; int nvars;
short *ritem; short *ritem = NULL;
short *rlhs; short *rlhs = NULL;
short *rrhs; short *rrhs = NULL;
short *rprec; short *rprec = NULL;
short *rprecsym; short *rprecsym = NULL;
short *sprec; short *sprec = NULL;
short *rassoc; short *rassoc = NULL;
short *sassoc; short *sassoc = NULL;
short *token_translations; short *token_translations = NULL;
short *rline; short *rline = NULL;
int start_symbol; int start_symbol;
int translations;
int max_user_token_number; int max_user_token_number;
int semantic_parser; int semantic_parser;
@@ -54,10 +52,10 @@ int pure_parser;
int error_token_number; int error_token_number;
/* This is to avoid linker problems which occur on VMS when using GCC, /* Free all the memory associated to these pointers. */
when the file in question contains data definitions only. */
void void
dummy (void) gram_free (void)
{ {
} }

View File

@@ -107,13 +107,9 @@ typedef enum
/* token translation table: indexed by a token number as returned by /* token translation table: indexed by a token number as returned by
the user's yylex routine, it yields the internal token number used the user's yylex routine, it yields the internal token number used
by the parser and throughout bison. If translations is zero, the by the parser and throughout bison. */
translation table is not used because the two kinds of token
numbers are the same. (It is noted in reader.c that "Nowadays
translations is always set to 1...") */
extern short *token_translations; extern short *token_translations;
extern int translations;
extern int max_user_token_number; extern int max_user_token_number;
/* SEMANTIC_PARSER is nonzero if the input file says to use the hairy /* SEMANTIC_PARSER is nonzero if the input file says to use the hairy

View File

@@ -419,7 +419,6 @@ lex (void)
case '\'': case '\'':
/* parse the literal token and compute character code in code */ /* parse the literal token and compute character code in code */
translations = -1;
{ {
int code, discode; int code, discode;
@@ -447,7 +446,6 @@ lex (void)
case '\"': case '\"':
/* parse the literal string token and treat as an identifier */ /* parse the literal string token and treat as an identifier */
translations = -1;
{ {
int code; /* ignored here */ int code; /* ignored here */

View File

@@ -295,25 +295,17 @@ output_token_translations (void)
\n\ \n\
/* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n"); /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n");
if (translations) obstack_fgrow2 (&table_obstack,
{
obstack_fgrow2 (&table_obstack,
"#define YYTRANSLATE(x) ((unsigned)(x) <= %d ? yytranslate[x] : %d)\ "#define YYTRANSLATE(x) ((unsigned)(x) <= %d ? yytranslate[x] : %d)\
\n\ \n\
\n", \n",
max_user_token_number, nsyms); max_user_token_number, nsyms);
output_short_or_char_table (&table_obstack, output_short_or_char_table (&table_obstack,
"YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX", "YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX",
ntokens < 127 ? "char" : "short", ntokens < 127 ? "char" : "short",
"yytranslate", token_translations, "yytranslate", token_translations,
0, 1, max_user_token_number + 1); 0, 1, max_user_token_number + 1);
}
else
{
obstack_sgrow (&table_obstack,
"\n#define YYTRANSLATE(x) (x)\n");
}
} }

View File

@@ -253,49 +253,26 @@ print_grammar (void)
_("Terminals, with rules where they appear")); _("Terminals, with rules where they appear"));
obstack_sgrow (&output_obstack, "\n\n"); obstack_sgrow (&output_obstack, "\n\n");
obstack_fgrow1 (&output_obstack, "%s (-1)\n", tags[0]); obstack_fgrow1 (&output_obstack, "%s (-1)\n", tags[0]);
if (translations)
{
for (i = 0; i <= max_user_token_number; i++)
if (token_translations[i] != 2)
{
buffer[0] = 0;
column = strlen (tags[token_translations[i]]);
obstack_sgrow (&output_obstack, tags[token_translations[i]]);
END_TEST (50);
sprintf (buffer, " (%d)", i);
for (j = 1; j <= nrules; j++) for (i = 0; i <= max_user_token_number; i++)
for (rule = &ritem[rrhs[j]]; *rule > 0; rule++) if (token_translations[i] != 2)
if (*rule == token_translations[i]) {
{ buffer[0] = 0;
END_TEST (65); column = strlen (tags[token_translations[i]]);
sprintf (buffer + strlen (buffer), " %d", j); obstack_sgrow (&output_obstack, tags[token_translations[i]]);
break; END_TEST (50);
} sprintf (buffer, " (%d)", i);
obstack_fgrow1 (&output_obstack, "%s\n", buffer);
}
}
else
{
for (i = 1; i < ntokens; i++)
{
buffer[0] = 0;
column = strlen (tags[i]);
obstack_sgrow (&output_obstack, tags[i]);
END_TEST (50);
sprintf (buffer, " (%d)", i);
for (j = 1; j <= nrules; j++) for (j = 1; j <= nrules; j++)
for (rule = &ritem[rrhs[j]]; *rule > 0; rule++) for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
if (*rule == i) if (*rule == token_translations[i])
{ {
END_TEST (65); END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j); sprintf (buffer + strlen (buffer), " %d", j);
break; break;
} }
obstack_fgrow1 (&output_obstack, "%s\n", buffer); obstack_fgrow1 (&output_obstack, "%s\n", buffer);
} }
}
obstack_sgrow (&output_obstack, "\n"); obstack_sgrow (&output_obstack, "\n");
obstack_sgrow (&output_obstack, obstack_sgrow (&output_obstack,

View File

@@ -512,7 +512,6 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
/* symbol and symval combined are only one symbol */ /* symbol and symval combined are only one symbol */
nsyms--; nsyms--;
} }
translations = 1;
symbol = NULL; symbol = NULL;
} }
else if (token == tok_identifier) else if (token == tok_identifier)
@@ -537,7 +536,6 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
else if (symbol && token == tok_number) else if (symbol && token == tok_number)
{ {
symbol->user_token_number = numval; symbol->user_token_number = numval;
translations = 1;
} }
else else
{ {
@@ -679,7 +677,6 @@ parse_assoc_decl (associativity assoc)
if (prev == tok_identifier) if (prev == tok_identifier)
{ {
symval->user_token_number = numval; symval->user_token_number = numval;
translations = 1;
} }
else else
{ {
@@ -827,7 +824,6 @@ parse_thong_decl (void)
char *typename = 0; char *typename = 0;
int usrtoknum; int usrtoknum;
translations = 1;
token = lex (); /* fetch typename or first token */ token = lex (); /* fetch typename or first token */
if (token == tok_typename) if (token == tok_typename)
{ {
@@ -1657,9 +1653,10 @@ output_token_defines (struct obstack *oout)
continue; continue;
obstack_fgrow2 (oout, "# define\t%s\t%d\n", obstack_fgrow2 (oout, "# define\t%s\t%d\n",
symbol, symbol, bp->user_token_number);
(translations ? bp->user_token_number : bp->value));
if (semantic_parser) if (semantic_parser)
/* FIXME: This is certainly dead wrong, and should be just as
above. --akim. */
obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value); obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value);
} }
@@ -1676,9 +1673,9 @@ output_token_defines (struct obstack *oout)
static void static void
packsymbols (void) packsymbols (void)
{ {
bucket *bp; bucket *bp = NULL;
int tokno = 1; int tokno = 1;
int i; int i, j;
int last_user_token_number; int last_user_token_number;
static char DOLLAR[] = "$"; static char DOLLAR[] = "$";
@@ -1744,7 +1741,7 @@ packsymbols (void)
if (bp->class == token_sym) if (bp->class == token_sym)
{ {
if (translations && !(bp->user_token_number)) if (!bp->user_token_number)
bp->user_token_number = ++last_user_token_number; bp->user_token_number = ++last_user_token_number;
if (bp->user_token_number > max_user_token_number) if (bp->user_token_number > max_user_token_number)
max_user_token_number = bp->user_token_number; max_user_token_number = bp->user_token_number;
@@ -1757,30 +1754,25 @@ packsymbols (void)
} }
if (translations) token_translations = XCALLOC (short, max_user_token_number + 1);
/* initialize all entries for literal tokens to 2, the internal
token number for $undefined., which represents all invalid
inputs. */
for (j = 0; j <= max_user_token_number; j++)
token_translations[j] = 2;
for (bp = firstsymbol; bp; bp = bp->next)
{ {
int j; if (bp->value >= ntokens)
continue; /* non-terminal */
token_translations = XCALLOC (short, max_user_token_number + 1); if (bp->user_token_number == SALIAS)
continue;
/* initialize all entries for literal tokens to 2, the internal if (token_translations[bp->user_token_number] != 2)
token number for $undefined., which represents all invalid complain (_("tokens %s and %s both assigned number %d"),
inputs. */ tags[token_translations[bp->user_token_number]],
for (j = 0; j <= max_user_token_number; j++) bp->tag, bp->user_token_number);
token_translations[j] = 2; token_translations[bp->user_token_number] = bp->value;
for (bp = firstsymbol; bp; bp = bp->next)
{
if (bp->value >= ntokens)
continue; /* non-terminal */
if (bp->user_token_number == SALIAS)
continue;
if (token_translations[bp->user_token_number] != 2)
complain (_("tokens %s and %s both assigned number %d"),
tags[token_translations[bp->user_token_number]],
bp->tag, bp->user_token_number);
token_translations[bp->user_token_number] = bp->value;
}
} }
error_token_number = errtoken->value; error_token_number = errtoken->value;
@@ -1906,15 +1898,6 @@ reader (void)
start_flag = 0; start_flag = 0;
startval = NULL; /* start symbol not specified yet. */ startval = NULL; /* start symbol not specified yet. */
#if 0
/* initially assume token number translation not needed. */
translations = 0;
#endif
/* Nowadays translations is always set to 1, since we give `error' a
user-token-number to satisfy the Posix demand for YYERRCODE==256.
*/
translations = 1;
nsyms = 1; nsyms = 1;
nvars = 0; nvars = 0;
nrules = 0; nrules = 0;