/* Output the generated parsing program for Bison.
- Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002
+
+ Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003
Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
Of course vector_number_t ought to be wide enough to contain
state_number and symbol_number. */
typedef short vector_number;
-#define state_number_to_vector_number(State) \
- ((vector_number) State)
-#define symbol_number_to_vector_number(Symbol) \
- ((vector_number) (state_number_as_int (nstates) + Symbol - ntokens))
+
+static inline vector_number
+state_number_to_vector_number (state_number s)
+{
+ return s;
+}
+
+static inline vector_number
+symbol_number_to_vector_number (symbol_number sym)
+{
+ return state_number_as_int (nstates) + sym - ntokens;
+}
int nvectors;
/* TABLE_SIZE is the allocated size of both TABLE and CHECK. We start
with more or less the original hard-coded value (which was
SHRT_MAX). */
-static size_t table_size = 32768;
+static int table_size = 32768;
base_number *table = NULL;
base_number *check = NULL;
/* The value used in TABLE to denote explicit syntax errors
`----------------------------------------------------------------*/
static void
-table_grow (size_t desired)
+table_grow (int desired)
{
- size_t old_size = table_size;
+ int old_size = table_size;
while (table_size <= desired)
table_size *= 2;
fprintf (stderr, "growing table and check from: %d to %d\n",
old_size, table_size);
- table = XREALLOC (table, base_number, table_size);
- check = XREALLOC (check, base_number, table_size);
- conflict_table = XREALLOC (conflict_table, unsigned int, table_size);
+ REALLOC (table, table_size);
+ REALLOC (check, table_size);
+ REALLOC (conflict_table, table_size);
for (/* Nothing. */; old_size < table_size; ++old_size)
{
int i, j;
reductions *reds = s->reductions;
- if (! glr_parser)
+ if (!nondeterministic_parser)
return;
for (j = 0; j < ntokens; j += 1)
transitions *trans = s->transitions;
errs *errp = s->errs;
/* Set to nonzero to inhibit having any default reduction. */
- int nodefault = 0;
- int conflicted = 0;
+ bool nodefault = false;
+ bool conflicted = false;
for (i = 0; i < ntokens; i++)
actrow[i] = conflrow[i] = 0;
/* and record this rule as the rule to use if that
token follows. */
if (actrow[j] != 0)
- conflicted = conflrow[j] = 1;
+ {
+ conflicted = true;
+ conflrow[j] = 1;
+ }
actrow[j] = rule_number_as_item_number (reds->rules[i]->number);
}
}
state *shift_state = trans->states[i];
if (actrow[sym] != 0)
- conflicted = conflrow[sym] = 1;
+ {
+ conflicted = true;
+ conflrow[sym] = 1;
+ }
actrow[sym] = state_number_as_int (shift_state->number);
/* Do not use any default reduction if there is a shift for
error */
if (sym == errtoken->number)
- nodefault = 1;
+ nodefault = true;
}
/* See which tokens are an explicit error in this state (due to
int j;
for (j = 0; j < ntokens; j++)
if (actrow[j] == rule_number_as_item_number (default_rule->number)
- && ! (glr_parser && conflrow[j]))
+ && ! (nondeterministic_parser && conflrow[j]))
actrow[j] = 0;
}
}
{
symbol_number i;
int count;
- base_number *sp = NULL;
- base_number *sp1 = NULL;
- base_number *sp2 = NULL;
- unsigned int *sp3 = NULL;
+ base_number *sp;
+ base_number *sp1;
+ base_number *sp2;
+ unsigned int *sp3 IF_LINT (= NULL);
/* Number of non default actions in S. */
count = 0;
return;
/* Allocate non defaulted actions. */
- froms[s] = sp1 = sp = XCALLOC (base_number, count);
- tos[s] = sp2 = XCALLOC (base_number, count);
- if (glr_parser)
- conflict_tos[s] = sp3 = XCALLOC (unsigned int, count);
- else
- conflict_tos[s] = NULL;
+ froms[s] = sp = CALLOC (sp1, count);
+ tos[s] = CALLOC (sp2, count);
+ conflict_tos[s] = nondeterministic_parser ? CALLOC (sp3, count) : NULL;
/* Store non defaulted actions. */
for (i = 0; i < ntokens; i++)
{
*sp1++ = i;
*sp2++ = actrow[i];
- if (glr_parser)
+ if (nondeterministic_parser)
*sp3++ = conflrow[i];
}
symbol_number j;
rule_number r;
- int nconflict = glr_parser ? conflicts_total_count () : 0;
+ int nconflict = nondeterministic_parser ? conflicts_total_count () : 0;
- yydefact = XCALLOC (rule_number, nstates);
+ CALLOC (yydefact, nstates);
- actrow = XCALLOC (action_number, ntokens);
- conflrow = XCALLOC (unsigned int, ntokens);
+ CALLOC (actrow, ntokens);
+ CALLOC (conflrow, ntokens);
- conflict_list = XCALLOC (unsigned int, 1 + 2 * nconflict);
+ CALLOC (conflict_list, 1 + 2 * nconflict);
conflict_list_free = 2 * nconflict;
conflict_list_cnt = 1;
/* Find the rules which are reduced. */
- if (!glr_parser)
+ if (!nondeterministic_parser)
for (r = 0; r < nrules; ++r)
rules[r].useful = false;
/* Now that the parser was computed, we can find which rules are
really reduced, and which are not because of SR or RR
conflicts. */
- if (!glr_parser)
+ if (!nondeterministic_parser)
{
for (j = 0; j < ntokens; ++j)
if (actrow[j] < 0 && actrow[j] != ACTION_NUMBER_MINIMUM)
int count;
vector_number symno = symbol_number_to_vector_number (sym);
- goto_number begin = goto_map[sym];
- goto_number end = goto_map[sym + 1];
+ goto_number begin = goto_map[sym - ntokens];
+ goto_number end = goto_map[sym - ntokens + 1];
/* Number of non default GOTO. */
count = 0;
return;
/* Allocate room for non defaulted gotos. */
- froms[symno] = sp1 = sp = XCALLOC (base_number, count);
- tos[symno] = sp2 = XCALLOC (base_number, count);
+ froms[symno] = sp = CALLOC (sp1, count);
+ tos[symno] = CALLOC (sp2, count);
/* Store the state numbers of the non defaulted gotos. */
for (i = begin; i < end; i++)
{
state_number s;
int i;
- goto_number m = goto_map[sym];
- goto_number n = goto_map[sym + 1];
- state_number default_state = (state_number) -1;
+ goto_number m = goto_map[sym - ntokens];
+ goto_number n = goto_map[sym - ntokens + 1];
+ state_number default_state = -1;
int max = 0;
if (m == n)
- return (state_number) -1;
+ return -1;
for (s = 0; s < nstates; s++)
state_count[s] = 0;
goto_actions (void)
{
symbol_number i;
- short *state_count = XCALLOC (short, nstates);
- yydefgoto = XMALLOC (state_number, nvars);
+ short *state_count = CALLOC (state_count, nstates);
+ MALLOC (yydefgoto, nvars);
/* For a given nterm I, STATE_COUNT[S] is the number of times there
is a GOTO to S on I. */
int prev;
/* If VECTOR is a nterm, return -1. */
- if (i >= (int) nstates)
+ if (nstates <= i)
return -1;
t = tally[i];
base_number *to = tos[i];
unsigned int *conflict_to = conflict_tos[i];
- if (! t)
+ if (!t)
abort ();
for (j = lowzero - from[0]; ; j++)
{
int k;
- int ok = 1;
+ bool ok = true;
- if ((int) table_size <= j)
+ if (table_size <= j)
abort ();
for (k = 0; ok && k < t; k++)
{
loc = j + state_number_as_int (from[k]);
- if (loc >= (int) table_size)
+ if (table_size <= loc)
table_grow (loc);
if (table[loc] != 0)
- ok = 0;
+ ok = false;
}
for (k = 0; ok && k < vector; k++)
if (pos[k] == j)
- ok = 0;
+ ok = false;
if (ok)
{
{
loc = j + from[k];
table[loc] = to[k];
- if (glr_parser && conflict_to != NULL)
+ if (nondeterministic_parser && conflict_to != NULL)
conflict_table[loc] = conflict_to[k];
check[loc] = from[k];
}
`-------------------------------------------------------------*/
static base_number
-table_ninf_remap (base_number tab[], size_t size, base_number ninf)
+table_ninf_remap (base_number tab[], int size, base_number ninf)
{
base_number res = 0;
- size_t i;
+ int i;
for (i = 0; i < size; i++)
if (tab[i] < res && tab[i] != ninf)
{
int i;
- base = XCALLOC (base_number, nvectors);
- pos = XCALLOC (base_number, nentries);
- table = XCALLOC (base_number, table_size);
- conflict_table = XCALLOC (unsigned int, table_size);
- check = XCALLOC (base_number, table_size);
+ CALLOC (base, nvectors);
+ CALLOC (pos, nentries);
+ CALLOC (table, table_size);
+ CALLOC (conflict_table, table_size);
+ CALLOC (check, table_size);
lowzero = 0;
high = 0;
for (i = 0; i < nvectors; i++)
base[i] = BASE_MINIMUM;
- for (i = 0; i < (int) table_size; i++)
+ for (i = 0; i < table_size; i++)
check[i] = -1;
for (i = 0; i < nentries; i++)
nvectors = state_number_as_int (nstates) + nvars;
- froms = XCALLOC (base_number *, nvectors);
- tos = XCALLOC (base_number *, nvectors);
- conflict_tos = XCALLOC (unsigned int *, nvectors);
- tally = XCALLOC (short, nvectors);
- width = XCALLOC (base_number, nvectors);
+ CALLOC (froms, nvectors);
+ CALLOC (tos, nvectors);
+ CALLOC (conflict_tos, nvectors);
+ CALLOC (tally, nvectors);
+ CALLOC (width, nvectors);
token_actions ();
goto_actions ();
- free (goto_map + ntokens);
+ free (goto_map);
free (from_state);
free (to_state);
- order = XCALLOC (vector_number, nvectors);
+ CALLOC (order, nvectors);
sort_actions ();
pack_table ();
free (order);