git @ Cat's Eye Technologies Quylthulg / 7bab2bc
Output terms in smth closer to Quylthulg's own syntax. Chris Pressey 1 year, 4 months ago
4 changed file(s) with 61 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
33
44 if command -v ghc >/dev/null 2>&1; then
55 echo "building $PROG.exe with ghc"
6 (cd src && ghc --make Main.hs -o ../bin/$PROG.exe)
6 (cd src && ghc --make Main.hs -o ../bin/$PROG.exe) || exit 1
77 else
88 echo "ghc not found, not building $PROG.exe"
99 fi
1010
1111 if command -v hastec >/dev/null 2>&1; then
1212 echo "building $PROG.js with hastec"
13 (cd src && hastec --make HasteMain.hs -o ../demo/$PROG.js)
13 (cd src && hastec --make HasteMain.hs -o ../demo/$PROG.js) || exit 1
1414 else
1515 echo "hastec not found, not building $PROG.js"
1616 fi
00 #!/bin/sh
11
2 rm -f src/*.hi src/*.o src/*.jsmod
2 rm -f src/*.hi src/*.o src/*.jsmod bin/*.exe
9393 followSplit lenv (follow lenv first)
9494 else
9595 (follow lenv first, follow lenv rest)
96
97 formatTerm (Int i) = show i
98 formatTerm (Str s) = "$" ++ s ++ "$" -- not quite (ignores quoting), but close enough
99 formatTerm (Cons h t) = "[" ++ (formatTerm h) ++ formatTail t
100 formatTerm Null = "null"
101 formatTerm (Label s t) = ":" ++ s ++ ":" ++ (formatTerm t)
102 formatTerm (Goto s) = "goto " ++ (formatTerm (Str s))
103 formatTerm Abort = "abort"
104
105 formatTail Null = "]"
106 formatTail (Cons h t) = "," ++ (formatTerm h) ++ formatTail t
107 formatTail x = "|" ++ formatTerm x ++ "]"
96108
97109 --
98110 -- Terms support a number of operations which require the "meaning" of the
608620 in
609621 result
610622
611 showRun = show . run
623 showRun = formatTerm . run
612624
613625 mrun :: String -> IO Term
614626
618630 lenv <- return (collectExprLabels expr)
619631 env <- return (initialEnv expansions)
620632 result <- mInterpret env lenv expr
621 print result
633 putStr (formatTerm result)
622634 return result
1010 --------------------
1111
1212 | 5
13 = Int 5
13 = 5
1414
1515 | +6+9+
16 = Int 15
16 = 15
1717
1818 | +1+*7*-8-1-*+
19 = Int 50
19 = 50
2020
2121 String expressions.
2222 -------------------
2323
2424 | &~$Shoes are $&&~~&~$4.99 a pair$&&
25 = Str "Shoes are $4.99 a pair"
25 = $Shoes are $4.99 a pair$
2626
2727 List expressions.
2828 -----------------
2929
3030 | [1,2,3]
31 = Cons (Int 1) (Cons (Int 2) (Cons (Int 3) Null))
31 = [1,2,3]
3232
3333 | [1,2|3]
34 = Cons (Int 1) (Cons (Int 2) (Int 3))
34 = [1,2|3]
3535
3636 | <[1,2|3]<abort<
37 = Int 1
37 = 1
3838
3939 | <1<abort<
40 = Abort
40 = abort
4141
4242 | >[1,2|3]>abort>
43 = Cons (Int 2) (Int 3)
43 = [2|3]
4444
4545 | >1>null>
46 = Null
46 = null
4747
4848 | <,1,2,<null<
49 = Int 1
49 = 1
5050
5151 | >,1,2,>null>
52 = Int 2
52 = 2
5353
5454 | ,1,,2,3,,
55 = Cons (Int 1) (Cons (Int 2) (Int 3))
55 = [1,2|3]
5656
5757 | ;[1,2];[3];
58 = Cons (Int 1) (Cons (Int 2) (Cons (Int 3) Null))
58 = [1,2,3]
5959
6060 | ;[1,2];3;
61 = Cons (Int 1) (Cons (Int 2) (Int 3))
61 = [1,2|3]
6262
6363 | ;null;null;
64 = Null
64 = null
6565
6666 | ;[1];null;
67 = Cons (Int 1) Null
67 = [1]
6868
6969 | ;null;[1];
70 = Cons (Int 1) Null
70 = [1]
7171
7272 Labels and gotos.
7373 -----------------
7474
7575 | :A:goto$A$
76 = Label "A" (Goto "A")
76 = :A:goto $A$
7777
7878 Foreach expressions.
7979 --------------------
8080
8181 | foreach $n$=[7,2,3] with $a$=0 be +$a$+$n$+ else be abort
82 = Int 12
82 = 12
8383
8484 | foreach $n$=null with $a$=0 be +$a$+$n$+ else be abort
85 = Abort
85 = abort
8686
8787 | foreach $n$=[1,2,3] with $a$=null be ,$n$,$a$, else be null
88 = Cons (Int 3) (Cons (Int 2) (Cons (Int 1) Null))
88 = [3,2,1]
8989
9090 This is how boolean expressions can be built with `foreach`es.
9191 We take `null` to mean **false** and `[1]` to mean **true**.
9393 Boolean NOT.
9494
9595 | foreach $n$=null with $a$=null be null else be [1]
96 = Cons (Int 1) Null
96 = [1]
9797
9898 | foreach $n$=[1] with $a$=null be null else be [1]
99 = Null
99 = null
100100
101101 Boolean OR.
102102
103103 | foreach $n$=;[1];[1]; with $a$=[1] be $a$ else be null
104 = Cons (Int 1) Null
104 = [1]
105105
106106 | foreach $n$=;null;[1]; with $a$=[1] be $a$ else be null
107 = Cons (Int 1) Null
107 = [1]
108108
109109 | foreach $n$=;[1];null; with $a$=[1] be $a$ else be null
110 = Cons (Int 1) Null
110 = [1]
111111
112112 | foreach $n$=;null;null; with $a$=[1] be $a$ else be null
113 = Null
113 = null
114114
115115 Boolean AND.
116116
118118 | foreach $m$=$a$ with $b$=null be [1]
119119 | else be null
120120 | else be null
121 = Cons (Int 1) Null
121 = [1]
122122
123123 | foreach $n$=null with $a$=[1] be
124124 | foreach $m$=$a$ with $b$=null be [1]
125125 | else be null
126126 | else be null
127 = Null
127 = null
128128
129129 | foreach $n$=[1] with $a$=null be
130130 | foreach $m$=$a$ with $b$=null be [1]
131131 | else be null
132132 | else be null
133 = Null
133 = null
134134
135135 | foreach $n$=null with $a$=null be
136136 | foreach $m$=$a$ with $b$=null be [1]
137137 | else be null
138138 | else be null
139 = Null
139 = null
140140
141141 Some list-processing-type things that you often see in functional
142142 programming.
148148 | ,$x$,$a$,
149149 | else be
150150 | null
151 = Cons (Int 80) (Cons (Int 40) (Cons (Int 20) (Cons (Int 10) Null)))
151 = [80,40,20,10]
152152
153153 Find the length and the sum of a list of integers.
154154
157157 | ,+<$a$<0<+1+,+>$a$>0>+$x$+,
158158 | else be
159159 | null
160 = Cons (Int 3) (Int 70)
160 = [3|70]
161161
162162 Take the first 3 elements from a list (in reverse order.)
163163
170170 | abort
171171 | else be
172172 | null
173 = Cons (Cons (Int 40) (Cons (Int 20) (Cons (Int 10) Null))) (Cons (Int 1) Null)
173 = [[40,20,10],1]
174174
175175 Take the first 5 elements from a cyclic list.
176176
183183 | abort
184184 | else be
185185 | null
186 = Cons (Cons (Int 10) (Cons (Int 20) (Cons (Int 10) (Cons (Int 20) (Cons (Int 10) Null))))) (Cons (Int 1) Null)
186 = [[10,20,10,20,10],1]
187187
188188 Macros.
189189 -------
190190
191191 | {*[Five][5]}{Five}
192 = Int 5
192 = 5
193193
194194 | {*[(A][1]}+{(A}+4+
195 = Int 5
195 = 5
196196
197197 | {*[SQR][*{X}*{X}*]}{*[X][5]}{SQR}
198 = Int 25
198 = 25
199199
200200 | {*[}][This is my comment!]}~${}}$
201 = Str "This is my comment!"
201 = $This is my comment!$
202202
203203 | {*[Dave][3]}{*[Emily][4]}$Number of Macros Defined$
204 = Int 2
204 = 2
205205
206206 | &~${$&~$*[S][T]}$&
207 = Str "{*[S][T]}"
207 = ${*[S][T]}$
208208
209209 | &~${$&~$S}$&
210 = Str "{S}"
210 = ${S}$
211211
212212 | %&~${$&~$*[S][T]}$&%&~${$&~$S}$&%
213 = Str "T"
213 = $T$