forked from fatiherikli/brainfuck-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·301 lines (291 loc) · 12.3 KB
/
index.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!DOCTYPE html>
<html>
<head>
<title>Brain Visualizer</title>
<link rel="stylesheet" href="css/screen.css" />
<script type="text/javascript" src="js/lib/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/lib/underscore-min.js"></script>
<script type="text/javascript" src="js/lib/backbone-min.js"></script>
<script type="text/javascript" src="js/interpreter.js"></script>
<script type="text/javascript" src="js/views.js"></script>
<script type="text/javascript" src="js/models.js"></script>
</head>
<body>
<header>
<p style="text-align:center;padding:2%;color:white;background:#ECB86F;">
Brain Online Visualizer does not perform any optimization on the interpreted code.</br>
If you want to run it faster, please visit the Brain Compiler project:
<a class="wlink" href="https://github.com/brain-labs/brain">https://github.com/brain-labs/brain</a>
</p>
</header>
<div id="interpreter">
<section class="machine">
<ul class="tape">
</ul>
<div class="pointer"><em></em></div>
</section>
<section class="editor">
<div class="actions">
<a class="button" href="#" id="run">Run</a>
<a class="button" href="#" id="first-step">Step</a>
<a class="button hidden" href="#" id="stop">Stop</a>
<a class="button hidden" href="#" id="step">Step</a>
<a class="button hidden" href="#" id="pause">Pause</a>
<a class="button hidden" href="#" id="continue">Continue</a>
<div id="delay-box">
<label for="delay">Delay</label>
<input id="delay" value="100" type="range" step="30" min="30" max="300"/>
</div>
<div id="input-box">
<label>Waiting for input</label>
<input type="text" id="input" maxlength="1"/>
</div>
</div>
<div id="preview"></div>
<textarea id="source">
++++++++++ make number 10 at cell 0
>+++*++ make number 32 at cell 1
>+*>+*>+*>+*>+*>+*> make number 32 from cell 2 to 7
<<<<<<%++*+ make number 65 at cell 2
>>>%<%+++*>+*+<------ make number 90 at cell 4 and 97 at cell 5
>>>%++++*------ make number 122 at cell 7
<<<----. print 'V'
>++++++++. print 'i'
>>-------. print 's'
<<. print 'i'
>>+. print 't'
<. print ' '
<<<<+. print 'B'
>>>>>--. print 'r'
<<--------. print 'a'
++++++++. print 'i'
+++++. print 'n'
<<<<<{>+++<}>----. print 'colon'
>>. print ' '
>>------. print 'h'
>>++. print 't'
. print 't'
----. print 'p'
+++.--- print 's'
<<<<<<. print 'colon'
>>>>>>>+*>+*<%++>/+ make number 57
<[>-----<-]>. print 'slash'
. print 'slash'
<<<<-. print 'g'
++. print 'i'
>>++++. print 't'
<<-. print 'h'
>>+. print 'u'
<<------. print 'b'
>>>>-.+ print 'dot'
<<<<+. print 'c'
>>------. print 'o'
--. print 'm'
>>. print 'slash'
<<<<-. print 'b'
>>+++++. print 'r'
<<-. print 'a'
++++++++. print 'i'
>>----. print 'n'
>>--.++ print 'dash'
<<--. print 'l'
<<--------. print 'a'
+. print 'b'
>>+++++++. print 's'
>>. print 'slash'
<<<<. print 'b'
>>-. print 'r'
<<-. print 'a'
++++++++. print 'i'
>>----. print 'n'</textarea>
<h3>Output</h3>
<p id="output"></p>
</section>
</div>
<section class="examples">
<h3>Examples</h3>
<h4 class="h4list">- Pow</h4>
<div style="height:155px;" class="source" id="source-pow">
++++++++++ make number 10 at cell 0
>+*** make 10 to its cube
# print out debug information
<a class="button" href="#" id="pow-btn">Try it!</a>
</div>
<h4 class="h4list">- If-Else</h4>
<div style="height:310px;" class="source" id="source-if-else">
+++ make the value 3 at cell 0
[ start infinite loop
? if cell 0 greater than 0 break
!
: else add 1
+
;
]
# print out debug information with value 3 at cell 0
<a class="button" href="#" id="if-else-btn">Try it!</a>
</div>
<h4 class="h4list">- Fibonacci</h4>
<div style="height:230px;" class="source" id="source-fibonacci">
+#>+# initialization
[
>+* copy the value from cell 1 to cell 2
<<{>>+<<} sum the value at the cell 0 with the value at the cell 2
>># move to cell 2 and print it out
]
<a class="button" href="#" id="fibonacci-btn">Try it!</a>
</div>
<h4 class="h4list">- Hell Box</h4>
<div style="height:280px;" class="source" id="source-hellbox">
[]><[][]><[][]><[][]><[][]><[][]><[][]><[][]><[][]><[][]><[]
[]>+>+>++>++<[>[->++++<<+++>]<<]>----.>->+.+++++++..+++.<+[]
[ This is hellbox, a 104 command Hello World ]
[ >+>+>++>++<[>[->++++<<+++>]<<]>----.>>+.+++++++..+++ ]
[ .>.<<<+++++++++++++++.>>.+++.------.--------.>+.>++. ]
[ -- Robert de Bath -- 2014 ]
[]>>.<<<+++++++++++++++.>>.+++.------.--------.>+.+>++.<<<[]
[]><[][]><[][]><[][]><[][]><[][]><[][]><[][]><[][]><[][]><[]
<a class="button" href="#" id="hellbox-btn">Try it!</a>
</div>
<h4 class="h4list">- Even or Odd</h4>
<div style="height:835px;" class="source" id="source-even-or-odd">
++ make number 2 at cell 0
>+++++ make the number to check if it is even or odd at cell 1
>++++++++++ make number 10 at cell 2
>+** make 10 square at cell 3
<[-] clear the cell 2
+* copy the number from cell 1 to cell 2
>* multiply the numbers at cell 3 and 2
<<% calc of the number at cell 1 mod 2
>>$ print out the value of the number at cell 3
>++++++++++
>+++*++. make number 32 at cell 5 and print it out ' '
<{>>+<<} copy the number 10 to the cell 6
>>>+**+++++. print out 'i'
++++++++++. print out 's'
<<. print out ' '
<<<<
? check if the number at cell 1 is odd
>>>>>>----. print out 'o'
-----------. print out 'd'
. print out 'd'
: otherwise it is even
>>>>>>>+* copy the number
<<++++ make the number 14 at cell 6
{>>-<<}>>. subtract it from 115 and print out 'e'
<+++. print out 'v'
>. print out 'e'
<--------. print out 'n'
;
<a class="button" href="#" id="even-or-odd-btn">Try it!</a>
</div>
</section>
<section id="info">
<h3>Quick Reference</h3>
<table>
<tbody>
<tr>
<td style="text-align:center"><code>></code></td>
<td>increment the data pointer (to point to the next cell to the right).</td>
</tr>
<tr>
<td style="text-align:center"><code><</code></td>
<td>decrement the data pointer (to point to the next cell to the left).</td>
</tr>
<tr>
<td style="text-align:center"><code>+</code></td>
<td>increment (increase by one) the byte at the data pointer.</td>
</tr>
<tr>
<td style="text-align:center"><code>-</code></td>
<td>decrement (decrease by one) the byte at the data pointer.</td>
</tr>
<tr>
<td style="text-align:center"><code>*</code></td>
<td>multiply <code>*ptr</code> with <code>*(ptr-1)</code>. Store result in <code>*ptr</code> <code>// format: 2 3 *</code></td>
</tr>
<tr>
<td style="text-align:center"><code>/</code></td>
<td>divide <code>*ptr</code> with <code>*(ptr-1)</code>. Store result in <code>*ptr</code> <code>// format: 2 3 /</code></td>
</tr>
<tr>
<td style="text-align:center"><code>%</code></td>
<td>divide <code>*ptr</code> with <code>*(ptr-1)</code>. Store the remainder in <code>*ptr</code> <code>// format: 2 3 %</code></td>
</tr>
<tr>
<td style="text-align:center"><code>.</code></td>
<td>output the byte at the data pointer.</td>
</tr>
<tr>
<td style="text-align:center"><code>$</code></td>
<td>prints out the value at the data pointer divided by 100.</td>
</tr>
<tr>
<td style="text-align:center"><code>#</code></td>
<td>prints out the current debug information.</td>
</tr>
<tr>
<td style="text-align:center"><code>,</code></td>
<td>accept one byte of input, storing its value in the byte at the data pointer.</td>
</tr>
<tr>
<td style="text-align:center"><code>[</code></td>
<td><code>a.k.a (while loop)</code>.If the value at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching <code>]</code> command.</td>
</tr>
<tr>
<td style="text-align:center"><code>]</code></td>
<td>jump to its correspondent <code>[</code> .</td>
</tr>
<tr>
<td style="text-align:center"><code>{</code></td>
<td><code>a.k.a (for loop)</code>. Iterates <code>'value-at-the-data-pointer' times</code> and needs to be closed with a matching <code>}</code> command. It does not decrease the value at the data pointer. It will only work for positive values greather than zero.</td>
</tr>
<tr>
<td style="text-align:center"><code>}</code></td>
<td>jump to its correspondent <code>{</code> .</td>
</tr>
<tr>
<td style="text-align:center"><code>!</code></td>
<td><code>a.k.a break</code>. jumps to the end of a loop (<code>[ ]</code> or <code>{ }</code>) .</td>
</tr>
<tr>
<td style="text-align:center"><code>?</code></td>
<td><code>a.k.a if</code>. if the value at the data pointer is zero, jumps to the block with <code>:</code> or <code>;</code> and executes the commands one by one up to its correlative <code>;</code>, otherwise, it executes the code until it finds a <code>:</code> or <code>;</code>.</td>
</tr>
<tr>
<td style="text-align:center"><code>:</code></td>
<td><code>a.k.a else</code>. it works as an <code>otherwise</code> for <code>?</code>.</td>
</tr>
<tr>
<td style="text-align:center"><code>;</code></td>
<td>ends a <code>?</code> or <code>:</code> statement.</td>
</tr>
</tbody></table>
<p style="color: #505050;">More information on: <a href="https://github.com/brain-labs/brain">https://github.com/brain-labs/brain</a></p>
</section>
<script type="text/javascript">
$(function () {
var cells = new Cells(_.range(17).map(function (index) {
return { index: index };
}));
var tape = new Tape({
cells: cells,
windowStart: 0,
windowSize: cells.length
});
var pointer = new Pointer();
new InterpreterView({
editor: $("#source"),
tape: tape,
pointer: pointer
}).render();
});
</script>
<iframe src="https://ghbtns.com/github-btn.html?user=brain-labs&repo=brain-visualizer&type=star&count=true&size=large"
style="position: absolute; top: 16px; right: 0; border: 0;"
frameborder="0"
scrolling="0"
width="160px"
height="30px">
</iframe>
</body>
</html>