1

Using pyparsing I have the rules to parse a math expression with parenthesis (), +, -, * and /. The operations can be nested and the parser knows how to achieve that. Credit goes to PaulMcG.

The expression can have logical operations with iif keyword this way:

iif(condition, value_if_true, value_if_false)

Condition has the regular operators =, >=, <=, >, <, <>, &, |

There is a way to calculate the result from a string expression. But I can not find a way to get the final value since the condition can have nested conditions.

So, is there any way to instruct pyparsing to calculate this final value using logic operations alonside math operations? Or there is any way to remove the conditions and return the original expression as single math expression and then be able to calculate the final value?

PS: I'm using python 3.6.7 and Linux Mint 19.1.

assembler
  • 3,098
  • 12
  • 43
  • 84
  • 1
    See how simpleBool.py (https://github.com/pyparsing/pyparsing/blob/master/examples/simpleBool.py) attaches evaluatable classes to each level of infixNotation, and to the operand expressions, so that after parsing, pyparsing will have built for you a fully evaluatable structure. Add a class to be the parse action for your `iif` statement and you are done. Start small and work your way up, you can do it! – PaulMcG Jun 17 '19 at 23:31

0 Answers0