Скачать Simple Calculator Function with Brackets

06.02.1999
Скачать файл (2,49 Кб)

Function Parse (S : String; Arg : Real; Var Result : Real) : Byte;
(****************************************************)
(*                    Examples:                     *)
(* S = "4 * 60 + 10 * 9"         => Result = 330.0  *)
(* S = "1.5E2+2.3e-1"            => Result = 150.23 *)
(* S = "-(X-3)*(x+5)", Arg = 4.0 => Result = -9.0   *)
(* S = "9.0^0.5"                 => Result = 3.0    *)
(* S = "x%8", Arg = 15.0         => Result = 7      *)
(****************************************************)

(****************************************************)
(*                 Return values:                   *)
(* 0 - successfuly - no error                       *)
(* 1 - error in numeric format like "1e" or "2.e3"  *)
(* 2 - unknown symbol in expression                 *)
(* 3 - not balanced brakets i.e. "(x-1)*(x+2"       *)
(* 4 - positional error like in "4+x-" or ")2"      *)
(* 5 - expression is empty - nothing to compute     *)
(* 6 - math error such as division by zero etc.     *)
(****************************************************)