Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse_term call gives StackOverflowException #6

Open
dungpa opened this issue Aug 27, 2013 · 1 comment
Open

parse_term call gives StackOverflowException #6

dungpa opened this issue Aug 27, 2013 · 1 comment

Comments

@dungpa
Copy link
Collaborator

dungpa commented Aug 27, 2013

In initializing arith module, the following parse_term call:

parse_term @"!m. m + 0 = m"

produces StackOverflowException. The same applies for subsequent parse_term calls.

This is probably related to parse_as_infix commands since if one comments out these commands in the beginning of arith module, StackOverflowException doesn't occur in some cases.

@jack-pappas
Copy link
Owner

My guess as to the cause of this issue is the way the parser-combinators are designed. Specifically, the parser-combinators handle alternatives/backtracking via throwing and catching exceptions; if one alternative doesn't match an input string, the parser will throw an exception which will be caught, then the second parser will be tried. Unfortunately, the second parser is called from within the catch part of the handler (with in F#), and for safety/security reasons the CLR does not allow tail-calls from within a protected block (try) or a handler (catch, finally, fault, filter).

This would explain why we only get the stack overflows in certain cases -- those are the cases where many alternatives have been added to the parser, and the parser for the string you're trying to parse (e.g., !m. m + 0 = m) is too far down the list of alternatives.

I expect this issue will be remedied whenever I get around to re-implementing the parsers (and related code) using FParsec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants