-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
61 lines (42 loc) · 1.36 KB
/
Main.hs
File metadata and controls
61 lines (42 loc) · 1.36 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
module Main where
import Language
import Pretty
import Parser
import Gm.Compiler
import Gm.Utils
import Gm.Evaluator
testProgram = "test arg1 arg2 = arg1 arg2"
testProgram2 = "f = 3 ;\n\
\g x y = let z = x in z ;\n\
\h x = case (let y = x in y) of\n\
\{ <1> -> 2 \n\
\; <2> -> 5 \n\
\}"
testProgram3 = "main = S K K 42"
testProgram4 = "\
\pair x y f = f x y ; \n\
\fst p = p K ; \n\
\snd p = p K1 ; \n\
\f x y = let rec \n\
\ a = pair x b ; \n\
\ b = pair y a \n\
\ in \n\
\ fst (snd (snd (snd a))) ; \n\
\main = f 3 42"
testProgram5 = "main = let rec a = 101 in 42"
testProgram6 = "f x = x ; main = let a = 42 in f a"
testProgram7 = "id x = x ; main = twice twice twice id 42"
testProgram8 = "main = negate -42"
testProgram9 = "main = twice negate 42"
testProgram10 = "main = mul 7 6"
testProgram11 = "main = plus (negate 10) 52"
testProgram12 = "main = minus 46 (div 8 2)"
testProgram13 = "fac n = if (eq n 0) 1 (mul n (fac (minus n 1))) ; main = plus (fac 4) 18"
-- parse and pretty-print
papp = putStrLn . either show (show . pretty) . parseCore
-- parse and eval
pae = eval . make . parseCore
where make = either (error . show) compile
trace = putStrLn . showResults . pae
--run = putStrLn . showResult . pae
main = papp testProgram