Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator precedence with --flex-syntax is broken. #242

Closed
skvadrik opened this issue Jan 16, 2019 · 1 comment

Comments

@skvadrik
Copy link
Owner

commented Jan 16, 2019

re2c parses ab* as (ab)*, while it should be a(b)*:

$ echo '/*!re2c ab* {} */' | re2c -Fi - 
/* Generated by re2c 1.0.3 on Wed Jan 16 23:12:56 2019 */

{
        YYCTYPE yych;
        goto yy0;
yy1:
        ++YYCURSOR;
yy0:
        if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *(YYMARKER = YYCURSOR);
        switch (yych) {
        case 'a':       goto yy3;
        default:        goto yy2;
        }
yy2:
        {}
yy3:
        ++YYCURSOR;
        if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
        switch (yych) {
        case 'b':       goto yy1;
        default:        goto yy4;
        }
yy4:
        YYCURSOR = YYMARKER;
        goto yy2;
}
$ echo '/*!re2c a(b)* {} */' | re2c -Fi - 
/* Generated by re2c 1.0.3 on Wed Jan 16 23:13:24 2019 */

{
        YYCTYPE yych;
        if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
        switch (yych) {
        case 'a':       goto yy3;
        default:        goto yy2;
        }
yy2:
yy3:
        ++YYCURSOR;
        if (YYLIMIT <= YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
        switch (yych) {
        case 'b':       goto yy3;
        default:        goto yy5;
        }
yy5:
        {}
}

skvadrik added a commit that referenced this issue Jan 17, 2019

Fixed operator precedence with --flex-syntax option.
Operator precedence was broken because re2c tried to parse whole strings
of characters at once instead of parsing one character at a time (in
much the same way as it would parse properly quotes string literals in
the original re2c format). This caused ab* being parsed as (ab)*, which
is clearly wrong (should be a(b)*).

This fixes bug #242:
    "Operator precedence with --flex-syntax is broken."
@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Jan 17, 2019

Fixed by commit 4dea13a.

This may certainly affect existing code that relies on old behaviour. But it was broken so badly that even a sudden change of behaviour seems a better option.

@skvadrik skvadrik closed this Jan 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.