I'm trying to figure out ways to parse an expression that uses all binary operators. Each operator is surrounded by exactly one set of parenthesis, such that:
5x^2 + 3x + 2
would be
((5*(x^2))+((3*x)+2))
and is taken as an args[] argument (more importantly, it is given as a String).
I'm recursively breaking this down, where each recursion breaks down the left part of the top binary operator and call the recursion with that expression as an argument, then again with the right. The base case is when the expression being passed contains no operators.
The problem I'm having is appropriately parsing the left side from the right side. I am trying to develop a way based upon a Scanner that counts the number of parenthesis counted overall, but can't seem to determine a final solution. Anyone have an idea how to parse this correctly in order to pass it as an expression to the recursive method.
P.s. - Language I am using is Java
EDIT::::
I am using this parser as a part of a GUI graph plotter, so I would set the variable (x) based on what value of the x-axis I am currently looking to generate on the GUI graph. So, the expression being parsed within the program (as shown in the second code tag above) would be broken down and operated on to produce a final "y" value that would correlate to the position on the window where a small dot would be used to represent that point on the line of the graph.
Maybe this will better explain how I am trying to use this.