open List let _ = while true do match fold_left (fun s w -> let f op = match s with | h1 :: h2 :: t -> op h2 h1 :: t | _ -> failwith "Stack underflow" in match w with | "+" -> f ( +. ) | "-" -> f ( -. ) | "*" -> f ( *. ) | "/" -> f ( /. ) | _ -> (float_of_string w) :: s) [] (Str.split (Str.regexp "[ \t]+") (read_line ())) with | h :: [] -> print_endline (string_of_float h) | _ -> failwith "Malformed expression" done