question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non-deterministic parser state for ambiguous example with priorities

See original GitHub issue

I have a very small example of an ambiguity in a parser:

from lark import Lark

l = Lark(
'''start: GENERIC | SPECIFIC
GENERIC.2: /\w+/
SPECIFIC.1: "HelloWorld"
''', parser="earley", lexer="dynamic", ambiguity="resolve"
)

for i in range(1, 101):
    print(l.parse("HelloWorld"))

Both GENERIC and SPECIFIC matches, but I have set a priority forcing GENERIC to match. This is not always the result though. If running this program multiple times it will match either GENERIC or SPECIFIC seemingly random. All matches for one run will be the same, but not between runs. This signals that a state in the parser is different between the runs.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
erezshcommented, Nov 16, 2018

@dirk-thomas 0.7b is the latest candidate. I hope to merge it to master in the next couple of weeks.

An official release might take a little longer, because I’ll want to make sure the documentation reflects all the changes.

0reactions
erezshcommented, Mar 28, 2019

0.7 published

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deterministic Parsing of Ambiguous Grammars
We shall give some examples of how ambiguities in grammars can be naturally resolved using operator precedence and recursive descent techniques. 2. We...
Read more >
How is non-ambuiguity different from determinism?
First off, a string is not a language; strings are not ambiguous, unambiguous, deterministic or nondeterministic; they're just strings. The ...
Read more >
Ambiguous Grammar - an overview | ScienceDirect Topics
First, make sure the grammar is not ambiguous; second, keep the grammar in Greibach Normal Form. If the same sentence can emerge from...
Read more >
LR parsing and conflicts - parglare - Igor Dejanović
LR parsing, ambiguities and conflicts resolving¶. LR parser operates as a deterministic PDA (Push-down automata). It is a state machine which is always...
Read more >
Analyzing Ambiguity of Context-Free Grammars
Ambiguity in context-free grammars is a recurring problem ... An increasing number of parser generators, for example, Bison [33], SDF [35],.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found