Question : Recommend method for parsing string

I have an application where I need to parse a particular math string and add in some parenthesis to ensure proper order of precedence for the operators.  

Input String:    1/-(3+4)

The parsing should recognize the "-" character and produce the following

Parsed String: 1/(-1*(3+4))


Can someone recommend the best way to parse such a string?  Should I look through each character and look for the "-" case and then keep track of the various parenthesis for opens and closed parenths.

Is this something that can be done via a regexp?

The length and number of the parenthesis is defined by the user.

The parsing is done in javascript

Note: I cannot use the regular javascript math parser on this because the program is using a custom parser to support things like complex numbers and user defined functions (which would crash the javascript math parser)

Answer : Recommend method for parsing string

I remeber the problem, I had to solve this in pascal about 20 years ago, in college.  What if while you were parsing the statement and you had a - as an operator and you hit a ( before you hit an operand, could you then just push a -1 to the stack and then change the operator to * ?  that would do the same thing with out changing the stament.
Random Solutions  
 
programming4us programming4us