3 ms·
I've implemented parsing left recursions with a memoized recursive descent parser generator. It requires hints to tell the generator it is left recursion[1] - b
by meric 11y ago
I've implemented parsing left recursions with a memoized recursive descent parser generator. It requires hints to tell the generator it is left recursion[1] - but even with this inconvenience, I think it's more convenient than having to refactor a left-recursive grammar into a right recursive one and then flipping the precedence back. I'm still finishing building the first useful parser using it, there may still be bugs.
It works by dynamically refactoring the grammar at each recursion. [2] The dynamic refactoring only happens if left recursion is hinted for that rule.
[1] See the `left(..)` call in `prefixexp` that tells the parser generator about the left recursion.
https://github.com/meric/l2l/blob/parser-generator/l2l/lua.lua#L261 https://github.com/meric/l2l/blob/parser-generator/l2l/lua.l...
[2] https://github.com/meric/l2l/blob/parser-generator/l2l/grammar.lua#L514 https://github.com/meric/l2l/blob/parser-generator/l2l/gramm...