Also handle the output file (--verbose) with obstacks.

* files.c (foutput): Remove.
(output_obstack): New.
Adjust all dependencies.
* src/conflicts.c: Return a string.
* src/system.h (obstack_grow_string): Rename as...
(obstack_sgrow): this.  Be ready to work with non literals.
(obstack_fgrow4): New.
This commit is contained in:
Akim Demaille
2000-12-20 17:21:14 +00:00
parent 956dba3a7c
commit ff4423cc28
9 changed files with 242 additions and 206 deletions

View File

@@ -1,3 +1,15 @@
2000-12-20 Akim Demaille <akim@epita.fr>
Also handle the output file (--verbose) with obstacks.
* files.c (foutput): Remove.
(output_obstack): New.
Adjust all dependencies.
* src/conflicts.c: Return a string.
* src/system.h (obstack_grow_string): Rename as...
(obstack_sgrow): this. Be ready to work with non literals.
(obstack_fgrow4): New.
2000-12-20 Akim Demaille <akim@epita.fr> 2000-12-20 Akim Demaille <akim@epita.fr>
* src/files.c (open_files): Fix the computation of short_base_name * src/files.c (open_files): Fix the computation of short_base_name

View File

@@ -45,11 +45,10 @@ static int rrc_count;
static inline void static inline void
log_resolution (int state, int LAno, int token, char *resolution) log_resolution (int state, int LAno, int token, char *resolution)
{ {
if (verbose_flag) obstack_fgrow4 (&output_obstack,
fprintf (foutput, _("\
_("\
Conflict in state %d between rule %d and token %s resolved as %s.\n"), Conflict in state %d between rule %d and token %s resolved as %s.\n"),
state, LAruleno[LAno], tags[token], resolution); state, LAruleno[LAno], tags[token], resolution);
} }
@@ -407,29 +406,38 @@ count_rr_conflicts (int state)
} }
} }
/*----------------------------------------------------------. /*--------------------------------------------------------------.
| Output to OUT a human readable report on shift/reduce and | | Return a human readable string which reports shift/reduce and |
| reduce/reduce conflict numbers (SRC_NUM, RRC_NUM). | | reduce/reduce conflict numbers (SRC_NUM, RRC_NUM). |
`----------------------------------------------------------*/ `--------------------------------------------------------------*/
static void static const char *
conflict_report (FILE *out, int src_num, int rrc_num) conflict_report (int src_num, int rrc_num)
{ {
static char res[4096];
char *cp = res;
if (src_num == 1) if (src_num == 1)
fprintf (out, _(" 1 shift/reduce conflict")); sprintf (cp, _(" 1 shift/reduce conflict"));
else if (src_num > 1) else if (src_num > 1)
fprintf (out, _(" %d shift/reduce conflicts"), src_num); sprintf (cp, _(" %d shift/reduce conflicts"), src_num);
cp += strlen (cp);
if (src_num > 0 && rrc_num > 0) if (src_num > 0 && rrc_num > 0)
fprintf (out, _(" and")); sprintf (cp, _(" and"));
cp += strlen (cp);
if (rrc_num == 1) if (rrc_num == 1)
fprintf (out, _(" 1 reduce/reduce conflict")); sprintf (cp, _(" 1 reduce/reduce conflict"));
else if (rrc_num > 1) else if (rrc_num > 1)
fprintf (out, _(" %d reduce/reduce conflicts"), rrc_num); sprintf (cp, _(" %d reduce/reduce conflicts"), rrc_num);
cp += strlen (cp);
putc ('.', out); *cp++ = '.';
putc ('\n', out); *cp++ = '\n';
*cp++ = '\0';
return res;
} }
@@ -458,8 +466,9 @@ print_conflicts (void)
if (verbose_flag) if (verbose_flag)
{ {
fprintf (foutput, _("State %d contains"), i); obstack_fgrow1 (&output_obstack, _("State %d contains"), i);
conflict_report (foutput, src_count, rrc_count); obstack_sgrow (&output_obstack,
conflict_report (src_count, rrc_count));
} }
} }
} }
@@ -481,7 +490,7 @@ print_conflicts (void)
else else
{ {
fprintf (stderr, _("%s contains"), infile); fprintf (stderr, _("%s contains"), infile);
conflict_report (stderr, src_total, rrc_total); fputs (conflict_report (src_total, rrc_total), stderr);
} }
} }
@@ -565,8 +574,9 @@ print_reductions (int state)
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
{ {
if (mask & *fp3) if (mask & *fp3)
fprintf (foutput, _(" %-4s\t[reduce using rule %d (%s)]\n"), obstack_fgrow3 (&output_obstack,
tags[i], default_rule, tags[rlhs[default_rule]]); _(" %-4s\t[reduce using rule %d (%s)]\n"),
tags[i], default_rule, tags[rlhs[default_rule]]);
mask <<= 1; mask <<= 1;
if (mask == 0) if (mask == 0)
@@ -576,8 +586,9 @@ print_reductions (int state)
} }
} }
fprintf (foutput, _(" $default\treduce using rule %d (%s)\n\n"), obstack_fgrow2 (&output_obstack,
default_rule, tags[rlhs[default_rule]]); _(" $default\treduce using rule %d (%s)\n\n"),
default_rule, tags[rlhs[default_rule]]);
} }
else if (n - m >= 1) else if (n - m >= 1)
{ {
@@ -664,7 +675,7 @@ print_reductions (int state)
if (j != default_LA) if (j != default_LA)
{ {
rule = LAruleno[j]; rule = LAruleno[j];
fprintf (foutput, obstack_fgrow3 (&output_obstack,
_(" %-4s\treduce using rule %d (%s)\n"), _(" %-4s\treduce using rule %d (%s)\n"),
tags[i], rule, tags[rlhs[rule]]); tags[i], rule, tags[rlhs[rule]]);
} }
@@ -678,13 +689,13 @@ print_reductions (int state)
if (defaulted) if (defaulted)
{ {
rule = LAruleno[default_LA]; rule = LAruleno[default_LA];
fprintf (foutput, obstack_fgrow3 (&output_obstack,
_(" %-4s\treduce using rule %d (%s)\n"), _(" %-4s\treduce using rule %d (%s)\n"),
tags[i], rule, tags[rlhs[rule]]); tags[i], rule, tags[rlhs[rule]]);
defaulted = 0; defaulted = 0;
} }
rule = LAruleno[j]; rule = LAruleno[j];
fprintf (foutput, obstack_fgrow3 (&output_obstack,
_(" %-4s\t[reduce using rule %d (%s)]\n"), _(" %-4s\t[reduce using rule %d (%s)]\n"),
tags[i], rule, tags[rlhs[rule]]); tags[i], rule, tags[rlhs[rule]]);
} }
@@ -705,12 +716,11 @@ print_reductions (int state)
} }
if (default_LA >= 0) if (default_LA >= 0)
{ obstack_fgrow2 (&output_obstack,
fprintf (foutput, _(" $default\treduce using rule %d (%s)\n"), _(" $default\treduce using rule %d (%s)\n"),
default_rule, tags[rlhs[default_rule]]); default_rule, tags[rlhs[default_rule]]);
}
putc ('\n', foutput); obstack_1grow (&output_obstack, '\n');
} }
} }

View File

@@ -27,13 +27,13 @@
#include "complain.h" #include "complain.h"
FILE *finput = NULL; FILE *finput = NULL;
FILE *foutput = NULL;
struct obstack action_obstack; struct obstack action_obstack;
struct obstack attrs_obstack; struct obstack attrs_obstack;
struct obstack table_obstack; struct obstack table_obstack;
struct obstack defines_obstack; struct obstack defines_obstack;
struct obstack guard_obstack; struct obstack guard_obstack;
struct obstack output_obstack;
char *spec_outfile; /* for -o. */ char *spec_outfile; /* for -o. */
char *spec_file_prefix; /* for -b. */ char *spec_file_prefix; /* for -b. */
@@ -249,11 +249,6 @@ open_files (void)
finput = xfopen (infile, "r"); finput = xfopen (infile, "r");
if (verbose_flag)
/* We used to use just .out if spec_name_prefix (-p) was used, but
that conflicts with Posix. */
foutput = xfopen (stringappend (short_base_name, EXT_OUTPUT), "w");
attrsfile = stringappend (short_base_name, EXT_STYPE_H); attrsfile = stringappend (short_base_name, EXT_STYPE_H);
/* Initialize the obstacks. */ /* Initialize the obstacks. */
@@ -262,6 +257,7 @@ open_files (void)
obstack_init (&table_obstack); obstack_init (&table_obstack);
obstack_init (&defines_obstack); obstack_init (&defines_obstack);
obstack_init (&guard_obstack); obstack_init (&guard_obstack);
obstack_init (&output_obstack);
} }
@@ -274,7 +270,6 @@ void
output_files (void) output_files (void)
{ {
xfclose (finput); xfclose (finput);
xfclose (foutput);
/* Output the main file. */ /* Output the main file. */
if (spec_outfile) if (spec_outfile)
@@ -298,4 +293,9 @@ output_files (void)
obstack_save (&guard_obstack, obstack_save (&guard_obstack,
stringappend (short_base_name, EXT_GUARD_C)); stringappend (short_base_name, EXT_GUARD_C));
} }
if (verbose_flag)
/* We used to use just .out if spec_name_prefix (-p) was used, but
that conflicts with Posix. */
obstack_save (&output_obstack, stringappend (short_base_name, EXT_OUTPUT));
} }

View File

@@ -37,10 +37,6 @@ extern char *spec_file_prefix;
/* Read grammar specifications. */ /* Read grammar specifications. */
extern FILE *finput; extern FILE *finput;
/* Optionally output messages describing the actions taken. */
extern FILE *foutput;
/* Output all the action code; precise form depends on which parser. */ /* Output all the action code; precise form depends on which parser. */
extern struct obstack action_obstack; extern struct obstack action_obstack;
@@ -57,6 +53,9 @@ extern struct obstack attrs_obstack;
/* ... and output yyguard, containing all the guard code. */ /* ... and output yyguard, containing all the guard code. */
extern struct obstack guard_obstack; extern struct obstack guard_obstack;
/* The verbose output. */
extern struct obstack output_obstack;
extern char *infile; extern char *infile;
extern char *attrsfile; extern char *attrsfile;

View File

@@ -150,7 +150,7 @@ output_short_or_char_table (struct obstack *oout,
if (j >= 10) if (j >= 10)
{ {
obstack_grow_string (oout, "\n "); obstack_sgrow (oout, "\n ");
j = 1; j = 1;
} }
else else
@@ -161,7 +161,7 @@ output_short_or_char_table (struct obstack *oout,
obstack_fgrow1 (oout, "%6d", short_table[i]); obstack_fgrow1 (oout, "%6d", short_table[i]);
} }
obstack_grow_string (oout, "\n};\n"); obstack_sgrow (oout, "\n};\n");
} }
@@ -234,7 +234,7 @@ output_headers (void)
if (semantic_parser) if (semantic_parser)
obstack_fgrow1 (&action_obstack, ACTSTR, attrsfile_quoted); obstack_fgrow1 (&action_obstack, ACTSTR, attrsfile_quoted);
else else
obstack_grow_string (&action_obstack, ACTSTR_SIMPLE); obstack_sgrow (&action_obstack, ACTSTR_SIMPLE);
/* Rename certain symbols if -p was specified. */ /* Rename certain symbols if -p was specified. */
if (spec_name_prefix) if (spec_name_prefix)
@@ -265,7 +265,7 @@ void
output_trailers (void) output_trailers (void)
{ {
if (semantic_parser) if (semantic_parser)
obstack_grow_string (&guard_obstack, "\n }\n}\n"); obstack_sgrow (&guard_obstack, "\n }\n}\n");
obstack_1grow (&action_obstack, '\n'); obstack_1grow (&action_obstack, '\n');
@@ -273,9 +273,9 @@ output_trailers (void)
return; return;
if (semantic_parser) if (semantic_parser)
obstack_grow_string (&action_obstack, " }\n"); obstack_sgrow (&action_obstack, " }\n");
obstack_grow_string (&action_obstack, "}\n"); obstack_sgrow (&action_obstack, "}\n");
} }
@@ -283,7 +283,7 @@ output_trailers (void)
static void static void
output_token_translations (void) output_token_translations (void)
{ {
obstack_grow_string (&table_obstack, "\ obstack_sgrow (&table_obstack, "\
\n\ \n\
/* YYRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n"); /* YYRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n");
@@ -303,7 +303,7 @@ output_token_translations (void)
} }
else else
{ {
obstack_grow_string (&table_obstack, obstack_sgrow (&table_obstack,
"\n#define YYTRANSLATE(x) (x)\n"); "\n#define YYTRANSLATE(x) (x)\n");
} }
} }
@@ -316,7 +316,7 @@ output_gram (void)
yyprhs and yyrhs are needed only for yydebug. */ yyprhs and yyrhs are needed only for yydebug. */
/* With the no_parser option, all tables are generated */ /* With the no_parser option, all tables are generated */
if (!semantic_parser && !no_parser_flag) if (!semantic_parser && !no_parser_flag)
obstack_grow_string (&table_obstack, "\n#if YYDEBUG != 0\n"); obstack_sgrow (&table_obstack, "\n#if YYDEBUG != 0\n");
output_short_table (&table_obstack, NULL, "yyprhs", rrhs, output_short_table (&table_obstack, NULL, "yyprhs", rrhs,
0, 1, nrules + 1); 0, 1, nrules + 1);
@@ -339,7 +339,7 @@ output_gram (void)
} }
if (!semantic_parser && !no_parser_flag) if (!semantic_parser && !no_parser_flag)
obstack_grow_string (&table_obstack, "\n#endif\n"); obstack_sgrow (&table_obstack, "\n#endif\n");
} }
@@ -358,7 +358,7 @@ output_rule_data (void)
int j; int j;
short *short_tab = NULL; short *short_tab = NULL;
obstack_grow_string (&table_obstack, "\n\ obstack_sgrow (&table_obstack, "\n\
#if YYDEBUG != 0\n"); #if YYDEBUG != 0\n");
output_short_table (&table_obstack, output_short_table (&table_obstack,
@@ -366,7 +366,7 @@ output_rule_data (void)
"yyrline", rline, "yyrline", rline,
0, 1, nrules + 1); 0, 1, nrules + 1);
obstack_grow_string (&table_obstack, "#endif\n\n"); obstack_sgrow (&table_obstack, "#endif\n\n");
if (token_table_flag || no_parser_flag) if (token_table_flag || no_parser_flag)
{ {
@@ -380,11 +380,11 @@ output_rule_data (void)
/* Output the table of symbol names. */ /* Output the table of symbol names. */
if (!token_table_flag && !no_parser_flag) if (!token_table_flag && !no_parser_flag)
obstack_grow_string (&table_obstack, obstack_sgrow (&table_obstack,
"\n#if YYDEBUG != 0 || defined YYERROR_VERBOSE\n\n"); "\n#if YYDEBUG != 0 || defined YYERROR_VERBOSE\n\n");
obstack_grow_string (&table_obstack, "\ obstack_sgrow (&table_obstack, "\
/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */\n"); /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */\n");
obstack_grow_string (&table_obstack, obstack_sgrow (&table_obstack,
"static const char *const yytname[] =\n{\n "); "static const char *const yytname[] =\n{\n ");
j = 0; j = 0;
@@ -408,7 +408,7 @@ output_rule_data (void)
if (j + strsize > 75) if (j + strsize > 75)
{ {
obstack_grow_string (&table_obstack, "\n "); obstack_sgrow (&table_obstack, "\n ");
j = 2; j = 2;
} }
@@ -418,25 +418,25 @@ output_rule_data (void)
if (*p == '"' || *p == '\\') if (*p == '"' || *p == '\\')
obstack_fgrow1 (&table_obstack, "\\%c", *p); obstack_fgrow1 (&table_obstack, "\\%c", *p);
else if (*p == '\n') else if (*p == '\n')
obstack_grow_string (&table_obstack, "\\n"); obstack_sgrow (&table_obstack, "\\n");
else if (*p == '\t') else if (*p == '\t')
obstack_grow_string (&table_obstack, "\\t"); obstack_sgrow (&table_obstack, "\\t");
else if (*p == '\b') else if (*p == '\b')
obstack_grow_string (&table_obstack, "\\b"); obstack_sgrow (&table_obstack, "\\b");
else if (*p < 040 || *p >= 0177) else if (*p < 040 || *p >= 0177)
obstack_fgrow1 (&table_obstack, "\\%03o", *p); obstack_fgrow1 (&table_obstack, "\\%03o", *p);
else else
obstack_1grow (&table_obstack, *p); obstack_1grow (&table_obstack, *p);
} }
obstack_grow_string (&table_obstack, "\", "); obstack_sgrow (&table_obstack, "\", ");
j += strsize; j += strsize;
} }
/* add a NULL entry to list of tokens */ /* add a NULL entry to list of tokens */
obstack_grow_string (&table_obstack, "NULL\n};\n"); obstack_sgrow (&table_obstack, "NULL\n};\n");
if (!token_table_flag && !no_parser_flag) if (!token_table_flag && !no_parser_flag)
obstack_grow_string (&table_obstack, "#endif\n\n"); obstack_sgrow (&table_obstack, "#endif\n\n");
/* Output YYTOKNUM. */ /* Output YYTOKNUM. */
if (token_table_flag) if (token_table_flag)
@@ -1150,7 +1150,7 @@ output_parser (void)
int actions_dumped = 0; int actions_dumped = 0;
if (pure_parser) if (pure_parser)
obstack_grow_string (&table_obstack, "#define YYPURE 1\n\n"); obstack_sgrow (&table_obstack, "#define YYPURE 1\n\n");
/* Loop over lines in the standard parser file. */ /* Loop over lines in the standard parser file. */
if (semantic_parser) if (semantic_parser)
@@ -1187,13 +1187,13 @@ output_parser (void)
if ((c = getc (fskel)) == 'e') if ((c = getc (fskel)) == 'e')
line_type = sync_line; line_type = sync_line;
else else
obstack_grow_string (&table_obstack, "#lin"); obstack_sgrow (&table_obstack, "#lin");
else else
obstack_grow_string (&table_obstack, "#li"); obstack_sgrow (&table_obstack, "#li");
else else
obstack_grow_string (&table_obstack, "#l"); obstack_sgrow (&table_obstack, "#l");
else else
obstack_grow_string (&table_obstack, "#"); obstack_sgrow (&table_obstack, "#");
} }
else if (c == '%') else if (c == '%')
{ {
@@ -1209,23 +1209,23 @@ output_parser (void)
if ((c = getc (fskel)) == 's') if ((c = getc (fskel)) == 's')
line_type = actions_line; line_type = actions_line;
else else
obstack_grow_string (&table_obstack, "%% action"); obstack_sgrow (&table_obstack, "%% action");
else else
obstack_grow_string (&table_obstack, "%% actio"); obstack_sgrow (&table_obstack, "%% actio");
else else
obstack_grow_string (&table_obstack, "%% acti"); obstack_sgrow (&table_obstack, "%% acti");
else else
obstack_grow_string (&table_obstack, "%% act"); obstack_sgrow (&table_obstack, "%% act");
else else
obstack_grow_string (&table_obstack, "%% ac"); obstack_sgrow (&table_obstack, "%% ac");
else else
obstack_grow_string (&table_obstack, "%% a"); obstack_sgrow (&table_obstack, "%% a");
else else
obstack_grow_string (&table_obstack, "%% "); obstack_sgrow (&table_obstack, "%% ");
else else
obstack_grow_string (&table_obstack, "%%"); obstack_sgrow (&table_obstack, "%%");
else else
obstack_grow_string (&table_obstack, "%"); obstack_sgrow (&table_obstack, "%");
} }
switch (line_type) switch (line_type)
@@ -1317,7 +1317,7 @@ output (void)
} }
reader_output_yylsp (&table_obstack); reader_output_yylsp (&table_obstack);
if (debug_flag) if (debug_flag)
obstack_grow_string (&table_obstack, "\ obstack_sgrow (&table_obstack, "\
#ifndef YYDEBUG\n\ #ifndef YYDEBUG\n\
# define YYDEBUG 1\n\ # define YYDEBUG 1\n\
#endif\n\ #endif\n\
@@ -1328,10 +1328,10 @@ output (void)
quotearg_style (c_quoting_style, attrsfile)); quotearg_style (c_quoting_style, attrsfile));
if (!no_parser_flag) if (!no_parser_flag)
obstack_grow_string (&table_obstack, "#include <stdio.h>\n\n"); obstack_sgrow (&table_obstack, "#include <stdio.h>\n\n");
/* Make "const" do nothing if not in ANSI C. */ /* Make "const" do nothing if not in ANSI C. */
obstack_grow_string (&table_obstack, "\ obstack_sgrow (&table_obstack, "\
#ifndef __cplusplus\n\ #ifndef __cplusplus\n\
# ifndef __STDC__\n\ # ifndef __STDC__\n\
# define const\n\ # define const\n\

View File

@@ -35,7 +35,7 @@
static void static void
print_token (int extnum, int token) print_token (int extnum, int token)
{ {
fprintf (foutput, _(" type %d is %s\n"), extnum, tags[token]); obstack_fgrow2 (&output_obstack, _(" type %d is %s\n"), extnum, tags[token]);
} }
#endif #endif
@@ -68,26 +68,26 @@ print_core (int state)
sp++; sp++;
rule = -(*sp); rule = -(*sp);
fprintf (foutput, " %s -> ", tags[rlhs[rule]]); obstack_fgrow1 (&output_obstack, " %s -> ", tags[rlhs[rule]]);
for (sp = ritem + rrhs[rule]; sp < sp1; sp++) for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
{ {
fprintf (foutput, "%s ", tags[*sp]); obstack_fgrow1 (&output_obstack, "%s ", tags[*sp]);
} }
putc ('.', foutput); obstack_1grow (&output_obstack, '.');
while (*sp > 0) while (*sp > 0)
{ {
fprintf (foutput, " %s", tags[*sp]); obstack_fgrow1 (&output_obstack, " %s", tags[*sp]);
sp++; sp++;
} }
fprintf (foutput, _(" (rule %d)"), rule); obstack_fgrow1 (&output_obstack, _(" (rule %d)"), rule);
putc ('\n', foutput); obstack_1grow (&output_obstack, '\n');
} }
putc ('\n', foutput); obstack_1grow (&output_obstack, '\n');
} }
static void static void
@@ -109,9 +109,9 @@ print_actions (int state)
if (!shiftp && !redp) if (!shiftp && !redp)
{ {
if (final_state == state) if (final_state == state)
fprintf (foutput, _(" $default\taccept\n")); obstack_sgrow (&output_obstack, _(" $default\taccept\n"));
else else
fprintf (foutput, _(" NO ACTIONS\n")); obstack_sgrow (&output_obstack, _(" NO ACTIONS\n"));
return; return;
} }
@@ -129,14 +129,16 @@ print_actions (int state)
if (ISVAR (symbol)) if (ISVAR (symbol))
break; break;
if (symbol == 0) /* I.e. strcmp(tags[symbol],"$")==0 */ if (symbol == 0) /* I.e. strcmp(tags[symbol],"$")==0 */
fprintf (foutput, _(" $ \tgo to state %d\n"), state1); obstack_fgrow1 (&output_obstack,
_(" $ \tgo to state %d\n"), state1);
else else
fprintf (foutput, _(" %-4s\tshift, and go to state %d\n"), obstack_fgrow2 (&output_obstack,
tags[symbol], state1); _(" %-4s\tshift, and go to state %d\n"),
tags[symbol], state1);
} }
if (i > 0) if (i > 0)
putc ('\n', foutput); obstack_1grow (&output_obstack, '\n');
} }
else else
{ {
@@ -155,20 +157,21 @@ print_actions (int state)
if (!errp->errs[j]) if (!errp->errs[j])
continue; continue;
symbol = errp->errs[j]; symbol = errp->errs[j];
fprintf (foutput, _(" %-4s\terror (nonassociative)\n"), obstack_fgrow1 (&output_obstack, _(" %-4s\terror (nonassociative)\n"),
tags[symbol]); tags[symbol]);
} }
if (j > 0) if (j > 0)
putc ('\n', foutput); obstack_1grow (&output_obstack, '\n');
} }
if (consistent[state] && redp) if (consistent[state] && redp)
{ {
rule = redp->rules[0]; rule = redp->rules[0];
symbol = rlhs[rule]; symbol = rlhs[rule];
fprintf (foutput, _(" $default\treduce using rule %d (%s)\n\n"), obstack_fgrow2 (&output_obstack,
rule, tags[symbol]); _(" $default\treduce using rule %d (%s)\n\n"),
rule, tags[symbol]);
} }
else if (redp) else if (redp)
{ {
@@ -183,20 +186,21 @@ print_actions (int state)
continue; continue;
state1 = shiftp->shifts[i]; state1 = shiftp->shifts[i];
symbol = accessing_symbol[state1]; symbol = accessing_symbol[state1];
fprintf (foutput, _(" %-4s\tgo to state %d\n"), tags[symbol], obstack_fgrow2 (&output_obstack,
state1); _(" %-4s\tgo to state %d\n"),
tags[symbol], state1);
} }
putc ('\n', foutput); obstack_1grow (&output_obstack, '\n');
} }
} }
static void static void
print_state (int state) print_state (int state)
{ {
fputs ("\n\n", foutput); obstack_sgrow (&output_obstack, "\n\n");
fprintf (foutput, _("state %d"), state); obstack_fgrow1 (&output_obstack, _("state %d"), state);
fputs ("\n\n", foutput); obstack_sgrow (&output_obstack, "\n\n");
print_core (state); print_core (state);
print_actions (state); print_actions (state);
} }
@@ -205,14 +209,15 @@ print_state (int state)
| Print information on the whole grammar. | | Print information on the whole grammar. |
`-----------------------------------------*/ `-----------------------------------------*/
#define END_TEST(end) \ #define END_TEST(End) \
do { \ do { \
if (column + strlen(buffer) > (end)) { \ if (column + strlen(buffer) > (End)) \
fprintf (foutput, "%s\n ", buffer); \ { \
column = 3; \ obstack_fgrow1 (&output_obstack, "%s\n ", buffer); \
buffer[0] = 0; \ column = 3; \
} \ buffer[0] = 0; \
} while (0) } \
} while (0)
static void static void
@@ -224,28 +229,30 @@ print_grammar (void)
int column = 0; int column = 0;
/* rule # : LHS -> RHS */ /* rule # : LHS -> RHS */
putc ('\n', foutput); obstack_1grow (&output_obstack, '\n');
fputs (_("Grammar"), foutput); obstack_sgrow (&output_obstack, _("Grammar"));
putc ('\n', foutput); obstack_1grow (&output_obstack, '\n');
for (i = 1; i <= nrules; i++) for (i = 1; i <= nrules; i++)
/* Don't print rules disabled in reduce_grammar_tables. */ /* Don't print rules disabled in reduce_grammar_tables. */
if (rlhs[i] >= 0) if (rlhs[i] >= 0)
{ {
fprintf (foutput, _("rule %-4d %s ->"), i, tags[rlhs[i]]); obstack_fgrow2 (&output_obstack,
_("rule %-4d %s ->"), i, tags[rlhs[i]]);
rule = &ritem[rrhs[i]]; rule = &ritem[rrhs[i]];
if (*rule > 0) if (*rule > 0)
while (*rule > 0) while (*rule > 0)
fprintf (foutput, " %s", tags[*rule++]); obstack_fgrow1 (&output_obstack, " %s", tags[*rule++]);
else else
fputs (_(" /* empty */"), foutput); obstack_sgrow (&output_obstack, _(" /* empty */"));
putc ('\n', foutput); obstack_1grow (&output_obstack, '\n');
} }
/* TERMINAL (type #) : rule #s terminal is on RHS */ /* TERMINAL (type #) : rule #s terminal is on RHS */
fputs ("\n", foutput); obstack_sgrow (&output_obstack, "\n");
fputs (_("Terminals, with rules where they appear"), foutput); obstack_sgrow (&output_obstack,
fputs ("\n\n", foutput); _("Terminals, with rules where they appear"));
fprintf (foutput, "%s (-1)\n", tags[0]); obstack_sgrow (&output_obstack, "\n\n");
obstack_fgrow1 (&output_obstack, "%s (-1)\n", tags[0]);
if (translations) if (translations)
{ {
for (i = 0; i <= max_user_token_number; i++) for (i = 0; i <= max_user_token_number; i++)
@@ -253,34 +260,32 @@ print_grammar (void)
{ {
buffer[0] = 0; buffer[0] = 0;
column = strlen (tags[token_translations[i]]); column = strlen (tags[token_translations[i]]);
fprintf (foutput, "%s", tags[token_translations[i]]); obstack_sgrow (&output_obstack, tags[token_translations[i]]);
END_TEST (50); END_TEST (50);
sprintf (buffer, " (%d)", i); 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 == token_translations[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);
}
fprintf (foutput, "%s\n", buffer);
} }
} }
else else
for (i = 1; i < ntokens; i++) {
{ for (i = 1; i < ntokens; i++)
buffer[0] = 0; {
column = strlen (tags[i]); buffer[0] = 0;
fprintf (foutput, "%s", tags[i]); column = strlen (tags[i]);
END_TEST (50); obstack_sgrow (&output_obstack, tags[i]);
sprintf (buffer, " (%d)", 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 == i)
{ {
@@ -288,13 +293,14 @@ print_grammar (void)
sprintf (buffer + strlen (buffer), " %d", j); sprintf (buffer + strlen (buffer), " %d", j);
break; break;
} }
} obstack_fgrow1 (&output_obstack, "%s\n", buffer);
fprintf (foutput, "%s\n", buffer); }
} }
fputs ("\n", foutput); obstack_sgrow (&output_obstack, "\n");
fputs (_("Nonterminals, with rules where they appear"), foutput); obstack_sgrow (&output_obstack,
fputs ("\n\n", foutput); _("Nonterminals, with rules where they appear"));
obstack_sgrow (&output_obstack, "\n\n");
for (i = ntokens; i <= nsyms - 1; i++) for (i = ntokens; i <= nsyms - 1; i++)
{ {
int left_count = 0, right_count = 0; int left_count = 0, right_count = 0;
@@ -312,7 +318,7 @@ print_grammar (void)
} }
buffer[0] = 0; buffer[0] = 0;
fprintf (foutput, "%s", tags[i]); obstack_sgrow (&output_obstack, tags[i]);
column = strlen (tags[i]); column = strlen (tags[i]);
sprintf (buffer, " (%d)", i); sprintf (buffer, " (%d)", i);
END_TEST (0); END_TEST (0);
@@ -347,7 +353,7 @@ print_grammar (void)
} }
} }
} }
fprintf (foutput, "%s\n", buffer); obstack_fgrow1 (&output_obstack, "%s\n", buffer);
} }
} }

View File

@@ -309,7 +309,7 @@ copy_at (FILE *fin, struct obstack *oout, int stack_offset)
c = getc (fin); c = getc (fin);
if (c == '$') if (c == '$')
{ {
obstack_grow_string (oout, "yyloc"); obstack_sgrow (oout, "yyloc");
locations_flag = 1; locations_flag = 1;
} }
else if (isdigit (c) || c == '-') else if (isdigit (c) || c == '-')
@@ -360,7 +360,7 @@ copy_dollar (FILE *fin, struct obstack *oout,
if (c == '$') if (c == '$')
{ {
obstack_grow_string (oout, "yyval"); obstack_sgrow (oout, "yyval");
if (!type_name) if (!type_name)
type_name = get_type_name (0, rule); type_name = get_type_name (0, rule);
@@ -732,9 +732,9 @@ parse_union_decl (void)
else else
obstack_1grow (&attrs_obstack, '\n'); obstack_1grow (&attrs_obstack, '\n');
obstack_grow_string (&attrs_obstack, "typedef union"); obstack_sgrow (&attrs_obstack, "typedef union");
if (defines_flag) if (defines_flag)
obstack_grow_string (&defines_obstack, "typedef union"); obstack_sgrow (&defines_obstack, "typedef union");
c = getc (finput); c = getc (finput);
@@ -764,9 +764,9 @@ parse_union_decl (void)
count--; count--;
if (count <= 0) if (count <= 0)
{ {
obstack_grow_string (&attrs_obstack, " YYSTYPE;\n"); obstack_sgrow (&attrs_obstack, " YYSTYPE;\n");
if (defines_flag) if (defines_flag)
obstack_grow_string (&defines_obstack, " YYSTYPE;\n"); obstack_sgrow (&defines_obstack, " YYSTYPE;\n");
/* JF don't choke on trailing semi */ /* JF don't choke on trailing semi */
c = skip_white_space (); c = skip_white_space ();
if (c != ';') if (c != ';')
@@ -1061,7 +1061,7 @@ copy_action (symbol_list *rule, int stack_offset)
} }
} }
obstack_grow_string (&action_obstack, ";\n break;}"); obstack_sgrow (&action_obstack, ";\n break;}");
} }
/*-------------------------------------------------------------------. /*-------------------------------------------------------------------.
@@ -1149,7 +1149,7 @@ copy_guard (symbol_list *rule, int stack_offset)
c = skip_white_space (); c = skip_white_space ();
obstack_grow_string (&guard_obstack, ";\n break;}"); obstack_sgrow (&guard_obstack, ";\n break;}");
if (c == '{') if (c == '{')
copy_action (rule, stack_offset); copy_action (rule, stack_offset);
else if (c == '=') else if (c == '=')
@@ -1540,10 +1540,10 @@ readgram (void)
/* We used to use `unsigned long' as YYSTYPE on MSDOS, /* We used to use `unsigned long' as YYSTYPE on MSDOS,
but it seems better to be consistent. but it seems better to be consistent.
Most programs should declare their own type anyway. */ Most programs should declare their own type anyway. */
obstack_grow_string (&attrs_obstack, obstack_sgrow (&attrs_obstack,
"#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n"); "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
if (defines_flag) if (defines_flag)
obstack_grow_string (&defines_obstack, "\ obstack_sgrow (&defines_obstack, "\
#ifndef YYSTYPE\n\ #ifndef YYSTYPE\n\
# define YYSTYPE int\n\ # define YYSTYPE int\n\
#endif\n"); #endif\n");
@@ -1753,7 +1753,7 @@ packsymbols (void)
obstack_fgrow1 (&defines_obstack, "\nextern YYSTYPE %slval;\n", obstack_fgrow1 (&defines_obstack, "\nextern YYSTYPE %slval;\n",
spec_name_prefix); spec_name_prefix);
else else
obstack_grow_string (&defines_obstack, obstack_sgrow (&defines_obstack,
"\nextern YYSTYPE yylval;\n"); "\nextern YYSTYPE yylval;\n");
} }
@@ -1906,7 +1906,7 @@ reader (void)
no_parser_flag ? "Bison-generated parse tables" : "A Bison parser", no_parser_flag ? "Bison-generated parse tables" : "A Bison parser",
infile, VERSION); infile, VERSION);
obstack_grow_string (&table_obstack, obstack_sgrow (&table_obstack,
"#define YYBISON 1 /* Identify Bison output. */\n\n"); "#define YYBISON 1 /* Identify Bison output. */\n\n");
read_declarations (); read_declarations ();
/* Start writing the guard and action files, if they are needed. */ /* Start writing the guard and action files, if they are needed. */
@@ -1921,7 +1921,7 @@ reader (void)
/* Write closing delimiters for actions and guards. */ /* Write closing delimiters for actions and guards. */
output_trailers (); output_trailers ();
if (locations_flag) if (locations_flag)
obstack_grow_string (&table_obstack, "#define YYLSP_NEEDED 1\n\n"); obstack_sgrow (&table_obstack, "#define YYLSP_NEEDED 1\n\n");
/* Assign the symbols their symbol numbers. Write #defines for the /* Assign the symbols their symbol numbers. Write #defines for the
token symbols into FDEFINES if requested. */ token symbols into FDEFINES if requested. */
packsymbols (); packsymbols ();
@@ -1942,7 +1942,7 @@ void
reader_output_yylsp (struct obstack *oout) reader_output_yylsp (struct obstack *oout)
{ {
if (locations_flag) if (locations_flag)
obstack_grow_string (oout, "\ obstack_sgrow (oout, "\
\n\ \n\
#ifndef YYLTYPE\n\ #ifndef YYLTYPE\n\
typedef struct yyltype\n\ typedef struct yyltype\n\

View File

@@ -401,11 +401,11 @@ print_results (void)
if (nuseless_nonterminals > 0) if (nuseless_nonterminals > 0)
{ {
fputs (_("Useless nonterminals:"), foutput); obstack_sgrow (&output_obstack, _("Useless nonterminals:"));
fputs ("\n\n", foutput); obstack_sgrow (&output_obstack, "\n\n");
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
if (!BITISSET (V, i)) if (!BITISSET (V, i))
fprintf (foutput, " %s\n", tags[i]); obstack_fgrow1 (&output_obstack, " %s\n", tags[i]);
} }
b = FALSE; b = FALSE;
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
@@ -414,36 +414,35 @@ print_results (void)
{ {
if (!b) if (!b)
{ {
fputs ("\n\n", foutput); obstack_sgrow (&output_obstack, "\n\n");
fprintf (foutput, _("Terminals which are not used:")); obstack_sgrow (&output_obstack,
fputs ("\n\n", foutput); _("Terminals which are not used:"));
obstack_sgrow (&output_obstack, "\n\n");
b = TRUE; b = TRUE;
} }
fprintf (foutput, " %s\n", tags[i]); obstack_fgrow1 (&output_obstack, " %s\n", tags[i]);
} }
} }
if (nuseless_productions > 0) if (nuseless_productions > 0)
{ {
fputs ("\n\n", foutput); obstack_sgrow (&output_obstack, "\n\n");
fprintf (foutput, _("Useless rules:")); obstack_sgrow (&output_obstack, _("Useless rules:"));
fputs ("\n\n", foutput); obstack_sgrow (&output_obstack, "\n\n");
for (i = 1; i <= nrules; i++) for (i = 1; i <= nrules; i++)
{ {
if (!BITISSET (P, i)) if (!BITISSET (P, i))
{ {
fprintf (foutput, "#%-4d ", i); obstack_fgrow1 (&output_obstack, "#%-4d ", i);
fprintf (foutput, "%s :\t", tags[rlhs[i]]); obstack_fgrow1 (&output_obstack, "%s :\t", tags[rlhs[i]]);
for (r = &ritem[rrhs[i]]; *r >= 0; r++) for (r = &ritem[rrhs[i]]; *r >= 0; r++)
{ obstack_fgrow1 (&output_obstack, " %s", tags[*r]);
fprintf (foutput, " %s", tags[*r]); obstack_sgrow (&output_obstack, ";\n");
}
fprintf (foutput, ";\n");
} }
} }
} }
if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b) if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b)
fputs ("\n\n", foutput); obstack_sgrow (&output_obstack, "\n\n");
} }
#if 0 /* XXX currently unused. */ #if 0 /* XXX currently unused. */
@@ -453,35 +452,38 @@ dump_grammar (void)
int i; int i;
rule r; rule r;
fprintf (foutput, obstack_fgrow5 (&output_obstack,
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n", "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n",
ntokens, nvars, nsyms, nrules, nitems); ntokens, nvars, nsyms, nrules, nitems);
fprintf (foutput, _("Variables\n---------\n\n")); obstack_sgrow (&output_obstack,
fprintf (foutput, _("Value Sprec Sassoc Tag\n")); _("Variables\n---------\n\n"));
obstack_sgrow (&output_obstack,
_("Value Sprec Sassoc Tag\n"));
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
fprintf (foutput, "%5d %5d %5d %s\n", i, sprec[i], sassoc[i], tags[i]); obstack_fgrow4 (&output_obstack,
fprintf (foutput, "\n\n"); "%5d %5d %5d %s\n", i, sprec[i], sassoc[i], tags[i]);
fprintf (foutput, _("Rules\n-----\n\n")); obstack_sgrow (&output_obstack, "\n\n");
obstack_sgrow (&output_obstack, _("Rules\n-----\n\n"));
for (i = 1; i <= nrules; i++) for (i = 1; i <= nrules; i++)
{ {
fprintf (foutput, "%-5d(%5d%5d)%5d : (@%-5d)", obstack_fgrow5 (&output_obstack, "%-5d(%5d%5d)%5d : (@%-5d)",
i, rprec[i], rassoc[i], rlhs[i], rrhs[i]); i, rprec[i], rassoc[i], rlhs[i], rrhs[i]);
for (r = &ritem[rrhs[i]]; *r > 0; r++) for (r = &ritem[rrhs[i]]; *r > 0; r++)
fprintf (foutput, "%5d", *r); obstack_fgrow1 (&output_obstack, "%5d", *r);
fprintf (foutput, " [%d]\n", -(*r)); obstack_fgrow1 (&output_obstack, " [%d]\n", -(*r));
} }
fprintf (foutput, "\n\n"); obstack_sgrow (&output_obstack, "\n\n");
fprintf (foutput, _("Rules interpreted\n-----------------\n\n")); obstack_sgrow (&output_obstack,
_("Rules interpreted\n-----------------\n\n"));
for (i = 1; i <= nrules; i++) for (i = 1; i <= nrules; i++)
{ {
fprintf (foutput, "%-5d %s :", i, tags[rlhs[i]]); obstack_fgrow2 (&output_obstack, "%-5d %s :", i, tags[rlhs[i]]);
for (r = &ritem[rrhs[i]]; *r > 0; r++) for (r = &ritem[rrhs[i]]; *r > 0; r++)
fprintf (foutput, " %s", tags[*r]); obstack_fgrow1 (&output_obstack, " %s", tags[*r]);
fprintf (foutput, "\n"); obstack_grow1 (&output_obstack, '\n');
} }
fprintf (foutput, "\n\n"); obstack_sgrow (&output_obstack, "\n\n");
} }
#endif #endif
@@ -544,7 +546,7 @@ reduce_grammar (void)
#if 0 #if 0
if (verbose_flag) if (verbose_flag)
{ {
fprintf (foutput, "REDUCED GRAMMAR\n\n"); obstack_fgrow1 (&output_obstack, "REDUCED GRAMMAR\n\n");
dump_grammar (); dump_grammar ();
} }
#endif #endif

View File

@@ -145,8 +145,8 @@ typedef int bool;
#define obstack_chunk_free free #define obstack_chunk_free free
#include "obstack.h" #include "obstack.h"
#define obstack_grow_string(Obs, Str) \ #define obstack_sgrow(Obs, Str) \
obstack_grow (Obs, Str, sizeof (Str) - 1) obstack_grow (Obs, Str, strlen (Str))
#define obstack_fgrow1(Obs, Format, Arg1) \ #define obstack_fgrow1(Obs, Format, Arg1) \
do { \ do { \
@@ -169,6 +169,13 @@ do { \
obstack_grow (Obs, buf, strlen (buf)); \ obstack_grow (Obs, buf, strlen (buf)); \
} while (0) } while (0)
#define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
do { \
char buf[4096]; \
sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
obstack_grow (Obs, buf, strlen (buf)); \
} while (0)
/*---------------------------------. /*---------------------------------.
| Machine-dependencies for Bison. | | Machine-dependencies for Bison. |