So, this is a problem that, in my opinion, is much more complicated than the related question allows (although the question is asked by a βsimpleβ parser).
Luckily for you, I think this is a really interesting problem and has already been written for you: DDMathParser
.
It has a good amount of documentation , including such things as how to add it to your project and a high overview of its capabilities . It supports all standard mathematical operators , including logical and comparative operators ( ||
, &&
, ==
!=
, <=
, Etc.).
In your case, you would do something like this:
NSNumber *result = [@"15+14 == 23" numberByEvaluatingString]; if ([result boolValue] == YES) { ....True statement.... } else { .....False statement..... }
As a heads-up, DDMathParser
is licensed under the MIT, which requires you to include copyright information and the full text of the license in everything that uses it.
Dave delong
source share