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.

Problem parsing with LALR

See original GitHub issue

I’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)')) - raises lark.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:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
erezshcommented, Oct 30, 2018

You can use Earley. It’s as capable as GLR, though perhaps not as fast.

After long battle against LALR parsing tables

As I said, they aren’t a good way to understand the algorithm.

0reactions
SupraSummuscommented, Oct 30, 2018

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 😉

Read more comments on GitHub >

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

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