Trying to find the best and most flexible way (parser, regex, etc..) to take in a string math equation that uses percentages and output a new string equation that changes the percentages in certain scenarios. It'll have to be flexible because of the many permutations an equation may have.
The rule if a non percentage number is added, subtracted, divided, etc by a percentage it expands the percentage to equal the the percentage of that following operand.
For example..
120 + 12%
would output..
120 + 12/100 * 120
.
so that 120 is increased by 12% of 120.
but 120% * 120%
.
would still equal 144%.
In these string equations, % never means modulus. Modulus is handled by mod
operator.
Any many many other combinations, not just these would have to work as well. What would be be the best technical choice to handle such a task?
This particular job is done in Javascript.