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

[rexx] Fix ambiguity between "assignment" and "command_", and search for others. #2820

Open
RossPatterson opened this issue Sep 14, 2022 · 1 comment
Labels

Comments

@RossPatterson
Copy link
Contributor

In ANTLR discussion 3321, @kaby76 wrote:

But, even before this change, there is an ambiguity for input "binary_good1 = '1'b
" in single_instruction, in choosing between assignment and command_ => expression => and_expression => comparison. The way expressions are written is an "anti-pattern" for Antlr in itself not even considering assignment. But, with both involved, it will cause adaptivePredict() to run down the entire derivation chain of command_ until the end of the assignment because it's trying to find a difference based on context.

This ambiguity was copied directly from the ANSI standard, and needs to be investigated. There may be other ambiguities that can be resolved by optimizing the grammar for ANTLR's use (and moving further away from a textual match to ANSI), and the entire grammar should be analyzed looking for them.

@KvanTTT KvanTTT added the rexx label Sep 16, 2022
@RossPatterson
Copy link
Contributor Author

RossPatterson commented Oct 19, 2022

The rules in question look like this:

single_instruction          :   assignment
                            |   keyword_instruction
                            |   command_
                            ;
assignment                  :   ( VAR_SYMBOL | SPECIAL_VAR ) EQ expression ;
command_                    :   expression ;

grun Rexx file_ --diagnostics does indeed indicate an ambiguity with the binary_good1 = '1'b input:

line 1:15 reportAttemptingFullContext d=11 (single_instruction), input='binary_good1 = '1'b'
line 1:19 reportAmbiguity d=11 (single_instruction): ambigAlts={1, 3}, input='binary_good1 = '1'b
'

Which makes sense - you can parse that either as assignment ("Set binarygood1 to '1'b") or as command_ -> expression -> and_expression -> comparison ("Execute the command composed of the value of the comparison of binarygood1 to '1'b"). But isn't ANTLR's processing of alternatives in the order they're written supposed to solve that ambuguity? single_instruction is firstly an assignment, and there the parse should stop - no need to consider command_. In fact, even without the input string, the grammar itself isn't ambiguous, knowing that ANTLR processes alternatives in order. No matter what the input, one token of look-ahead should identify the EQ and class it as an assignment, or not, and class it as a command_.

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

No branches or pull requests

2 participants