4

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.

4 Answers 4

6

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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

1 Comment

Great solution , from different point of view you just let the c# compiler to do the parsing!!!! Thank you very much!
3

The Irony library is very simple to use, and comes with an expressions parser in the examples.

Comments

2

If your goal is evaluating the expression and not the tree itself - you can look at this: http://www.codeproject.com/KB/recipes/sota_expression_evaluator.aspx

It's probably worth noting, that the implementation of most expression evaluators is using RPN. http://en.wikipedia.org/wiki/Reverse_Polish_notation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.