Boost logo

Boost :

From: joel de guzman (djowel_at_[hidden])
Date: 2002-01-16 20:27:31


----- Original Message -----
From: "David A. Greene" :

> rogeeff wrote:
>
>
> > First of all I would like to say that IMO it is odd even to discuss
> > an ability to use Spirit for generic command line parser. It's like
> > use a canon to kill a fly. For one It is very expensive and heavy and
> > also I should drag it all over the place.
>
>
> How do you know this? I cannot make a judgement because I haven't
> used Spirit (yet). But I know from reading the Spirit mailing list
> that Joel, et. al. have put in lots of thought on how to keep things
> lightweight.

That statement is unfounded and simply false. The code generated
by the one-liner complex parser that Dan wrote shouldn't be much
more than the size of a similar hand written parser. The framework
is rich but you only pay for what you use.

> Depends what "complex" means, I suppose. I think people get way too
> caught up arguing about overhead for command-line parsing. It's a
> one-shot job so performance shouldn't be an issue. Size is certainly
> a concern. I don't have a feel for how Spirit scales in that sense.
>
> It would be nice to have some numbers. Joel, do the Spirit guys
> working on command-line parsers have any size numbers they can share?

I'll ask... Judging from experience though, again, The code
generated by Spirit shouldn't be much more the size of a similar
hand written one.

> I agree Spirit looks a little cryptic. In particular the assignment
> of values is rather "magical" ("ref" should probably be named
> "assign_to"). But even so, as someone who has experience with YACC
> but zero with Spirit, I can follow this and understand what it means
> (except for the bang, which I had to look up, but it makes sense
> if you consider it an "|" with an empty left operand).

The next version (V1.4) will use var(x) instead. ref(x), although similar
to boost::ref(x) is quite a different beast now and should (IMO) have a
different syntax. One could also write:

    int_p[ var(n) = arg1 ]

which is equivalent to:

    int_p[ var(n) ]

Which btw parses integers and passes on to the variable 'i'.

> > I would implement the same logic in 2-3 lines using tokenizer or
> > regexp. Something like this:
>
> > token_iterator it( str, " \t," );
> >
> > real = lexical_cast<double>( *it++ );
> > imaginary = lexical_cast<double>( *it );

It's not the same! Dan's one-liner could parse complex numbers of the
form:

     r or (r) or (r, i)

Now rewrite that again using tokenizer. Then when you are done,
try parsing a vector of comma separated complex numbers where
the first number parsed is the size of the vector. Of the form:

    N { c0, c1, c2, .... cN }

With Spirit, this is still a one-liner.

Regards,
--Joel


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