Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
let reduce op = function
|
||||
| b::a::r -> (op a b)::r
|
||||
| _ -> failwith "invalid expression"
|
||||
|
||||
let interprete s = function
|
||||
| "+" -> "add", reduce ( + ) s
|
||||
| "-" -> "subtr", reduce ( - ) s
|
||||
| "*" -> "mult", reduce ( * ) s
|
||||
| "/" -> "divide", reduce ( / ) s
|
||||
| "^" -> "exp", reduce ( ** ) s
|
||||
| str -> "push", (System.Double.Parse str) :: s
|
||||
|
||||
let interp_and_show s inp =
|
||||
let op,s'' = interprete s inp
|
||||
printf "%5s%8s " inp op
|
||||
List.iter (printf " %-6.3F") (List.rev s'')
|
||||
printf "\n";
|
||||
s''
|
||||
|
||||
let eval str =
|
||||
printfn "Token Action Stack";
|
||||
let ss = str.ToString().Split() |> Array.toList
|
||||
List.fold interp_and_show [] ss
|
||||
Loading…
Add table
Add a link
Reference in a new issue