Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing calculation tree from string

I there any built in library in c# or automatic code generator which recieves configuration file and builds parser of calculaton tree from string if there is no could you please help me with advice Example: "-2+5>3" I would like to build calculation tree where < is root '+' is its right son 3 is left son '-2' is left son of the + and 5 is its right son. And the tree could do evaluation in this case true or false.

Thank you.

like image 984
Sergey Kucher Avatar asked Dec 07 '22 21:12

Sergey Kucher


2 Answers

Take a look at sprache. It's a simple parser which would allow you to build the expression tree and then evaluating it should be the easy bit.

like image 198
Jeff Foster Avatar answered Dec 17 '22 07:12

Jeff Foster


Have you looked at the System.Linq.Expressions? for example How to convert string into System.Linq.Expressions.Expression in C#?

like image 28
k3b Avatar answered Dec 17 '22 07:12

k3b