Replace function node in mathematical expression [closed]

I have a mathematical expression such as:

expression = function123(v1, v2)

and I want to transform it to:

expression = (function1(v1, v2) + function2(v1, v2) + function3(v1, v2))

In order to solve this problem, I tried to utilize regular expressions, such as:

"function123(([^)]+),([^)]+))"

and replace using the interior tokens to get what I want.

Regular expressions come with certain limitations and problems. that can be identified in the following examples:

expression = myfunction123(v1, v2) + function123(v1, v2)

The above example would create problems because my would be get messed up.

expression = function123(normalized(v1), normalized(v1))

The above example would create problems because the interior nodes would not be able to be extracted.

So basically I understood that regular expressions are not enough to solve this problem so I need something like an abstract syntax tree.

Does anybody have any experience with such a problem that could guide me to accomplish what I described?

Thanks a lot in advance.

Source: Windows Questions C++

LEAVE A COMMENT