-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
No viable alternative can be incorrectly thrown for start rules without explicit EOF #118
Comments
I think the key insight here is we can create a "pseudo-rule" during ATN deserialization with the following form, where During SLL prediction, a configuration which steps out of the decision rule will have at least one configuration which ends up in the wildcard loop in the implicit follow rule. Special care must be taken for the following:
|
… behavior of antlr#118, but the performance overhead is extreme)
When the parser is configured to fall back to LL prediction in the event of SLL conflict, the "Special care" conditions listed above are implicitly handled by the full-context parsing algorithm. |
I looked into the source code and found that the above is happening because of new error handling strategy introduced in ANTLR 4 as part of org.antlr.v4.runtime.DefaultErrorStrategy class. |
I believe you may have misinterpreted the problem described above. To make sure I understand what you are saying, here are the two parts to your comment that led me to this conclusion.
By the time the error handler identifies a problem and attempts to report and/or recover from it, the prediction mechanism has already failed to return a correct prediction for a previous input.
This issue describes a case where the parser should match the input, but fails to do so. Suppressing the error message but failing to find a match would still be the wrong result. |
@sharwell, We used Antlr3 for file parsing and java objects created out of it. Parsing is done partially so that one object is created at a time. Example grammar is as below
Object is created once a record is identified. After upgrading to Antlr4, it doesnt stop after finding one a record rather continues till EOF and prints error for every record from second instance of it. The error is thrown from DefaultErrorStrategy.sync() method. I posted it because others may find it useful as well. Do you see any issue with this approach? |
Do you have a copy of the grammar and example input demonstrating the problem? |
According to antlr/antlr4#118, it is better to add EOF for the first rule in grammar. This can solve the potential incorrect error message.
According to antlr/antlr4#118, incorrect error message might be returned if start rule doesn't contains EOF.
Not able to pass double datatype getting error: |
If the start rule does not contain an explicit EOF transition,
ParserATNSimulator.adaptivePredict
may fail to return a viable alternative.Grammar:
Input:
x 1
The text was updated successfully, but these errors were encountered: