-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShow.hs
48 lines (38 loc) · 1.53 KB
/
Show.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Show where
import Lambda
import Data.List (intercalate)
import Krivine
removeTags1 :: String -> Bool -> String
removeTags1 [] _ = []
removeTags1 (';':s) _ = removeTags1 s True
removeTags1 (' ':s) _ = ' ' : (removeTags1 s False)
removeTags1 ('.':s) _ = '.' : (removeTags1 s False)
removeTags1 (a:s) b
| elem a ['0'..'9'] && b = removeTags1 s b
| otherwise = a : (removeTags1 s b)
removeTags :: String -> String
removeTags s = removeTags1 s False
removeCommaR :: String -> String
removeCommaR (' ':',':xs) = xs
removeCommaR (x:xs) = x : removeComma xs
removeCommaR [] = []
removeComma :: String -> String
removeComma = (reverse . removeCommaR . reverse)
t2str :: Term -> String
t2str (Var a) = a
t2str (Lambda x e) = "λ"++(t2str x)++"."++(t2str e)
t2str (App a b) = "("++(t2str a)++" "++(t2str b)++")"
t2str (Cont c) = removeComma $ "continuation " ++ "[" ++ (concat $ (map (\x -> (t2str x ++ ", ")) c)) ++ "]"
t2str (Instr n) = "instr n°" ++ show n
s2str :: [Term] -> String -> String
s2str s i = intercalate i (map t2str s)
showKrivine1 :: Either String [KMachine] -> String
showKrivine1 (Left s) = s++"\n"
showKrivine1 (Right []) = ""
showKrivine1 (Right [((t@(Var x), s@(a:as), n),c)]) =
(t2str t)++" *** "++ "[" ++ (s2str s ", ")++"]\nnot evaluated.\n"
showKrivine1 (Right (((t,s,n),c):kr)) =
(t2str t)++" *** " ++ "["++ (s2str s ", ")++"]\n" ++ (showKrivine1 (Right kr))
showKrivine :: Either String [KMachine] -> String
showKrivine s@(Left _) = showKrivine1 s
showKrivine a = removeTags $ showKrivine1 a