I am trying to make a small tool that transfers a math equation to a Java BigDecimal line.
for example:
A + B * C => A.add(B.multiply(C))
A / B + C => A.divide(B).add(C)
Things are getting nasty with brackets.
A - (B + C) / D => A.substract(B.add(C).divide(D))
A - (B * (C + D)) => A.substract(B.multiply(C.add(D)))
My approach is to do it recursively. for example: A + B * C
1. convert( A + B * C )
2. A.add( convert (B * C) )
3. A.add(B.multiply(C))
Math Symbols that supports: + - * / % ( )
I was wondering if there is a better way to handle this.
Is there a name for this kind of issue is it? Compiler? (Sorry if it is not, I have never done any work with compiler.) Thanks in advance.