Boost logo

Boost :

From: joel de guzman (djowel_at_[hidden])
Date: 2002-01-15 13:17:45


----- Original Message -----
From: "Vladimir Prus" :

> joel de guzman wrote:
>
> > > Because:
> > > 1. I think that parsing proper is not the most complex thing. It's
> > > assigment to program variables and validation that was hard, at least for
> > > me.
> >
> > Have you seen Spirit's semantic expressions?
>
> Do you refer to "expr[ref(var)]". I don't think this is enough. Command line
> parsing library must provide storage for values, validate them, handle
> multiple assignments and so on.

Much more than that now. But I am not sure what you mean by "validate them,
handle multiple assignments and so on". Here's a *fully working* calculator
(not just a parser) for example using semantic expressions:
 
            factor
                = ureal_p[factor(m0)]
                | '(' >> expr[factor(m0)] >> ')'
                | ('-' >> factor[factor(m0) = -arg])
                | ('+' >> factor[factor(m0)])
                ;

            term
                = factor[term(m0)] >>
                *( ('*' >> factor[term(m0) *= arg])
                | ('/' >> factor[term(m0) /= arg])
                )
                ;

            expr
                = term[expr(m0)] >>
                *( ('+' >> term[expr(m0) += arg])
                | ('-' >> term[expr(m0) -= arg])
                )
                ;

Semantic expressions implement a full fledged Lambda lib. with an
interesting twist: It has *true* closures that work on *true* local variables.

> Do you really think that Spirit will be great improvement to a command line
> handling library? At this moment the hand-written code which deal with
> parsing proper is only 44 lines.

I am not sure. I am not an expert on command line interfaces. I
haven't programmed one yet. The only thing I am sure is that it can
be done and it can do much more.

> > > 2. Spirit is nondeterministic recursive descent parser. I don't find this
> > > is acceptable. We want to detect ambiguity in option specification.
> >
> > Not accurate. There are already more deterministic stuff going on.
> > Ambiguity can be constrained. RD is an implementation detail.
> > Research is now towards recursive ascent and even template-
> > metaprogrammed-automata.
>
> Is it already implemented?

Soon. There are precursors though: Dan Nuffer wrote a dynamic
lexer for Spirit written in Spirit for example. Hartmut Kaiser is now
using that as the lexer over a *full* C preprocessor also using
Spirit. Hartmut already wrote a C parser BTW.

Also, forgive me but why isn't nondeterministic RD not
acceptable for parsing command lines?

--Joel


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