|
Boost Users : |
From: Misza (Misza.B_at_[hidden])
Date: 2005-06-27 07:52:46
I've recently switched from YACC to Spirit
and I've been trying to rewrite some examples
from YACC manual, starting with a RPN calculator.
Based on http://www.boost.org/libs/spirit/doc/grammar.html
I made something like this:
/* #includes and usings */
struct rpn_calc : public grammar<rpn_calc>
{
template <typename ScannerT>
struct definition
{
definition (rpn_calc const& self)
{
expr_add = expr >> ch_p(' ') >>
expr >> ch_p(' ') >> ch_p('+');
expr_sub = expr >> ch_p(' ') >>
expr >> ch_p(' ') >> ch_p('-');
expr_mul = expr >> ch_p(' ') >>
expr >> ch_p(' ') >> ch_p('*');
expr_div = expr >> ch_p(' ') >>
expr >> ch_p(' ') >> ch_p('/');
expr_pow = expr >> ch_p(' ') >>
expr >> ch_p(' ') >> ch_p('^');
expr = expr_add | expr_sub |
expr_mul | expr_div |
expr_pow | real_p;
}
rule<ScannerT> expr, expr_add,
expr_sub, expr_mul,
expr_div, expr_pow;
rule<ScannerT> const&
start () const { return expr; }
};
};
int main (void)
{
rpn_calc calc;
std::string str("1 2 + 3 4 + *");
if (parse(str.begin(), str.end(), calc, space_p).full)
cout << "Parsing succeeded.\n";
else
cout << "Parsing failed!\n";
return 0;
}
Now this compiles OK, but when executed it doesn't
output anything, which means that parse(...) quits
without any warnings - what's the problem?
Am I doing something wrong?
Thanks,
Misza
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