c++ - Spirit semantic actions after eliminating Left Recursion -
To eliminate the left recursive after following the sample in the Spirit Classic FAQ, I understand the correct placeholder for Phoenix I am unable to interpret the meaning of my non-work grammar as shown below:
template & lt; Typename this, typename Skipper = qi :: space_type & gt; Structure Parser: qi :: grammar & lt; This, xp (), ska & gt; {Parser (): Parser :: Base_type (expression) {Namespace QI; Expression = word [_val = _1]> & gt; * ((Four _ ('+') >> [_val = phx :: construct & lt; binop & lt; op_add & gt; & gt; (_ 1, _2)] | (four _ ('-')> gt; & gt; _val = phx :: creation & lt; binop & lt; op_sub & gt; (_ 1, _2)]); word = factor [_val = _1]> gt; ; & gt; * ((four _ ('*')>> Factor) [_val = phx :: construct & lt; binop & lt; op_mul & gt; & gt; (_ 1, _2)] | (_ _ _ _ _ = Phx :: creation & lt; binop & lt; op_div & gt; & gt; (_ 1, _2)]); factor = uint_ [4] _val = _1] | var_ [_val = _1] | ('('> expression> gt; & gt; ')' | [_val = _1] | | (four _ ('-')> gt ; Factor) [_val = phx :: creation & lt; unop & lt; op_uminus & gt; & gt; (_ 1)] | (four_ ('+'> gt; factor) [_val = _1]; var_ = Qi :: lexem [+ alpha]; BOOST_SPIRIT_DEBUG_NODE (expression); BOOST_SPIRIT_DEBUG_ NODE (word); BOOST_SPIRIT_DEBUG_NODE (factor); BOOST_SPIRIT_DEBUG_NODE (var_);} Private: qi :: rule & lt; it, var (), skip & gt; var_; qi :: rule & lt; it, xp () Skipper & gt; expression, duration, factor;}; post text "itemprop =" text "> I think you can actually
& gt; & Gt; * ((Four _ ('+') >> [_val = phx :: construct & lt; binop & lt; op_add & gt; & gt; (_ 1, _2)] | (four _ ('-')> gt; & gt; _val = phx :: construct & lt; binop & lt; op_sub & gt; & gt; (_ 1, _2)] pass Do '+' as the first constructor parameter, because type binop op_add & gt; already reflects as an operator. It is argued that you now parse here:
word [_val = _1] This probably indicates to you : You got this to _val ! Then, your solution is: & gt; & gt; * ((four_ ('+')> gt ; & Gt; Words) [_val = phx :: construct & lt; binop & lt; op_add & gt; & gt; (_ val, _2)] | (four _ ('-')> gt; & gt; ) [_val = phx :: construct & lt; binop & lt; op_sub & gt; & gt; (_ val, _2)] However, since four_ (. ..) is not used, you can change it: & gt; & Gt; * ((Published ('+')> gt; & gt; m) [_val = phx :: construct & lt; binop & lt; op_add & gt; & gt; (_ val, _1)] | (lit (' - ') & gt; & gt; [_value] [_val = phx :: construct & lt; binop & lt; op_sub & gt; & gt; (_ val, _1 )]
Comments
Post a Comment