Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit, phoenix] grammars and phoenix actions
From: Joel de Guzman (joel_at_[hidden])
Date: 2012-03-25 20:23:48


On 3/26/2012 1:22 AM, Brian Budge wrote:
> Hi all -
>
> I'm trying to transition my grammar from something like this:
>
> simple_expr = _int
> | '(' >> full_expr >> ')'
> ;
> sum_expr = simple_expr
> | (simple_expr >> '+' >> simple_expr)[_ret = _1 + _2]
> ;
> ...
>
> to something like
>
> sum_expr = simple_expr >> *(sum_expr >> '+' >> sum_expr)
> ;
>
> I have full grammars coded up for essentially all integer operations
> that could be done in C. I extended one of the simple AST examples
> that Joel de Guzman has written, by adding the bitwise ops and ternary
> operations. I'm not entirely sure why (not a grammar/parser guru),
> but the latter grammer is far more efficient to parse using spirit
> than the former. I remember writing grammars more like the first back
> when I used bison, but I understand the kind of parser is different
> (LR vs recursive descent).

Iteration is always faster than recursion in an RD parser
like Spirit.

> Anyway, on to my question. I am fine using the second type of
> grammar, but I've timed the parsing and evaluation of my little
> calculator, and AST creation and desctruction actually dwarfs parsing
> time. I wonder if using phoenix could speed up evaluation, and also
> how exactly something like the "plus" operator could be evaluated in
> this curried context? I've tried many searches in google, but haven't
> found the magic example.

What do you mean by "speed up evaluation"? Do you mean interpretation
of your expressions?

FYI, there's a separate Spirit mailing list. I suggest
posting Spirit related support requests there:

  http://boost-spirit.com/home/feedback-and-support/

Also, please post more info. E.g. timing results, test code, etc.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://boost-spirit.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net