mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 00:03:03 +00:00
* 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:
@@ -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>
|
2001-12-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/lalr.c (traverse): Use arrays instead of pointers.
|
* src/lalr.c (traverse): Use arrays instead of pointers.
|
||||||
|
|||||||
@@ -19,11 +19,6 @@
|
|||||||
Boston, MA 02111-1307, USA. */
|
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 "system.h"
|
||||||
#include "getargs.h"
|
#include "getargs.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@@ -31,8 +26,7 @@
|
|||||||
#include "gram.h"
|
#include "gram.h"
|
||||||
#include "derives.h"
|
#include "derives.h"
|
||||||
|
|
||||||
short **derives;
|
short **derives = NULL;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_derives (void)
|
print_derives (void)
|
||||||
@@ -51,7 +45,7 @@ print_derives (void)
|
|||||||
fprintf (stderr, "\t\t%d:", *sp);
|
fprintf (stderr, "\t\t%d:", *sp);
|
||||||
for (rhsp = ritem + rule_table[*sp].rhs; *rhsp > 0; ++rhsp)
|
for (rhsp = ritem + rule_table[*sp].rhs; *rhsp > 0; ++rhsp)
|
||||||
fprintf (stderr, " %s", tags[*rhsp]);
|
fprintf (stderr, " %s", tags[*rhsp]);
|
||||||
fputc ('\n', stderr);
|
fprintf (stderr, " (rule %d)\n", -*rhsp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* Match rules with nonterminals for bison,
|
/* 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.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -21,12 +21,11 @@
|
|||||||
#ifndef DERIVES_H_
|
#ifndef DERIVES_H_
|
||||||
# define 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;
|
extern short **derives;
|
||||||
|
|
||||||
/* set_derives finds, for each variable (nonterminal), which rules can
|
/* Compute DERIVES. */
|
||||||
derive it. It sets up the value of derives so that derives[i -
|
|
||||||
ntokens] points to a vector of rule numbers, terminated with -1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void set_derives PARAMS((void));
|
void set_derives PARAMS((void));
|
||||||
void free_derives PARAMS((void));
|
void free_derives PARAMS((void));
|
||||||
|
|||||||
66
src/lalr.c
66
src/lalr.c
@@ -358,14 +358,11 @@ initialize_F (void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int k;
|
|
||||||
shifts *sp;
|
|
||||||
short *edge;
|
short *edge;
|
||||||
unsigned *rowp;
|
unsigned *rowp;
|
||||||
short *rp;
|
short *rp;
|
||||||
short **reads;
|
short **reads;
|
||||||
int nedges;
|
int nedges;
|
||||||
int stateno;
|
|
||||||
int symbol;
|
int symbol;
|
||||||
int nwords;
|
int nwords;
|
||||||
|
|
||||||
@@ -379,14 +376,12 @@ initialize_F (void)
|
|||||||
rowp = F;
|
rowp = F;
|
||||||
for (i = 0; i < ngotos; i++)
|
for (i = 0; i < ngotos; i++)
|
||||||
{
|
{
|
||||||
stateno = to_state[i];
|
int stateno = to_state[i];
|
||||||
sp = state_table[stateno].shift_table;
|
shifts *sp = state_table[stateno].shift_table;
|
||||||
|
|
||||||
if (sp)
|
if (sp)
|
||||||
{
|
{
|
||||||
k = sp->nshifts;
|
for (j = 0; j < sp->nshifts; j++)
|
||||||
|
|
||||||
for (j = 0; j < k; j++)
|
|
||||||
{
|
{
|
||||||
symbol = state_table[sp->shifts[j]].accessing_symbol;
|
symbol = state_table[sp->shifts[j]].accessing_symbol;
|
||||||
if (ISVAR (symbol))
|
if (ISVAR (symbol))
|
||||||
@@ -394,7 +389,7 @@ initialize_F (void)
|
|||||||
SETBIT (rowp, symbol);
|
SETBIT (rowp, symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; j < k; j++)
|
for (; j < sp->nshifts; j++)
|
||||||
{
|
{
|
||||||
symbol = state_table[sp->shifts[j]].accessing_symbol;
|
symbol = state_table[sp->shifts[j]].accessing_symbol;
|
||||||
if (nullable[symbol])
|
if (nullable[symbol])
|
||||||
@@ -460,15 +455,13 @@ transpose (short **R_arg, int n)
|
|||||||
short **new_R;
|
short **new_R;
|
||||||
short **temp_R;
|
short **temp_R;
|
||||||
short *nedges;
|
short *nedges;
|
||||||
short *sp;
|
|
||||||
int i;
|
int i;
|
||||||
int k;
|
|
||||||
|
|
||||||
nedges = XCALLOC (short, n);
|
nedges = XCALLOC (short, n);
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
sp = R_arg[i];
|
short *sp = R_arg[i];
|
||||||
if (sp)
|
if (sp)
|
||||||
{
|
{
|
||||||
while (*sp >= 0)
|
while (*sp >= 0)
|
||||||
@@ -480,27 +473,22 @@ transpose (short **R_arg, int n)
|
|||||||
temp_R = XCALLOC (short *, n);
|
temp_R = XCALLOC (short *, n);
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
if (nedges[i] > 0)
|
||||||
k = nedges[i];
|
{
|
||||||
if (k > 0)
|
short *sp = XCALLOC (short, nedges[i] + 1);
|
||||||
{
|
new_R[i] = sp;
|
||||||
sp = XCALLOC (short, k + 1);
|
temp_R[i] = sp;
|
||||||
new_R[i] = sp;
|
sp[nedges[i]] = -1;
|
||||||
temp_R[i] = sp;
|
}
|
||||||
sp[k] = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XFREE (nedges);
|
XFREE (nedges);
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
sp = R_arg[i];
|
short *sp = R_arg[i];
|
||||||
if (sp)
|
if (sp)
|
||||||
{
|
while (*sp >= 0)
|
||||||
while (*sp >= 0)
|
*temp_R[*sp++]++ = i;
|
||||||
*temp_R[*sp++]++ = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XFREE (temp_R);
|
XFREE (temp_R);
|
||||||
@@ -514,18 +502,13 @@ build_relations (void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int k;
|
|
||||||
short *rulep;
|
short *rulep;
|
||||||
short *rp;
|
short *rp;
|
||||||
shifts *sp;
|
|
||||||
int length;
|
|
||||||
int nedges;
|
int nedges;
|
||||||
int done;
|
int done;
|
||||||
int state1;
|
int state1;
|
||||||
int stateno;
|
int stateno;
|
||||||
int symbol1;
|
int symbol1;
|
||||||
int symbol2;
|
|
||||||
short *shortp;
|
|
||||||
short *edge;
|
short *edge;
|
||||||
short *states;
|
short *states;
|
||||||
short **new_includes;
|
short **new_includes;
|
||||||
@@ -542,17 +525,16 @@ build_relations (void)
|
|||||||
|
|
||||||
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
|
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
|
||||||
{
|
{
|
||||||
length = 1;
|
int length = 1;
|
||||||
states[0] = state1;
|
states[0] = state1;
|
||||||
stateno = state1;
|
stateno = state1;
|
||||||
|
|
||||||
for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
|
for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
|
||||||
{
|
{
|
||||||
symbol2 = *rp;
|
int symbol2 = *rp;
|
||||||
sp = state_table[stateno].shift_table;
|
shifts *sp = state_table[stateno].shift_table;
|
||||||
k = sp->nshifts;
|
|
||||||
|
|
||||||
for (j = 0; j < k; j++)
|
for (j = 0; j < sp->nshifts; j++)
|
||||||
{
|
{
|
||||||
stateno = sp->shifts[j];
|
stateno = sp->shifts[j];
|
||||||
if (state_table[stateno].accessing_symbol == symbol2)
|
if (state_table[stateno].accessing_symbol == symbol2)
|
||||||
@@ -584,19 +566,17 @@ build_relations (void)
|
|||||||
|
|
||||||
if (nedges)
|
if (nedges)
|
||||||
{
|
{
|
||||||
includes[i] = shortp = XCALLOC (short, nedges + 1);
|
includes[i] = XCALLOC (short, nedges + 1);
|
||||||
for (j = 0; j < nedges; j++)
|
for (j = 0; j < nedges; j++)
|
||||||
shortp[j] = edge[j];
|
includes[i][j] = edge[j];
|
||||||
shortp[nedges] = -1;
|
includes[i][nedges] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_includes = transpose (includes, ngotos);
|
new_includes = transpose (includes, ngotos);
|
||||||
|
|
||||||
for (i = 0; i < ngotos; i++)
|
for (i = 0; i < ngotos; i++)
|
||||||
if (includes[i])
|
XFREE (includes[i]);
|
||||||
XFREE (includes[i]);
|
|
||||||
|
|
||||||
XFREE (includes);
|
XFREE (includes);
|
||||||
|
|
||||||
includes = new_includes;
|
includes = new_includes;
|
||||||
|
|||||||
Reference in New Issue
Block a user