What is the proper way to handle deep recursion in boost :: spirit :: qi grammar?

I have a working grammar similar to the following:

stock_price = symbol_ >> date_ >> price_; stock_prices_ = stock_price_ >> stock_prices_ | eps; grammar_ = lit( "PRICES" ) >> stock_prices_ >> lit( "END" ); 

The problem is that when the list of stock prices becomes too high (say, around 1000 prices), seg-faults are parsed using exc_bad_access. I really can solve this:

 stock_prices_ = stock_price_ >> stock_price_ >> stock_price_ >> stock_price >> stock_prices_ | stock_price_ >> stock_prices_ | eps; 

but I do not see this as an elegant solution. Is there a better solution?

+7
c ++ recursion boost-spirit boost-spirit-qi
source share
1 answer

I could completely miss the problem here, but what is wrong with kleene star , plus the parser and list parser directive

 stock_prices_ = +stock_price_ | eps; // one or more stock_price_ or nothing 

However, it looks like the semantics of only wedge stars:

 stock_price = symbol_ >> date_ >> price_; grammar_ = "PRICES" >> *stock_price_ >> "END"; // zero or more stock_price_ 

Now, if you want them to be split by line, for example, use 1 :

 grammar_ = "PRICES" >> -(stock_price_ % eol) >> "END"; 

1 combine with, for example, the skipper qi::blank , which does not feed on newline characters

+5
source share

All Articles