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

Wrong priority for distfix operator with Pratt parser #353

Open
bourguet opened this issue Nov 5, 2023 · 0 comments
Open

Wrong priority for distfix operator with Pratt parser #353

bourguet opened this issue Nov 5, 2023 · 0 comments

Comments

@bourguet
Copy link

bourguet commented Nov 5, 2023

For the grammar

{
    extends(".*_expr")=expr
}
File ::= expr*

expr ::= mult_expr | postfix_expr | primary_expr
mult_expr ::= expr '*' expr
postfix_expr ::= expr '(' expr ')'
primary_expr ::= ID

the generated code and the preview report an error for input a(b*b). If I replace

postfix_expr ::= expr '(' expr ')'

by

postfix_expr ::= expr '(' index ')'
index ::= expr

the input is accepted. The issue seems to be in the generated code:

  public static boolean expr_0(PsiBuilder b, int l, int g) {
    ...
      else if (g < 1 && consumeTokenSmart(b, OPEN_PAR)) {
        r = report_error_(b, expr(b, l, 1));
        r = consumeToken(b, CLOSE_PAR) && r;
        exit_section_(b, l, m, POSTFIX_EXPR, r, true, null);
      }
    ...
    return r;
  }

I'd have expected:

        r = report_error_(b, expr(b, l, -1));

as we are matching CLOSE_PAR afterwards. (If there had been a third expression -- let's say ternary_expr ::= expr '?' expr ':' expr -- then that third expression should be parser with g=1 or whatever the priority for the rule is, but priority shouldn't play a role for the middle expression).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant