Skip to content

Can Lark be restricted to act as an SLR(1) or LR(1) parser? #1010

Answered by erezsh
jpivarski asked this question in Q&A
Discussion options

You must be logged in to vote

SLR(1) and LALR(1) are very very similar. So if a grammar is LALR(1) compatible, it is very likely it will also be SLR(1) compatible. If you really want to make sure it's SLR(1), you can go back to earlier versions of Lark which implemented SLR instead of LALR. (I'll try to find the exact version if you're interested). It will have fewer features than the latest version, of course, but it should be good enough for most purposes.

As for size of table, you can do something like this:

>>> calc_parser = lark.Lark(...)
>>> len( calc_parser.parser.parser.parser.parse_table.states )
23
>>>> sum({1+len(v) for k, v in calc_parser.parser.parser.parser.parse_table.states.items()})
35

It's not "offic…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jpivarski
Comment options

Answer selected by jpivarski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants