#include "system.h"
#include "getargs.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "files.h"
#include "gram.h"
-#include "state.h"
+#include "LR0.h"
#include "complain.h"
#include "output.h"
+#include "lalr.h"
+#include "reader.h"
+#include "conflicts.h"
extern void berror PARAMS((const char *));
-extern char **tags;
-extern short *user_toknums;
-extern int tokensetsize;
-extern int final_state;
-extern core **state_table;
-extern shifts **shift_table;
-extern errs **err_table;
-extern reductions **reduction_table;
-extern short *accessing_symbol;
-extern unsigned *LA;
-extern short *LAruleno;
-extern short *lookaheads;
-extern char *consistent;
-extern short *goto_map;
-extern short *from_state;
-extern short *to_state;
-
-extern void reader_output_yylsp PARAMS ((FILE *));
+
static int nvectors;
static int nentries;
if (semantic_parser)
fprintf (fguard, GUARDSTR, attrsfile);
- if (noparserflag)
+ if (no_parser_flag)
return;
fprintf (faction, (semantic_parser ? ACTSTR : ACTSTR_SIMPLE), attrsfile);
fprintf (faction, "\n");
- if (noparserflag)
+ if (no_parser_flag)
return;
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)
+ /* With the no_parser option, all tables are generated */
+ if (!semantic_parser && !no_parser_flag)
fprintf (ftable, "\n#if YYDEBUG != 0\n");
output_short_table (ftable, "yyprhs", rrhs,
fprintf (ftable, "\n};\n");
- if (!semantic_parser && !noparserflag)
+ if (!semantic_parser && !no_parser_flag)
fprintf (ftable, "\n#endif\n");
}
fputs ("#endif\n\n", ftable);
- if (toknumflag || noparserflag)
+ if (token_table_flag || no_parser_flag)
{
fprintf (ftable, "#define YYNTOKENS %d\n", ntokens);
fprintf (ftable, "#define YYNNTS %d\n", nvars);
fprintf (ftable, "#define YYMAXUTOK %d\n\n", max_user_token_number);
}
- if (!toknumflag && !noparserflag)
+ if (!token_table_flag && !no_parser_flag)
fprintf (ftable, "\n#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)\n\n");
/* Output the table of symbol names. */
/* add a NULL entry to list of tokens */
fprintf (ftable, ", NULL\n};\n");
- if (!toknumflag && !noparserflag)
+ if (!token_table_flag && !no_parser_flag)
fprintf (ftable, "#endif\n\n");
/* Output YYTOKNUM. */
- if (toknumflag)
+ if (token_table_flag)
{
output_short_table (ftable, "yytoknum", user_toknums,
0, 1, ntokens + 1);
output_short_table (ftable, "yyr1", rlhs,
0, 1, nrules + 1);
- FREE (rlhs + 1);
+ XFREE (rlhs + 1);
putc ('\n', ftable);
putc ('\n', ftable);
fprintf (ftable, "%6d\n};\n", nitems - rrhs[nrules] - 1);
- FREE (rrhs + 1);
+ XFREE (rrhs + 1);
}
if (count == 0)
return;
- froms[state] = sp1 = sp = NEW2 (count, short);
- tos[state] = sp2 = NEW2 (count, short);
+ froms[state] = sp1 = sp = XCALLOC (short, count);
+ tos[state] = sp2 = XCALLOC (short, count);
for (i = 0; i < ntokens; i++)
{
token_actions (void)
{
int i;
- short *yydefact = NEW2 (nstates, short);
+ short *yydefact = XCALLOC (short, nstates);
- actrow = NEW2 (ntokens, short);
+ actrow = XCALLOC (short, ntokens);
for (i = 0; i < nstates; ++i)
{
yydefact[i] = action_row (i);
save_row (i);
}
- FREE (actrow);
+ XFREE (actrow);
output_short_table (ftable, "yydefact", yydefact,
yydefact[0], 1, nstates);
- FREE (yydefact);
+ XFREE (yydefact);
}
{
shifts *sp, *sptmp; /* JF derefrenced freed ptr */
- FREE (shift_table);
+ XFREE (shift_table);
for (sp = first_shift; sp; sp = sptmp)
{
sptmp = sp->next;
- FREE (sp);
+ XFREE (sp);
}
}
{
reductions *rp, *rptmp; /* JF fixed freed ptr */
- FREE (reduction_table);
+ XFREE (reduction_table);
for (rp = first_reduction; rp; rp = rptmp)
{
rptmp = rp->next;
- FREE (rp);
+ XFREE (rp);
}
}
symno = symbol - ntokens + nstates;
- froms[symno] = sp1 = sp = NEW2 (count, short);
- tos[symno] = sp2 = NEW2 (count, short);
+ froms[symno] = sp1 = sp = XCALLOC (short, count);
+ tos[symno] = sp2 = XCALLOC (short, count);
for (i = m; i < n; i++)
{
{
int i, j, k;
- state_count = NEW2 (nstates, short);
+ state_count = XCALLOC (short, nstates);
k = default_goto (ntokens);
fprintf (ftable, "\nstatic const short yydefgoto[] = {%6d", k);
}
fprintf (ftable, "\n};\n");
- FREE (state_count);
+ XFREE (state_count);
}
int t;
int w;
- order = NEW2 (nvectors, short);
+ order = XCALLOC (short, nvectors);
nentries = 0;
for (i = 0; i < nvectors; i++)
i = order[vector];
t = tally[i];
- if (t == 0)
- berror ("pack_vector");
+ assert (t);
from = froms[i];
to = tos[i];
int place;
int state;
- base = NEW2 (nvectors, short);
- pos = NEW2 (nentries, short);
- table = NEW2 (MAXTABLE, short);
- check = NEW2 (MAXTABLE, short);
+ base = XCALLOC (short, nvectors);
+ pos = XCALLOC (short, nentries);
+ table = XCALLOC (short, MAXTABLE);
+ check = XCALLOC (short, MAXTABLE);
lowzero = 0;
high = 0;
for (i = 0; i < nvectors; i++)
{
if (froms[i])
- FREE (froms[i]);
+ XFREE (froms[i]);
if (tos[i])
- FREE (tos[i]);
+ XFREE (tos[i]);
}
- FREE (froms);
- FREE (tos);
- FREE (pos);
+ XFREE (froms);
+ XFREE (tos);
+ XFREE (pos);
}
/* the following functions output yytable, yycheck
output_short_table (ftable, "yypgoto", base,
base[nstates], nstates + 1, nvectors);
- FREE (base);
+ XFREE (base);
}
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);
+ XFREE (table);
}
{
output_short_table (ftable, "yycheck", check,
check[0], 1, high + 1);
- FREE (check);
+ XFREE (check);
}
/* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable
{
nvectors = nstates + nvars;
- froms = NEW2 (nvectors, short *);
- tos = NEW2 (nvectors, short *);
- tally = NEW2 (nvectors, short);
- width = NEW2 (nvectors, short);
+ froms = XCALLOC (short *, nvectors);
+ tos = XCALLOC (short *, nvectors);
+ tally = XCALLOC (short, nvectors);
+ width = XCALLOC (short, nvectors);
token_actions ();
free_shifts ();
free_reductions ();
- FREE (lookaheads);
- FREE (LA);
- FREE (LAruleno);
- FREE (accessing_symbol);
+ XFREE (lookaheads);
+ XFREE (LA);
+ XFREE (LAruleno);
+ XFREE (accessing_symbol);
goto_actions ();
- FREE (goto_map + ntokens);
- FREE (from_state);
- FREE (to_state);
+ XFREE (goto_map + ntokens);
+ XFREE (from_state);
+ XFREE (to_state);
sort_actions ();
pack_table ();
output_parser (void)
{
int c;
+ static int number_of_dollar_signs = 0;
#ifdef DONTDEF
FILE *fpars;
#else
if (pure_parser)
fprintf (ftable, "#define YYPURE 1\n\n");
-#ifdef DONTDEF /* JF no longer needed 'cuz open_extra_files changes the
- currently open parser from bison.simple to bison.hairy */
+#ifdef DONTDEF
+ /* JF no longer needed 'cuz open_extra_files changes the currently
+ open parser from bison.simple to bison.hairy */
if (semantic_parser)
fpars = fparser;
else
/* See if the line starts with `#line.
If so, set write_line to 0. */
- if (nolinesflag)
+ if (no_lines_flag)
if (c == '#')
{
c = getc (fpars);
{
if (c == '$')
{
+ number_of_dollar_signs++;
+ assert (number_of_dollar_signs == 1);
/* `$' in the parser file indicates where to put the actions.
Copy them in at this point. */
rewind (faction);
for (c = getc (faction); c != EOF; c = getc (faction))
putc (c, ftable);
+ /* Skip the end of the line containing `$'. */
+ write_line = 0;
}
else
putc (c, ftable);
break;
putc (c, ftable);
}
+ assert (number_of_dollar_signs == 1);
}
static void
{
int c;
- if (!nolinesflag)
+ if (!no_lines_flag)
fprintf (ftable, "#line %d \"%s\"\n", lineno, infile);
c = getc (finput);
{
core *cp, *cptmp;
- FREE (state_table);
+ XFREE (state_table);
for (cp = first_state; cp; cp = cptmp)
{
cptmp = cp->next;
- FREE (cp);
+ XFREE (cp);
}
}
putc (c, ftable);
}
reader_output_yylsp (ftable);
- if (debugflag)
+ if (debug_flag)
fputs ("\
#ifndef YYDEBUG\n\
-#define YYDEBUG 1\n\
+# define YYDEBUG 1\n\
#endif\n\
\n",
ftable);
if (semantic_parser)
fprintf (ftable, "#include \"%s\"\n", attrsfile);
- if (!noparserflag)
+ if (!no_parser_flag)
fprintf (ftable, "#include <stdio.h>\n\n");
/* Make "const" do nothing if not in ANSI C. */
/* if (semantic_parser) */
/* This is now unconditional because debugging printouts can use it. */
output_gram ();
- FREE (ritem);
+ XFREE (ritem);
if (semantic_parser)
output_stos ();
output_rule_data ();
output_actions ();
- if (!noparserflag)
+ if (!no_parser_flag)
output_parser ();
output_program ();
}