* src/derives.h, src/derives.c (derives): A `rule_t***' instead of

`rule_number_t**'.
(set_derives, free_derives): Rename as...
(derives_compute, derives_free): this.
Adjust all dependencies.
* src/nullable.c (set_nullable, free_nullable): Rename as...
(nullable_compute, nullable_free): these.
(rule_list_t): Store rule_t *, not rule_number_t.
* src/state.c (state_rule_lookaheads_print): Directly compare rule
pointers, instead of their numbers.
* src/main.c (main): Call nullable_free, and derives_free earlier,
as they were lo longer used.
This commit is contained in:
Akim Demaille
2002-08-01 18:13:29 +00:00
parent 3325ddc49c
commit bb0027a9ac
9 changed files with 71 additions and 53 deletions

View File

@@ -1,3 +1,18 @@
2002-08-01 Akim Demaille <akim@epita.fr>
* src/derives.h, src/derives.c (derives): A `rule_t***' instead of
`rule_number_t**'.
(set_derives, free_derives): Rename as...
(derives_compute, derives_free): this.
Adjust all dependencies.
* src/nullable.c (set_nullable, free_nullable): Rename as...
(nullable_compute, nullable_free): these.
(rule_list_t): Store rule_t *, not rule_number_t.
* src/state.c (state_rule_lookaheads_print): Directly compare rule
pointers, instead of their numbers.
* src/main.c (main): Call nullable_free, and derives_free earlier,
as they were lo longer used.
2002-08-01 Akim Demaille <akim@epita.fr> 2002-08-01 Akim Demaille <akim@epita.fr>
* lib/timevar.c (get_time): Include children time. * lib/timevar.c (get_time): Include children time.

View File

@@ -125,9 +125,9 @@ set_firsts (void)
firsts = bitsetv_create (nvars, nvars, BITSET_FIXED); firsts = bitsetv_create (nvars, nvars, BITSET_FIXED);
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
for (j = 0; derives[i][j] >= 0; ++j) for (j = 0; derives[i][j]; ++j)
{ {
int symbol = rules[derives[i][j]].rhs[0]; int symbol = derives[i][j]->rhs[0];
if (ISVAR (symbol)) if (ISVAR (symbol))
bitset_set (FIRSTS (i), symbol - ntokens); bitset_set (FIRSTS (i), symbol - ntokens);
} }
@@ -165,8 +165,8 @@ set_fderives (void)
for (i = ntokens; i < nsyms; ++i) for (i = ntokens; i < nsyms; ++i)
for (j = ntokens; j < nsyms; ++j) for (j = ntokens; j < nsyms; ++j)
if (bitset_test (FIRSTS (i), j - ntokens)) if (bitset_test (FIRSTS (i), j - ntokens))
for (k = 0; derives[j][k] >= 0; ++k) for (k = 0; derives[j][k]; ++k)
bitset_set (FDERIVES (i), derives[j][k]); bitset_set (FDERIVES (i), derives[j][k]->number);
if (trace_flag & trace_sets) if (trace_flag & trace_sets)
print_fderives (); print_fderives ();

View File

@@ -1,5 +1,5 @@
/* Match rules with nonterminals for bison, /* Match rules with nonterminals for bison,
Copyright 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -30,10 +30,10 @@
typedef struct rule_list_s typedef struct rule_list_s
{ {
struct rule_list_s *next; struct rule_list_s *next;
rule_number_t value; rule_t *value;
} rule_list_t; } rule_list_t;
rule_number_t **derives = NULL; rule_t ***derives = NULL;
static void static void
print_derives (void) print_derives (void)
@@ -44,12 +44,12 @@ print_derives (void)
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {
rule_number_t *rp; rule_t **rp;
fprintf (stderr, "\t%s derives\n", symbols[i]->tag); fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
for (rp = derives[i]; *rp >= 0; rp++) for (rp = derives[i]; *rp; ++rp)
{ {
fprintf (stderr, "\t\t%3d ", *rp); fprintf (stderr, "\t\t%3d ", (*rp)->user_number);
rule_rhs_print (&rules[*rp], stderr); rule_rhs_print (*rp, stderr);
} }
} }
@@ -58,11 +58,11 @@ print_derives (void)
void void
set_derives (void) derives_compute (void)
{ {
symbol_number_t i; symbol_number_t i;
int r; int r;
rule_number_t *q; rule_t **q;
/* DSET[NTERM] -- A linked list of the numbers of the rules whose /* DSET[NTERM] -- A linked list of the numbers of the rules whose
LHS is NTERM. */ LHS is NTERM. */
@@ -79,15 +79,15 @@ set_derives (void)
rule_list_t *p = &delts[r]; rule_list_t *p = &delts[r];
/* A new LHS is found. */ /* A new LHS is found. */
p->next = dset[lhs]; p->next = dset[lhs];
p->value = r; p->value = &rules[r];
dset[lhs] = p; dset[lhs] = p;
} }
/* DSET contains what we need under the form of a linked list. Make /* DSET contains what we need under the form of a linked list. Make
it a single array. */ it a single array. */
derives = XCALLOC (rule_number_t *, nvars) - ntokens; derives = XCALLOC (rule_t **, nvars) - ntokens;
q = XCALLOC (rule_number_t, nvars + int_of_rule_number (nrules)); q = XCALLOC (rule_t *, nvars + int_of_rule_number (nrules));
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {
@@ -98,7 +98,7 @@ set_derives (void)
*q++ = p->value; *q++ = p->value;
p = p->next; p = p->next;
} }
*q++ = -1; *q++ = NULL;
} }
if (trace_flag & trace_sets) if (trace_flag & trace_sets)
@@ -110,7 +110,7 @@ set_derives (void)
void void
free_derives (void) derives_free (void)
{ {
XFREE (derives[ntokens]); XFREE (derives[ntokens]);
XFREE (derives + ntokens); XFREE (derives + ntokens);

View File

@@ -1,5 +1,5 @@
/* Match rules with nonterminals for bison, /* Match rules with nonterminals for bison,
Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. Copyright (C) 1984, 1989, 2000, 2001, 2002 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,13 +21,13 @@
#ifndef DERIVES_H_ #ifndef DERIVES_H_
# define DERIVES_H_ # define DERIVES_H_
/* DERIVES[SYMBOL - NTOKENS] points to a vector of the number of the /* DERIVES[SYMBOL - NTOKENS] points to a vector of the rules that
rules that SYMBOL derives, terminated with -1. */ SYMBOL derives, terminated with NULL. */
extern rule_number_t **derives; extern rule_t ***derives;
/* Compute DERIVES. */ /* Compute DERIVES. */
void set_derives PARAMS((void)); void derives_compute PARAMS((void));
void free_derives PARAMS((void)); void derives_free PARAMS((void));
#endif /* !DERIVES_H_ */ #endif /* !DERIVES_H_ */

View File

@@ -244,16 +244,16 @@ initialize_F (void)
static void static void
add_lookback_edge (state_t *state, rule_number_t ruleno, int gotono) add_lookback_edge (state_t *state, rule_t *rule, int gotono)
{ {
int i; int i;
goto_list_t *sp; goto_list_t *sp;
for (i = 0; i < state->nlookaheads; ++i) for (i = 0; i < state->nlookaheads; ++i)
if (state->lookaheads_rule[i]->number == ruleno) if (state->lookaheads_rule[i] == rule)
break; break;
assert (state->lookaheads_rule[i]->number == ruleno); assert (state->lookaheads_rule[i] == rule);
sp = XCALLOC (goto_list_t, 1); sp = XCALLOC (goto_list_t, 1);
sp->next = lookback[(state->lookaheads - LA) + i]; sp->next = lookback[(state->lookaheads - LA) + i];
@@ -276,9 +276,9 @@ build_relations (void)
{ {
int nedges = 0; int nedges = 0;
symbol_number_t symbol1 = states[to_state[i]]->accessing_symbol; symbol_number_t symbol1 = states[to_state[i]]->accessing_symbol;
rule_number_t *rulep; rule_t **rulep;
for (rulep = derives[symbol1]; *rulep >= 0; rulep++) for (rulep = derives[symbol1]; *rulep; rulep++)
{ {
int done; int done;
int length = 1; int length = 1;
@@ -286,7 +286,7 @@ build_relations (void)
state_t *state = states[from_state[i]]; state_t *state = states[from_state[i]];
states1[0] = state->number; states1[0] = state->number;
for (rp = rules[*rulep].rhs; *rp >= 0; rp++) for (rp = (*rulep)->rhs; *rp >= 0; rp++)
{ {
state = transitions_to (state->transitions, state = transitions_to (state->transitions,
item_number_as_symbol_number (*rp)); item_number_as_symbol_number (*rp));

View File

@@ -1,5 +1,5 @@
/* Top level entry point of bison, /* Top level entry point of bison,
Copyright 1984, 1986, 1989, 1992, 1995, 2000, 2001, 2002 Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000, 2001, 2002
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -84,8 +84,8 @@ main (int argc, char *argv[])
/* Record other info about the grammar. In files derives and /* Record other info about the grammar. In files derives and
nullable. */ nullable. */
timevar_push (TV_SETS); timevar_push (TV_SETS);
set_derives (); derives_compute ();
set_nullable (); nullable_compute ();
timevar_pop (TV_SETS); timevar_pop (TV_SETS);
/* Convert to nondeterministic finite state machine. In file LR0. /* Convert to nondeterministic finite state machine. In file LR0.
@@ -99,6 +99,11 @@ main (int argc, char *argv[])
lalr (); lalr ();
timevar_pop (TV_LALR); timevar_pop (TV_LALR);
timevar_push (TV_FREE);
nullable_free ();
derives_free ();
timevar_pop (TV_FREE);
/* Find and record any conflicts: places where one token of /* Find and record any conflicts: places where one token of
lookahead is not enough to disambiguate the parsing. In file lookahead is not enough to disambiguate the parsing. In file
conflicts. Also resolve s/r conflicts based on precedence conflicts. Also resolve s/r conflicts based on precedence
@@ -152,8 +157,6 @@ main (int argc, char *argv[])
states_free (); states_free ();
reduce_free (); reduce_free ();
conflicts_free (); conflicts_free ();
free_nullable ();
free_derives ();
grammar_free (); grammar_free ();
/* The scanner memory cannot be released right after parsing, as it /* The scanner memory cannot be released right after parsing, as it

View File

@@ -30,14 +30,14 @@
#include "reduce.h" #include "reduce.h"
#include "nullable.h" #include "nullable.h"
/* Linked list of rule numbers. */ /* Linked list of rules. */
typedef struct rule_list_s typedef struct rule_list_s
{ {
struct rule_list_s *next; struct rule_list_s *next;
rule_number_t value; rule_t *value;
} rule_list_t; } rule_list_t;
char *nullable = NULL; bool *nullable = NULL;
static void static void
nullable_print (FILE *out) nullable_print (FILE *out)
@@ -50,7 +50,7 @@ nullable_print (FILE *out)
} }
void void
set_nullable (void) nullable_compute (void)
{ {
rule_number_t ruleno; rule_number_t ruleno;
symbol_number_t *s1; symbol_number_t *s1;
@@ -66,7 +66,7 @@ set_nullable (void)
Supposedly NRITEMS - NRULES is enough. But why take the risk? */ Supposedly NRITEMS - NRULES is enough. But why take the risk? */
rule_list_t *relts = XCALLOC (rule_list_t, nritems + nvars + 1); rule_list_t *relts = XCALLOC (rule_list_t, nritems + nvars + 1);
nullable = XCALLOC (char, nvars) - ntokens; nullable = XCALLOC (bool, nvars) - ntokens;
s1 = s2 = squeue; s1 = s2 = squeue;
p = relts; p = relts;
@@ -91,7 +91,7 @@ set_nullable (void)
{ {
rcount[ruleno]++; rcount[ruleno]++;
p->next = rsets[*r]; p->next = rsets[*r];
p->value = ruleno; p->value = rule;
rsets[*r] = p; rsets[*r] = p;
p++; p++;
} }
@@ -111,12 +111,12 @@ set_nullable (void)
while (s1 < s2) while (s1 < s2)
for (p = rsets[*s1++]; p; p = p->next) for (p = rsets[*s1++]; p; p = p->next)
{ {
ruleno = p->value; rule_t *rule = p->value;
if (--rcount[ruleno] == 0) if (--rcount[rule->number] == 0)
if (rules[ruleno].useful && !nullable[rules[ruleno].lhs->number]) if (rule->useful && !nullable[rule->lhs->number])
{ {
nullable[rules[ruleno].lhs->number] = 1; nullable[rule->lhs->number] = 1;
*s2++ = rules[ruleno].lhs->number; *s2++ = rule->lhs->number;
} }
} }
@@ -131,7 +131,7 @@ set_nullable (void)
void void
free_nullable (void) nullable_free (void)
{ {
XFREE (nullable + ntokens); XFREE (nullable + ntokens);
} }

View File

@@ -1,5 +1,5 @@
/* Part of the bison parser generator, /* Part of the bison parser generator,
Copyright 2000 Free Software Foundation, Inc. Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -23,11 +23,11 @@
/* A vector saying which nonterminals can expand into the null string. /* A vector saying which nonterminals can expand into the null string.
NULLABLE[I - NTOKENS] is nonzero if symbol I can do so. */ NULLABLE[I - NTOKENS] is nonzero if symbol I can do so. */
extern char *nullable; extern bool *nullable;
/* Set up NULLABLE. */ /* Set up NULLABLE. */
extern void set_nullable PARAMS((void)); extern void nullable_compute PARAMS((void));
/* Free NULLABLE. */ /* Free NULLABLE. */
extern void free_nullable PARAMS((void)); extern void nullable_free PARAMS((void));
#endif /* !NULLABLE_H_ */ #endif /* !NULLABLE_H_ */

View File

@@ -223,7 +223,7 @@ state_rule_lookaheads_print (state_t *state, rule_t *rule, FILE *out)
/* Count the number of lookaheads corresponding to this rule. */ /* Count the number of lookaheads corresponding to this rule. */
for (j = 0; j < state->nlookaheads; ++j) for (j = 0; j < state->nlookaheads; ++j)
BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0) BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0)
if (state->lookaheads_rule[j]->number == rule->number) if (state->lookaheads_rule[j] == rule)
nlookaheads++; nlookaheads++;
/* Print them if there are. */ /* Print them if there are. */
@@ -232,7 +232,7 @@ state_rule_lookaheads_print (state_t *state, rule_t *rule, FILE *out)
fprintf (out, " ["); fprintf (out, " [");
for (j = 0; j < state->nlookaheads; ++j) for (j = 0; j < state->nlookaheads; ++j)
BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0) BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0)
if (state->lookaheads_rule[j]->number == rule->number) if (state->lookaheads_rule[j] == rule)
fprintf (out, "%s%s", fprintf (out, "%s%s",
symbols[k]->tag, symbols[k]->tag,
--nlookaheads ? ", " : ""); --nlookaheads ? ", " : "");