Ocean West Posted March 28, 2006 Posted March 28, 2006 Name & Parameters: [color:red][big] RPN ( expression ) [/big] Description: This CF will allow you to evaluate an expression with Rerverse Polish Notation. where entry detrmines order of operation, using a stack to push and pull from. RPN input would be written 10 25 2 * + 40 + Infix input would be written : ((25 * 2) + 10) + 40 For more info: http://en.wikipedia.org/wiki/Reverse_Polish_notation Sample Input: 10 25 2 * + 40 + Results: 100 Recursive: yes Formula: // RPN( expression ) or Reverse Polish Notation // by Stephen Dolenski Let ([ exp = Substitute( expression ; " " ; ¶) ; // pivot expression into a return sep list. exp_len = ValueCount ( exp ) // count entries. ]; //============================ If( $i > exp_len ; Let( $i = 1 ; $stack) ; If( Filter( GetValue(exp ; $i) ; "*+-/") ≠ $null ; // value is operator Let ([ $result = Evaluate(GetValue ($stack ; 1 ) & GetValue(exp ; $i) & GetValue ($stack ; 2 )) ; $stack = Substitute( $stack ; [GetValue ( $stack; 1 ) & "¶" & GetValue ( $stack; 2 ) & "¶" ; $result &¶] ; [GetValue ( $stack; 1 ) & "¶" & GetValue ( $stack; 2 ) ; $result]); $i = $i+1 ]; RPN( exp ) ) // end let ; // else append stack Let ([ $stack = Case( $i = 1; GetValue (exp ; 1 ) ; GetValue(exp ; $i) & ¶& $stack ); $i = $i+1 ]; RPN( exp ) ) // end let ) // end if ) // end if //============================ ) // close let Required Functions: Author(s): Ocean West Date: 03/28/06 Credits: Disclaimer: FM Forums does not endorse or warrantee these files are fit for any particular purpose. Do not post or distribute files without written approval from the copyright owner. All files are deemed public domain unless otherwise indictated. Please backup every file that you intend to modify. RPN.fp7.zip
Recommended Posts
This topic is 6813 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now