You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to using LALR and I'm attempting to implement a grammar as follows:
A: "a"
B: "b"
a: b A
b: (A | B)+
However, when I try to parse the input string aaaba, I encounter the following error:
lark.exceptions.UnexpectedToken: Unexpected token Token('$END', '') at line 1, column 5.
Expected one of:
* A
* B
It seems that rule b is greedy in this case, despite my attempts to set a higher priority for the grammar rule a.
Proposed Solution
After making a simple modification to the grammar, I was able to get it working as follows:
A: "a"
B: "b"
a: b+ A
b: A | B
This adjustment resolved the error for the aforementioned input string.
Questions
What is the key difference between the two grammar definitions:
a: b+ A and b: A | B
a: b A and b: (A | B)+
How can I avoid the greediness in the first grammar configuration, specifically when defining rules for b? Any insights or guidance on this issue would be greatly appreciated. Thank you!
The text was updated successfully, but these errors were encountered:
Description
I am new to using LALR and I'm attempting to implement a grammar as follows:
However, when I try to parse the input string aaaba, I encounter the following error:
It seems that rule
b
is greedy in this case, despite my attempts to set a higher priority for the grammar rulea
.Proposed Solution
After making a simple modification to the grammar, I was able to get it working as follows:
This adjustment resolved the error for the aforementioned input string.
Questions
What is the key difference between the two grammar definitions:
a: b+ A
andb: A | B
a: b A
andb: (A | B)+
How can I avoid the greediness in the first grammar configuration, specifically when defining rules for
b
? Any insights or guidance on this issue would be greatly appreciated. Thank you!The text was updated successfully, but these errors were encountered: