1 |
/* Generate the nondeterministic finite state machine for bison, |
/* Generate the nondeterministic finite state machine for Bison. |
2 |
|
|
3 |
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 Free Software |
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 Free Software |
4 |
Foundation, Inc. |
Foundation, Inc. |
59 |
static state * |
static state * |
60 |
state_list_append (symbol_number sym, size_t core_size, item_number *core) |
state_list_append (symbol_number sym, size_t core_size, item_number *core) |
61 |
{ |
{ |
62 |
state_list *node = XMALLOC (state_list, 1); |
state_list *node = MALLOC (node, 1); |
63 |
state *s = state_new (sym, core_size, core); |
state *s = state_new (sym, core_size, core); |
64 |
|
|
65 |
if (trace_flag & trace_automaton) |
if (trace_flag & trace_automaton) |
106 |
browsed too, hence we need to allocate room for _all_ the |
browsed too, hence we need to allocate room for _all_ the |
107 |
symbols. */ |
symbols. */ |
108 |
int count = 0; |
int count = 0; |
109 |
short *symbol_count = XCALLOC (short, nsyms + nuseless_nonterminals); |
short *symbol_count = CALLOC (symbol_count, nsyms + nuseless_nonterminals); |
110 |
|
|
111 |
for (r = 0; r < nrules; ++r) |
for (r = 0; r < nrules; ++r) |
112 |
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) |
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) |
121 |
appears as an item, which is SYMBOL_COUNT[S]. |
appears as an item, which is SYMBOL_COUNT[S]. |
122 |
We allocate that much space for each symbol. */ |
We allocate that much space for each symbol. */ |
123 |
|
|
124 |
kernel_base = XCALLOC (item_number *, nsyms); |
CALLOC (kernel_base, nsyms); |
125 |
if (count) |
if (count) |
126 |
kernel_items = XCALLOC (item_number, count); |
CALLOC (kernel_items, count); |
127 |
|
|
128 |
count = 0; |
count = 0; |
129 |
for (i = 0; i < nsyms; i++) |
for (i = 0; i < nsyms; i++) |
133 |
} |
} |
134 |
|
|
135 |
free (symbol_count); |
free (symbol_count); |
136 |
kernel_size = XCALLOC (int, nsyms); |
CALLOC (kernel_size, nsyms); |
137 |
} |
} |
138 |
|
|
139 |
|
|
142 |
{ |
{ |
143 |
allocate_itemsets (); |
allocate_itemsets (); |
144 |
|
|
145 |
shiftset = XCALLOC (state *, nsyms); |
CALLOC (shiftset, nsyms); |
146 |
redset = XCALLOC (rule *, nrules); |
CALLOC (redset, nrules); |
147 |
state_hash_new (); |
state_hash_new (); |
148 |
shift_symbol = XCALLOC (symbol_number, nsyms); |
CALLOC (shift_symbol, nsyms); |
149 |
} |
} |
150 |
|
|
151 |
|
|
157 |
free (shiftset); |
free (shiftset); |
158 |
free (kernel_base); |
free (kernel_base); |
159 |
free (kernel_size); |
free (kernel_size); |
160 |
XFREE (kernel_items); |
free (kernel_items); |
161 |
state_hash_free (); |
state_hash_free (); |
162 |
} |
} |
163 |
|
|
296 |
static void |
static void |
297 |
set_states (void) |
set_states (void) |
298 |
{ |
{ |
299 |
states = XCALLOC (state *, nstates); |
CALLOC (states, nstates); |
300 |
|
|
301 |
while (first_state) |
while (first_state) |
302 |
{ |
{ |