X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/720d742f8e74acf1ade85a7d39c02fa5b9528b5a..8f52a1e790ca98162fc0625d81f3a032800d025e:/src/print.c?ds=sidebyside diff --git a/src/print.c b/src/print.c index 8e10e4cf..5f9ad9b6 100644 --- a/src/print.c +++ b/src/print.c @@ -20,59 +20,18 @@ #include "system.h" -#include "alloc.h" +#include "xalloc.h" #include "files.h" #include "gram.h" -#include "state.h" +#include "LR0.h" #include "lalr.h" +#include "conflicts.h" +#include "getargs.h" +#include "state.h" +#include "reader.h" +#include "print.h" -extern char **tags; -extern int nstates; -extern errs **err_table; -extern char any_conflicts; -extern char *conflicts; -extern int final_state; - -extern void conflict_log PARAMS ((void)); -extern void verbose_conflict_log PARAMS ((void)); -extern void print_reductions PARAMS ((int)); - -extern void terse PARAMS ((void)); -extern void verbose PARAMS ((void)); - -#if 0 /* XXX currently unused. */ -static void print_token PARAMS ((int, int)); -#endif - -static void print_state PARAMS ((int)); -static void print_core PARAMS ((int)); -static void print_actions PARAMS ((int)); -static void print_grammar PARAMS ((void)); - -void -terse (void) -{ - if (any_conflicts) - conflict_log (); -} - - -void -verbose (void) -{ - int i; - - if (any_conflicts) - verbose_conflict_log (); - - print_grammar (); - - for (i = 0; i < nstates; i++) - print_state (i); -} - - -#if 0 /* XXX currently unused. */ +#if 0 static void print_token (int extnum, int token) { @@ -80,15 +39,10 @@ print_token (int extnum, int token) } #endif - -static void -print_state (int state) -{ - fprintf (foutput, _("\n\nstate %d\n\n"), state); - print_core (state); - print_actions (state); -} - + +/*================================\ +| Report information on a state. | +\================================*/ static void print_core (int state) @@ -136,7 +90,6 @@ print_core (int state) putc ('\n', foutput); } - static void print_actions (int state) { @@ -238,6 +191,20 @@ print_actions (int state) } } +static void +print_state (int state) +{ + fputs ("\n\n", foutput); + fprintf (foutput, _("state %d"), state); + fputs ("\n\n", foutput); + print_core (state); + print_actions (state); +} + +/*-----------------------------------------. +| Print information on the whole grammar. | +`-----------------------------------------*/ + #define END_TEST(end) \ do { \ if (column + strlen(buffer) > (end)) { \ @@ -247,6 +214,7 @@ print_actions (int state) } \ } while (0) + static void print_grammar (void) { @@ -256,7 +224,9 @@ print_grammar (void) int column = 0; /* rule # : LHS -> RHS */ - fputs (_("\nGrammar\n"), foutput); + putc ('\n', foutput); + fputs (_("Grammar"), foutput); + putc ('\n', foutput); for (i = 1; i <= nrules; i++) /* Don't print rules disabled in reduce_grammar_tables. */ if (rlhs[i] >= 0) @@ -272,7 +242,9 @@ print_grammar (void) } /* TERMINAL (type #) : rule #s terminal is on RHS */ - fputs (_("\nTerminals, with rules where they appear\n\n"), foutput); + fputs ("\n", foutput); + fputs (_("Terminals, with rules where they appear"), foutput); + fputs ("\n\n", foutput); fprintf (foutput, "%s (-1)\n", tags[0]); if (translations) { @@ -320,7 +292,9 @@ print_grammar (void) fprintf (foutput, "%s\n", buffer); } - fputs (_("\nNonterminals, with rules where they appear\n\n"), foutput); + fputs ("\n", foutput); + fputs (_("Nonterminals, with rules where they appear"), foutput); + fputs ("\n\n", foutput); for (i = ntokens; i <= nsyms - 1; i++) { int left_count = 0, right_count = 0; @@ -376,3 +350,19 @@ print_grammar (void) fprintf (foutput, "%s\n", buffer); } } + +void +print_results (void) +{ + int i; + + if (any_conflicts) + print_conflicts (); + + if (verbose_flag) + print_grammar (); + + if (verbose_flag) + for (i = 0; i < nstates; i++) + print_state (i); +}