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.

priorities in LALR and Earley

See original GitHub issue

Hey,

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:closed
  • Created 4 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
erezshcommented, Jun 11, 2019

@night199uk If it overwrote i, that would cause a deterministic error. Anyway, I fixed that line, and the non-determinism persists.

1reaction
erezshcommented, May 9, 2019

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 as B, because 1 is the default priority. So yeah, you need to use B.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 before b.

Read more comments on GitHub >

github_iconTop 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 >

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