PistonDevelopers / meta

A DSL parsing library for human readable text documents
MIT License
90 stars 5 forks source link

Use stack with indices and loop to avoid stack overflow #320

Open bvssvni opened 7 years ago

bvssvni commented 7 years ago

Currently, when a rule call itself recursively, it leads to stack overflow.

epurdy commented 6 years ago

IIRC yacc has some way around this that requires you to write recursive rules backwards. I.e.

foos = [foos foo]

instead of

foos = [foo foos]

I'm not sure if their trick is still possible to use if your grammars aren't LR(1) or whatever... but maybe a place to draw inspiration from.