我有一个类似于以下的工作语法:
stock_price = symbol_ >> date_ >> price_; stock_prices_ = stock_price_ >> stock_prices_ | eps; grammar_ = lit( "PRICES" ) >> stock_prices_ >> lit( "END" );
问题是,当股票价格列表_太高(比如大约1000个价格)时,用exc_bad_access解析seg-fault.我实际上可以解决这个问题:
stock_prices_ = stock_price_ >> stock_price_ >> stock_price_ >> stock_price >> stock_prices_ | stock_price_ >> stock_prices_ | eps;
解决方法
我可能在这里完全错过了这个问题,但是
kleene star,plus parser和/或
list parser directives有什么问题?
stock_prices_ = +stock_price_ | eps; // one or more stock_price_ or nothing
然而,这看起来恰好是kleene star的语义:
stock_price = symbol_ >> date_ >> price_; grammar_ = "PRICES" >> *stock_price_ >> "END"; // zero or more stock_price_
现在,如果你想让它们以行分隔,例如,使用1:
grammar_ = "PRICES" >> -(stock_price_ % eol) >> "END";
1与例如qi :: blank队长,不吃换行符