Search code examples
c++boost-spirit

Boost spirit stack overflow exception in recursive rule


I have the following simple grammar:

expr_ = lit("+") > expr_
            | qi::uint_
            ;

Basically, it's simply ignoring + signs in front of an int.

The following input causes a stack overflow:

+++ ...(~195 more + chars )... ++1

I understand that the recursivity in the rule would indeed cause this behavior, but is there a way to avoid such exceptions (kind of indicating that the rule is tail recursive somehow)?


Solution

  • As you are probably aware, you can rewrite your rule to remove the recursion:

    expr_ = *lit("+") > qi::uint_;
    

    As to your question about tail recursion, basically the answer is no.