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!