Lark: not finding ambiguous parse

Created on 24 Mar 2020  路  1Comment  路  Source: lark-parser/lark

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
bug

Most helpful comment

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, [])])])])

>All comments

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, [])])])])
Was this page helpful?
0 / 5 - 0 ratings

Related issues

supposedly picture supposedly  路  5Comments

RyannDaGreat picture RyannDaGreat  路  5Comments

napulen picture napulen  路  9Comments

solartes picture solartes  路  5Comments

petee-d picture petee-d  路  9Comments