* src/output.c (output_short_or_char_table): New function.

(output_short_table, output_token_translations): Use it.
(goto_actions): Use output_short_table.
This commit is contained in:
Akim Demaille
2000-10-16 18:33:38 +00:00
parent 1e9798d569
commit 43591cec98
4 changed files with 78 additions and 81 deletions

View File

@@ -1,3 +1,9 @@
2000-10-16 Akim Demaille <akim@epita.fr>
* src/output.c (output_short_or_char_table): New function.
(output_short_table, output_token_translations): Use it.
(goto_actions): Use output_short_table.
2000-10-16 Akim Demaille <akim@epita.fr> 2000-10-16 Akim Demaille <akim@epita.fr>
* src/symtab.c (bucket_new): New function. * src/symtab.c (bucket_new): New function.
@@ -9,14 +15,14 @@
(output_gram): Use it. (output_gram): Use it.
(output_rule_data): Nicer output layout for YYTNAME. (output_rule_data): Nicer output layout for YYTNAME.
2000-10-16 Akim Demaille <akim@epita.fr> 2000-10-16 Akim Demaille <akim@epita.fr>
* src/lex.c (read_typename): New function. * src/lex.c (read_typename): New function.
(lex): Use it. (lex): Use it.
* src/reader.c (copy_dollar): Likewise. * src/reader.c (copy_dollar): Likewise.
2000-10-16 Akim Demaille <akim@epita.fr> 2000-10-16 Akim Demaille <akim@epita.fr>
* src/reader.c (copy_comment2): Expect the input stream to be on * src/reader.c (copy_comment2): Expect the input stream to be on
@@ -25,19 +31,19 @@
(copy_comment, copy_definition, parse_union_decl, copy_action) (copy_comment, copy_definition, parse_union_decl, copy_action)
(copy_guard): Adjust. (copy_guard): Adjust.
2000-10-16 Akim Demaille <akim@epita.fr> 2000-10-16 Akim Demaille <akim@epita.fr>
* src/reader.c (parse_expect_decl): Use `skip_white_space' and * src/reader.c (parse_expect_decl): Use `skip_white_space' and
`read_signed_integer'. `read_signed_integer'.
2000-10-16 Akim Demaille <akim@epita.fr> 2000-10-16 Akim Demaille <akim@epita.fr>
* src/reader.c (copy_dollar): New function. * src/reader.c (copy_dollar): New function.
(copy_guard, copy_action): Use it. (copy_guard, copy_action): Use it.
2000-10-16 Akim Demaille <akim@epita.fr> 2000-10-16 Akim Demaille <akim@epita.fr>
* lib/quote.h, lib/quote.c, lib/quotearg.h, lib/quotearg.c: * lib/quote.h, lib/quote.c, lib/quotearg.h, lib/quotearg.c:

View File

@@ -354,7 +354,9 @@ set_goto_map (void)
/* Map_goto maps a state/symbol pair into its numeric representation. */ /*----------------------------------------------------------.
| Map a state/symbol pair into its numeric representation. |
`----------------------------------------------------------*/
static int static int
map_goto (int state, int symbol) map_goto (int state, int symbol)
@@ -379,8 +381,8 @@ map_goto (int state, int symbol)
high = middle - 1; high = middle - 1;
} }
berror ("map_goto"); assert (0);
/* NOTREACHED */ /* NOTREACHED */
return 0; return 0;
} }

View File

@@ -1,5 +1,5 @@
/* Compute look-ahead criteria for bison, /* Compute look-ahead criteria for bison,
Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc. Copyright (C) 1984, 1986, 1989, 2000 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -35,14 +35,15 @@ void lalr PARAMS ((void));
/* lalr() builds these data structures. */ /* lalr() builds these data structures. */
/* goto_map, from_state and to_state --record each shift transition /* GOTO_MAP, FROM_STATE and TO_STATE -- record each shift transition
which accepts a variable (a nonterminal). which accepts a variable (a nonterminal).
from_state[t] is the state number which a transition leads from and FROM_STATE[T] -- state number which a transition leads from.
to_state[t] is the state number it leads to. All the transitions TO_STATE[T] -- state number it leads to.
that accept a particular variable are grouped together and
goto_map[i - ntokens] is the index in from_state and to_state of All the transitions that accept a particular variable are grouped
the first of them. */ together and GOTO_MAP[I - NTOKENS] is the index in FROM_STATE and
TO_STATE of the first of them. */
extern short *goto_map; extern short *goto_map;
extern short *from_state; extern short *from_state;

View File

@@ -125,20 +125,21 @@ static int high;
static inline void static inline void
output_short_table (FILE *out, output_short_or_char_table (FILE *out,
const char *comment, const char *comment,
const char *table_name, const char *type,
short *short_table, const char *table_name,
short first_value, short *short_table,
short begin, short end) short first_value,
short begin, short end)
{ {
int i, j; int i, j;
if (comment) if (comment)
fprintf (out, "/* %s. */\n", comment); fprintf (out, "/* %s. */\n", comment);
fprintf (out, "static const short %s[] =\n{\n %6d", fprintf (out, "static const %s %s[] =\n{\n %6d",
table_name, first_value); type, table_name, first_value);
j = 1; j = 1;
for (i = begin; i < end; i++) for (i = begin; i < end; i++)
@@ -162,6 +163,19 @@ output_short_table (FILE *out,
} }
static inline void
output_short_table (FILE *out,
const char *comment,
const char *table_name,
short *short_table,
short first_value,
short begin, short end)
{
output_short_or_char_table (out, comment, "short", table_name, short_table,
first_value, begin, end);
}
/*--------------------------------------------------------------. /*--------------------------------------------------------------.
| output_headers -- Output constant strings to the beginning of | | output_headers -- Output constant strings to the beginning of |
| certain files. | | certain files. |
@@ -256,39 +270,23 @@ output_trailers (void)
static void static void
output_token_translations (void) output_token_translations (void)
{ {
int i, j; fputs ("\
/* short *sp; JF unused */ \n\
/* YYRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n",
ftable);
if (translations) if (translations)
{ {
fprintf (ftable, fprintf (ftable,
"\n#define YYTRANSLATE(x) ((unsigned)(x) <= %d ? yytranslate[x] : %d)\n", "#define YYTRANSLATE(x) ((unsigned)(x) <= %d ? yytranslate[x] : %d)\
\n\
\n",
max_user_token_number, nsyms); max_user_token_number, nsyms);
if (ntokens < 127) /* play it very safe; check maximum element value. */ output_short_or_char_table (ftable,
fprintf (ftable, "\nstatic const char yytranslate[] = { 0"); "YYRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX",
else ntokens < 127 ? "char" : "short",
fprintf (ftable, "\nstatic const short yytranslate[] = { 0"); "yytranslate", token_translations,
0, 1, max_user_token_number + 1);
j = 10;
for (i = 1; i <= max_user_token_number; i++)
{
putc (',', ftable);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
fprintf (ftable, "%6d", token_translations[i]);
}
fprintf (ftable, "\n};\n");
} }
else else
{ {
@@ -724,8 +722,13 @@ token_actions (void)
} }
XFREE (actrow); XFREE (actrow);
output_short_table (ftable, NULL, "yydefact", yydefact, output_short_table (ftable,
"YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE\n\
doesn't specify something else to do. Zero means the default is an\n\
error",
"yydefact", yydefact,
yydefact[0], 1, nstates); yydefact[0], 1, nstates);
putc ('\n', ftable);
XFREE (yydefact); XFREE (yydefact);
} }
@@ -765,19 +768,17 @@ static void
save_column (int symbol, int default_state) save_column (int symbol, int default_state)
{ {
int i; int i;
int m;
int n;
short *sp; short *sp;
short *sp1; short *sp1;
short *sp2; short *sp2;
int count; int count;
int symno; int symno;
m = goto_map[symbol]; short begin = goto_map[symbol];
n = goto_map[symbol + 1]; short end = goto_map[symbol + 1];
count = 0; count = 0;
for (i = m; i < n; i++) for (i = begin; i < end; i++)
{ {
if (to_state[i] != default_state) if (to_state[i] != default_state)
count++; count++;
@@ -791,7 +792,7 @@ save_column (int symbol, int default_state)
froms[symno] = sp1 = sp = XCALLOC (short, count); froms[symno] = sp1 = sp = XCALLOC (short, count);
tos[symno] = sp2 = XCALLOC (short, count); tos[symno] = sp2 = XCALLOC (short, count);
for (i = m; i < n; i++) for (i = begin; i < end; i++)
{ {
if (to_state[i] != default_state) if (to_state[i] != default_state)
{ {
@@ -853,36 +854,23 @@ default_goto (int symbol)
static void static void
goto_actions (void) goto_actions (void)
{ {
int i, j, k; int i;
short *yydefgoto = XMALLOC (short, nsyms - ntokens);
state_count = XCALLOC (short, nstates); state_count = XCALLOC (short, nstates);
k = default_goto (ntokens); for (i = ntokens; i < nsyms; ++i)
fprintf (ftable, "\nstatic const short yydefgoto[] = {%6d", k);
save_column (ntokens, k);
j = 10;
for (i = ntokens + 1; i < nsyms; i++)
{ {
putc (',', ftable); int default_state = default_goto (i);
save_column (i, default_state);
if (j >= 10) yydefgoto[i - ntokens] = default_state;
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
k = default_goto (i);
fprintf (ftable, "%6d", k);
save_column (i, k);
} }
fprintf (ftable, "\n};\n"); output_short_table (ftable, NULL, "yydefgoto", yydefgoto,
yydefgoto[0], 1, nsyms - ntokens);
XFREE (state_count); XFREE (state_count);
XFREE (yydefgoto);
} }