From: Ulya Trofimovich Date: Tue, 27 Jun 2017 12:53:09 +0000 (+0100) Subject: Once again fixed history comparison for POSIX disambiguation. X-Git-Tag: 1.0~39^2~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f78312b92060671e0fa82455070c7b04a65aae7;p=re2c Once again fixed history comparison for POSIX disambiguation. --- diff --git a/re2c/src/dfa/closure.cc b/re2c/src/dfa/closure.cc index c57fdfb3..aa01c227 100644 --- a/re2c/src/dfa/closure.cc +++ b/re2c/src/dfa/closure.cc @@ -52,39 +52,6 @@ bool cmpby_rule_state(const clos_t &x, const clos_t &y) assert(false); } -// POSIX disambiguation for orbit tags: compare by orders -// and tag histories. Lookahead may consist of multiple orbit subhistories -// (each containing either a single bottom value, or one or many cursor -// values); because of the shortest-path algorithm earlier subhistories -// do not necessarily coincide, so we cannot just compare the last pair -// of subhistories. -// see note [POSIX orbit tags] -static int32_t cmp_orbit(const clos_t &x, const clos_t &y, size_t t, Tagpool &tagpool) -{ - const tagver_t - ox = tagpool[x.order][t], - oy = tagpool[y.order][t]; - if (ox < oy) return -1; - if (ox > oy) return 1; - return tagpool.history.compare_orbit(x.tlook, y.tlook, t); -} - -// POSIX disambiguation for opening/closing tags: maximize (first lookahead, -// then orders). Lookahead may consist of multiple subhistories (each -// containing exactly one lookahead item: cursor or bottom). -// Comparing the last values is not enough: because of the shortest-path -// algorithm mismatch may occur at some earlier point (not at the last pair -// of subhistories), in which case we still need to re-run the search. -static int32_t cmp_max(const clos_t &x, const clos_t &y, size_t t, Tagpool &tagpool) -{ - int32_t cmp = tagpool.history.compare_max(x.tlook, y.tlook, t); - if (cmp != 0) return cmp; - tagver_t vx = -tagpool[x.order][t], vy = -tagpool[y.order][t]; - if (vx > vy) return -1; - if (vx < vy) return 1; - return 0; -} - // leftmost greedy disambiguation: order equals item's position // in leftmost NFA traversal (it's the same for all tags) static int32_t cmp_leftmost(const clos_t &x, const clos_t &y, Tagpool &tagpool) @@ -273,10 +240,13 @@ bool better(const clos_t &c1, const clos_t &c2, if (cmp > 0) return true; return false; } else { + tagtree_t &h = tagpool.history; for (size_t t = 0; t < tagpool.ntags; ++t) { - const int32_t cmp = orbit(tags[t]) - ? cmp_orbit(c1, c2, t, tagpool) - : cmp_max(c1, c2, t, tagpool); + const hidx_t i1 = c1.tlook, i2 = c2.tlook; + const tagver_t + o1 = -tagpool[c1.order][t], + o2 = -tagpool[c2.order][t]; + const int32_t cmp = h.compare_histories(i1, i2, o1, o2, t, orbit(tags[t])); if (cmp < 0) return false; if (cmp > 0) return true; } @@ -414,20 +384,19 @@ tcmd_t *generate_versions(closure_t &clos, const std::vector &tags, * This part of the algorithm was invented by Christopher Kuklewicz. */ -struct cmp_orbit_t +struct cmp_posix_t { Tagpool &tagpool; size_t tag; + bool orbit; bool operator()(cclositer_t x, cclositer_t y) - { return cmp_orbit(*x, *y, tag, tagpool) < 0; } -}; - -struct cmp_max_t -{ - Tagpool &tagpool; - size_t tag; - bool operator()(cclositer_t x, cclositer_t y) - { return cmp_max(*x, *y, tag, tagpool) < 0; } + { + const hidx_t i1 = x->tlook, i2 = y->tlook; + const tagver_t + o1 = -tagpool[x->order][tag], + o2 = -tagpool[y->order][tag]; + return tagpool.history.compare_last_subhistories(i1, i2, o1, o2, tag, orbit) < 0; + } }; struct cmp_leftmost_t @@ -482,13 +451,8 @@ void orders(closure_t &clos, Tagpool &tagpool, const std::vector &tags) } } else { for (size_t t = 0; t < ntag; ++t) { - if (orbit(tags[t])) { - cmp_orbit_t cmp = {tagpool, t}; - assign_orders(ps, pe, os0, cmp); - } else { - cmp_max_t cmp = {tagpool, t}; - assign_orders(ps, pe, os0, cmp); - } + cmp_posix_t cmp = {tagpool, t, orbit(tags[t])}; + assign_orders(ps, pe, os0, cmp); o = os; for (c = b; c != e; ++c, o += ntag) { o[t] = os0[std::find(ps, pe, c) - ps]; diff --git a/re2c/src/dfa/tagtree.cc b/re2c/src/dfa/tagtree.cc index a09a795d..0011c205 100644 --- a/re2c/src/dfa/tagtree.cc +++ b/re2c/src/dfa/tagtree.cc @@ -1,4 +1,5 @@ #include +#include #include #include "src/dfa/tagtree.h" @@ -6,6 +7,8 @@ namespace re2c { +static const tagver_t DELIM = TAGVER_CURSOR - 1; + tagtree_t::tagtree_t(): nodes(), path1(), path2() {} tagver_t tagtree_t::elem(hidx_t i) const { return nodes[i].elem; } @@ -33,27 +36,6 @@ static void subhistory(const tagtree_t &history, } } -// cut out a list of subhistories of this tag separated by occurences -// of higher-priority tags (separator has the highest value: 2, elements -// have lower values: 1 for cursor and 0 for bottom --- this way comparison -// will stop at separator and shorter subhistory will dominate). -static void subhistory_list(const tagtree_t &history, - std::vector &path, hidx_t idx, size_t tag) -{ - path.clear(); - hidx_t i = idx; - for (;;) { - for (; i != HROOT && history.tag(i) != tag; i = history.pred(i)); - if (i == HROOT) break; - path.push_back(2); - for (; i != HROOT && history.tag(i) >= tag; i = history.pred(i)) { - if (history.tag(i) == tag) { - path.push_back(history.elem(i) == TAGVER_CURSOR ? 1 : 0); - } - } - } -} - static int32_t compare_reversed( const std::vector &h1, const std::vector &h2) @@ -81,29 +63,98 @@ int32_t tagtree_t::compare_plain(hidx_t x, hidx_t y, size_t t) return compare_reversed(path1, path2); } -int32_t tagtree_t::compare_orbit(hidx_t x, hidx_t y, size_t t) +static size_t boundary_tag(size_t tag) { - subhistory_list(*this, path1, x, t); - subhistory_list(*this, path2, y, t); - return compare_reversed(path1, path2); + // for start tags, return itself; for end tags, return start tag + // (start tags have even numbers, end tags have odd numbers) + return tag & ~1u; } -int32_t tagtree_t::compare_max(hidx_t x, hidx_t y, size_t t) +// returns all subhistories of the given tag as one list (individual +// subhistories are separated by delimiter) +static int32_t subhistory_list(const tagtree_t &history, + std::vector &path, hidx_t idx, size_t tag) { - // compare starting from tail: at the first mismatch maximal value - // wins; if one subhistory is shorter, it's last value is assumed - // to be zero, so that comparison depends on the next value of the - // longer subgistory + path.clear(); + int32_t nsub = 0; + hidx_t i = idx; + + const size_t bound = boundary_tag(tag); + path.push_back(DELIM); for (;;) { - for (; x != HROOT && tag(x) != t; x = pred(x)); - for (; y != HROOT && tag(y) != t; y = pred(y)); - if (x == HROOT && y == HROOT) return 0; - if (x == HROOT) return (elem(y) == TAGVER_BOTTOM ? -1 : 1); - if (y == HROOT) return (elem(x) == TAGVER_BOTTOM ? 1 : -1); - if (elem(x) > elem(y)) return -1; - if (elem(x) < elem(y)) return 1; - x = pred(x); y = pred(y); + for (; i != HROOT && history.tag(i) >= bound; i = history.pred(i)) { + if (history.tag(i) == tag) { + path.push_back(history.elem(i)); + } + } + if (i == HROOT) break; + ++nsub; + path.push_back(DELIM); + for (; i != HROOT && history.tag(i) != tag; i = history.pred(i)); } + + return nsub; +} + +// Lookahead may consist of multiple subhistories (each containing either +// a single bottom value, or one or more cursor values (exactly one for +// non-orbit subhistories). Because of the shortest-path algorithm earlier +// subhistories do not necessarily coincide, so comparing only the last +// pair of subhistories is not enough. +// see note [POSIX orbit tags] +int32_t tagtree_t::compare_histories(hidx_t x, hidx_t y, + tagver_t ox, tagver_t oy, size_t t, bool orbit) +{ + const int32_t + n1 = subhistory_list(*this, path1, x, t), + n2 = subhistory_list(*this, path2, y, t); + + assert(n1 == n2); + if (orbit) { + path1.push_back(ox); + path2.push_back(oy); + } else { + if (path1.back() == DELIM) path1.push_back(ox); + if (path2.back() == DELIM) path2.push_back(oy); + } + + std::vector::const_reverse_iterator + i1 = path1.rbegin(), e1 = path1.rend(), + i2 = path2.rbegin(), e2 = path2.rend(); + for (;;) { + if (i1 == e1 && i2 == e2) return 0; + assert(i1 != e1 && i2 != e2); + const tagver_t v1 = *i1++, v2 = *i2++; + if (v1 == DELIM && v2 == DELIM) continue; + if (v1 == DELIM) return -1; + if (v2 == DELIM) return 1; + if (v1 > v2) return -1; + if (v1 < v2) return 1; + } +} + +static void last_subhistory(const tagtree_t &history, std::vector &path, + hidx_t idx, tagver_t order, size_t tag, bool orbit) +{ + path.clear(); + hidx_t i = idx; + const size_t bound = boundary_tag(tag); + for (; i != HROOT && history.tag(i) >= bound; i = history.pred(i)) { + if (history.tag(i) == tag) { + path.push_back(history.elem(i)); + } + } + if (i == HROOT && (orbit || path.empty())) { + path.push_back(order); + } +} + +int32_t tagtree_t::compare_last_subhistories(hidx_t x, hidx_t y, + tagver_t ox, tagver_t oy, size_t t, bool orbit) +{ + last_subhistory(*this, path1, x, ox, t, orbit); + last_subhistory(*this, path2, y, oy, t, orbit); + return compare_reversed(path1, path2); } tagver_t tagtree_t::last(hidx_t i, size_t t) const diff --git a/re2c/src/dfa/tagtree.h b/re2c/src/dfa/tagtree.h index 92eadb24..390b2891 100644 --- a/re2c/src/dfa/tagtree.h +++ b/re2c/src/dfa/tagtree.h @@ -34,8 +34,8 @@ struct tagtree_t size_t tag(hidx_t i) const; hidx_t push(hidx_t i, size_t t, tagver_t v); int32_t compare_plain(hidx_t x, hidx_t y, size_t t); - int32_t compare_orbit(hidx_t x, hidx_t y, size_t t); - int32_t compare_max(hidx_t x, hidx_t y, size_t t); + int32_t compare_histories(hidx_t x, hidx_t y, tagver_t ox, tagver_t oy, size_t t, bool orbit); + int32_t compare_last_subhistories(hidx_t x, hidx_t y, tagver_t ox, tagver_t oy, size_t t, bool orbit); tagver_t last(hidx_t i, size_t t) const; FORBID_COPY(tagtree_t); }; diff --git a/re2c/test/posix_captures/basic/51.i--flex-syntax.c b/re2c/test/posix_captures/basic/51.i--flex-syntax.c index 0fe7ddca..05a73a30 100644 --- a/re2c/test/posix_captures/basic/51.i--flex-syntax.c +++ b/re2c/test/posix_captures/basic/51.i--flex-syntax.c @@ -20,7 +20,7 @@ yy3: yych = *++YYCURSOR; switch (yych) { case 'b': - yyt1 = YYCURSOR; + yyt2 = YYCURSOR; goto yy5; case 'c': yyt1 = yyt2 = YYCURSOR; @@ -37,7 +37,7 @@ yy5: switch (yych) { case 'b': goto yy5; case 'c': - yyt2 = YYCURSOR; + yyt1 = YYCURSOR; goto yy7; default: goto yy4; } @@ -48,7 +48,7 @@ yy7: switch (yych) { case 'b': goto yy5; case 'c': - yyt2 = YYCURSOR; + yyt1 = YYCURSOR; goto yy7; case 'd': goto yy9; default: goto yy4; @@ -58,11 +58,11 @@ yy9: { const size_t yynmatch = 3; const YYCTYPE *yypmatch[yynmatch * 2]; - yypmatch[2] = yyt1; - yypmatch[4] = yyt2; - yypmatch[0] = yyt1 - 1; + yypmatch[2] = yyt2; + yypmatch[4] = yyt1; + yypmatch[0] = yyt2 - 1; yypmatch[1] = YYCURSOR; - yypmatch[3] = yyt2; + yypmatch[3] = yyt1; yypmatch[5] = YYCURSOR; {} } diff --git a/re2c/test/posix_captures/categorize/01.i--flex-syntax.c b/re2c/test/posix_captures/categorize/01.i--flex-syntax.c index e52b8b8f..9d665938 100644 --- a/re2c/test/posix_captures/categorize/01.i--flex-syntax.c +++ b/re2c/test/posix_captures/categorize/01.i--flex-syntax.c @@ -3,7 +3,7 @@ { YYCTYPE yych; unsigned int yyaccept = 0; - if (YYLIMIT <= YYCURSOR) YYFILL(1); + if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); yych = *YYCURSOR; switch (yych) { case 'a': @@ -12,7 +12,7 @@ case 'b': yyt3 = yyt4 = NULL; yyt1 = yyt2 = yyt5 = YYCURSOR; - goto yy5; + goto yy4; default: yyt3 = yyt4 = NULL; yyt1 = yyt2 = yyt5 = YYCURSOR; @@ -33,53 +33,64 @@ yy2: {} } yy3: + yych = *++YYCURSOR; + switch (yych) { + case 'b': + yyt3 = yyt4 = NULL; + yyt5 = YYCURSOR; + goto yy8; + default: goto yy7; + } +yy4: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'b': goto yy4; + default: goto yy2; + } +yy6: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; +yy7: switch (yych) { case 'a': - yyt2 = YYCURSOR; - goto yy3; + yyt5 = YYCURSOR; + goto yy6; case 'b': + yyt2 = yyt5; yyt3 = yyt4 = NULL; yyt5 = YYCURSOR; - goto yy7; + goto yy8; default: yyt3 = yyt4 = NULL; yyt2 = yyt5 = YYCURSOR; goto yy2; } -yy5: - ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - switch (yych) { - case 'b': goto yy5; - default: goto yy2; - } -yy7: +yy8: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { case 'a': yyt6 = YYCURSOR; - goto yy8; + goto yy9; case 'b': yyt2 = yyt5; - goto yy5; + goto yy4; default: yyt2 = yyt5; goto yy2; } -yy8: +yy9: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; switch (yych) { - case 'b': goto yy10; - default: goto yy9; + case 'b': goto yy11; + default: goto yy10; } -yy9: +yy10: YYCURSOR = YYMARKER; if (yyaccept == 0) { yyt2 = yyt5; @@ -88,7 +99,7 @@ yy9: yyt4 = yyt5 = YYCURSOR; goto yy2; } -yy10: +yy11: yyaccept = 1; YYMARKER = ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -97,11 +108,11 @@ yy10: case 'a': yyt3 = yyt6; yyt6 = YYCURSOR; - goto yy8; + goto yy9; case 'b': yyt3 = yyt6; yyt4 = yyt5 = YYCURSOR; - goto yy5; + goto yy4; default: yyt3 = yyt6; yyt4 = yyt5 = YYCURSOR; diff --git a/re2c/test/posix_captures/forcedassoc/13.i--flex-syntax.c b/re2c/test/posix_captures/forcedassoc/13.i--flex-syntax.c index e7d3a1b2..b783361f 100644 --- a/re2c/test/posix_captures/forcedassoc/13.i--flex-syntax.c +++ b/re2c/test/posix_captures/forcedassoc/13.i--flex-syntax.c @@ -2,7 +2,7 @@ { YYCTYPE yych; - if (YYLIMIT <= YYCURSOR) YYFILL(1); + if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); yych = *(YYMARKER = YYCURSOR); switch (yych) { case 'a': @@ -10,7 +10,7 @@ goto yy3; case 'b': yyt1 = yyt2 = YYCURSOR; - goto yy6; + goto yy5; default: goto yy2; } yy2: @@ -22,24 +22,19 @@ yy2: {} } yy3: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; + yych = *++YYCURSOR; switch (yych) { - case 'a': - yyt2 = YYCURSOR; - goto yy3; case 'b': yyt3 = YYCURSOR; - goto yy8; - default: goto yy5; + goto yy9; + default: goto yy8; } -yy5: +yy4: YYCURSOR = YYMARKER; goto yy2; -yy6: +yy5: ++YYCURSOR; -yy7: +yy6: { const size_t yynmatch = 3; const YYCTYPE *yypmatch[yynmatch * 2]; @@ -51,13 +46,28 @@ yy7: yypmatch[5] = YYCURSOR; {} } +yy7: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; yy8: + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy7; + case 'b': + yyt2 = yyt3; + yyt3 = YYCURSOR; + goto yy9; + default: goto yy4; + } +yy9: yych = *++YYCURSOR; switch (yych) { - case 'c': goto yy6; + case 'c': goto yy5; default: yyt2 = yyt3; - goto yy7; + goto yy6; } } diff --git a/re2c/test/posix_captures/forcedassoc/14.i--flex-syntax.c b/re2c/test/posix_captures/forcedassoc/14.i--flex-syntax.c index e7d3a1b2..b783361f 100644 --- a/re2c/test/posix_captures/forcedassoc/14.i--flex-syntax.c +++ b/re2c/test/posix_captures/forcedassoc/14.i--flex-syntax.c @@ -2,7 +2,7 @@ { YYCTYPE yych; - if (YYLIMIT <= YYCURSOR) YYFILL(1); + if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); yych = *(YYMARKER = YYCURSOR); switch (yych) { case 'a': @@ -10,7 +10,7 @@ goto yy3; case 'b': yyt1 = yyt2 = YYCURSOR; - goto yy6; + goto yy5; default: goto yy2; } yy2: @@ -22,24 +22,19 @@ yy2: {} } yy3: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; + yych = *++YYCURSOR; switch (yych) { - case 'a': - yyt2 = YYCURSOR; - goto yy3; case 'b': yyt3 = YYCURSOR; - goto yy8; - default: goto yy5; + goto yy9; + default: goto yy8; } -yy5: +yy4: YYCURSOR = YYMARKER; goto yy2; -yy6: +yy5: ++YYCURSOR; -yy7: +yy6: { const size_t yynmatch = 3; const YYCTYPE *yypmatch[yynmatch * 2]; @@ -51,13 +46,28 @@ yy7: yypmatch[5] = YYCURSOR; {} } +yy7: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; yy8: + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy7; + case 'b': + yyt2 = yyt3; + yyt3 = YYCURSOR; + goto yy9; + default: goto yy4; + } +yy9: yych = *++YYCURSOR; switch (yych) { - case 'c': goto yy6; + case 'c': goto yy5; default: yyt2 = yyt3; - goto yy7; + goto yy6; } } diff --git a/re2c/test/posix_captures/forcedassoc/15.i--flex-syntax.c b/re2c/test/posix_captures/forcedassoc/15.i--flex-syntax.c index 597736c8..c5ac0ad4 100644 --- a/re2c/test/posix_captures/forcedassoc/15.i--flex-syntax.c +++ b/re2c/test/posix_captures/forcedassoc/15.i--flex-syntax.c @@ -2,7 +2,7 @@ { YYCTYPE yych; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *(YYMARKER = YYCURSOR); switch (yych) { case 'a': @@ -10,7 +10,7 @@ goto yy3; case 'b': yyt1 = yyt2 = YYCURSOR; - goto yy6; + goto yy5; default: goto yy2; } yy2: @@ -22,26 +22,21 @@ yy2: {} } yy3: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); - yych = *YYCURSOR; + yych = *++YYCURSOR; switch (yych) { - case 'a': - yyt2 = YYCURSOR; - goto yy3; case 'b': yyt3 = YYCURSOR; - goto yy8; - default: goto yy5; + goto yy9; + default: goto yy8; } -yy5: +yy4: YYCURSOR = YYMARKER; goto yy2; -yy6: +yy5: yych = *++YYCURSOR; yyt3 = YYCURSOR; - goto yy10; -yy7: + goto yy11; +yy6: { const size_t yynmatch = 5; const YYCTYPE *yypmatch[yynmatch * 2]; @@ -57,23 +52,38 @@ yy7: yypmatch[9] = YYCURSOR; {} } +yy7: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); + yych = *YYCURSOR; yy8: + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy7; + case 'b': + yyt2 = yyt3; + yyt3 = YYCURSOR; + goto yy9; + default: goto yy4; + } +yy9: yych = *++YYCURSOR; switch (yych) { - case 'c': goto yy6; + case 'c': goto yy5; default: yyt2 = yyt3; yyt3 = YYCURSOR; - goto yy7; + goto yy6; } -yy9: +yy10: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy10: +yy11: switch (yych) { - case 'c': goto yy9; - default: goto yy7; + case 'c': goto yy10; + default: goto yy6; } } diff --git a/re2c/test/posix_captures/forcedassoc/16.i--flex-syntax.c b/re2c/test/posix_captures/forcedassoc/16.i--flex-syntax.c index 597736c8..c5ac0ad4 100644 --- a/re2c/test/posix_captures/forcedassoc/16.i--flex-syntax.c +++ b/re2c/test/posix_captures/forcedassoc/16.i--flex-syntax.c @@ -2,7 +2,7 @@ { YYCTYPE yych; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *(YYMARKER = YYCURSOR); switch (yych) { case 'a': @@ -10,7 +10,7 @@ goto yy3; case 'b': yyt1 = yyt2 = YYCURSOR; - goto yy6; + goto yy5; default: goto yy2; } yy2: @@ -22,26 +22,21 @@ yy2: {} } yy3: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); - yych = *YYCURSOR; + yych = *++YYCURSOR; switch (yych) { - case 'a': - yyt2 = YYCURSOR; - goto yy3; case 'b': yyt3 = YYCURSOR; - goto yy8; - default: goto yy5; + goto yy9; + default: goto yy8; } -yy5: +yy4: YYCURSOR = YYMARKER; goto yy2; -yy6: +yy5: yych = *++YYCURSOR; yyt3 = YYCURSOR; - goto yy10; -yy7: + goto yy11; +yy6: { const size_t yynmatch = 5; const YYCTYPE *yypmatch[yynmatch * 2]; @@ -57,23 +52,38 @@ yy7: yypmatch[9] = YYCURSOR; {} } +yy7: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); + yych = *YYCURSOR; yy8: + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy7; + case 'b': + yyt2 = yyt3; + yyt3 = YYCURSOR; + goto yy9; + default: goto yy4; + } +yy9: yych = *++YYCURSOR; switch (yych) { - case 'c': goto yy6; + case 'c': goto yy5; default: yyt2 = yyt3; yyt3 = YYCURSOR; - goto yy7; + goto yy6; } -yy9: +yy10: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy10: +yy11: switch (yych) { - case 'c': goto yy9; - default: goto yy7; + case 'c': goto yy10; + default: goto yy6; } } diff --git a/re2c/test/posix_captures/forcedassoc/19.i--flex-syntax.c b/re2c/test/posix_captures/forcedassoc/19.i--flex-syntax.c index e7d3a1b2..b783361f 100644 --- a/re2c/test/posix_captures/forcedassoc/19.i--flex-syntax.c +++ b/re2c/test/posix_captures/forcedassoc/19.i--flex-syntax.c @@ -2,7 +2,7 @@ { YYCTYPE yych; - if (YYLIMIT <= YYCURSOR) YYFILL(1); + if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); yych = *(YYMARKER = YYCURSOR); switch (yych) { case 'a': @@ -10,7 +10,7 @@ goto yy3; case 'b': yyt1 = yyt2 = YYCURSOR; - goto yy6; + goto yy5; default: goto yy2; } yy2: @@ -22,24 +22,19 @@ yy2: {} } yy3: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; + yych = *++YYCURSOR; switch (yych) { - case 'a': - yyt2 = YYCURSOR; - goto yy3; case 'b': yyt3 = YYCURSOR; - goto yy8; - default: goto yy5; + goto yy9; + default: goto yy8; } -yy5: +yy4: YYCURSOR = YYMARKER; goto yy2; -yy6: +yy5: ++YYCURSOR; -yy7: +yy6: { const size_t yynmatch = 3; const YYCTYPE *yypmatch[yynmatch * 2]; @@ -51,13 +46,28 @@ yy7: yypmatch[5] = YYCURSOR; {} } +yy7: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; yy8: + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy7; + case 'b': + yyt2 = yyt3; + yyt3 = YYCURSOR; + goto yy9; + default: goto yy4; + } +yy9: yych = *++YYCURSOR; switch (yych) { - case 'c': goto yy6; + case 'c': goto yy5; default: yyt2 = yyt3; - goto yy7; + goto yy6; } } diff --git a/re2c/test/posix_captures/forcedassoc/20.i--flex-syntax.c b/re2c/test/posix_captures/forcedassoc/20.i--flex-syntax.c index e7d3a1b2..b783361f 100644 --- a/re2c/test/posix_captures/forcedassoc/20.i--flex-syntax.c +++ b/re2c/test/posix_captures/forcedassoc/20.i--flex-syntax.c @@ -2,7 +2,7 @@ { YYCTYPE yych; - if (YYLIMIT <= YYCURSOR) YYFILL(1); + if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); yych = *(YYMARKER = YYCURSOR); switch (yych) { case 'a': @@ -10,7 +10,7 @@ goto yy3; case 'b': yyt1 = yyt2 = YYCURSOR; - goto yy6; + goto yy5; default: goto yy2; } yy2: @@ -22,24 +22,19 @@ yy2: {} } yy3: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; + yych = *++YYCURSOR; switch (yych) { - case 'a': - yyt2 = YYCURSOR; - goto yy3; case 'b': yyt3 = YYCURSOR; - goto yy8; - default: goto yy5; + goto yy9; + default: goto yy8; } -yy5: +yy4: YYCURSOR = YYMARKER; goto yy2; -yy6: +yy5: ++YYCURSOR; -yy7: +yy6: { const size_t yynmatch = 3; const YYCTYPE *yypmatch[yynmatch * 2]; @@ -51,13 +46,28 @@ yy7: yypmatch[5] = YYCURSOR; {} } +yy7: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; yy8: + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy7; + case 'b': + yyt2 = yyt3; + yyt3 = YYCURSOR; + goto yy9; + default: goto yy4; + } +yy9: yych = *++YYCURSOR; switch (yych) { - case 'c': goto yy6; + case 'c': goto yy5; default: yyt2 = yyt3; - goto yy7; + goto yy6; } } diff --git a/re2c/test/posix_captures/forcedassoc/21.i--flex-syntax.c b/re2c/test/posix_captures/forcedassoc/21.i--flex-syntax.c index 597736c8..c5ac0ad4 100644 --- a/re2c/test/posix_captures/forcedassoc/21.i--flex-syntax.c +++ b/re2c/test/posix_captures/forcedassoc/21.i--flex-syntax.c @@ -2,7 +2,7 @@ { YYCTYPE yych; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *(YYMARKER = YYCURSOR); switch (yych) { case 'a': @@ -10,7 +10,7 @@ goto yy3; case 'b': yyt1 = yyt2 = YYCURSOR; - goto yy6; + goto yy5; default: goto yy2; } yy2: @@ -22,26 +22,21 @@ yy2: {} } yy3: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); - yych = *YYCURSOR; + yych = *++YYCURSOR; switch (yych) { - case 'a': - yyt2 = YYCURSOR; - goto yy3; case 'b': yyt3 = YYCURSOR; - goto yy8; - default: goto yy5; + goto yy9; + default: goto yy8; } -yy5: +yy4: YYCURSOR = YYMARKER; goto yy2; -yy6: +yy5: yych = *++YYCURSOR; yyt3 = YYCURSOR; - goto yy10; -yy7: + goto yy11; +yy6: { const size_t yynmatch = 5; const YYCTYPE *yypmatch[yynmatch * 2]; @@ -57,23 +52,38 @@ yy7: yypmatch[9] = YYCURSOR; {} } +yy7: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); + yych = *YYCURSOR; yy8: + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy7; + case 'b': + yyt2 = yyt3; + yyt3 = YYCURSOR; + goto yy9; + default: goto yy4; + } +yy9: yych = *++YYCURSOR; switch (yych) { - case 'c': goto yy6; + case 'c': goto yy5; default: yyt2 = yyt3; yyt3 = YYCURSOR; - goto yy7; + goto yy6; } -yy9: +yy10: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy10: +yy11: switch (yych) { - case 'c': goto yy9; - default: goto yy7; + case 'c': goto yy10; + default: goto yy6; } } diff --git a/re2c/test/posix_captures/forcedassoc/22.i--flex-syntax.c b/re2c/test/posix_captures/forcedassoc/22.i--flex-syntax.c index 597736c8..c5ac0ad4 100644 --- a/re2c/test/posix_captures/forcedassoc/22.i--flex-syntax.c +++ b/re2c/test/posix_captures/forcedassoc/22.i--flex-syntax.c @@ -2,7 +2,7 @@ { YYCTYPE yych; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *(YYMARKER = YYCURSOR); switch (yych) { case 'a': @@ -10,7 +10,7 @@ goto yy3; case 'b': yyt1 = yyt2 = YYCURSOR; - goto yy6; + goto yy5; default: goto yy2; } yy2: @@ -22,26 +22,21 @@ yy2: {} } yy3: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); - yych = *YYCURSOR; + yych = *++YYCURSOR; switch (yych) { - case 'a': - yyt2 = YYCURSOR; - goto yy3; case 'b': yyt3 = YYCURSOR; - goto yy8; - default: goto yy5; + goto yy9; + default: goto yy8; } -yy5: +yy4: YYCURSOR = YYMARKER; goto yy2; -yy6: +yy5: yych = *++YYCURSOR; yyt3 = YYCURSOR; - goto yy10; -yy7: + goto yy11; +yy6: { const size_t yynmatch = 5; const YYCTYPE *yypmatch[yynmatch * 2]; @@ -57,23 +52,38 @@ yy7: yypmatch[9] = YYCURSOR; {} } +yy7: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); + yych = *YYCURSOR; yy8: + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy7; + case 'b': + yyt2 = yyt3; + yyt3 = YYCURSOR; + goto yy9; + default: goto yy4; + } +yy9: yych = *++YYCURSOR; switch (yych) { - case 'c': goto yy6; + case 'c': goto yy5; default: yyt2 = yyt3; yyt3 = YYCURSOR; - goto yy7; + goto yy6; } -yy9: +yy10: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy10: +yy11: switch (yych) { - case 'c': goto yy9; - default: goto yy7; + case 'c': goto yy10; + default: goto yy6; } } diff --git a/re2c/test/posix_captures/other/08.i--flex-syntax.c b/re2c/test/posix_captures/other/08.i--flex-syntax.c index c28fcf86..0e9e442d 100644 --- a/re2c/test/posix_captures/other/08.i--flex-syntax.c +++ b/re2c/test/posix_captures/other/08.i--flex-syntax.c @@ -6,7 +6,7 @@ yych = *YYCURSOR; switch (yych) { case 'a': - yyt1 = yyt2 = YYCURSOR; + yyt1 = yyt3 = YYCURSOR; goto yy3; default: yyt2 = yyt3 = NULL; @@ -18,8 +18,8 @@ yy2: const size_t yynmatch = 2; const YYCTYPE *yypmatch[yynmatch * 2]; yypmatch[0] = yyt1; - yypmatch[2] = yyt2; - yypmatch[3] = yyt3; + yypmatch[2] = yyt3; + yypmatch[3] = yyt2; yypmatch[1] = YYCURSOR; {} } @@ -30,7 +30,7 @@ yy3: switch (yych) { case 'a': goto yy4; default: - yyt3 = YYCURSOR; + yyt2 = YYCURSOR; goto yy2; } yy4: @@ -39,10 +39,10 @@ yy4: yych = *YYCURSOR; switch (yych) { case 'a': - yyt2 = YYCURSOR; + yyt3 = YYCURSOR; goto yy3; default: - yyt3 = YYCURSOR; + yyt2 = YYCURSOR; goto yy2; } } diff --git a/re2c/test/posix_captures/other/11.i--flex-syntax.c b/re2c/test/posix_captures/other/11.i--flex-syntax.c index 430d5b91..3baf918c 100644 --- a/re2c/test/posix_captures/other/11.i--flex-syntax.c +++ b/re2c/test/posix_captures/other/11.i--flex-syntax.c @@ -7,7 +7,7 @@ yych = *(YYMARKER = YYCURSOR); switch (yych) { case 'a': - yyt1 = yyt2 = yyt4 = YYCURSOR; + yyt1 = yyt4 = yyt5 = YYCURSOR; goto yy3; default: yyt2 = yyt3 = yyt4 = yyt5 = NULL; @@ -19,10 +19,10 @@ yy2: const size_t yynmatch = 3; const YYCTYPE *yypmatch[yynmatch * 2]; yypmatch[0] = yyt1; - yypmatch[2] = yyt2; - yypmatch[3] = yyt3; - yypmatch[4] = yyt4; - yypmatch[5] = yyt5; + yypmatch[2] = yyt4; + yypmatch[3] = yyt2; + yypmatch[4] = yyt5; + yypmatch[5] = yyt3; yypmatch[1] = YYCURSOR; {} } @@ -42,13 +42,13 @@ yy4: yyt1 = YYCURSOR; goto yy2; case 1: - yyt4 = yyt5 = NULL; - yyt3 = YYCURSOR; + yyt3 = yyt5 = NULL; + yyt2 = YYCURSOR; goto yy2; default: - yyt2 = yyt3; - yyt4 = yyt5 = NULL; - yyt3 = YYCURSOR; + yyt4 = yyt2; + yyt3 = yyt5 = NULL; + yyt2 = YYCURSOR; goto yy2; } yy5: @@ -57,11 +57,11 @@ yy5: yych = *YYCURSOR; switch (yych) { case 'a': - yyt2 = YYCURSOR; + yyt4 = YYCURSOR; goto yy6; default: - yyt4 = yyt5 = NULL; - yyt3 = YYCURSOR; + yyt3 = yyt5 = NULL; + yyt2 = YYCURSOR; goto yy2; } yy6: @@ -71,8 +71,8 @@ yy6: switch (yych) { case 'a': goto yy7; default: - yyt2 = yyt3 = NULL; - yyt5 = YYCURSOR; + yyt2 = yyt4 = NULL; + yyt3 = YYCURSOR; goto yy2; } yy7: @@ -82,11 +82,11 @@ yy7: yych = *YYCURSOR; switch (yych) { case 'a': - yyt3 = YYCURSOR; + yyt2 = YYCURSOR; goto yy8; default: - yyt4 = yyt5 = NULL; - yyt3 = YYCURSOR; + yyt3 = yyt5 = NULL; + yyt2 = YYCURSOR; goto yy2; } yy8: @@ -104,12 +104,12 @@ yy9: yych = *YYCURSOR; switch (yych) { case 'a': - yyt2 = yyt4 = YYCURSOR; + yyt4 = yyt5 = YYCURSOR; goto yy3; default: - yyt2 = yyt3; - yyt4 = yyt5 = NULL; - yyt3 = YYCURSOR; + yyt4 = yyt2; + yyt3 = yyt5 = NULL; + yyt2 = YYCURSOR; goto yy2; } }