tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,21 @@
open string console list format read
eval str = writen "Input\tOperation\tStack after" $
eval' (split " " str) []
where eval' [] (s::_) = printfn "Result: {0}" s
eval' (x::xs) sta | "+"? = eval' xs <| op (+)
| "-"? = eval' xs <| op (-)
| "^"? = eval' xs <| op (**)
| "/"? = eval' xs <| op (/)
| "*"? = eval' xs <| op (*)
| else = eval' xs <| conv x
where c? = x == c
op (^) = out "Operate" st' $ st'
where st' = (head ss ^ s) :: tail ss
conv x = out "Push" st' $ st'
where st' = readStr x :: sta
(s,ss) | sta == [] = ((),[])
| else = (head sta,tail sta)
out op st' = printfn "{0}\t{1}\t\t{2}" x op st'
eval "3 4 2 * 1 5 - 2 3 ^ ^ / +"