From cbbbc8ec0230cf82765da33ecff7be9824006519 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 16 Jun 2019 11:31:54 +1000 Subject: [PATCH 1/1] parsegen: fix up look-ahead for $$NEWLINE items. I was discarding all non-newlines from the lookahead in the wrong place. I need to do it based on the productions added, not the item the are generated by. Signed-off-by: NeilBrown --- csrc/oceani.mdc | 8 +++++--- csrc/parsergen.mdc | 25 ++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 478186a..af7768d 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -3557,7 +3557,7 @@ defined. case Xcond_statement: free_cond_statement(cast(cond_statement, e)); break; ###### ComplexStatement Grammar - | CondStatement $$NEWLINE ${ $0 = $<1; }$ + | CondStatement ${ $0 = $<1; }$ ###### Grammar @@ -3585,9 +3585,11 @@ defined. $0->condpart = $1.condpart; $1.condpart = NULL; $0->dopart = $1.dopart; $1.dopart = NULL; }$ - | SwitchPart CondSuffix ${ - $0 = $<2; + | SwitchPart CasePart CondSuffix ${ + $0 = $<3; $0->condpart = $<1; + $2->next = $0->casepart; + $0->casepart = $<2; }$ | IfPart IfSuffix ${ $0 = $<2; diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 04974c3..1981c90 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -1309,6 +1309,8 @@ into the go to set, so the item is ineffective. struct symbol *s; struct symset LA = INIT_SYMSET; unsigned short sn = 0; + struct symset LAnl = INIT_SYMSET; + unsigned short snnl = 0; if (is->min_prefix == 0 || (bs > 0 && bs < is->min_prefix)) @@ -1341,15 +1343,14 @@ into the go to set, so the item is ineffective. int to_end; add_first(pr, bs+1, &LA, g, &to_end); if (to_end) { - if (pr->line_like) - symset_add(&LA, TK_newline, 0); - else { - struct symset ss = set_find(g, is->items.data[i]); - symset_union(&LA, &ss); - } + struct symset ss = set_find(g, is->items.data[i]); + symset_union(&LA, &ss); } sn = save_set(g, LA); LA = set_find(g, sn); + symset_add(&LAnl, TK_newline, 0); + snnl = save_set(g, LAnl); + LAnl = set_find(g, snnl); } /* Add productions for this symbol */ @@ -1360,19 +1361,25 @@ into the go to set, so the item is ineffective. int itm = item_num(p2, 0); int pos = symset_find(&is->items, itm); if (pos < 0) { - symset_add(&is->items, itm, sn); + if (g->productions[p2]->line_like) + symset_add(&is->items, itm, snnl); + else + symset_add(&is->items, itm, sn); /* Will have re-ordered, so start * from beginning again */ i = -1; } else if (type >= LALR) { struct symset ss = set_find(g, is->items.data[pos]); struct symset tmp = INIT_SYMSET; + struct symset *la = &LA; + if (g->productions[p2]->line_like) + la = &LAnl; symset_union(&tmp, &ss); - if (symset_union(&tmp, &LA)) { + if (symset_union(&tmp, la)) { is->items.data[pos] = save_set(g, tmp); i = -1; - }else + } else symset_free(tmp); } } -- 2.43.0