REBOL [ author: 'chl date: 2003-01-13 ] eval-expr: func [expr /local e r] [ if number? expr/1 [ return expr/1 ] switch expr/1 [ "+" [r: 0 foreach e next expr [r: r + e] r] "/" [r: 0 foreach e next expr [r: r + (1 / e)] 1 / r] ] ] op-chars: charset "+/" num-chars: charset "1234567890" op: [ copy o op-chars ( either number? pick (last stack) 1 [ insert (last stack) o ] [ if not (o = pick (last stack) 1) [ make error! "wrong op" ] ] ) ] number: [copy n some num-chars (append (last stack) to-integer n)] arg: [number | "(" expr ")"] expr: [ (append/only stack copy []) arg any [op arg] ( append (pick stack (-1 + length? stack)) (eval-expr last stack) remove back tail stack ) ] eval: func [expr-str] [ stack: reduce [copy []] parse expr-str expr stack/1/1 ]