Here is a parser (use * for multiplication and ^ for exponentiation):
Infix precedence is:
- Parenthesis ()
- Exponentiation ^ (Left to Right)
- Multiplication *, Division / (Left to Right)
- Addition +, Subtraction - (Left to Right)
Use Please Excuse My Dear Aunt Sally to help remember basic precedence!
Some suggestions:
If the parser does not work then the equation is probably not formed well.
Check the equation by putting it in infix notation, then dink
with the pre or postfix version.
Also note that only a single character operand works at this time (upper or lowercase)
Additional Exercises:
Try modifying the Java source to handle exponentiation the mathematical
way, that is right to left. The modification is not that difficult! Good luck!
Caution:
The postfix parser handles precedence of exponentiation from left to right, while the prefix parser handles it from left to right.
Java Source code for the parser