user_toknums' is output as a short[]' in `output.c', while it is

defined as a `int[]' in `reader.c'.  For consistency with the
other output tables, `user_toknums' is now defined as a table of
shorts.

* src/reader.c (user_toknums): Be a short table instead of an int
table.
Adjust dependencies.

Factor the short table outputs.

* src/output.c (output_short_table): New function.
* src/output.c (output_gram, output_stos, output_rule_data)
(output_base, output_table, output_check):  Use it.
This commit is contained in:
Akim Demaille
2000-10-02 07:53:36 +00:00
parent 6c89f1c138
commit d019d65507
4 changed files with 95 additions and 204 deletions

View File

@@ -1,3 +1,20 @@
2000-10-02 Akim Demaille <akim@epita.fr>
`user_toknums' is output as a `short[]' in `output.c', while it is
defined as a `int[]' in `reader.c'. For consistency with the
other output tables, `user_toknums' is now defined as a table of
shorts.
* src/reader.c (user_toknums): Be a short table instead of an int
table.
Adjust dependencies.
Factor the short table outputs.
* src/output.c (output_short_table): New function.
* src/output.c (output_gram, output_stos, output_rule_data)
(output_base, output_table, output_check): Use it.
2000-10-02 Akim Demaille <akim@epita.fr>
* src/output.c (output): Topological sort of the functions, in

View File

@@ -35,6 +35,8 @@ static int failure;
/* The name this program was run with, for messages. */
char *program_name;
extern void berror PARAMS((const char *));
extern char *printable_version PARAMS ((int));
extern void openfiles PARAMS ((void));

View File

@@ -99,8 +99,10 @@
#include "complain.h"
#include "output.h"
extern void berror PARAMS((const char *));
extern char **tags;
extern int *user_toknums;
extern short *user_toknums;
extern int tokensetsize;
extern int final_state;
extern core **state_table;
@@ -136,6 +138,44 @@ static int high;
static inline void
output_short_table (FILE *out,
const char *table_name,
short *short_table,
short first_value,
short begin, short end)
{
int i, j;
fprintf (out, "static const short %s[] = {%6d", table_name, first_value);
j = 10;
for (i = begin; i < end; i++)
{
putc (',', out);
if (j >= 10)
{
putc ('\n', out);
j = 1;
}
else
{
j++;
}
fprintf (out, "%6d", short_table[i]);
}
fprintf (out, "\n};\n");
}
/*--------------------------------------------------------------.
| output_headers -- Output constant strings to the beginning of |
| certain files. |
`--------------------------------------------------------------*/
#define GUARDSTR \
"\n\
#include \"%s\"\n\
@@ -171,11 +211,6 @@ register YYLTYPE *yylsp;\n\
#define ACTSTR_SIMPLE "\n switch (yyn) {\n"
/*------------------------------------------------------------.
| Output constant strings to the beginning of certain files. |
`------------------------------------------------------------*/
void
output_headers (void)
{
@@ -274,7 +309,6 @@ output_token_translations (void)
static void
output_gram (void)
{
int i;
int j;
short *sp;
@@ -282,29 +316,10 @@ output_gram (void)
yyprhs and yyrhs are needed only for yydebug. */
/* With the noparser option, all tables are generated */
if (!semantic_parser && !noparserflag)
fprintf (ftable, "\n#if YYDEBUG != 0");
fprintf (ftable, "\n#if YYDEBUG != 0\n");
fprintf (ftable, "\nstatic const short yyprhs[] = { 0");
j = 10;
for (i = 1; i <= nrules; i++)
{
putc (',', ftable);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
fprintf (ftable, "%6d", rrhs[i]);
}
fprintf (ftable, "\n};\n");
output_short_table (ftable, "yyprhs", rrhs,
0, 1, nrules + 1);
fprintf (ftable, "\nstatic const short yyrhs[] = {%6d", ritem[0]);
@@ -339,30 +354,8 @@ output_gram (void)
static void
output_stos (void)
{
int i;
int j;
fprintf (ftable, "\nstatic const short yystos[] = { 0");
j = 10;
for (i = 1; i < nstates; i++)
{
putc (',', ftable);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
fprintf (ftable, "%6d", accessing_symbol[i]);
}
fprintf (ftable, "\n};\n");
output_short_table (ftable, "yystos", accessing_symbol,
0, 1, nstates);
}
@@ -374,27 +367,13 @@ output_rule_data (void)
fputs ("\n\
#if YYDEBUG != 0\n\
/* YYRLINE[yyn]: source line where rule number YYN was defined. */\n\
static const short yyrline[] = { 0", ftable);
/* YYRLINE[yyn]: source line where rule number YYN was defined. */\n",
ftable);
j = 10;
for (i = 1; i <= nrules; i++)
{
putc (',', ftable);
output_short_table (ftable, "yyrline", rline,
0, 1, nrules + 1);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
fprintf (ftable, "%6d", rline[i]);
}
fprintf (ftable, "\n};\n#endif\n\n");
fputs ("#endif\n\n", ftable);
if (toknumflag || noparserflag)
{
@@ -477,49 +456,19 @@ static const short yyrline[] = { 0", ftable);
/* Output YYTOKNUM. */
if (toknumflag)
{
fprintf (ftable, "static const short yytoknum[] = { 0");
j = 10;
for (i = 1; i <= ntokens; i++)
{
putc (',', ftable);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
j++;
fprintf (ftable, "%6d", user_toknums[i]);
}
fprintf (ftable, "\n};\n\n");
output_short_table (ftable, "yytoknum", user_toknums,
0, 1, ntokens + 1);
}
/* Output YYR1. */
fputs ("\
/* YYR1[YYN]: Symbol number of symbol that rule YYN derives. */\n\
static const short yyr1[] = { 0", ftable);
/* YYR1[YYN]: Symbol number of symbol that rule YYN derives. */\n", ftable);
j = 10;
for (i = 1; i <= nrules; i++)
{
putc (',', ftable);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
fprintf (ftable, "%6d", rlhs[i]);
}
output_short_table (ftable, "yyr1", rlhs,
0, 1, nrules + 1);
FREE (rlhs + 1);
fputs ("\n\
};\n\
\n", ftable);
putc ('\n', ftable);
/* Output YYR2. */
fputs ("\
@@ -1179,51 +1128,14 @@ pack_table (void)
static void
output_base (void)
{
int i;
int j;
output_short_table (ftable, "yypact", base,
base[0], 1, nstates);
fprintf (ftable, "\nstatic const short yypact[] = {%6d", base[0]);
putc ('\n', ftable);
j = 10;
for (i = 1; i < nstates; i++)
{
putc (',', ftable);
output_short_table (ftable, "yypgoto", base,
base[nstates], nstates + 1, nvectors);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
fprintf (ftable, "%6d", base[i]);
}
fprintf (ftable, "\n};\n\nstatic const short yypgoto[] = {%6d",
base[nstates]);
j = 10;
for (i = nstates + 1; i < nvectors; i++)
{
putc (',', ftable);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
fprintf (ftable, "%6d", base[i]);
}
fprintf (ftable, "\n};\n");
FREE (base);
}
@@ -1231,31 +1143,9 @@ output_base (void)
static void
output_table (void)
{
int i;
int j;
fprintf (ftable, "\n\n#define\tYYLAST\t\t%d\n\n", high);
fprintf (ftable, "\nstatic const short yytable[] = {%6d", table[0]);
j = 10;
for (i = 1; i <= high; i++)
{
putc (',', ftable);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
fprintf (ftable, "%6d", table[i]);
}
fprintf (ftable, "\n};\n");
fprintf (ftable, "\n\n#define\tYYLAST\t\t%d\n\n\n", high);
output_short_table (ftable, "yytable", table,
table[0], 1, high + 1);
FREE (table);
}
@@ -1263,30 +1153,8 @@ output_table (void)
static void
output_check (void)
{
int i;
int j;
fprintf (ftable, "\nstatic const short yycheck[] = {%6d", check[0]);
j = 10;
for (i = 1; i <= high; i++)
{
putc (',', ftable);
if (j >= 10)
{
putc ('\n', ftable);
j = 1;
}
else
{
j++;
}
fprintf (ftable, "%6d", check[i]);
}
fprintf (ftable, "\n};\n");
output_short_table (ftable, "yycheck", check,
check[0], 1, high + 1);
FREE (check);
}
@@ -1318,8 +1186,10 @@ output_actions (void)
sort_actions ();
pack_table ();
putc ('\n', ftable);
output_base ();
output_table ();
putc ('\n', ftable);
output_check ();
}

View File

@@ -118,7 +118,7 @@ static int get_type PARAMS((void));
int lineno;
char **tags;
int *user_toknums;
short *user_toknums;
static symbol_list *grammar;
static int start_flag;
static bucket *startval;
@@ -296,8 +296,10 @@ copy_comment2 (FILE *in, FILE *out1, FILE* out2, int c)
}
/* Dump the comment from FIN to FOUT. C is either `*' or `/',
depending upon the type of comments used. */
/*------------------------------------------------------------.
| Dump the comment from FIN to FOUT. C is either `*' or `/', |
| depending upon the type of comments used. |
`------------------------------------------------------------*/
static inline void
copy_comment (FILE *fin, FILE *fout, int c)
@@ -1737,7 +1739,7 @@ packsymbols (void)
tags = NEW2(nsyms + 1, char *);
tags[0] = DOLLAR;
user_toknums = NEW2(nsyms + 1, int);
user_toknums = NEW2(nsyms + 1, short);
user_toknums[0] = 0;
sprec = NEW2(nsyms, short);