Comments (11)
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
r1_results = []
and then we parse token A
, which sets
r1_results = [()]
Next, we process the other alternative, which yields
r1_results = r1_results ++ [()]
which is our final result. The stack overflow you see is from trying to force this value. I would expect the report
function to work for this example because it doesn't force the result. (But it won't be useful to you since it doesn't say anything about ambiguity.)
We could write results to the end instead (but this has performance implications, discussed in #15), which would yield
r1_results = [()] ++ r1_results
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 <|>
.
from earley.
But if what I've written here is correct, your example would work if you flipped the arguments to
<|>
I just checked. No, null $ fst $ fullParses (parser lang) [A]
still causes stack overflow in ghci
I would expect the report function to work for this example because it doesn't force the result
Yes, report (parser lang) [A]
works. With both (pure () <* token A) <|> r1
and r1 <|> (pure () <* token A)
from earley.
Hmm, okay, it's been a while so I may be getting the details wrong.
from earley.
upTo 1 (generator lang [A])
gives stack overflow, too
from earley.
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
from earley.
Cool! I wonder if you could implement the same on a grammar from this library. :)
from earley.
Cool! I wonder if you could implement the same on a grammar from this library. :)
What you mean?
from earley.
You mean implementing my algorithm on your Grammar
type?
from earley.
Yes.
from earley.
I don't know. My type of grammar is very simple (Data.Map.Map n [[TerminalOrNonterminal t n]]
). t
and n
are any kind of IDs for terminals and nonterminals (for example, strings with names). TerminalOrNonterminal
is essentially Either
. I will repeat explanation of my algorithm from haskell-cafe:
I generate all strings of symbols, which can be reached from start symbol by replacing nonterminals with their productions no more than "count" times. If I get duplicate, then the grammar is ambiguous. This strings are strings of any symbols, not necessary terminals. And "count" means count of replacements, i. e. count of productions applications.
This is simple brute force algorithm. It does not really checks grammar for ambiguity (this is impossible on Turing machine)
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 count
expansions, and then try to find duplicates. And strings contain both terminals and nonterminals.
Also, I am currently writing library, which gets grammar in some big bloated form, and then produces both Data.Map.Map n [[TerminalOrNonterminal t n]]
and Earley's Grammar
. Then this grammar checked for ambiguity using check-cfg-ambiguity and also used to actually parse something using Earley. Also I produce pretty-printer
from earley.
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
from earley.
Related Issues (20)
- Q: How to do error recovery? HOT 1
- Wrong(?) result on some grammars with infinite results HOT 10
- Is Earley’s implementation related to Marpa? HOT 3
- Add a `eof` terminal HOT 5
- Behavior of Semigroup/Monoid instances for Prod? HOT 5
- Capture result as well as matched tokens HOT 2
- Generate ABNF/EBNF from Earley grammar HOT 1
- Suggestion: Make it so that `<$` rules return at most one result. HOT 3
- Parsing into a list delimited by a token HOT 5
- INDENT and DEDENT HOT 5
- feature: constraint validation of production parse result HOT 7
- Please add tags "test ambiguity" etc HOT 2
- Is it okey to use "many" and heavily use Applicative parsing techniques? HOT 2
- Diverges with sepEndBy from parser-combinator HOT 1
- Report doesn't include enough information HOT 2
- Is there any possible optimization for getting non-exhaustive outputs for ambiguous grammars HOT 1
- Disambiguate/Filter productions HOT 1
- Missing case for Constraint for fmap and <*> HOT 3
- Something like Ruby Slippers parsing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from earley.