lark
lark copied to clipboard
not finding ambiguous parse
Greetings, and thank you for your excellent package.
I'm not sure if I'm doing something wrong here, but the following CFG gives me an unambiguous parse on the input "a b", when I believe it should be ambiguous
%import common.WS
%ignore WS
start: a -> start_0
a: "a" b -> a_0
| "a" "b" -> a_1
b: "b" -> b_0
this grammar works though, and provides an ambiguous parse for "a b":
%import common.WS
%ignore WS
start: a -> start_0
| a2 -> start_1
a: "a" b -> a_0
a2: "a" "b" -> a_1
b: "b" -> b_0
I think you're right, and this is a bug. I'll mark it as such.
I hope you can work around it for now.
I'll also add another version of this bug, which is even more innocent.
from lark import Lark
g1 = """
start: a
a: "a" "b" -> a_0
| a2
a2: "a" b -> a_1
b: "b"
"""
g2 = """
start: a
a: "a" b -> a_0
| a2
a2: "a" "b" -> a_1
b: "b"
"""
print(Lark(g1, ambiguity='explicit').parse("ab"))
print(Lark(g2, ambiguity='explicit').parse("ab"))
# Tree(start, [Tree(a_0, [])])
# Tree(start, [Tree(_ambig, [Tree(a_0, [Tree(b, [])]), Tree(a, [Tree(a_1, [])])])])