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>
+
+ `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
2000-10-02 Akim Demaille <akim@epita.fr>
* src/output.c (output): Topological sort of the functions, in
/* The name this program was run with, for messages. */
char *program_name;
/* 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));
extern char *printable_version PARAMS ((int));
extern void openfiles PARAMS ((void));
#include "complain.h"
#include "output.h"
#include "complain.h"
#include "output.h"
+extern void berror PARAMS((const char *));
+
-extern int *user_toknums;
+extern short *user_toknums;
extern int tokensetsize;
extern int final_state;
extern core **state_table;
extern int tokensetsize;
extern int final_state;
extern core **state_table;
+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\
#define GUARDSTR \
"\n\
#include \"%s\"\n\
#define ACTSTR_SIMPLE "\n switch (yyn) {\n"
#define ACTSTR_SIMPLE "\n switch (yyn) {\n"
-
-/*------------------------------------------------------------.
-| Output constant strings to the beginning of certain files. |
-`------------------------------------------------------------*/
-
void
output_headers (void)
{
void
output_headers (void)
{
static void
output_gram (void)
{
static void
output_gram (void)
{
yyprhs and yyrhs are needed only for yydebug. */
/* With the noparser option, all tables are generated */
if (!semantic_parser && !noparserflag)
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, "\nstatic const short yyprhs[] = { 0");
+ fprintf (ftable, "\n#if YYDEBUG != 0\n");
- 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]);
fprintf (ftable, "\nstatic const short yyrhs[] = {%6d", ritem[0]);
static void
output_stos (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);
fputs ("\n\
#if YYDEBUG != 0\n\
fputs ("\n\
#if YYDEBUG != 0\n\
-/* YYRLINE[yyn]: source line where rule number YYN was defined. */\n\
-static const short yyrline[] = { 0", ftable);
-
- j = 10;
- for (i = 1; i <= nrules; i++)
- {
- putc (',', ftable);
+/* YYRLINE[yyn]: source line where rule number YYN was defined. */\n",
+ ftable);
- if (j >= 10)
- {
- putc ('\n', ftable);
- j = 1;
- }
- else
- {
- j++;
- }
+ output_short_table (ftable, "yyrline", rline,
+ 0, 1, nrules + 1);
- fprintf (ftable, "%6d", rline[i]);
- }
- fprintf (ftable, "\n};\n#endif\n\n");
+ fputs ("#endif\n\n", ftable);
if (toknumflag || noparserflag)
{
if (toknumflag || noparserflag)
{
/* Output YYTOKNUM. */
if (toknumflag)
{
/* 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 ("\
}
/* Output YYR1. */
fputs ("\
-/* YYR1[YYN]: Symbol number of symbol that rule YYN derives. */\n\
-static const short yyr1[] = { 0", ftable);
-
- j = 10;
- for (i = 1; i <= nrules; i++)
- {
- putc (',', ftable);
-
- if (j >= 10)
- {
- putc ('\n', ftable);
- j = 1;
- }
- else
- {
- j++;
- }
+/* YYR1[YYN]: Symbol number of symbol that rule YYN derives. */\n", ftable);
- fprintf (ftable, "%6d", rlhs[i]);
- }
+ output_short_table (ftable, "yyr1", rlhs,
+ 0, 1, nrules + 1);
- fputs ("\n\
-};\n\
-\n", ftable);
/* Output YYR2. */
fputs ("\
/* Output YYR2. */
fputs ("\
static void
output_base (void)
{
static void
output_base (void)
{
+ output_short_table (ftable, "yypact", base,
+ base[0], 1, nstates);
- fprintf (ftable, "\nstatic const short yypact[] = {%6d", base[0]);
- 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");
static void
output_table (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);
static void
output_check (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);
sort_actions ();
pack_table ();
sort_actions ();
pack_table ();
output_base ();
output_table ();
output_base ();
output_table ();
static symbol_list *grammar;
static int start_flag;
static bucket *startval;
static symbol_list *grammar;
static int start_flag;
static bucket *startval;
-/* 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)
static inline void
copy_comment (FILE *fin, FILE *fout, int c)
tags = NEW2(nsyms + 1, char *);
tags[0] = DOLLAR;
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);
user_toknums[0] = 0;
sprec = NEW2(nsyms, short);