For something like this, where we know that X is:
In converting an algebraic representation to RPN, the order of the operands will be unchanged. You wind up either pushing an operand to the stack or applying an operator the previous 2 things on the stack. (well there is the case of an unary operator, 4+ (-8), etc.)(2(4*x-8)+3*x)-(11*x+1-9) (2*(4*x-8)+3*x)-(11*x+1-9)
In Perl, you can compile and execute an expression "on the fly" using "eval". No conversion by you to RPN is necessary. Any legal Perl statement can be executed via eval. There are ways to intercept and report errors in the eval'ed expression (divide by zero), etc.(2*(4*x-8)): push 2 push 4 push x op *; (4*x) is now last on stack push 8 op -; now 4*x-8 is last on stack op * ; now result is last thing on stack
An expression like this:
where you want "x", is not so easy. I am flummoxed as to why you think that RPN could help here?2(4x-8)+3x=11x+1-9
In reply to Re: Reverse Polish Notation Question
by Marshall
in thread RPN Question
by nat47
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |