Is there an easy way to turn the string "5 <6" to true in C ++, linux?

I am coding an algorithm that counts the number of solutions for a constraint system. The constraints in this case are predicates, such as "a <b" or "a = 3 + b or = 6 + b," which I will receive as input strings. I need to ask if any given choice of values ​​for variables is the right combination, and I would prefer not to create a parser for this.

Is there a quick C ++ library that evaluates strings as mathematical expressions? I think I have a simple way to convert "a <b" to "5 <6", I just need a way to evaluate this.

+3
source share
7 answers

Writing a simple arithmetic expression analyzer was an exercise in school. It really is not that difficult. Give it a try!

The idea was to convert it to the reverse Polish notation , and then it is easy to evaluate. The above Wikipedia article has all the necessary information.

The "Flex" and "Bison" tools also come to mind, although I have not used them myself.

+4
source

In C or C ++ there is no easy way to do this.

You will need to create your own parser.

+1
source

, , , , (, ).
- .

0

, Lua, . .

0

, ..:)

boost:: spirit.

, , , , . bison, lex yacc..

0
0

Source: https://habr.com/ru/post/1782507/


All Articles