0

Our input expressions are similar to this (even more complex):

( ( ?var1 <= (?var2 + 125) && ?var1 > (?var2 + 10) ) || !(?var1 == ?var3) )

Note: variables are always started by either '?' or '_'

Our desired output:

                            ||
                          /   \
                        /      \  
                      /          \
                    /              \ 
                   /                 \ 
                 &&                   ! 
                /  \                  |
              /     \                 | 
            /        \                ==
          /            \             /  \
        /                \      ?var1    ?var3
      <=                   >
     / \                  / \
    /   \                /   \
   /     \              /     \
?var1      +        ?var1      +
          / \                 / \
         /   \               /   \
        /     \             /     \
      ?var2   125         ?var2   10

Your helps are really appreciated.

  • Maybe you can start here https://stackoverflow.com/questions/8706356/boolean-expression-grammar-parser-in-c/8707598#8707598 – sehe Jan 27 '20 at 12:04
  • Thanks sehe. I've seen your informative and comprehensive answers before. That link is also quite related, but I've just started to learn Spirit and I do not know how to change that code to detect extra characters such as '<', '>=', '+', etc. –  Jan 27 '20 at 12:41
  • 1
    you should just try, and when you get stuck you have a question to ask. As it is, this is not very suited for [SO] because it's not a coding question (we tend to avoid the kind of "can you do it for me" or "can you show me" only questions). – sehe Jan 27 '20 at 13:03
  • As a starting hint, don't consider it as detecting "extra characters" but instead replace the existing tokens ("and" -> "&&") and then add the logic that a variable must start with a specific character. Finally, some richer grammars are based on that answer, and also go on to evaluating the expression(s) https://stackoverflow.com/questions/linked/8706356?sort=active – sehe Jan 27 '20 at 13:08

0 Answers0