From: NeilBrown Date: Sun, 9 Jun 2019 23:00:43 +0000 (+1000) Subject: parsergen: flip ordering of precedence declarations. X-Git-Url: https://ocean-lang.org/code/?a=commitdiff_plain;ds=sidebyside;h=417af80ca582de9bfd2bcc77da37cd1e556da975;hp=d8c3a8ef69e0c14c23f7175b60deef3f14e6a88b;p=ocean parsergen: flip ordering of precedence declarations. Change so first precedence declaration is the lowest precedence. This is consistent with bison, and will make converting 'oceani' easer. When not using precedence, it is easier to do the lowest precedence first - so keep for approach. Signed-off-by: NeilBrown --- diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index d2ff898..d12a400 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -277,6 +277,9 @@ declares how it associates. This level is stored in each symbol listed and may be inherited by any production which uses the symbol. A production inherits from the last symbol which has a precedence. +The symbols on the first precedence line have the lowest precedence. +Subsequent lines introduce symbols with higher precedence. + ###### grammar fields struct text current_type; int type_isref; @@ -1287,12 +1290,11 @@ When itemsets are created we assign a precedence to the itemset from the complete item, if there is one. We ignore the possibility of there being two and don't (currently) handle precedence in such grammars. When completing a grammar we ignore any item where DOT is -followed by a terminal with a precedence lower (numerically higher) -than that for the itemset. Unless the terminal has right -associativity, we also ignore items where the terminal has the same -precedence. The result is that unwanted items are still in the -itemset, but the terminal doesn't get into the go to set, so the item -is ineffective. +followed by a terminal with a precedence lower than that for the +itemset. Unless the terminal has right associativity, we also ignore +items where the terminal has the same precedence. The result is that +unwanted items are still in the itemset, but the terminal doesn't get +into the go to set, so the item is ineffective. ###### complete itemset for (i = 0; i < is->items.cnt; i++) { @@ -1311,7 +1313,7 @@ is ineffective. continue; s = pr->body[bs]; if (s->precedence && is->precedence && - is->precedence < s->precedence) + is->precedence > s->precedence) /* This terminal has a low precedence and * shouldn't be shifted */ @@ -1404,8 +1406,7 @@ with a pre-existing itemset). pos = symset_find(&newitemset, pr->head->num); if (bp + 1 == pr->body_size && pr->precedence > 0 && - (precedence == 0 || - pr->precedence < precedence)) { + pr->precedence > precedence) { // new itemset is reducible and has a precedence. precedence = pr->precedence; assoc = pr->assoc; @@ -3089,8 +3090,8 @@ an error. # calc: grammar - $LEFT * / $LEFT + - + $LEFT * / Session -> Session Line | Line