I already found a solution to my problem on stackoverflow but it is in Objective-C. See this link DDMathParser - Getting tokens
I translated this into Swift as shown below. So what is the latest way to get tokens from a string and to get grouped tokens?
For example: 1 + ($a - (3 / 4))
Here is my try:
do{
let token = try Tokenizer(string: "1 + ($a - (3 /4))").tokenize()
for element in token {
print(element)
}
} catch {
print(error)
}
But I get the following messages:
MathParser.DecimalNumberToken
MathParser.OperatorToken
MathParser.OperatorToken
MathParser.VariableToken
MathParser.OperatorToken
MathParser.OperatorToken
MathParser.DecimalNumberToken
MathParser.OperatorToken
MathParser.DecimalNumberToken
MathParser.OperatorToken
MathParser.OperatorToken
How do I get the specific tokens from my string?