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.

Early parser fails to detect ambiguity in terminals

See original GitHub issue

I am working on Python 3.7.3, Lark 0.7.1

Consider the following very simple example:

grammar = r"""
    start           : item_list
    item_list       : item_list? item
    item            : A | B 
    A               : "a" | "ab"
    B               : "b"
"""
parser = Lark(grammar, parser="earley", ambiguity="explicit", debug=True)

result = parser.parse("ab")
print(result.pretty())

With the explicit option, I expected something like:

start
  __ambig
    item_list
      item_list
        item	a
      item	b
    item_list
      item ab

However, the output is:

start
  item_list
    item_list
      item	a
    item	b

Is this a bug? Or am I misunderstanding something?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
erezshcommented, Jul 1, 2019

That does look like a bug, from a cursory glance. I’ll add the “bug” tag until proven otherwise.

@night199uk Do you have any insight to add?

0reactions
erezshcommented, Sep 10, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Lecture 8: Parser Conflicts, Using Ambiguity, Error Recovery
When parser gets to the y, will detect error. • Then pops items off parsing stack until it finds a state that allows...
Read more >
Resolving Grammar Errors - Common Prefix Ambiguities
In some rare cases the Parser may detect ambiguities that are not actually possible or are perhaps implicitly resolved, e.g: by the order...
Read more >
Ambiguity Detection: Scaling towards Scannerless
Abstract. Static ambiguity detection would be an important aspect of language workbenches for textual software languages. The challenge is that automatic.
Read more >
Detecting Ambiguity in Programming Language Grammars
Ambiguous Context Free Grammars (CFGs) are problematic for programming languages, as they allow inputs to be parsed in more than one way.
Read more >
compiler construction - Ambiguous non-terminal in GLR
How does knowing which non-terminals can produce an ambiguity simplify parse tree construction in a practical way?
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