Boost logo

Boost Users :

Subject: [Boost-users] [spirit, phoenix] grammars and phoenix actions
From: Brian Budge (brian.budge_at_[hidden])
Date: 2012-03-25 13:22:53


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).

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.

Thanks,
  Brian


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