Boost::Spirit Expression Parser

It isn’t entirely clear to me what you are trying to achieve. Most importantly, are you not worried about operator associativity? I’ll just show simple answers based on using right-recursion – this leads to left-associative operators being parsed. The straight answer to your visible question would be to juggle a fusion::vector2<char, ast::expression> – which isn’t … Read more

Boost Spirit X3 cannot compile repeat directive with variable factor

From what I gather, reading the source and the mailing list, Phoenix is not integrated into X3 at all: the reason being that c++14 makes most of it obsolete. I agree that this leaves a few spots where Qi used to have elegant solutions, e.g. eps(DEFERRED_CONDITION), lazy(*RULE_PTR) (the Nabialek trick), and indeed, this case. Spirit … Read more

boost spirit V2 qi bug associated with optimization level

It’s a bug in your code, nothing wrong with the compiler or the optimization levels. The cinch is with expression templates (like the ones used by Boost Proto, and hence by Boost Spirit). They are only valid to the end of their enclosing full expression [1] The canonical workaound is: BOOST_SPIRIT_AUTO(ana, *~qi::char_(‘*’) > +qi::char_(‘*’)); You … Read more

Compiling a simple parser with Boost.Spirit

Mmm. I feel that we have discussed a few more details in chat than have been reflected in the question as it is. Let me entertain you with my ‘toy’ implementation, complete with test cases, of a grammar that will recognize <<macros>> like this, including nested expansion of the same. Notable features: Expansion is done … Read more

undefined behaviour somewhere in boost::spirit::qi::phrase_parse

You cannot use auto to store parser expressions¹ Either you need to evaluate from the temporary expression directly, or you need to assign to a rule/grammar: const qi::rule<std::string::const_iterator, qi::space_type> doubles_parser_local = qi::double_ >> *(‘,’ >> qi::double_); You can have your cake and eat it too on most recent BOost versions (possibly the dev branch) there … Read more

Understanding Boost.spirit’s string parser

It’s not the string matcher per se. It’s [attribute propagation] + [backtracking] in action. A string attribute is a container attribute and many elements could be assigned into it by different parser subexpressions. Now for efficiency reasons, Spirit doesn’t rollback the values of emitted attributes on backtracking. Often this is no problem at all, but … Read more

How can I use polymorphic attributes with boost::spirit::qi parsers?

Spirit is a lot friendlier to compiletime-polymorphism typedef variant<Command1, Command2, Command3> Command; But, let’s suppose you really want to do the old-fashioned polymorphism thing… Just newing-up the polymorphic objects on the fly during parsing, however, is a sure-fire way to make your parser bloated with semantic actions create lot of memory leaks on back-tracking in … Read more