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

ANTLR 4.2 and later fail to report error with mislocated 'assoc' #4629

Open
4 tasks done
blueglyph opened this issue May 24, 2024 · 0 comments
Open
4 tasks done

ANTLR 4.2 and later fail to report error with mislocated 'assoc' #4629

blueglyph opened this issue May 24, 2024 · 0 comments

Comments

@blueglyph
Copy link

  • I have reproduced my issue using the latest version of ANTLR
  • I have asked at checked stackoverflow
  • Responses from the above seem to indicate that my issue could be an ANTLR bug
  • I have done a search of the existing issues to make sure I'm not sending in a duplicate

(note: I'm using 4.13.1, though this isn't relevant)

Since 4.2, the location of <assoc=right> has changed: instead of being after the terminal, it must be at the beginning of the production.

Example before: expr: expr '^'<assoc=right> expr;
Example since 4.2: expr: <assoc=right> expr '^' expr;

While I'm sure there was a good reason for this change, the compiler doesn't report an error if assoc is still after the terminal. It only gives a warning and ignores the attribute, resulting in a potentially undetected erroneous behaviour.

I had this problem, and it took a while for me to find out where it was coming from. It didn't help that The Definitive ANTLR4 Reference was mentioning the former syntax. Indeed, I would expect a change that isn't back-compatible to bump the major version number (too late for that now). Apparently, I'm not the only one to be confused by the problem:

=> I suggest therefore to make the compiler report an error when the assoc isn't at the correct place. By default of a major number bump, that's the only safe way to make sure the users WILL notice the change and update their grammar (or use an older version of ANTLR).

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