#include #include #include #include /////////////////////////////////////////////////////////////////////////////// using namespace std; using namespace spirit; ////////////////////////////////// bool is_real = false; ////////////////////////////////// template struct my_number_parser_policies : public ureal_parser_policies { ////////////////////////////////// template static match parse_dot(IteratorT& first, IteratorT const& last) { match r = ch_p('.').parse(first, last); if (r) is_real = true; return r; } ////////////////////////////////// template static match parse_exp(IteratorT& first, IteratorT const& last) { match r = nocase_d['e'].parse(first, last); if (r) is_real = true; return r; } }; real_parser > const my_number_p = real_parser >(); /////////////////////////////////////////////////////////////////////////////// int main() { cout << "/////////////////////////////////////////////////////////\n\n"; cout << "\t\tDetermining an int or a real...\n\n"; cout << "/////////////////////////////////////////////////////////\n\n"; cout << "Type a number...or [q or Q] to quit\n\n"; double x; rule<> r = my_number_p[ref(x)]; // our rule while (true) { char str[256]; cin.getline(str, 256); if (str[0] == 'q' || str[0] == 'Q') break; is_real = false; if (parse(str, r, space_p).full) { cout << x; if (is_real) cout << ": is real\n"; else cout << ": is integer\n"; } else { cout << "parse error\n"; } } return 0; }