-
I'm considering a project that would require DSL parsing on very low-end processors (like Z80s), in which the syntax of the language can be designed to fit the hardware limitations. However, I'm familiar with Lark and Python, and would much rather do prototyping (designing the syntax of the mini-language) in Lark, to get a sense of what kinds of languages would be possible before learning all about emulators and probably writing shift-reduce in assembly. I've heard that SLR(1) and LR(1) use smaller parse tables and would be more low-end hardware-friendly. Lark has an LALR(1) option, so these parsing algorithms are subsets of what Lark provides in LALR(1) mode. I'm reading lessons like this one about what exactly these rules are, but I'll need some automated check to tell me I'm overstepping the SLR(1) or LR(1) bounds while developing the DSL grammar (writing the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The answer is currently not, but that should not be impossible to add. It might even be reasonably possible to replace the |
Beta Was this translation helpful? Give feedback.
-
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 "official API", as you might imagine, but it's close enough. |
Beta Was this translation helpful? Give feedback.
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:
It's not "offic…