From 41fd3e529b1ea61cbced5ff8417aa5c5a9163edd Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 2 Oct 2014 20:51:36 +1000 Subject: [PATCH] parsergen: calculate and record "min_prefix" for each state. This is needed to determine when we can cancel an TK_out. Signed-off-by: NeilBrown --- csrc/parsergen.mdc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 573f6de..45fb09e 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -1178,6 +1178,7 @@ should happen, so we don't need to search a second time. struct symset go_to; char completed; char starts_line; + int min_prefix; }; ###### grammar fields @@ -1284,6 +1285,9 @@ though. struct symset LA = INIT_SYMSET; unsigned short sn = 0; + if (is->min_prefix == 0 || + (bs > 0 && bs < is->min_prefix)) + is->min_prefix = bs; if (bs == pr->body_size) continue; s = pr->body[bs]; @@ -1629,7 +1633,8 @@ Now we can report all the item sets complete with items, LA sets, and GO TO. for (s = 0; s < g->states; s++) { int j; struct itemset *is = g->statetab[s]; - printf(" Itemset %d:%s\n", s, is->starts_line?" (startsline)":""); + printf(" Itemset %d:%s min prefix=%d\n", + s, is->starts_line?" (startsline)":"", is->min_prefix); for (j = 0; j < is->items.cnt; j++) { report_item(g, is->items.syms[j]); if (is->items.data != NO_DATA) @@ -1893,6 +1898,7 @@ The go to table is stored in a simple array of `sym` and corresponding short reduce_sym; short shift_sym; short starts_line; + short min_prefix; }; @@ -1949,15 +1955,15 @@ The go to table is stored in a simple array of `sym` and corresponding } if (prod >= 0) - fprintf(f, "\t[%d] = { %d, goto_%d, %d, %d, %d, 0, %d },\n", + fprintf(f, "\t[%d] = { %d, goto_%d, %d, %d, %d, 0, %d, %d },\n", i, is->go_to.cnt, i, prod, g->productions[prod]->body_size, g->productions[prod]->head->num, - is->starts_line); + is->starts_line, is->min_prefix); else - fprintf(f, "\t[%d] = { %d, goto_%d, -1, -1, -1, %d, %d },\n", + fprintf(f, "\t[%d] = { %d, goto_%d, -1, -1, -1, %d, %d, %d },\n", i, is->go_to.cnt, i, shift_sym, - is->starts_line); + is->starts_line, is->min_prefix); } fprintf(f, "};\n\n"); } -- 2.43.0