48 |
|
|
49 |
static int ngotos; |
static int ngotos; |
50 |
short *goto_map = NULL; |
short *goto_map = NULL; |
51 |
short *from_state = NULL; |
state_number_t *from_state = NULL; |
52 |
short *to_state = NULL; |
state_number_t *to_state = NULL; |
53 |
|
|
54 |
/* And for the famous F variable, which name is so descriptive that a |
/* And for the famous F variable, which name is so descriptive that a |
55 |
comment is hardly needed. <grin>. */ |
comment is hardly needed. <grin>. */ |
134 |
static void |
static void |
135 |
initialize_LA (void) |
initialize_LA (void) |
136 |
{ |
{ |
137 |
size_t i; |
state_number_t i; |
138 |
int j; |
int j; |
139 |
rule_t **np; |
rule_t **np; |
140 |
|
|
157 |
static void |
static void |
158 |
set_goto_map (void) |
set_goto_map (void) |
159 |
{ |
{ |
160 |
size_t state; |
state_number_t state; |
|
int i; |
|
161 |
short *temp_map; |
short *temp_map; |
162 |
|
|
163 |
goto_map = XCALLOC (short, nvars + 1) - ntokens; |
goto_map = XCALLOC (short, nvars + 1) - ntokens; |
167 |
for (state = 0; state < nstates; ++state) |
for (state = 0; state < nstates; ++state) |
168 |
{ |
{ |
169 |
shifts *sp = states[state]->shifts; |
shifts *sp = states[state]->shifts; |
170 |
|
int i; |
171 |
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i) |
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i) |
172 |
{ |
{ |
173 |
if (ngotos == SHRT_MAX) |
if (ngotos == SHRT_MAX) |
180 |
|
|
181 |
{ |
{ |
182 |
int k = 0; |
int k = 0; |
183 |
|
int i; |
184 |
for (i = ntokens; i < nsyms; i++) |
for (i = ntokens; i < nsyms; i++) |
185 |
{ |
{ |
186 |
temp_map[i] = k; |
temp_map[i] = k; |
194 |
temp_map[nsyms] = ngotos; |
temp_map[nsyms] = ngotos; |
195 |
} |
} |
196 |
|
|
197 |
from_state = XCALLOC (short, ngotos); |
from_state = XCALLOC (state_number_t, ngotos); |
198 |
to_state = XCALLOC (short, ngotos); |
to_state = XCALLOC (state_number_t, ngotos); |
199 |
|
|
200 |
for (state = 0; state < nstates; ++state) |
for (state = 0; state < nstates; ++state) |
201 |
{ |
{ |
202 |
shifts *sp = states[state]->shifts; |
shifts *sp = states[state]->shifts; |
203 |
|
int i; |
204 |
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i) |
for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i) |
205 |
{ |
{ |
206 |
int k = temp_map[SHIFT_SYMBOL (sp, i)]++; |
int k = temp_map[SHIFT_SYMBOL (sp, i)]++; |
219 |
`----------------------------------------------------------*/ |
`----------------------------------------------------------*/ |
220 |
|
|
221 |
static int |
static int |
222 |
map_goto (int state, symbol_number_t symbol) |
map_goto (state_number_t state, symbol_number_t symbol) |
223 |
{ |
{ |
224 |
int high; |
int high; |
225 |
int low; |
int low; |
226 |
int middle; |
int middle; |
227 |
int s; |
state_number_t s; |
228 |
|
|
229 |
low = goto_map[symbol]; |
low = goto_map[symbol]; |
230 |
high = goto_map[symbol + 1] - 1; |
high = goto_map[symbol + 1] - 1; |
260 |
|
|
261 |
for (i = 0; i < ngotos; i++) |
for (i = 0; i < ngotos; i++) |
262 |
{ |
{ |
263 |
int stateno = to_state[i]; |
state_number_t stateno = to_state[i]; |
264 |
shifts *sp = states[stateno]->shifts; |
shifts *sp = states[stateno]->shifts; |
265 |
|
|
266 |
int j; |
int j; |
402 |
build_relations (void) |
build_relations (void) |
403 |
{ |
{ |
404 |
short *edge = XCALLOC (short, ngotos + 1); |
short *edge = XCALLOC (short, ngotos + 1); |
405 |
short *states1 = XCALLOC (short, ritem_longest_rhs () + 1); |
state_number_t *states1 = XCALLOC (state_number_t, ritem_longest_rhs () + 1); |
406 |
int i; |
int i; |
407 |
|
|
408 |
includes = XCALLOC (short *, ngotos); |
includes = XCALLOC (short *, ngotos); |
516 |
static void |
static void |
517 |
states_lookaheads_count (void) |
states_lookaheads_count (void) |
518 |
{ |
{ |
519 |
size_t i; |
state_number_t i; |
520 |
nLA = 0; |
nLA = 0; |
521 |
|
|
522 |
/* Count */ |
/* Count */ |
557 |
static void |
static void |
558 |
states_lookaheads_initialize (void) |
states_lookaheads_initialize (void) |
559 |
{ |
{ |
560 |
size_t i; |
state_number_t i; |
561 |
bitsetv pLA = LA; |
bitsetv pLA = LA; |
562 |
rule_t **pLArule = LArule; |
rule_t **pLArule = LArule; |
563 |
|
|
580 |
static void |
static void |
581 |
lookaheads_print (FILE *out) |
lookaheads_print (FILE *out) |
582 |
{ |
{ |
583 |
size_t i; |
state_number_t i; |
584 |
int j, k; |
int j, k; |
585 |
fprintf (out, "Lookaheads: BEGIN\n"); |
fprintf (out, "Lookaheads: BEGIN\n"); |
586 |
for (i = 0; i < nstates; ++i) |
for (i = 0; i < nstates; ++i) |