Problem parsing with LALR
See original GitHub issueI’m not sure if it’s fault of grammar incompatible with LALR or is it a bug. Here it goes:
- Python 3.7.0
- lark revision 3c1c867b5f59397757dfec65d98d96e15b7de6e2
grammar.lark
(extremely boiled down dhall grammar)whitespace_chunk: " " | "\n" whitespace_optional: whitespace_chunk* reserved_func: "f" whitespace_optional open_parens: "(" whitespace_optional close_parens: ")" whitespace_optional expression_application: expression_parens (whitespace_chunk expression_parens)* expression_parens: expression_reserved | (open_parens expression_application close_parens) expression_reserved: reserved_func start: whitespace_optional expression_application
- input
f (f f)
- earley can parse (
lark.Lark(open('grammar.lark'), parser='earley').parse('f (f f)')
) - lalr fails to parse (
lark.Lark(open('grammar.lark'), parser='lalr').parse('f (f f)')
) - raiseslark.exceptions.UnexpectedToken
- standalone lalr also fails to parse
If this is because of this grammar being not parsable by LALR, I wonder if it would be possible to add error messages telling this. Currently I get something like “Unexpected token ‘(’, expected one of …”. For me, ideally constructing parser from grammar of unsupported class should raise “Can’t do it. Fix your grammar to be lalr.”.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
LALR Parser (with Examples) - GeeksforGeeks
LALR Parser : LALR Parser is lookahead LR parser. It is the most powerful parser which can handle large classes of grammar.
Read more >14: LALR Parsing - CS106X Handout #01
Is there something in between? With LALR (lookahead LR) parsing, we attempt to reduce the number of states in an LR(1) parser by...
Read more >Syntax Analysis (LR, LALR Parsers)
◦ LALR parser reduces several more steps and detects an error before shifting any symbols. Exercise: 1. Compare the steps for cdcd. 2....
Read more >3.3.5 Practical Considerations for LALR(1) Grammars
Another thing we can do when specifying an LALR(1) grammar for a parser generator is error recovery. All the entries in the ACTION...
Read more >LALR parser - Wikipedia
In computer science, an LALR parser or Look-Ahead LR parser is a simplified version of a canonical LR parser, to parse a text...
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
You can use Earley. It’s as capable as GLR, though perhaps not as fast.
As I said, they aren’t a good way to understand the algorithm.
After long battle against LALR parsing tables I think I’ve lost. The language I’m trying to encode may not be LALR or maybe I’m just not understanding LALR enough. Currently I’m switching to GLR parser and it seems a lot easier (and slower probably, but still faster than earley).
@erezsh thank you very much for support and explaining things 😉