225 |
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_short_table, short) |
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_short_table, short) |
226 |
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number_t) |
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number_t) |
227 |
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number_t) |
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number_t) |
228 |
|
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number_t) |
229 |
|
|
230 |
|
|
231 |
/*-----------------------------------------------------------------. |
/*-----------------------------------------------------------------. |
351 |
static void |
static void |
352 |
prepare_states (void) |
prepare_states (void) |
353 |
{ |
{ |
354 |
size_t i; |
state_number_t i; |
355 |
symbol_number_t *values = |
symbol_number_t *values = |
356 |
(symbol_number_t *) alloca (sizeof (symbol_number_t) * nstates); |
(symbol_number_t *) alloca (sizeof (symbol_number_t) * nstates); |
357 |
for (i = 0; i < nstates; ++i) |
for (i = 0; i < nstates; ++i) |
358 |
values[i] = states[i]->accessing_symbol; |
values[i] = states[i]->accessing_symbol; |
359 |
muscle_insert_symbol_number_table ("stos", values, |
muscle_insert_symbol_number_table ("stos", values, |
360 |
0, 1, nstates); |
0, 1, nstates); |
361 |
} |
} |
362 |
|
|
363 |
|
|
464 |
for (i = 0; i < shiftp->nshifts; i++) |
for (i = 0; i < shiftp->nshifts; i++) |
465 |
{ |
{ |
466 |
symbol_number_t symbol; |
symbol_number_t symbol; |
467 |
int shift_state = shiftp->shifts[i]; |
state_number_t shift_state = shiftp->shifts[i]; |
468 |
if (!shift_state) |
if (!shift_state) |
469 |
continue; |
continue; |
470 |
|
|
475 |
|
|
476 |
if (actrow[symbol] != 0) |
if (actrow[symbol] != 0) |
477 |
conflicted = conflrow[symbol] = 1; |
conflicted = conflrow[symbol] = 1; |
478 |
actrow[symbol] = shift_state; |
actrow[symbol] = state_number_as_int (shift_state); |
479 |
|
|
480 |
/* Do not use any default reduction if there is a shift for |
/* Do not use any default reduction if there is a shift for |
481 |
error */ |
error */ |
551 |
|
|
552 |
|
|
553 |
static void |
static void |
554 |
save_row (int state) |
save_row (state_number_t state) |
555 |
{ |
{ |
556 |
int i; |
symbol_number_t i; |
557 |
int count; |
int count; |
558 |
short *sp = NULL; |
short *sp = NULL; |
559 |
short *sp1 = NULL; |
short *sp1 = NULL; |
600 |
static void |
static void |
601 |
token_actions (void) |
token_actions (void) |
602 |
{ |
{ |
603 |
size_t i; |
state_number_t i; |
604 |
int nconflict = conflicts_total_count (); |
int nconflict = conflicts_total_count (); |
605 |
|
|
606 |
short *yydefact = XCALLOC (short, nstates); |
short *yydefact = XCALLOC (short, nstates); |
797 |
|
|
798 |
|
|
799 |
static void |
static void |
800 |
save_column (int symbol, int default_state) |
save_column (symbol_number_t symbol, state_number_t default_state) |
801 |
{ |
{ |
802 |
int i; |
int i; |
803 |
short *sp; |
short *sp; |
804 |
short *sp1; |
short *sp1; |
805 |
short *sp2; |
short *sp2; |
806 |
int count; |
int count; |
807 |
int symno = symbol - ntokens + nstates; |
int symno = symbol - ntokens + state_number_as_int (nstates); |
808 |
|
|
809 |
short begin = goto_map[symbol]; |
int begin = goto_map[symbol]; |
810 |
short end = goto_map[symbol + 1]; |
int end = goto_map[symbol + 1]; |
811 |
|
|
812 |
count = 0; |
count = 0; |
813 |
for (i = begin; i < end; i++) |
for (i = begin; i < end; i++) |
831 |
width[symno] = sp1[-1] - sp[0] + 1; |
width[symno] = sp1[-1] - sp[0] + 1; |
832 |
} |
} |
833 |
|
|
834 |
static int |
|
835 |
default_goto (int symbol) |
static state_number_t |
836 |
|
default_goto (symbol_number_t symbol) |
837 |
{ |
{ |
838 |
size_t i; |
state_number_t s; |
839 |
size_t m = goto_map[symbol]; |
int i; |
840 |
size_t n = goto_map[symbol + 1]; |
int m = goto_map[symbol]; |
841 |
int default_state = -1; |
int n = goto_map[symbol + 1]; |
842 |
|
state_number_t default_state = (state_number_t) -1; |
843 |
int max = 0; |
int max = 0; |
844 |
|
|
845 |
if (m == n) |
if (m == n) |
846 |
return -1; |
return (state_number_t) -1; |
847 |
|
|
848 |
for (i = 0; i < nstates; i++) |
for (s = 0; s < nstates; s++) |
849 |
state_count[i] = 0; |
state_count[s] = 0; |
850 |
|
|
851 |
for (i = m; i < n; i++) |
for (i = m; i < n; i++) |
852 |
state_count[to_state[i]]++; |
state_count[to_state[i]]++; |
853 |
|
|
854 |
for (i = 0; i < nstates; i++) |
for (s = 0; s < nstates; s++) |
855 |
if (state_count[i] > max) |
if (state_count[s] > max) |
856 |
{ |
{ |
857 |
max = state_count[i]; |
max = state_count[s]; |
858 |
default_state = i; |
default_state = s; |
859 |
} |
} |
860 |
|
|
861 |
return default_state; |
return default_state; |
874 |
static void |
static void |
875 |
goto_actions (void) |
goto_actions (void) |
876 |
{ |
{ |
877 |
int i; |
symbol_number_t i; |
878 |
short *yydefgoto = XMALLOC (short, nsyms - ntokens); |
state_number_t *yydefgoto = XMALLOC (state_number_t, nsyms - ntokens); |
879 |
|
|
880 |
state_count = XCALLOC (short, nstates); |
state_count = XCALLOC (short, nstates); |
881 |
for (i = ntokens; i < nsyms; ++i) |
for (i = ntokens; i < nsyms; ++i) |
882 |
{ |
{ |
883 |
int default_state = default_goto (i); |
state_number_t default_state = default_goto (i); |
884 |
save_column (i, default_state); |
save_column (i, default_state); |
885 |
yydefgoto[i - ntokens] = default_state; |
yydefgoto[i - ntokens] = default_state; |
886 |
} |
} |
887 |
|
|
888 |
muscle_insert_short_table ("defgoto", yydefgoto, |
muscle_insert_state_number_table ("defgoto", yydefgoto, |
889 |
yydefgoto[0], 1, nsyms - ntokens); |
yydefgoto[0], 1, nsyms - ntokens); |
890 |
XFREE (state_count); |
XFREE (state_count); |
891 |
XFREE (yydefgoto); |
XFREE (yydefgoto); |
892 |
} |
} |
981 |
|
|
982 |
for (k = 0; ok && k < t; k++) |
for (k = 0; ok && k < t; k++) |
983 |
{ |
{ |
984 |
loc = j + from[k]; |
loc = j + state_number_as_int (from[k]); |
985 |
if (loc > (int) table_size) |
if (loc > (int) table_size) |
986 |
table_grow (loc); |
table_grow (loc); |
987 |
|
|
997 |
{ |
{ |
998 |
for (k = 0; k < t; k++) |
for (k = 0; k < t; k++) |
999 |
{ |
{ |
1000 |
loc = j + from[k]; |
loc = j + state_number_as_int (from[k]); |
1001 |
table[loc] = to[k]; |
table[loc] = state_number_as_int (to[k]); |
1002 |
if (glr_parser && conflict_to != NULL) |
if (glr_parser && conflict_to != NULL) |
1003 |
conflict_table[loc] = conflict_to[k]; |
conflict_table[loc] = conflict_to[k]; |
1004 |
check[loc] = from[k]; |
check[loc] = state_number_as_int (from[k]); |
1005 |
} |
} |
1006 |
|
|
1007 |
while (table[lowzero] != 0) |
while (table[lowzero] != 0) |
1132 |
static void |
static void |
1133 |
output_actions (void) |
output_actions (void) |
1134 |
{ |
{ |
1135 |
size_t i; |
state_number_t i; |
1136 |
nvectors = nstates + nvars; |
|
1137 |
|
/* That's a poor way to make sure the sizes are properly corelated, |
1138 |
|
in particular the signedness is not taking into account, but it's |
1139 |
|
not useless. */ |
1140 |
|
assert (sizeof (nvectors) >= sizeof (nstates)); |
1141 |
|
assert (sizeof (nvectors) >= sizeof (nvars)); |
1142 |
|
|
1143 |
|
nvectors = state_number_as_int (nstates) + nvars; |
1144 |
|
|
1145 |
froms = XCALLOC (short *, nvectors); |
froms = XCALLOC (short *, nvectors); |
1146 |
tos = XCALLOC (short *, nvectors); |
tos = XCALLOC (short *, nvectors); |
1276 |
MUSCLE_INSERT_INT ("pure", pure_parser); |
MUSCLE_INSERT_INT ("pure", pure_parser); |
1277 |
MUSCLE_INSERT_INT ("nsym", nsyms); |
MUSCLE_INSERT_INT ("nsym", nsyms); |
1278 |
MUSCLE_INSERT_INT ("debug", debug_flag); |
MUSCLE_INSERT_INT ("debug", debug_flag); |
1279 |
MUSCLE_INSERT_INT ("final", final_state); |
MUSCLE_INSERT_INT ("final", final_state->number); |
1280 |
MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number); |
MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number); |
1281 |
MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number); |
MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number); |
1282 |
MUSCLE_INSERT_INT ("error_verbose", error_verbose); |
MUSCLE_INSERT_INT ("error_verbose", error_verbose); |