hi, currently i am doing a program on a calculator parser, i have successfully done the easy parts with + and - and is able to convert it from infix to postfix , however when converting from multiple digits there would be a problem, and the resulting postfix would be wrong as it reads 10 as 1 and 0 and not as 10
with this constructor for the above calcParser calc = new calcParser("1+3+4");
the output would be
however with ("10+3+4") output would be
which is wrong.
I'd preserve spaces as well, or add them where needed. And why are you always popping in between? If I try to convert "+ - 10 2 3 + 4 5" (with brackets "+ (- 10 2 3) (+ 4 5)") it gives me "+ 10 2 3 - 4 5 +" where I expected the first + at the end. I think you should only pop an operator if you encounter an operator and the previous was a digit. Never mind. That's prefix, not infix.
Here's your code slightly modified. The only differences are the added spaces and the combination of the equal if and else blocks.
10-2-3+4+5 now leads to 10 2 - 3 - 4 + 5 +, 1+3+4 to 1 3 + 4 + and 10+3+4 to 10 3 + 4 +.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: parsing multiple digits and converting from infix to postfix