1 |
/* Subroutines for bison |
/* Subroutines for bison |
2 |
Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of Bison, the GNU Compiler Compiler. |
This file is part of Bison, the GNU Compiler Compiler. |
5 |
|
|
19 |
02111-1307, USA. */ |
02111-1307, USA. */ |
20 |
|
|
21 |
#include "system.h" |
#include "system.h" |
22 |
|
#include "bitset.h" |
23 |
|
#include "bitsetv.h" |
24 |
#include "getargs.h" |
#include "getargs.h" |
25 |
#include "symtab.h" |
#include "symtab.h" |
26 |
#include "gram.h" |
#include "gram.h" |
27 |
#include "reader.h" |
#include "reader.h" |
28 |
#include "closure.h" |
#include "closure.h" |
29 |
#include "derives.h" |
#include "derives.h" |
|
#include "bitset.h" |
|
30 |
#include "warshall.h" |
#include "warshall.h" |
31 |
|
|
32 |
/* NITEMSET is the size of the array ITEMSET. */ |
/* NITEMSET is the size of the array ITEMSET. */ |
36 |
static bitset ruleset; |
static bitset ruleset; |
37 |
|
|
38 |
/* internal data. See comments before set_fderives and set_firsts. */ |
/* internal data. See comments before set_fderives and set_firsts. */ |
39 |
static bitset *fderives = NULL; |
static bitsetv fderives = NULL; |
40 |
static bitset *firsts = NULL; |
static bitsetv firsts = NULL; |
41 |
|
|
42 |
/* Retrieve the FDERIVES/FIRSTS sets of the nonterminals numbered Var. */ |
/* Retrieve the FDERIVES/FIRSTS sets of the nonterminals numbered Var. */ |
43 |
#define FDERIVES(Var) fderives[(Var) - ntokens] |
#define FDERIVES(Var) fderives[(Var) - ntokens] |
121 |
{ |
{ |
122 |
int i, j; |
int i, j; |
123 |
|
|
124 |
firsts = XCALLOC (bitset, nvars); |
firsts = bitsetv_create (nvars, nvars, BITSET_FIXED); |
125 |
|
|
126 |
for (i = ntokens; i < nsyms; i++) |
for (i = ntokens; i < nsyms; i++) |
127 |
{ |
for (j = 0; derives[i][j] >= 0; ++j) |
128 |
FIRSTS (i) = bitset_create (nvars, BITSET_FIXED); |
{ |
129 |
for (j = 0; derives[i][j] >= 0; ++j) |
int symbol = ritem[rules[derives[i][j]].rhs]; |
130 |
{ |
if (ISVAR (symbol)) |
131 |
int symbol = ritem[rules[derives[i][j]].rhs]; |
bitset_set (FIRSTS (i), symbol - ntokens); |
132 |
if (ISVAR (symbol)) |
} |
|
bitset_set (FIRSTS (i), symbol - ntokens); |
|
|
} |
|
|
} |
|
133 |
|
|
134 |
RTC (firsts, nvars); |
RTC (firsts); |
135 |
|
|
136 |
if (trace_flag) |
if (trace_flag) |
137 |
print_firsts (); |
print_firsts (); |
152 |
{ |
{ |
153 |
int i, j, k; |
int i, j, k; |
154 |
|
|
155 |
fderives = XCALLOC (bitset, nvars); |
fderives = bitsetv_create (nvars, nrules + 1, BITSET_FIXED); |
|
bitset_stats_init (); |
|
|
for (i = 0 ; i < nvars; ++i) |
|
|
fderives[i] = bitset_create (nrules + 1, BITSET_FIXED); |
|
156 |
|
|
157 |
set_firsts (); |
set_firsts (); |
158 |
|
|
165 |
if (trace_flag) |
if (trace_flag) |
166 |
print_fderives (); |
print_fderives (); |
167 |
|
|
168 |
for (i = ntokens; i < nsyms; ++i) |
bitsetv_free (firsts); |
|
bitset_free (FIRSTS (i)); |
|
|
XFREE (firsts); |
|
169 |
} |
} |
170 |
|
|
171 |
|
|
240 |
void |
void |
241 |
free_closure (void) |
free_closure (void) |
242 |
{ |
{ |
|
int i; |
|
243 |
XFREE (itemset); |
XFREE (itemset); |
|
|
|
244 |
bitset_free (ruleset); |
bitset_free (ruleset); |
245 |
|
bitsetv_free (fderives); |
|
for (i = 0 ; i < nvars; ++i) |
|
|
bitset_free (fderives[i]); |
|
|
free (fderives); |
|
246 |
} |
} |