-
Notifications
You must be signed in to change notification settings - Fork 0
/
bf_self_interpreter.bf
60 lines (59 loc) · 5.4 KB
/
bf_self_interpreter.bf
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
[ Self-Interpreter in brainf*** by VilgotanL
2021-06-14
Originally written in VBF (bf with better control-flow), transpiled to bf and minified.
Run this with the program as the input, optionally also use ! and then the program input
Example: "program!input" or just "program"
Assumes zero or no-change on eof, interprets with zero on eof.
Errors when the pointer is out of bounds, also errors on unbalanced [] when they dont act as no-ops.
Supports infinite memory and infinite [] depth, requires 8-bit wrapping brainf**k.
]
>>->>>>>>,---------------------------------[+++++++++++++++++++++++++++++++++>>>>>>>>>>,[->+>>+<<<]>
>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<+++++++++++++++++++++++++++++++++>>>]<<<----------------------------
-----][-]>>>>+[-<<<<<<<<<<+]->>>>>>>>+<<<<+<<<<[>>>>>>>>-[+>>>>>>>>>>-]+<<--------------------------
-----------------[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<<<<<<<<+]->>>>-[+>>>>>>>>>>
-]+<<+<<+[-<<<<<<<<<<+]->>>>>>>>-[+>>>>>>>>>>-]+>]<<<--[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<
<<<<<+[-<<<<<<<<<<+]->>>>-[+>>>>>>>>>>-]+<<-<<+[-<<<<<<<<<<+]->>>>>>>>-[+>>>>>>>>>>-]+>]<<<-[->+>>+<
<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<<<<<<<<+]->>>>-[+>>>>>>>>>>-]+<<.<<+[-<<<<<<<<<<+]->
>>>>>>>-[+>>>>>>>>>>-]+>]<<<++[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<<<<<<<<+]->>>>
-[+>>>>>>>>>>-]+<<[-],<<+[-<<<<<<<<<<+]->>>>>>>>-[+>>>>>>>>>>-]+>]<<<------------------[->+>>+<<<]>>
>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<<<<<<<<+]->>>>-[+>>>>>>>>>>-]>>>>>>>>>>+<<<<<<<<<<<<<<+[-
<<<<<<<<<<+]->>>>>>>>-[+>>>>>>>>>>-]+>]<<<++[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<
<<<<<<<+]->>>>-[+>>>>>>>>>>-]+<<<<+[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<-<<+>>>>>>>>>>>>+++++
+++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++..-------------------
-----.--------------------------.++++++++++++++++++++++++++++++++++++++++++++++++.++++.--.[-]+++++++
+++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++.++++++.-.[-]++++++++++++++
++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++.---------.[-]++++++++++++++++++++
++++++++++++.++++++++++++++++++++++++++++++++++.+++++++++++++.++++++.-------.----------.++++++++++++
+++.[-]<<<<<<<<<<+>>>]<<<[->+>>+<<<]>[-<+>]>>[[-]<<<->>>>-<<<<<<<<<<+>>>>>>+>>>]<<<[-<<<<<<<<<<+]->>
>>>>>>-[+>>>>>>>>>>-]+>]<<<-------------------------------[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<
<<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<<<+
[-<<<<<<<<<<+]->>>>-[+>>>>>>>>>>-]+<<[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<<+[-<<<<<<<<<<+]->
>>>>>>>>>+[<<-[+>>>>>>>>>>-]>>>>>>>>>>+<<-----------------------------------------------------------
--------------------------------[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<<<<<<<<+]->>
>>>>>>>>[>>>>>>>>>>]+<<<<<<<<<<+[-<<<<<<<<<<+]->>>>>>>>-[+>>>>>>>>>>-]+>]<<<--[->+>>+<<<]>>>[-<<<+>>
>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<<<<<<<<+]->>>>>>>>>>[>>>>>>>>>>]<<<<<<<<<<-<<<<<<<<<<+[-<<<<<<<<<<
+]->>>>>>>>-[+>>>>>>>>>>-]+>]<<<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[->[-]++++++++++.+++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++.+++++++++++++..------------------------.-------------------
-------.+++++++++++++++++++++++++++++++++++++++++++++.----.++++++++++..----------.+++++.-------.[-]+
+++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<<
<<<<<<<+[-<<<<<<<<<<+]-<<[-]+>>>>>>>>>>>>[-]<<-[+>>>>>>>>>>-]+>]<<<<<<<<<+[-<<<<<<<<<<+]->>>>>>>>>>]
<<<<<<-[+>>>>>>>>>>-]+>]<<<<<+[-<<<<<<<<<<+]->>>>>>>>-[+>>>>>>>>>>-]+<<-----------------------------
-------------------------------------------------------------->>>]<<<--[->+>>+<<<]>>>[-<<<+>>>]+<<[[
-]>>-<<]>>[-<<<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++<<<<<<+[-<<<<<<<<<<+]->>>>-[+>>>>>>>>>>-]+<<[->+>>+<<<]>[-<+>]>>[[-]<<<<<+[-<<<<<<<<<<+]->>>
>>>>>>>+[<<-[+>>>>>>>>>>-]<<<<<<<<<<+<<-------------------------------------------------------------
--------------------------------[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<<<<<<<<+]->>
>>>>>>>>[>>>>>>>>>>]+<<<<<<<<<<+[-<<<<<<<<<<+]->>>>>>>>-[+>>>>>>>>>>-]+>]<<<++[->+>>+<<<]>>>[-<<<+>>
>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<<<<<<<<+]->>>>>>>>>>[>>>>>>>>>>]<<<<<<<<<<-<<<<<<<<<<+[-<<<<<<<<<<
+]->>>>>>>>-[+>>>>>>>>>>-]+>]<<<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++<<<<<<+[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<->>>>>>>>>>[-]++++++++++.+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++..------------------------.-
-------------------------.+++++++++++++++++++++++++++++++++++++++++++++.----.++++++++++..----------.
+++++.-------.[-]++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++.[-]<<<<<<<<<<+[-<<<<<<<<<<+]-<<[-]+>>>>>>>>>>>>[-]<<-[+>>>>>>>>>>-]+<<<<<<<<+>>>]<<<[-<<<<
<<<<<<+]->>>>>>>>>>]<<<<<<-[+>>>>>>>>>>-]+>]<<<<<+[-<<<<<<<<<<+]->>>>>>>>-[+>>>>>>>>>>-]+<<---------
------------------------------------------------------------------------------------>>>]<<<+++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>->>>>>>>>>>+<<
[->+>>+<<<]>>>[-<<<+>>>]+<<[[-]>>-<<]>>[-<<<<<<<<<+[-<<<<<<<<<<+]-<<[-]+>>>>>>>>>>-[+>>>>>>>>>>-]+>]
<<<<<<<<<+[-<<<<<<<<<<+]-<<[->+>>+<<<]>[-<+>]>>[[-]<+>]<]