|
Boost : |
From: Firingme (firingme_at_[hidden])
Date: 2003-09-07 19:53:51
Why you choose Spirit but not YACC???
I've seen some comment that says Spirit is much slower than YACC ,does it
true ?
"Hartmut Kaiser" <hartmutkaiser_at_[hidden]>
??????:000001c37512$a8d50620$0100a8c0_at_sirius...
> Michael Burbidge wrote:
>
> > The following is a simple program that uses spirit to parse a trivial
> > grammar. Of course my real grammar is not so simple, but I've
> > narrowed
> > it down to a very small example. When I run the program it crashes
> > during the call to parse. I've tried this program on Windows and
> > Macintosh and using the spirit in boost 1.30.2 and the latest spirit
> > 1.7.0. They all crash. This code was derived from the ast
> > calc example.
> >
> > If I change the line:
> >
> > rule<ScannerT, parser_context, parser_tag<escaped_expr_id> >
> > escaped_expr;
> >
> > to:
> >
> > rule<ScannerT > escaped_expr;
> >
> > it doesn't crash. But since I'm trying to build a abstract
> > syntax tree
> > I really need the rule id. Can anyone tell me how I might change my
> > simple program so that it doesn't crash?
>
> My compiler spits out a warning about returning a reference to a
> temporary object here:
>
> rule<ScannerT, parser_context, parser_tag<escaped_expr_id> >
> escaped_expr;
> rule<ScannerT> const& start() const
> { return escaped_expr; } // <<--- HERE
>
> which is the root of your problem. The compiler has to implicitely
> construct a temporary of the type rule<ScannerT> to fit your type
> conversion needs. To solve this problem you'd need to insert another
> indirection rule at the top of your parser hierarchy:
>
> template <typename ScannerT>
> struct definition
> {
> definition(expr_grammar const& self)
> {
> start_rule = escaped_expr;
> escaped_expr
> = ch_p('{') >> ch_p('}')
> ;
> }
>
> rule<ScannerT, parser_context, parser_tag<escaped_expr_id> >
> escaped_expr;
> rule<ScannerT> start_rule;
> rule<ScannerT> const& start() const { return start_rule; }
> };
>
>
> HTH
> Regards Hartmut
>
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk