So, this is a problem that I believe is a lot more complicated than the linked question lets on (although the question is asking for a "simple" equation parser).
Fortunately for you, I think this is a really interesting problem and have already written one for you: DDMathParser
.
It has a good amount of documentation, including things like how to add it to your project and a high overview of its capabilities. It supports all of the standard mathematical operators, including logical and comparison operators (||
, &&
, ==
, !=
, <=
, etc).
In your case, you'd 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 made available under the MIT license, which requires you to include the copyright information and the full text of the license in anything that uses it.