priorities in LALR and Earley
See original GitHub issueHey,
Is it correctly understood that priority can be set on rules only for earley and on terminals only for lalr?
I expected to be able to switch seamlessly between the two algorigthms for my unambiguous and non-recursive grammar but I get a lot of parsing errors when switching from earley to larl. I think that most of them are due to priorities on rules not understood by lalr.
Also btw there may be some inconsistency in the index of priority between the two algorithm.
This grammar parses ‘1’ to b with earley:
%import common.INT
start: a | b
a: INT
b.1: INT
while it resolves to A with lalr:
%import common.INT
start: A | B
A: INT
B.1: INT
One has to increment to B.2 to get the grammar to parse ‘1’ to B.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Confusion around priority of tokens in lark grammar
In LALR mode, priorities on rules only affect which one is chosen in case of a reduce/reduce collision. It has no effect on...
Read more >LALR's contextual lexer - Lark documentation - Read the Docs
This example demonstrates the power of LALR's contextual lexer, by parsing a toy ... based on priority, which would lead to a (confusing)...
Read more >LR(1) and LALR Parsing - CS [45]12[01] Spring 2022
Notice that an Earley parser would simply try both the Scan and Complete actions ... its priority with respect to other productions of...
Read more >lark-parser/Lobby - Gitter
and what would be the drawback using Earley instead of LALR ? Erez Shinan. @erezsh ... When two rules can match, it will...
Read more >Ubuntu Manpage: lark - Lark Documentation
Lark implements the following parsing algorithms: Earley, LALR(1), and CYK Earley An Earley Parser is a chart parser capable of parsing any context-free ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@night199uk If it overwrote
i
, that would cause a deterministic error. Anyway, I fixed that line, and the non-determinism persists.Yes, there is a difference in how the two algorithms handle priority. It’s not impossible to fix, it’s just a lot of work.
Regarding your example,
B.1
is the same asB
, because 1 is the default priority. So yeah, you need to useB.2
or higher.This is the same for Earley. The reason Earley resolves this as
a
, is because when priorities are even (that is, both 1), it determines according to the order of appearance. In this case,a
beforeb
.