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

Error reporting differs between clox and jlox #1178

Open
s7effeno opened this issue Oct 7, 2024 · 0 comments
Open

Error reporting differs between clox and jlox #1178

s7effeno opened this issue Oct 7, 2024 · 0 comments

Comments

@s7effeno
Copy link

s7effeno commented Oct 7, 2024

Why doesn't clox support non-synchronizing errors for its compiler? This alters error reporting quite a bit in some cases.
Take this input in exam:
if (1 = 1) { print 1; }

jlox parses the whole assignment, then reports [line 1] Error at '=': Invalid assignment target., then calls statement() to parse the then-branch and doesn't find any more errors.

clox does this:

  • consumes "if 1 =", reports [line 1] Error at '=': Invalid assignment target. and enables panic mode
  • expects a ')' but finds the second '1' so it triggers a silent error
  • tries to parse the then-branch as an expression statement starting with "1) ..."
  • consumes '1' but finds ')' instead of ';' so it triggers a silent error
  • starts synchronization
  • consumes up to "print" exluded
  • flawlessly parses "print 1;"
  • tries to parse the expression statement starting with '}'
  • reports [line 1] Error at '}': Expect expression.
  • tl;dr: skips to print... and signals unopened block

Is this design intended for simplicity? Am I missing something?

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

4 participants
@s7effeno and others