From: Ulya Trofimovich Date: Wed, 30 Nov 2016 12:37:38 +0000 (+0000) Subject: Skeleton: apply 'copy' commands before 'save' commands. X-Git-Tag: 1.0~39^2~216 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b98063be484bc99599cdc38d266327954f3b38b;p=re2c Skeleton: apply 'copy' commands before 'save' commands. This is how the generated TDFA does and how it should be done. Found by slyfox's fuzzer. :) --- diff --git a/re2c/src/ir/skeleton/generate_data.cc b/re2c/src/ir/skeleton/generate_data.cc index 204125e3..103b98e4 100644 --- a/re2c/src/ir/skeleton/generate_data.cc +++ b/re2c/src/ir/skeleton/generate_data.cc @@ -93,12 +93,12 @@ static uint32_t nsteps(uint32_t lower, uint32_t upper) static void apply(size_t *tags, const tcmd_t *cmd, size_t pos) { if (!cmd) return; - for (const tagsave_t *p = cmd->save; p; p = p->next) { - tags[p->ver] = p->bottom ? Skeleton::DEFTAG : pos; - } for (const tagcopy_t *p = cmd->copy; p; p = p->next) { tags[p->lhs] = tags[p->rhs]; } + for (const tagsave_t *p = cmd->save; p; p = p->next) { + tags[p->ver] = p->bottom ? Skeleton::DEFTAG : pos; + } } static size_t path_width(const path_t &path, const Skeleton &skel) diff --git a/re2c/test/tags/copy_save.i--tags.c b/re2c/test/tags/copy_save.i--tags.c new file mode 100644 index 00000000..dbb5b417 --- /dev/null +++ b/re2c/test/tags/copy_save.i--tags.c @@ -0,0 +1,56 @@ +/* Generated by re2c */ + +{ + YYCTYPE yych; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': + yyt2 = NULL; + yyt1 = YYCURSOR; + goto yy3; + default: + yyt1 = NULL; + goto yy2; + } +yy2: + p = yyt1; + {} +yy3: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': + yyt2 = yyt1; + yyt1 = YYCURSOR; + goto yy3; + case 'b': goto yy5; + default: goto yy2; + } +yy5: + YYMARKER = ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy6; + default: + yyt1 = yyt2; + goto yy2; + } +yy6: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'b': goto yy5; + default: goto yy7; + } +yy7: + YYCURSOR = YYMARKER; + yyt1 = yyt2; + goto yy2; +} + +re2c: warning: line 3: rule matches empty string [-Wmatch-empty-string] +re2c: warning: line 3: tag 'p' is nondeterministic [-Wnondeterministic-tags] diff --git a/re2c/test/tags/copy_save.i--tags.re b/re2c/test/tags/copy_save.i--tags.re new file mode 100644 index 00000000..acc3367b --- /dev/null +++ b/re2c/test/tags/copy_save.i--tags.re @@ -0,0 +1,5 @@ +/*!re2c + +(@p "a")* "ab"* {} + +*/