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

Understanding ambiguity: possible bug with "-" character? #624

Open
springcomp opened this issue Aug 19, 2022 · 0 comments
Open

Understanding ambiguity: possible bug with "-" character? #624

springcomp opened this issue Aug 19, 2022 · 0 comments

Comments

@springcomp
Copy link

springcomp commented Aug 19, 2022

I’m having a hard time figuring out what is and is not ambiguous in a grammar.

For instance, in the grammar below, the "-" (U+002D HYPHEN MINUS) character alone in the unsescaped_char rule makes the grammar ambiguous and the parser return three results.

identifier -> quote unescaped_char:+ quote
unescaped_char -> digit | letter |  "-"
digit -> [0-9]
letter -> [A-Z] |  [a-z] |  "_"
quote -> "\""

Remove the "-" and the grammar becomes unambiguous. 🤔

This can be seen in this BNF Playground example:

<identifier> ::= <quote> <unescaped_char>+ <quote>
<unescaped_char> ::= <digit> | <letter>
<digit> ::= [0-9]
<letter> ::= [A-Z] | [a-z] | "_"
<quote> ::= "\""

This parses as a unambiguous.

Now, lets add a simple "-" (U+002D HYPHEN MINUS) character to the unescaped_char rule.


<unescaped_char> ::= <digit> | <letter> | "-"

Now the grammar is ambiguous and the parser returns three results!
Am I missing something ?

@springcomp springcomp changed the title Understanding ambiguity Understanding ambiguity: possible bug with "-" character? Aug 19, 2022
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