Given an expression in the form of a string, solve for x. The highest power of x in the expression will be equal to 1. Operators allowed are +, * and -. These are all binary operators. So, 2x would be written as 2*x. Every operator will be followed by a single term or a constant.
For example, consider the following equation:
2*x+5-(4*x-7+(4-2))=10*x-9
This is a perfectly valid equation. Expressions of the form 1*2*3 are invalid, but 1*(2*3) is valid.
Given such an equation, we need to find a solution to x. If the equation is invalid, the program should display an error message.
Can someone give any idea about how this problem can be solved? The only thing that is coming to my mind right now is Lexical Analysis and Parsing using Context Free Grammars. But I have a feeling there is a much easier solution than that. Can someone throw some light on it ?