recursion - C++ Run-time Preempting Stack-Overflows -


i'm trying write library can parse end user files used adding simple user generated content project , want try , make library flexible possible. use recursion tokenisation process of 'objects' goes through chain of 4 functions conflicted how handle potential situation of end user going nested object happy. know can set hard limit on how many times program can recurse make flexible possible. there way can calculate (maximum - 1) number of times process can execute can preempt stack overflow error , return error or handled?

is there way can calculate (maximum - 1) number of times [recursive] process can execute ...

no. it's not guaranteed each stack frame in call chain same size.

transforming recursive implementation iterative 1 simple , well-defined: just

  1. replace implicit call stack (and function call operation) explicit state container, such std::stack<state>
  2. instead of recursive call, push new call's state onto stack, , continue loop
  3. instead of being called, loop starts popping current state off stack, , processes that, may require pushing new state on there if have made recursive call

alternatively, can split current recursive descent parser tokenizer , lalr (or similar) parser, both iterative in first place. can generate these flex , bison (lex/yacc), example.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -