0

I've come up with following boolean expression parser after reading the Spirit tutorials:

expression =
          bool_                           [_val =  _1]
            >> *(  ("&&" >> expression    [_val && _1])
                |  ("||" >> expression    [_val || _1])
                )
            ;

For constants I get the correct results from the parser:

true -> 1

false -> 0

But for slightly more complex expressions things go horribly wrong:

true && false -> 1 (incorrect!)

false && true -> 0 (correct)

false || true -> 0 (incorrect!)

true || false -> 1 (correct)

Community
  • 1
  • 1
Boris
  • 8,551
  • 25
  • 67
  • 120
  • Do you notice a pattern in the correct/incorrect output? Like `false` first in the expression always seems to result in `false`, and `true` first in the expression always seems to result in a `true` result? – Some programmer dude Dec 03 '13 at 08:12
  • There seem to be no "&&=" and "||=" operators... – Boris Dec 03 '13 at 08:19
  • 1
    Sorry Boris - should just use `&=` and `|=`, or `_val = _val && _1` etc.. The point is you're not changing `_val` in your action. After that you can work on precedence etc.. – Tony Delroy Dec 03 '13 at 08:52
  • Yep, that did the trick. Thanks! With precedence you mean right to left parsing? – Boris Dec 03 '13 at 09:04

0 Answers0