Boost logo

Boost :

From: joel de guzman (isis-tech_at_[hidden])
Date: 2001-06-02 10:27:07


Hello,

Micro parser functionality as hinted by Vesa Karvonen
is already implemented in the Spirit parser framework.
Here's a working code snippet:

int
main()
{
    int a, b;

    char const* str = "( -123456, 654321 )";
    Scanner<> scanner(str, space);

   bool ok = ('(' >> int_p(a) >> ',' >> int_p(b) >> ')').Parse(scanner);

    /*... if successful, a and b will hold the parsed numbers */
    /* if not, scanner will point to error in the input */
}

Notes:

* int_p terminal is a const object that takes a templatized place-holder
data.
this can be an int, a long, even a float, or possibly a big integer.
Doesn't matter; as long as it conforms to the semantics of an integer.

* There's a corresponding uint_p terminal for unsigned ints.

* I am working on the floating point counterpart of int_p: float_p
   I welcome suggestions on how to make the code generic such that
   big floats can be supported but without penalizing float and double
   built in types (template partial specialisation?).

* The parser can of course be quite complicated (with many rules)

Comments and suggestions welcome.
I will upload the code tomorrow: http://isis-tech.n3.net

Cheers,
Joel de Guzman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk