* 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.
This commit is contained in:
Akim Demaille
2001-12-05 09:28:00 +00:00
parent fe96109760
commit 80a6975034
4 changed files with 36 additions and 56 deletions

View File

@@ -1,3 +1,10 @@
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.

View File

@@ -19,11 +19,6 @@
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"
@@ -31,8 +26,7 @@
#include "gram.h"
#include "derives.h"
short **derives;
short **derives = NULL;
static void
print_derives (void)
@@ -51,7 +45,7 @@ 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);
}
}

View File

@@ -1,5 +1,5 @@
/* 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.
@@ -21,12 +21,11 @@
#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));

View File

@@ -358,14 +358,11 @@ initialize_F (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;
@@ -379,14 +376,12 @@ initialize_F (void)
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))
@@ -394,7 +389,7 @@ initialize_F (void)
SETBIT (rowp, symbol);
}
for (; j < k; j++)
for (; j < sp->nshifts; j++)
{
symbol = state_table[sp->shifts[j]].accessing_symbol;
if (nullable[symbol])
@@ -460,15 +455,13 @@ transpose (short **R_arg, int n)
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)
@@ -480,27 +473,22 @@ transpose (short **R_arg, int n)
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);
@@ -514,18 +502,13 @@ build_relations (void)
{
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;
@@ -542,17 +525,16 @@ build_relations (void)
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)
@@ -584,19 +566,17 @@ build_relations (void)
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;