I use DDMathParser to solver formula expressions using Swift. The following code works fine, however, implicit multiplication doesn't. Reading the docs it should work... So, what do I miss here? my code:
...
substitutions.updateValue(3, forKey: "x")
let myString = "3$x"
do{
let expression = try Expression(string: myString, operatorSet: operatorSet, options: myTRO, locale: myLocale)
let result = try evaluator.evaluate(expression, substitutions: substitutions)
print("expression is: \(expression), the result is : \(result)")
} catch {
print("Error")
}
...
The code throws the "Error". Using the string "3*$x" the expression is calculated as expected.
DDMathParser author here.
So, the
.invalidFormaterror is thrown when the framework has a sequence of tokens and is looking for an operator in order to figure out what goes around it. If it can't find an operator but still has tokens to resolve but no operator, then it throws the.invalidFormaterror.This implies that you have a
3.0number token and a$xvariable token, but no×multiplication token.I see also that you're passing in a custom set of
TokenResolverOptions(themyTROvariable). I'd guess that you're passing in an option set that does not include the.allowImplicitMultiplicationvalue. If I try to parse3$xwithout the.allowImplicitMultiplicationresolver option, then I get the.invalidFormaterror thrown.