* 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>
+
+ 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>
* configure.in: Invoke AM_LIB_DMALLOC.
int ntokens;
int nvars;
-short *ritem;
-short *rlhs;
-short *rrhs;
-short *rprec;
-short *rprecsym;
-short *sprec;
-short *rassoc;
-short *sassoc;
-short *token_translations;
-short *rline;
+short *ritem = NULL;
+short *rlhs = NULL;
+short *rrhs = NULL;
+short *rprec = NULL;
+short *rprecsym = NULL;
+short *sprec = NULL;
+short *rassoc = NULL;
+short *sassoc = NULL;
+short *token_translations = NULL;
+short *rline = NULL;
int start_symbol;
-int translations;
-
int max_user_token_number;
int semantic_parser;
int error_token_number;
-/* This is to avoid linker problems which occur on VMS when using GCC,
- when the file in question contains data definitions only. */
+/* Free all the memory associated to these pointers. */
void
-dummy (void)
+gram_free (void)
{
+
}
/* token translation table: indexed by a token number as returned by
the user's yylex routine, it yields the internal token number used
- by the parser and throughout bison. If translations is zero, the
- 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...") */
+ by the parser and throughout bison. */
extern short *token_translations;
-extern int translations;
extern int max_user_token_number;
/* SEMANTIC_PARSER is nonzero if the input file says to use the hairy
case '\'':
/* parse the literal token and compute character code in code */
- translations = -1;
{
int code, discode;
case '\"':
/* parse the literal string token and treat as an identifier */
- translations = -1;
{
int code; /* ignored here */
\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)\
\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",
- ntokens < 127 ? "char" : "short",
- "yytranslate", token_translations,
- 0, 1, max_user_token_number + 1);
- }
- else
- {
- obstack_sgrow (&table_obstack,
- "\n#define YYTRANSLATE(x) (x)\n");
- }
+ ntokens < 127 ? "char" : "short",
+ "yytranslate", token_translations,
+ 0, 1, max_user_token_number + 1);
}
_("Terminals, with rules where they appear"));
obstack_sgrow (&output_obstack, "\n\n");
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 (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
- if (*rule == token_translations[i])
- {
- END_TEST (65);
- sprintf (buffer + strlen (buffer), " %d", j);
- break;
- }
- 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 (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
- if (*rule == i)
- {
- END_TEST (65);
- sprintf (buffer + strlen (buffer), " %d", j);
- break;
- }
- obstack_fgrow1 (&output_obstack, "%s\n", buffer);
- }
- }
+ 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 (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
+ if (*rule == token_translations[i])
+ {
+ END_TEST (65);
+ sprintf (buffer + strlen (buffer), " %d", j);
+ break;
+ }
+ obstack_fgrow1 (&output_obstack, "%s\n", buffer);
+ }
obstack_sgrow (&output_obstack, "\n");
obstack_sgrow (&output_obstack,
/* symbol and symval combined are only one symbol */
nsyms--;
}
- translations = 1;
symbol = NULL;
}
else if (token == tok_identifier)
else if (symbol && token == tok_number)
{
symbol->user_token_number = numval;
- translations = 1;
}
else
{
if (prev == tok_identifier)
{
symval->user_token_number = numval;
- translations = 1;
}
else
{
while (c != EOF)
{
-
+
/* If C contains '/', it is output by copy_comment (). */
if (c != '/')
{
if (defines_flag)
obstack_1grow (&defines_obstack, c);
}
-
+
switch (c)
{
case '\n':
char *typename = 0;
int usrtoknum;
- translations = 1;
token = lex (); /* fetch typename or first token */
if (token == tok_typename)
{
continue;
obstack_fgrow2 (oout, "# define\t%s\t%d\n",
- symbol,
- (translations ? bp->user_token_number : bp->value));
+ symbol, bp->user_token_number);
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);
}
static void
packsymbols (void)
{
- bucket *bp;
+ bucket *bp = NULL;
int tokno = 1;
- int i;
+ int i, j;
int last_user_token_number;
static char DOLLAR[] = "$";
if (bp->class == token_sym)
{
- if (translations && !(bp->user_token_number))
+ if (!bp->user_token_number)
bp->user_token_number = ++last_user_token_number;
if (bp->user_token_number > max_user_token_number)
max_user_token_number = bp->user_token_number;
}
- if (translations)
- {
- int j;
+ token_translations = XCALLOC (short, max_user_token_number + 1);
- 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;
- /* 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)
- {
- 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;
- }
+ 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;
start_flag = 0;
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;
nvars = 0;
nrules = 0;