let eval_rpn tokens =
  let stack = Stack.create () in
  List.iter (fun tok ->
    if tok = "+" || tok = "-" || tok = "*" || tok = "/" then begin
      let b = Stack.pop stack in
      let a = Stack.pop stack in
      let r = if tok = "+" then a + b
              else if tok = "-" then a - b
              else if tok = "*" then a * b
              else a / b
      in
      Stack.push r stack
    end else
      Stack.push (int_of_string tok) stack
  ) tokens;
  Stack.pop stack

;;

eval_rpn ["3"; "4"; "+"; "2"; "*"; "5"; "-"]
