Boost logo

Boost Users :

Subject: [Boost-users] Quick (hopefully simple) Spirit::Qi question
From: david.weber_at_[hidden]
Date: 2012-02-20 19:37:12


I have a grammar that fully works. I'm in the process of now adding
semantic actions to actually *do* something, and I'm hitting a snag.
(BTW, I've used Boost::Spirit::Classic, but this is my first time w/ Qi)

 

 

Grammar:

 

template <typename Iterator>

struct FortranLineGrammar : grammar<Iterator, space_type>

{

 

    FortranLineGrammar() :

        FortranLineGrammar::base_type(start)

    {

        lvalue %= !hex_int >> lexeme[alpha >> *(alnum | '_')] >> *dim;

        BOOST_SPIRIT_DEBUG_NODE(lvalue);

 

        assignment = lvalue[ppp_print] >> "=" >> command;

        BOOST_SPIRIT_DEBUG_NODE(assignment);

 

                ...

    }

    typedef rule<Iterator, std::string(), space_type> string_rule_t;

    string_rule_t lvalue;

 

 

};

 

 

Semantic action:

 

 

extern void ppp_print(std::string& b);

 

and later

 

void ppp_print(std::string& b)

{

    std::cout << b << std::endl;

}

 

 

So, what I'm going for, is when an lvalue is encountered, to call
ppp_print with whatever matched that value.

 

Unfortunately, I'm only getting the first character?!?

 

Here is the debug output, not the right match, but I'm still tweaking
the grammar. Looking at the actions only...

 

PRINT *, 'AHHHH! '

<start>

<lvalue>

  <try>PRINT *, 'AHHHH! '</try>

    <dim>

      <try> *, 'AHHHH! '</try>

      <fail/>

    </dim>

  <success> *, 'AHHHH! '</success>

  <attributes>[[P]]</attributes>

</lvalue>

 

 

So what gives?

 



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net