/* Find and resolve or report look-ahead conflicts for bison,
- Copyright (C) 1984, 1989 Free Software Foundation, Inc.
+ Copyright (C) 1984, 1989, 1992, 2000 Free Software Foundation, Inc.
-This file is part of Bison, the GNU Compiler Compiler.
+ This file is part of Bison, the GNU Compiler Compiler.
-Bison is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+ Bison is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
-Bison is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ Bison is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
-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. */
+ 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, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
-#ifdef _AIX
- #pragma alloca
-#endif
-#include <stdio.h>
#include "system.h"
-#include "machine.h"
-#include "new.h"
+#include "getargs.h"
+#include "alloc.h"
#include "files.h"
#include "gram.h"
#include "state.h"
-#ifndef __GNUC__
-#undef alloca
-#define alloca __builtin_alloca
-#else
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#else
-#ifndef _AIX
-extern char *alloca ();
-#endif
-#endif
-#endif
-
extern char **tags;
extern int tokensetsize;
extern char *consistent;
extern unsigned *LA;
extern short *LAruleno;
extern short *lookaheads;
-extern int verboseflag;
-
-void set_conflicts();
-void resolve_sr_conflict();
-void flush_shift();
-void log_resolution();
-void total_conflicts();
-void count_sr_conflicts();
-void count_rr_conflicts();
+extern int fixed_outfiles;
+
+extern void initialize_conflicts PARAMS((void));
+extern void conflict_log PARAMS((void));
+extern void verbose_conflict_log PARAMS((void));
+extern void print_reductions PARAMS((int));
+extern void finalize_conflicts PARAMS((void));
+
+static void set_conflicts PARAMS((int));
+static void resolve_sr_conflict PARAMS((int, int));
+static void flush_shift PARAMS((int, int));
+static void log_resolution PARAMS((int, int, int, char *));
+static void total_conflicts PARAMS((void));
+static void count_sr_conflicts PARAMS((int));
+static void count_rr_conflicts PARAMS((int));
char any_conflicts;
-char *conflicts;
errs **err_table;
int expected_conflicts;
+static char *conflicts;
static unsigned *shiftset;
void
-initialize_conflicts()
+initialize_conflicts (void)
{
register int i;
/* register errs *sp; JF unused */
}
-void
-set_conflicts(state)
-int state;
+static void
+set_conflicts (int state)
{
register int i;
register int k;
fp1 = LA + i * tokensetsize;
fp2 = fp1;
fp3 = lookaheadset;
-
+
while (fp3 < fp4)
{
if (*fp2++ & *fp3++)
A conflict is resolved by modifying the shift or reduce tables
so that there is no longer a conflict. */
-void
-resolve_sr_conflict(state, lookaheadnum)
-int state;
-int lookaheadnum;
+static void
+resolve_sr_conflict (int state, int lookaheadnum)
{
register int i;
register int mask;
register unsigned *fp1;
register unsigned *fp2;
register int redprec;
- /* Extra parens avoid errors on Ultrix 4.3. */
- errs *errp = (errs *) alloca ((sizeof(errs) + ntokens * sizeof(short)));
+ errs *errp = (errs *) xmalloc (sizeof(errs) + ntokens * sizeof(short));
short *errtokens = errp->errs;
/* find the rule to reduce by to get precedence of reduction */
{
if (sprec[i] < redprec)
{
- if (verboseflag) log_resolution(state, lookaheadnum, i, "reduce");
+ if (verboseflag) log_resolution(state, lookaheadnum, i, _("reduce"));
*fp2 &= ~mask; /* flush the shift for this token */
flush_shift(state, i);
}
else if (sprec[i] > redprec)
{
- if (verboseflag) log_resolution(state, lookaheadnum, i, "shift");
+ if (verboseflag) log_resolution(state, lookaheadnum, i, _("shift"));
*fp1 &= ~mask; /* flush the reduce for this token */
}
else
{
case RIGHT_ASSOC:
- if (verboseflag) log_resolution(state, lookaheadnum, i, "shift");
+ if (verboseflag) log_resolution(state, lookaheadnum, i, _("shift"));
break;
case LEFT_ASSOC:
- if (verboseflag) log_resolution(state, lookaheadnum, i, "reduce");
+ if (verboseflag) log_resolution(state, lookaheadnum, i, _("reduce"));
break;
case NON_ASSOC:
- if (verboseflag) log_resolution(state, lookaheadnum, i, "an error");
+ if (verboseflag) log_resolution(state, lookaheadnum, i, _("an error"));
break;
}
}
else
err_table[state] = 0;
+ free(errp);
}
/* turn off the shift recorded for the specified token in the specified state.
Used when we resolve a shift-reduce conflict in favor of the reduction. */
-void
-flush_shift(state, token)
-int state;
-int token;
+static void
+flush_shift (int state, int token)
{
register shifts *shiftp;
register int k, i;
}
-void
-log_resolution(state, LAno, token, resolution)
-int state, LAno, token;
-char *resolution;
+static void
+log_resolution (int state, int LAno, int token, char *resolution)
{
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);
}
void
-conflict_log()
+conflict_log (void)
{
register int i;
total_conflicts();
}
-
+
void
-verbose_conflict_log()
+verbose_conflict_log (void)
{
register int i;
src_total += src_count;
rrc_total += rrc_count;
- fprintf(foutput, "State %d contains", i);
+ fprintf(foutput, _("State %d contains"), i);
if (src_count == 1)
- fprintf(foutput, " 1 shift/reduce conflict");
+ fprintf(foutput, _(" 1 shift/reduce conflict"));
else if (src_count > 1)
- fprintf(foutput, " %d shift/reduce conflicts", src_count);
+ fprintf(foutput, _(" %d shift/reduce conflicts"), src_count);
if (src_count > 0 && rrc_count > 0)
- fprintf(foutput, " and");
+ fprintf(foutput, _(" and"));
if (rrc_count == 1)
- fprintf(foutput, " 1 reduce/reduce conflict");
+ fprintf(foutput, _(" 1 reduce/reduce conflict"));
else if (rrc_count > 1)
- fprintf(foutput, " %d reduce/reduce conflicts", rrc_count);
+ fprintf(foutput, _(" %d reduce/reduce conflicts"), rrc_count);
putc('.', foutput);
putc('\n', foutput);
}
-void
-total_conflicts()
+static void
+total_conflicts (void)
{
- extern int fixed_outfiles;
-
if (src_total == expected_conflicts && rrc_total == 0)
return;
{
/* If invoked under the name `yacc', use the output format
specified by POSIX. */
- fprintf(stderr, "conflicts: ");
+ fprintf(stderr, _("conflicts: "));
if (src_total > 0)
- fprintf(stderr, " %d shift/reduce", src_total);
+ fprintf(stderr, _(" %d shift/reduce"), src_total);
if (src_total > 0 && rrc_total > 0)
fprintf(stderr, ",");
if (rrc_total > 0)
- fprintf(stderr, " %d reduce/reduce", rrc_total);
+ fprintf(stderr, _(" %d reduce/reduce"), rrc_total);
putc('\n', stderr);
}
else
{
- fprintf(stderr, "%s contains", infile);
+ fprintf(stderr, _("%s contains"), infile);
if (src_total == 1)
- fprintf(stderr, " 1 shift/reduce conflict");
+ fprintf(stderr, _(" 1 shift/reduce conflict"));
else if (src_total > 1)
- fprintf(stderr, " %d shift/reduce conflicts", src_total);
+ fprintf(stderr, _(" %d shift/reduce conflicts"), src_total);
if (src_total > 0 && rrc_total > 0)
- fprintf(stderr, " and");
+ fprintf(stderr, _(" and"));
if (rrc_total == 1)
- fprintf(stderr, " 1 reduce/reduce conflict");
+ fprintf(stderr, _(" 1 reduce/reduce conflict"));
else if (rrc_total > 1)
- fprintf(stderr, " %d reduce/reduce conflicts", rrc_total);
+ fprintf(stderr, _(" %d reduce/reduce conflicts"), rrc_total);
putc('.', stderr);
putc('\n', stderr);
}
-void
-count_sr_conflicts(state)
-int state;
+static void
+count_sr_conflicts (int state)
{
register int i;
register int k;
}
-void
-count_rr_conflicts(state)
-int state;
+static void
+count_rr_conflicts (int state)
{
register int i;
register int j;
void
-print_reductions(state)
-int state;
+print_reductions (int state)
{
register int i;
register int j;
register int m;
register int n;
register int default_LA;
- register int default_rule;
+ register int default_rule = 0;
register int cmax;
register int count;
register shifts *shiftp;
for (i = 0; i < ntokens; i++)
{
if (mask & *fp3)
- fprintf(foutput, " %-4s\t[reduce using rule %d (%s)]\n",
+ fprintf(foutput, _(" %-4s\t[reduce using rule %d (%s)]\n"),
tags[i], default_rule, tags[rlhs[default_rule]]);
mask <<= 1;
}
}
- fprintf(foutput, " $default\treduce using rule %d (%s)\n\n",
+ fprintf(foutput, _(" $default\treduce using rule %d (%s)\n\n"),
default_rule, tags[rlhs[default_rule]]);
}
else if (n - m >= 1)
fp1 = LA + i * tokensetsize;
fp2 = shiftset;
fp3 = lookaheadset;
-
+
while (fp3 < fp4)
- *fp3++ = *fp1++ & ( ~ (*fp2++));
-
+ *fp3++ = *fp1++ & (~(*fp2++));
+
count = 0;
mask = 1;
fp3 = lookaheadset;
{
if (mask & *fp3)
count++;
-
+
mask <<= 1;
if (mask == 0)
{
fp3++;
}
}
-
+
if (count > cmax)
{
cmax = count;
default_LA = i;
default_rule = LAruleno[i];
}
-
+
fp2 = shiftset;
fp3 = lookaheadset;
-
+
while (fp3 < fp4)
*fp2++ |= *fp3++;
}
if (j != default_LA)
{
rule = LAruleno[j];
- fprintf(foutput, " %-4s\treduce using rule %d (%s)\n",
+ fprintf(foutput, _(" %-4s\treduce using rule %d (%s)\n"),
tags[i], rule, tags[rlhs[rule]]);
}
else defaulted = 1;
if (defaulted)
{
rule = LAruleno[default_LA];
- fprintf(foutput, " %-4s\treduce using rule %d (%s)\n",
+ fprintf(foutput, _(" %-4s\treduce using rule %d (%s)\n"),
tags[i], rule, tags[rlhs[rule]]);
defaulted = 0;
}
rule = LAruleno[j];
- fprintf(foutput, " %-4s\t[reduce using rule %d (%s)]\n",
+ fprintf(foutput, _(" %-4s\t[reduce using rule %d (%s)]\n"),
tags[i], rule, tags[rlhs[rule]]);
}
}
if (default_LA >= 0)
{
- fprintf(foutput, " $default\treduce using rule %d (%s)\n",
+ fprintf(foutput, _(" $default\treduce using rule %d (%s)\n"),
default_rule, tags[rlhs[default_rule]]);
}
void
-finalize_conflicts()
+finalize_conflicts (void)
{
FREE(conflicts);
FREE(shiftset);