F#: 196 chars
Minimized code:
let rpn input=String.split[' ']input|>Seq.fold (fun xs x->match((["*",(*);"+",(+);"-",(-);"/",(/)]|>Map.of_list).TryFind x),xs with|Some f,x::y::rest->f x y::rest|None,xs->xs@[float x])[]|>List.hd
Readable code:
let rpn input =
String.split [' '] input
|> Seq.fold (fun xs x ->
let lookup = ["*", (*); "+", (+); "-", (-); "/" ,(/)] |> Map.of_list
match lookup.TryFind x, xs with
| Some f, x::y::rest -> f x y::rest
| None, xs -> xs @ [float x]) []
|> List.hd
Explanation: I have a lookup table which maps strings to functions. If we find a function f
in the lookup table, we replace the first two values on our eval queue -- which is really a stack -- with f(pop first two values off stack). If we don't find our function, we append the value to end of our queue. Finally, we return the first value from the top of our queue.
Guaranteed to be very inefficient, would probably get you fired from your job if implemented like this in practice.
Here's the function in fsi:
val rpn : string -> float
> rpn "1 2 +";;
val it : float = 3.0
> rpn "1 2 + 3 *";;
val it : float = 9.0
> rpn "0 1 2 3 + + - 2 6 * + 3 / 1 -";;
val it : float = 1.0
> rpn "3 2 / 2.0 +";;
val it : float = 3.5