/* Output the generated parsing program for bison,
- Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
+ Copyright (C) 1984, 1986, 1989, 1992 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
You should have received a copy of the GNU General Public License
along with Bison; see the file COPYING. If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
/* functions to output parsing data to various files. Entries are:
The parser tables consist of these tables.
Starred ones needed only for the semantic parser.
+Double starred are output only if switches are set.
yytranslate = vector mapping yylex's token numbers into bison's token numbers.
-yytname = vector of string-names indexed by bison token number
+** yytname = vector of string-names indexed by bison token number
+
+** yytoknum = vector of yylex token numbers corresponding to entries in yytname
yyrline = vector of line-numbers of all rules. For yydebug printouts.
yypgoto[i] = the index in yytable of the portion describing
what to do after reducing a rule that derives variable i + ntokens.
- This portion is indexed by the parser state number
+ This portion is indexed by the parser state number, s,
as of before the text for this nonterminal was read.
- The value from yytable is the state to go to.
+ The value from yytable is the state to go to if
+ the corresponding value in yycheck is s.
yytable = a vector filled with portions for different uses,
found via yypact and yypgoto.
#include <stdio.h>
#include "system.h"
#include "machine.h"
-#include "new.h"
+#include "alloc.h"
#include "files.h"
#include "gram.h"
#include "state.h"
extern int debugflag;
extern int nolinesflag;
+extern int noparserflag;
+extern int toknumflag;
extern char **tags;
+extern int *user_toknums;
extern int tokensetsize;
extern int final_state;
extern core **state_table;
extern short *goto_map;
extern short *from_state;
extern short *to_state;
-
-void output_token_translations();
-void output_gram();
-void output_stos();
-void output_rule_data();
-void output_defines();
-void output_actions();
-void token_actions();
-void save_row();
-void goto_actions();
-void save_column();
-void sort_actions();
-void pack_table();
-void output_base();
-void output_table();
-void output_check();
-void output_parser();
-void output_program();
-void free_itemset();
-void free_shifts();
-void free_reductions();
-void free_itemsets();
-int action_row();
-int default_goto();
-int matching_state();
-int pack_vector();
-
-extern void berror();
-extern void fatals();
+extern int lineno;
+
+void output_headers PARAMS((void));
+void output_trailers PARAMS((void));
+void output PARAMS((void));
+void output_token_translations PARAMS((void));
+void output_gram PARAMS((void));
+void output_stos PARAMS((void));
+void output_rule_data PARAMS((void));
+void output_defines PARAMS((void));
+void output_actions PARAMS((void));
+void token_actions PARAMS((void));
+void save_row PARAMS((int));
+void goto_actions PARAMS((void));
+void save_column PARAMS((int, int));
+void sort_actions PARAMS((void));
+void pack_table PARAMS((void));
+void output_base PARAMS((void));
+void output_table PARAMS((void));
+void output_check PARAMS((void));
+void output_parser PARAMS((void));
+void output_program PARAMS((void));
+void free_shifts PARAMS((void));
+void free_reductions PARAMS((void));
+void free_itemsets PARAMS((void));
+int action_row PARAMS((int));
+int default_goto PARAMS((int));
+int matching_state PARAMS((int));
+int pack_vector PARAMS((int));
+
+extern void berror PARAMS((char *));
+extern void fatals PARAMS((char *, char *));
+extern char *int_to_string PARAMS((int));
+extern void reader_output_yylsp PARAMS((FILE *));
static int nvectors;
static int nentries;
void
-output_headers()
+output_headers (void)
{
if (semantic_parser)
fprintf(fguard, GUARDSTR, attrsfile);
+
+ if (noparserflag)
+ return;
+
fprintf(faction, (semantic_parser ? ACTSTR : ACTSTR_SIMPLE), attrsfile);
/* if (semantic_parser) JF moved this below
fprintf(ftable, "#include \"%s\"\n", attrsfile);
void
-output_trailers()
+output_trailers (void)
{
if (semantic_parser)
- {
fprintf(fguard, "\n }\n}\n");
- fprintf(faction, "\n }\n}\n");
- }
- else
- fprintf(faction, "\n}\n");
+
+ fprintf(faction, "\n");
+
+ if (noparserflag)
+ return;
+
+ if (semantic_parser)
+ fprintf(faction, " }\n");
+ fprintf(faction, "}\n");
}
void
-output()
+output (void)
{
int c;
while ((c=getc(fattrs))!=EOF)
putc(c,ftable);
}
-
+ reader_output_yylsp(ftable);
if (debugflag)
fprintf(ftable, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n\n",
!!debugflag);
if (semantic_parser)
fprintf(ftable, "#include \"%s\"\n", attrsfile);
- fprintf(ftable, "#include <stdio.h>\n\n");
+
+ if (! noparserflag)
+ fprintf(ftable, "#include <stdio.h>\n\n");
/* Make "const" do nothing if not in ANSI C. */
fprintf (ftable, "#ifndef __cplusplus\n#ifndef __STDC__\n#define const\n#endif\n#endif\n\n");
output_stos();
output_rule_data();
output_actions();
- output_parser();
+ if (! noparserflag)
+ output_parser();
output_program();
}
void
-output_token_translations()
+output_token_translations (void)
{
register int i, j;
/* register short *sp; JF unused */
void
-output_gram()
+output_gram (void)
{
register int i;
register int j;
register short *sp;
- /* With the ordinary parser,
- yyprhs and yyrhs are needed only for yydebug. */
- if (!semantic_parser)
+ /* With the ordinary parser,
+ 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};\n");
- if(!semantic_parser)
+ if (! semantic_parser && ! noparserflag)
fprintf(ftable, "\n#endif\n");
}
void
-output_stos()
+output_stos (void)
{
register int i;
register int j;
void
-output_rule_data()
+output_rule_data (void)
{
register int i;
register int j;
- fprintf(ftable, "\n#if YYDEBUG != 0\nstatic const short yyrline[] = { 0");
+ fprintf(ftable, "\n#if YYDEBUG != 0\n");
+ fprintf(ftable, "static const short yyrline[] = { 0");
j = 10;
for (i = 1; i <= nrules; i++)
fprintf(ftable, "%6d", rline[i]);
}
+ fprintf(ftable, "\n};\n#endif\n\n");
+
+ if (toknumflag || noparserflag)
+ {
+ fprintf(ftable, "#define YYNTOKENS %d\n", ntokens);
+ fprintf(ftable, "#define YYNNTS %d\n", nvars);
+ fprintf(ftable, "#define YYNRULES %d\n", nrules);
+ fprintf(ftable, "#define YYNSTATES %d\n", nstates);
+ fprintf(ftable, "#define YYMAXUTOK %d\n\n", max_user_token_number);
+ }
+
+ if (! toknumflag && ! noparserflag)
+ fprintf(ftable, "\n#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)\n\n");
/* Output the table of symbol names. */
fprintf(ftable,
- "\n};\n\nstatic const char * const yytname[] = { \"%s\"",
+ "static const char * const yytname[] = { \"%s\"",
tags[0]);
j = strlen (tags[0]) + 44;
- for (i = 1; i <= nsyms; i++)
+ for (i = 1; i < nsyms; i++)
+ /* this used to be i<=nsyms, but that output a final "" symbol
+ almost by accident */
{
register char *p;
putc(',', ftable);
putc ('\"', ftable);
j++;
}
+ fprintf(ftable, ", NULL\n};\n"); /* add a NULL entry to list of tokens */
- fprintf(ftable, "\n};\n#endif\n\nstatic const short yyr1[] = { 0");
+ if (! toknumflag && ! noparserflag)
+ fprintf(ftable, "#endif\n\n");
+
+ 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");
+ }
+
+ fprintf(ftable, "static const short yyr1[] = { 0");
j = 10;
for (i = 1; i <= nrules; i++)
void
-output_defines()
+output_defines (void)
{
fprintf(ftable, "\n\n#define\tYYFINAL\t\t%d\n", final_state);
fprintf(ftable, "#define\tYYFLAG\t\t%d\n", MINSHORT);
/* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable and yycheck. */
void
-output_actions()
+output_actions (void)
{
nvectors = nstates + nvars;
is saved for putting into yytable later. */
void
-token_actions()
+token_actions (void)
{
register int i;
register int j;
a token gets to handle it. */
int
-action_row(state)
-int state;
+action_row (int state)
{
register int i;
register int j;
register int k;
- register int m;
- register int n;
+ register int m = 0;
+ register int n = 0;
register int count;
register int default_rule;
register int nreds;
void
-save_row(state)
-int state;
+save_row (int state)
{
register int i;
register int count;
is saved for putting into yytable later. */
void
-goto_actions()
+goto_actions (void)
{
register int i;
register int j;
int
-default_goto(symbol)
-int symbol;
+default_goto (int symbol)
{
register int i;
register int m;
void
-save_column(symbol, default_state)
-int symbol;
-int default_state;
+save_column (int symbol, int default_state)
{
register int i;
register int m;
the actions and gotos information into yytable. */
void
-sort_actions()
+sort_actions (void)
{
register int i;
register int j;
void
-pack_table()
+pack_table (void)
{
register int i;
register int place;
int
-matching_state(vector)
-int vector;
+matching_state (int vector)
{
register int i;
register int j;
int
-pack_vector(vector)
-int vector;
+pack_vector (int vector)
{
register int i;
register int j;
register int k;
register int t;
- register int loc;
+ register int loc = 0;
register int ok;
register short *from;
register short *to;
{
loc = j + from[k];
if (loc > MAXTABLE)
- fatals("maximum table size (%d) exceeded",MAXTABLE);
+ fatals(_("maximum table size (%s) exceeded"), int_to_string(MAXTABLE));
if (table[loc] != 0)
ok = 0;
and the vectors whose elements index the portion starts */
void
-output_base()
+output_base (void)
{
register int i;
register int j;
void
-output_table()
+output_table (void)
{
register int i;
register int j;
void
-output_check()
+output_check (void)
{
register int i;
register int j;
/* copy the parser code into the ftable file at the end. */
void
-output_parser()
+output_parser (void)
{
register int c;
#ifdef DONTDEF
}
/* now write out the line... */
- for ( ; c != '\n' && c != EOF; c = getc(fpars))
- if (write_line)
+ for (; c != '\n' && c != EOF; c = getc(fpars))
+ if (write_line) {
if (c == '$')
{
/* `$' in the parser file indicates where to put the actions.
}
else
putc(c, ftable);
+ }
if (c == EOF)
break;
putc(c, ftable);
}
}
-
void
-output_program()
+output_program (void)
{
register int c;
- extern int lineno;
if (!nolinesflag)
fprintf(ftable, "#line %d \"%s\"\n", lineno, infile);
void
-free_itemsets()
+free_itemsets (void)
{
register core *cp,*cptmp;
void
-free_shifts()
+free_shifts (void)
{
register shifts *sp,*sptmp;/* JF derefrenced freed ptr */
void
-free_reductions()
+free_reductions (void)
{
register reductions *rp,*rptmp;/* JF fixed freed ptr */