+2001-12-05 Akim Demaille <akim@epita.fr>
+
+ * src/derives.c (print_derives): Display the ruleno.
+ * src/lalr.c (initialize_F, transpose): Better variable locality
+ to improve readability.
+ Avoid variables used as mere abbreviations.
+
2001-12-05 Akim Demaille <akim@epita.fr>
* src/lalr.c (traverse): Use arrays instead of pointers.
Boston, MA 02111-1307, USA. */
-/* set_derives finds, for each variable (nonterminal), which rules can
- derive it. It sets up the value of derives so that derives[i -
- ntokens] points to a vector of rule numbers, terminated with -1.
- */
-
#include "system.h"
#include "getargs.h"
#include "types.h"
#include "gram.h"
#include "derives.h"
-short **derives;
-
+short **derives = NULL;
static void
print_derives (void)
fprintf (stderr, "\t\t%d:", *sp);
for (rhsp = ritem + rule_table[*sp].rhs; *rhsp > 0; ++rhsp)
fprintf (stderr, " %s", tags[*rhsp]);
- fputc ('\n', stderr);
+ fprintf (stderr, " (rule %d)\n", -*rhsp);
}
}
/* Match rules with nonterminals for bison,
- Copyright 1984, 1989, 2000 Free Software Foundation, Inc.
+ Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
#ifndef DERIVES_H_
# define DERIVES_H_
+/* DERIVES[SYMBOL - NTOKENS] points to a vector of the number of the
+ rules that SYMBOL derives, terminated with -1. */
extern short **derives;
-/* set_derives finds, for each variable (nonterminal), which rules can
- derive it. It sets up the value of derives so that derives[i -
- ntokens] points to a vector of rule numbers, terminated with -1.
- */
+/* Compute DERIVES. */
void set_derives PARAMS((void));
void free_derives PARAMS((void));
{
int i;
int j;
- int k;
- shifts *sp;
short *edge;
unsigned *rowp;
short *rp;
short **reads;
int nedges;
- int stateno;
int symbol;
int nwords;
rowp = F;
for (i = 0; i < ngotos; i++)
{
- stateno = to_state[i];
- sp = state_table[stateno].shift_table;
+ int stateno = to_state[i];
+ shifts *sp = state_table[stateno].shift_table;
if (sp)
{
- k = sp->nshifts;
-
- for (j = 0; j < k; j++)
+ for (j = 0; j < sp->nshifts; j++)
{
symbol = state_table[sp->shifts[j]].accessing_symbol;
if (ISVAR (symbol))
SETBIT (rowp, symbol);
}
- for (; j < k; j++)
+ for (; j < sp->nshifts; j++)
{
symbol = state_table[sp->shifts[j]].accessing_symbol;
if (nullable[symbol])
short **new_R;
short **temp_R;
short *nedges;
- short *sp;
int i;
- int k;
nedges = XCALLOC (short, n);
for (i = 0; i < n; i++)
{
- sp = R_arg[i];
+ short *sp = R_arg[i];
if (sp)
{
while (*sp >= 0)
temp_R = XCALLOC (short *, n);
for (i = 0; i < n; i++)
- {
- k = nedges[i];
- if (k > 0)
- {
- sp = XCALLOC (short, k + 1);
- new_R[i] = sp;
- temp_R[i] = sp;
- sp[k] = -1;
- }
- }
+ if (nedges[i] > 0)
+ {
+ short *sp = XCALLOC (short, nedges[i] + 1);
+ new_R[i] = sp;
+ temp_R[i] = sp;
+ sp[nedges[i]] = -1;
+ }
XFREE (nedges);
for (i = 0; i < n; i++)
{
- sp = R_arg[i];
+ short *sp = R_arg[i];
if (sp)
- {
- while (*sp >= 0)
- *temp_R[*sp++]++ = i;
- }
+ while (*sp >= 0)
+ *temp_R[*sp++]++ = i;
}
XFREE (temp_R);
{
int i;
int j;
- int k;
short *rulep;
short *rp;
- shifts *sp;
- int length;
int nedges;
int done;
int state1;
int stateno;
int symbol1;
- int symbol2;
- short *shortp;
short *edge;
short *states;
short **new_includes;
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
{
- length = 1;
+ int length = 1;
states[0] = state1;
stateno = state1;
for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
{
- symbol2 = *rp;
- sp = state_table[stateno].shift_table;
- k = sp->nshifts;
+ int symbol2 = *rp;
+ shifts *sp = state_table[stateno].shift_table;
- for (j = 0; j < k; j++)
+ for (j = 0; j < sp->nshifts; j++)
{
stateno = sp->shifts[j];
if (state_table[stateno].accessing_symbol == symbol2)
if (nedges)
{
- includes[i] = shortp = XCALLOC (short, nedges + 1);
+ includes[i] = XCALLOC (short, nedges + 1);
for (j = 0; j < nedges; j++)
- shortp[j] = edge[j];
- shortp[nedges] = -1;
+ includes[i][j] = edge[j];
+ includes[i][nedges] = -1;
}
}
new_includes = transpose (includes, ngotos);
for (i = 0; i < ngotos; i++)
- if (includes[i])
- XFREE (includes[i]);
-
+ XFREE (includes[i]);
XFREE (includes);
includes = new_includes;