-
Notifications
You must be signed in to change notification settings - Fork 24
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
Crashes if grammar is infinitely ambiguous on given input #54
Comments
I think the reason for this is that when Earley builds its result lists, it will add later results to the start of the list. Intuitively, we start with
and then we parse
Next, we process the other alternative, which yields
which is our final result. The stack overflow you see is from trying to force this value. I would expect the We could write results to the end instead (but this has performance implications, discussed in #15), which would yield
This would work for your example since it's productive. But note that it would stop being productive again if you flipped the arguments to So I can't see an easy fix that would always work. But if what I've written here is correct, your example would work if you flipped the arguments to |
I just checked. No,
Yes, |
Hmm, okay, it's been a while so I may be getting the details wrong. |
|
This motivated me to publish alternative library for checking ambiguity: https://hackage.haskell.org/package/check-cfg-ambiguity . My library does not freeze on this example. I hope you are not offended |
Cool! I wonder if you could implement the same on a grammar from this library. :) |
What you mean? |
You mean implementing my algorithm on your |
Yes. |
I don't know. My type of grammar is very simple (
My algorithm is trivial, and you can easily get idea by looking at code of lowLevelTestAmbiguity: https://hackage.haskell.org/package/check-cfg-ambiguity-0.0.0.1/docs/src/CheckCFGAmbiguity.html#lowLevelTestAmbiguity . My algorithm requires that nonterminals can be checked for equality. Because I generate all strings which I could get using Also, I am currently writing library, which gets grammar in some big bloated form, and then produces both |
I wrote parsing library I talked about in #54 (comment) : https://mail.haskell.org/pipermail/haskell-cafe/2021-July/134217.html , it is based on Earley. Also, I recently published another parsing library, which is based on Earley, too: https://mail.haskell.org/pipermail/haskell-cafe/2021-July/134205.html |
Consider this code:
This program crashes with stack overflow if I run it in ghci. And freezes if I compile and run it. I cannot even test whether list of parses is null, i. e.
null $ fst $ fullParses (parser lang) [A]
crashes in ghci.I want some function, which can test whether given token list has multiple parses. I. e. I don't want list of parses or even count of parses. I simply want one of 3 results: 0 parses, 1 parse, more than 1 parse. And this function should terminate in case of infinitely ambiguous grammar.
I use Earley 0.13.0.1
The text was updated successfully, but these errors were encountered: