B
Balazs Endresz
Recently I made a parser combinator lib, based on Parsec:
http://code.google.com/p/jsparsec/
and I started to rewrite it in trampolined style to avoid "too much
recursion". But above about 3000 "recursive" calls (in Firefox) it
doesn't work as expected. I might have messed something up, but I
can't seem to figure out what's happening. The parser operates on a
ParseState object, which indicates how much of the text has been
consumed. And it *does* seem to fully consume the input no matter how
deep the recursion is, but when it approaches to the last function
call, then it fails with "Internal error: too much recursion". I even
inserted timeouts between every few hundred calls but it fails then as
well, but with a slightly different error: "too much recursion (802
out of range 13)" - this is a bit strange but I don't think it's
related. If I stop it before the last computation and evaluate the
remaining thunks manually, one by one, then again: "Internal error:
too much recursion".
Here's the code I used to test it:
http://code.google.com/p/jsparsec/source/browse/branches/tailopt-test/test.js
So, what seems to be happening, is that it works properly until 3000
recursive calls but above that, when the last callback function should
receive the final result, it fails. But I can see that the input in
the ParseState object has been fully consumed. How could such thing
happen?
http://code.google.com/p/jsparsec/
and I started to rewrite it in trampolined style to avoid "too much
recursion". But above about 3000 "recursive" calls (in Firefox) it
doesn't work as expected. I might have messed something up, but I
can't seem to figure out what's happening. The parser operates on a
ParseState object, which indicates how much of the text has been
consumed. And it *does* seem to fully consume the input no matter how
deep the recursion is, but when it approaches to the last function
call, then it fails with "Internal error: too much recursion". I even
inserted timeouts between every few hundred calls but it fails then as
well, but with a slightly different error: "too much recursion (802
out of range 13)" - this is a bit strange but I don't think it's
related. If I stop it before the last computation and evaluate the
remaining thunks manually, one by one, then again: "Internal error:
too much recursion".
Here's the code I used to test it:
http://code.google.com/p/jsparsec/source/browse/branches/tailopt-test/test.js
So, what seems to be happening, is that it works properly until 3000
recursive calls but above that, when the last callback function should
receive the final result, it fails. But I can see that the input in
the ParseState object has been fully consumed. How could such thing
happen?