-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.wc
55 lines (45 loc) · 1.12 KB
/
Program.wc
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
$current_instruction = 0;
$pointer = 0;
$instructions_ran = 0;
@point = $pointer + 0.25;
@get = get($0, $current_instruction);
@forward = (
$open = 1;
$current_instruction += 1;
while($open > 0,
if($current_instruction >= len($0), throw("mismatched brackets, ] not found"));
if(@get == '[', $open += 1);
if(@get == ']', $open -= 1);
$current_instruction += 1;
);
$current_instruction -= 1;
);
@back = (
$open = 1;
$current_instruction -= 1;
while($open > 0,
if($current_instruction < 0, throw("mismatched brackets, [ not found"));
if(@get == '[', $open -= 1);
if(@get == ']', $open += 1);
$current_instruction -= 1;
);
$current_instruction += 1;
);
@bf = (
while($current_instruction < len($0),
switch(@get,
'>', $pointer += 1,
'<', $pointer -= 1,
'+', $@point += 1,
'-', $@point -= 1,
'.', $@point : $TXT,
',', ($0.5 ? $TXT; $@point = $1.5),
'[', if($@point == 0, @forward),
']', if($@point != 0, @back),
$instructions_ran -= 1
);
$current_instruction += 1;
$instructions_ran += 1;
);
$instructions_ran;
);