forked from Kapcash/Compilation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_while.wh
53 lines (41 loc) · 1.35 KB
/
tests_while.wh
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
function okSimpliest: read A,B%nop%write R
function okMultipleCommands: read A,B%A:=a; B:=B% write R
function okIfThen: read A,B%if (nil) then nop fi%write ZYX
function okIfThenElse: read A1%if (nil) then nop else nop fi%write Z
function okWhile: read Var1,Var2%while ! Var1=?Var2 do Ret:=a1 od%write Var1,Ret
function okForEach: read Var1%foreach Var1 in (list) l1 do nop od%write Ret
function okFor: read I,Var%for (Bool) && ! stop=?true do nop od%write Ret
function okDoubleFor: read A,B%for (A) do for (B) do nop od od%write Ret
function okComplete: read A%B:=nil while A do if ! B=?A then B:=(cons (hd A) B); R:=a else R:=b fi od%write R
function errNoBody: read A%%write A
function errVariable: read noUpperCase%nop% write Ret
function errMultipleCommands: read A,B%A:=a B:=B% write R
function errDoubleFor: read A,B%for (A) do for (B) od do nop od%write Ret
function errIfThen: read A1%if (nil) fi%write Z
function aB: read ABZ%for condition do nop od%write Ab
function tEST: read ABZ%if (nil) then nop fi%write ZBA
function xyz: read AB,JK%AB:=JK%write JK
function mod:
read A,B
%K:=0;
I:=A-K*B;
while (I >= B) do
Result:= A - K*B;
K:=K+1
I:=A-K*B;
od
%write Result
function factorial:
read N
%P:=1;
K:=1;
while K<=N do
P:=P*K;
od
%write P
function aaa:
read A,B,C%X,Y,Z:=A,B,C
%write Ba
function testForeach:
read ZZZ%foreach a in b do ZZZ:=ZZZ*B; od
%write ZZZ