4 ms·
> Because we rely on recursive function calls, it is possible that your parser may run out of space on the call stack for deeply nested expressions, like 1^1^1^
by kazinator 3y ago
> Because we rely on recursive function calls, it is possible that your parser may run out of space on the call stack for deeply nested expressions, like 1^1^1^1.... You could mitigate this by keeping track of the depth of the expression while parsing and throwing a custom “This expression is nested too deeply” error. Another strategy is to move the parsing stack into the heap, either by managing the parser state yourself or using something like trampolining.
That would be Dijkstra's "shunting yard" algorithm.
https://en.wikipedia.org/wiki/Shunting_yard_algorithm https://en.wikipedia.org/wiki/Shunting_yard_algorithm
https://stackoverflow.com/a/13637731/1250772 https://stackoverflow.com/a/13637731/1250772
Shunting Yard in TXR Lisp [2015]
https://stackoverflow.com/a/34377302/1250772 https://stackoverflow.com/a/34377302/1250772