Accepted answer

You could parse the string into a syntax tree of Nodes.

Take a look at scala parser combinators. You can define your own parsers and combine them to generate a nested structure of Nodes, then process the nested structure.

It seems like you want to parse the string to polish notation. Here is an example of a reverse polish notation parser.

Related Query