I try to build an expression string evaluated with DDMathParser from user input (string)
for example: 3 + ln(2) + var
I try to use the built-in Tokenizer function from DDMathParser in order to find all kind of tokens. But using the following code will not find any function tokens:
equationInputString = "3+ln(2)+var"
do{
let token = try Tokenizer(string: equationInputString).tokenize()
for element in token {
let tokenString = element.string
let tokenKind = element.kind
print(tokenString, ";", tokenKind)
}
} catch {
print("Tokenizer error in VC!", error)
}
/* output:
3 ; number
+ ; operator
ln ; identifier <-- not recognized as "ln()" function
( ; operator
2 ; number
) ; operator
+ ; operator
var ; identifier
*/
Is there a way to extract ln as function token? Do I need to use another approach within DDMathParser to find standard function strings?
Thanks!
DDMathParser author here...
The answer is "it depends". What are you trying to do? Typical usage of DDMathParser would just be to turn the whole thing in to the final
Expressiontype, and the recurse through the resulting tree looking for anExpressionof kind.functionthat has anameof"ln".