0
votes

Is there any API for WP7 to get an arithmetic expression in a string and eval it?

Searched for it on google, but nothing comes up..

Thanks in advance.

1
Take a look at this project. Evaluation is done by LINQ, the project does only parsing.Sergey Kalinichenko
I don't know anything about Windows Phone 7, but last week I got the hint to try the Jurassic JavaScript engine for a similar problem (not on Windows Phone, though). stackoverflow.com/questions/10773499/…JohnB

1 Answers

1
votes

Searching for "C# parse arithmetic from string" I found a good bunch of resources, with this one the most appealing to me. I haven't tried, but I suppose it will compile on WP7.

Anyways, there's always the possibility of building your own parser. You can approach this using expression trees: read about this in this article (scroll down to the section Expression Trees) (in Java, but explains the concept pretty well and the language is similar enough to C# to be comprehensible).

You can also use the Shunting Yard algorithm, which uses a stack to evaluate the expression. These are only two approachs I remember now, I'm sure there are a lot more. It's harder than using third party libraries, but you can adapt them to your own requeriments.