X-Git-Url: https://ocean-lang.org/code/?a=blobdiff_plain;f=csrc%2Fparsergen.mdc;h=5d2e164221fb38488948210128bf007390f0e561;hb=caac8a86d23d6d058a4234e265c2f50e7e7c9b84;hp=ad20195f51b8f355bc0bca3eebe021eb495106e0;hpb=25de15d0a49d4211534ce13442b31656b9058ea9;p=ocean diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index ad20195..5d2e164 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -1488,18 +1488,21 @@ itemsets (or merged with a pre-existing itemset). continue; if (pr->body[bp] != sym) continue; + + bp += 1; if (type >= LALR) la = is->items.data[j]; - pos = symset_find(&newitemset, pr->head->num); - if (bp + 1 == pr->body_size && + if (bp == pr->body_size && pr->precedence > 0 && pr->precedence > precedence) { // new itemset is reducible and has a precedence. precedence = pr->precedence; assoc = pr->assoc; } + pos = symset_find(&newitemset, item_num(p, bp)); + if (pos < 0) - symset_add(&newitemset, item_num(p, bp+1), la); + symset_add(&newitemset, item_num(p, bp), la); else if (type >= LALR) { // Need to merge la set. int la2 = newitemset.data[pos]; @@ -2062,10 +2065,13 @@ The go to table is stored in a simple array of `sym` and corresponding int i; fprintf(f, "#line 0 \"gen_goto\"\n"); for (i = 0; i < g->states; i++) { + struct symset gt = g->statetab[i]->go_to; int j; + + if (gt.cnt == 0) + continue; fprintf(f, "static const struct lookup goto_%d[] = {\n", i); - struct symset gt = g->statetab[i]->go_to; for (j = 0; j < gt.cnt; j++) fprintf(f, "\t{ %d, %d },\n", gt.syms[j], gt.data[j]); @@ -2096,18 +2102,21 @@ The go to table is stored in a simple array of `sym` and corresponding prod_len = pr->body_size; } } - - if (prod >= 0) - fprintf(f, "\t[%d] = { %d, goto_%d, %d, %d, %d, %d, %d, %d },\n", - i, is->go_to.cnt, i, prod, - g->productions[prod]->body_size, - g->productions[prod]->head->num, + if (is->go_to.cnt) + fprintf(f, "\t[%d] = { %d, goto_%d, ", + i, is->go_to.cnt, i); + else + fprintf(f, "\t[%d] = { 0, NULL, ", i); + if (prod >= 0) { + struct production *pr = g->productions[prod]; + fprintf(f, "%d, %d, %d, %d, %d, %d },\n", prod, + pr->body_size, + pr->head->num, is->starts_line, - g->productions[prod]->line_like, + pr->line_like, is->min_prefix); - else - fprintf(f, "\t[%d] = { %d, goto_%d, -1, -1, -1, %d, 0, %d },\n", - i, is->go_to.cnt, i, + } else + fprintf(f, "-1, -1, -1, %d, 0, %d },\n", is->starts_line, is->min_prefix); } fprintf(f, "};\n\n"); @@ -2303,15 +2312,15 @@ transformed, and will cause an error when the code is compiled. ###### functions static void gen_reduce(FILE *f, struct grammar *g, char *file, - struct code_node *code) + struct code_node *pre_reduce) { int i; fprintf(f, "#line 1 \"gen_reduce\"\n"); fprintf(f, "static int do_reduce(int prod, void **body, struct token_config *config, void *ret)\n"); fprintf(f, "{\n"); fprintf(f, "\tint ret_size = 0;\n"); - if (code) - code_node_print(f, code, file); + if (pre_reduce) + code_node_print(f, pre_reduce, file); fprintf(f, "#line 4 \"gen_reduce\"\n"); fprintf(f, "\tswitch(prod) {\n"); @@ -2446,7 +2455,7 @@ grammar file). case 't': tag = optarg; break; default: - fprintf(stderr, "Usage: parsergen ...\n"); + fprintf(stderr, "Usage: parsergen -[05SL1R] [-t tag] [-o output] input\n"); exit(1); } }