diff options
author | Case Duckworth | 2022-07-06 22:00:30 -0500 |
---|---|---|
committer | Case Duckworth | 2022-07-06 22:00:30 -0500 |
commit | 3c6ce827a002c54deb88e40cbddddb03866e695b (patch) | |
tree | f9286a57c2c6821b718efb682ddbca453411c17e /examples | |
parent | Probably version ... whatever the next higher one is (diff) | |
download | trainfuck-3c6ce827a002c54deb88e40cbddddb03866e695b.tar.gz trainfuck-3c6ce827a002c54deb88e40cbddddb03866e695b.zip |
Big update
Diffstat (limited to 'examples')
-rw-r--r-- | examples/add2.tf | 500 | ||||
-rw-r--r-- | examples/hello-world.bf | 55 | ||||
-rw-r--r-- | examples/hello-world.tf | 388 | ||||
-rw-r--r-- | examples/printchar.bf | 5 | ||||
-rw-r--r-- | examples/printchar.tf | 10 | ||||
-rw-r--r-- | examples/rot13.tf | 215 |
6 files changed, 1145 insertions, 28 deletions
diff --git a/examples/add2.tf b/examples/add2.tf new file mode 100644 index 0000000..3c1529b --- /dev/null +++ b/examples/add2.tf | |||
@@ -0,0 +1,500 @@ | |||
1 | Add two values | ||
2 | from https://en.wikipedia.org/wiki/Brainfuck#Adding_two_values | ||
3 | |||
4 | |||
5 | |||
6 | |||
7 | ALL ABOARD | ||
8 | chug chug | ||
9 | END OF THE LINE | ||
10 | Cell c0 = 2 | ||
11 | |||
12 | ALL ABOARD | ||
13 | choo | ||
14 | |||
15 | END OF THE LINE | ||
16 | |||
17 | ALL ABOARD | ||
18 | chug chug chug chug chug | ||
19 | END OF THE LINE | ||
20 | Cell c1 = 5 | ||
21 | |||
22 | |||
23 | ALL ABOARD | ||
24 | tickets please | ||
25 | END OF THE LINE | ||
26 | Start your loops with your cell pointer on the loop counter (c1 in our case) | ||
27 | |||
28 | ALL ABOARD | ||
29 | choo choo | ||
30 | |||
31 | END OF THE LINE | ||
32 | |||
33 | ALL ABOARD | ||
34 | chug | ||
35 | END OF THE LINE | ||
36 | Add 1 to c0 | ||
37 | |||
38 | ALL ABOARD | ||
39 | choo | ||
40 | |||
41 | END OF THE LINE | ||
42 | |||
43 | ALL ABOARD | ||
44 | chugga | ||
45 | END OF THE LINE | ||
46 | Subtract 1 from c1 | ||
47 | |||
48 | ALL ABOARD | ||
49 | your ticket please | ||
50 | END OF THE LINE | ||
51 | End your loops with the cell pointer on the loop counter | ||
52 | |||
53 | At this point our program has added 5 to 2 leaving 7 in c0 and 0 in c1 | ||
54 | but we cannot output this value to the terminal since it is not ASCII encoded | ||
55 | |||
56 | To display the ASCII character "7" we must add 48 to the value 7 | ||
57 | We use a loop to compute 48 = 6 * 8 | ||
58 | |||
59 | |||
60 | ALL ABOARD | ||
61 | chug chug chug chug | ||
62 | END OF THE LINE | ||
63 | |||
64 | ALL ABOARD | ||
65 | chug chug chug chug | ||
66 | END OF THE LINE | ||
67 | c1 = 8 and this will be our loop counter again | ||
68 | |||
69 | ALL ABOARD | ||
70 | tickets please | ||
71 | choo choo | ||
72 | |||
73 | END OF THE LINE | ||
74 | |||
75 | ALL ABOARD | ||
76 | chug chug chug | ||
77 | END OF THE LINE | ||
78 | |||
79 | ALL ABOARD | ||
80 | chug chug chug | ||
81 | END OF THE LINE | ||
82 | Add 6 to c0 | ||
83 | |||
84 | ALL ABOARD | ||
85 | choo | ||
86 | |||
87 | END OF THE LINE | ||
88 | |||
89 | ALL ABOARD | ||
90 | chugga | ||
91 | END OF THE LINE | ||
92 | Subtract 1 from c1 | ||
93 | |||
94 | ALL ABOARD | ||
95 | your ticket please | ||
96 | choo choo | ||
97 | |||
98 | END OF THE LINE | ||
99 | |||
100 | ALL ABOARD | ||
101 | click | ||
102 | END OF THE LINE | ||
103 | Print out c0 which has the value 55 which translates to "7"! | ||
104 | |||
105 | Finally print a newline: | ||
106 | |||
107 | ALL ABOARD | ||
108 | chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga | ||
109 | chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga | ||
110 | chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga | ||
111 | chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga | ||
112 | chugga click | ||
113 | This program prints "Hello World!" and a newline to the screen, its | ||
114 | length is 106 active command characters. [It is not the shortest.] | ||
115 | |||
116 | This loop is an "initial comment loop", a simple way of adding a comment | ||
117 | to a BF program such that you don't have to worry about any command | ||
118 | characters. Any ".", ",", "+", "-", "<" and ">" characters are simply | ||
119 | ignored, the "[" and "]" characters just have to be balanced. This | ||
120 | loop and the commands it contains are ignored because the current cell | ||
121 | defaults to a value of 0; the 0 value causes this loop to be skipped. | ||
122 | |||
123 | from https://en.wikipedia.org/wiki/Brainfuck#Hello_World! | ||
124 | |||
125 | |||
126 | ALL ABOARD | ||
127 | chug chug chug chug chug chug chug chug | ||
128 | END OF THE LINE | ||
129 | Set Cell #0 to 8 | ||
130 | |||
131 | ALL ABOARD | ||
132 | tickets please | ||
133 | choo | ||
134 | chug chug chug chug | ||
135 | END OF THE LINE | ||
136 | Add 4 to Cell #1; this will always set Cell #1 to 4 | ||
137 | |||
138 | ALL ABOARD | ||
139 | tickets please | ||
140 | END OF THE LINE | ||
141 | as the cell will be cleared by the loop | ||
142 | |||
143 | ALL ABOARD | ||
144 | choo | ||
145 | chug chug | ||
146 | END OF THE LINE | ||
147 | Add 2 to Cell #2 | ||
148 | |||
149 | ALL ABOARD | ||
150 | choo | ||
151 | chug chug chug | ||
152 | END OF THE LINE | ||
153 | Add 3 to Cell #3 | ||
154 | |||
155 | ALL ABOARD | ||
156 | choo | ||
157 | chug chug chug | ||
158 | END OF THE LINE | ||
159 | Add 3 to Cell #4 | ||
160 | |||
161 | ALL ABOARD | ||
162 | choo | ||
163 | chug | ||
164 | END OF THE LINE | ||
165 | Add 1 to Cell #5 | ||
166 | |||
167 | ALL ABOARD | ||
168 | choo choo | ||
169 | choo choo | ||
170 | choo choo | ||
171 | choo choo | ||
172 | chugga | ||
173 | END OF THE LINE | ||
174 | Decrement the loop counter in Cell #1 | ||
175 | |||
176 | ALL ABOARD | ||
177 | your ticket please | ||
178 | END OF THE LINE | ||
179 | Loop until Cell #1 is zero; number of iterations is 4 | ||
180 | |||
181 | ALL ABOARD | ||
182 | choo | ||
183 | chug | ||
184 | END OF THE LINE | ||
185 | Add 1 to Cell #2 | ||
186 | |||
187 | ALL ABOARD | ||
188 | choo | ||
189 | chug | ||
190 | END OF THE LINE | ||
191 | Add 1 to Cell #3 | ||
192 | |||
193 | ALL ABOARD | ||
194 | choo | ||
195 | chugga | ||
196 | END OF THE LINE | ||
197 | Subtract 1 from Cell #4 | ||
198 | |||
199 | ALL ABOARD | ||
200 | choo | ||
201 | choo | ||
202 | chug | ||
203 | END OF THE LINE | ||
204 | Add 1 to Cell #6 | ||
205 | |||
206 | ALL ABOARD | ||
207 | tickets please choo choo | ||
208 | your ticket please | ||
209 | END OF THE LINE | ||
210 | Move back to the first zero cell you find; this will | ||
211 | be Cell #1 which was cleared by the previous loop | ||
212 | |||
213 | ALL ABOARD | ||
214 | choo choo | ||
215 | chugga | ||
216 | END OF THE LINE | ||
217 | Decrement the loop Counter in Cell #0 | ||
218 | |||
219 | ALL ABOARD | ||
220 | your ticket please | ||
221 | END OF THE LINE | ||
222 | Loop until Cell #0 is zero; number of iterations is 8 | ||
223 | |||
224 | The result of this is: | ||
225 | Cell no : 0 1 2 3 4 5 6 | ||
226 | Contents: 0 0 72 104 88 32 8 | ||
227 | Pointer : ^ | ||
228 | |||
229 | |||
230 | ALL ABOARD | ||
231 | choo | ||
232 | choo | ||
233 | click | ||
234 | END OF THE LINE | ||
235 | Cell #2 has value 72 which is 'H' | ||
236 | |||
237 | ALL ABOARD | ||
238 | choo | ||
239 | chugga chugga chugga click | ||
240 | END OF THE LINE | ||
241 | Subtract 3 from Cell #3 to get 101 which is 'e' | ||
242 | |||
243 | ALL ABOARD | ||
244 | chug chug chug chug chug chug chug clickety click chug chug chug click | ||
245 | |||
246 | END OF THE LINE | ||
247 | Likewise for 'llo' from Cell #3 | ||
248 | |||
249 | ALL ABOARD | ||
250 | choo | ||
251 | choo | ||
252 | click | ||
253 | END OF THE LINE | ||
254 | Cell #5 is 32 for the space | ||
255 | |||
256 | ALL ABOARD | ||
257 | choo choo | ||
258 | chugga clickety | ||
259 | END OF THE LINE | ||
260 | Subtract 1 from Cell #4 for 87 to give a 'W' | ||
261 | |||
262 | ALL ABOARD | ||
263 | choo choo | ||
264 | clickety | ||
265 | END OF THE LINE | ||
266 | Cell #3 was set to 'o' from the end of 'Hello' | ||
267 | |||
268 | ALL ABOARD | ||
269 | chug chug chug click chugga chugga chugga chugga chugga chugga clickety | ||
270 | chugga chugga chugga chugga chugga chugga chugga chugga click | ||
271 | END OF THE LINE | ||
272 | Cell #3 for 'rl' and 'd' | ||
273 | |||
274 | ALL ABOARD | ||
275 | choo | ||
276 | choo | ||
277 | chug click | ||
278 | END OF THE LINE | ||
279 | Add 1 to Cell #5 gives us an exclamation point | ||
280 | |||
281 | ALL ABOARD | ||
282 | choo | ||
283 | chug chug click | ||
284 | END OF THE LINE | ||
285 | And finally a newline from Cell #6 | ||
286 | ROT13 in Brainfuck | ||
287 | from https://en.wikipedia.org/wiki/Brainfuck#ROT13 | ||
288 | |||
289 | |||
290 | |||
291 | |||
292 | ALL ABOARD | ||
293 | chugga clack chug tickets please | ||
294 | END OF THE LINE | ||
295 | Read first character and start outer character reading loop | ||
296 | |||
297 | ALL ABOARD | ||
298 | chugga tickets please | ||
299 | END OF THE LINE | ||
300 | Skip forward if character is 0 | ||
301 | |||
302 | ALL ABOARD | ||
303 | choo | ||
304 | choo | ||
305 | chug chug chug chug tickets please choo | ||
306 | chug chug chug chug chug chug chug chug | ||
307 | choo choo | ||
308 | chugga your ticket please | ||
309 | END OF THE LINE | ||
310 | Set up divisor (32) for division loop | ||
311 | (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) | ||
312 | |||
313 | ALL ABOARD | ||
314 | choo choo | ||
315 | chug choo choo | ||
316 | chugga tickets please | ||
317 | END OF THE LINE | ||
318 | Set up dividend (x minus 1) and enter division loop | ||
319 | |||
320 | ALL ABOARD | ||
321 | choo | ||
322 | chug choo | ||
323 | chug choo | ||
324 | chugga tickets please choo | ||
325 | choo | ||
326 | choo | ||
327 | your ticket please | ||
328 | END OF THE LINE | ||
329 | Increase copy and remainder / reduce divisor / Normal case: skip forward | ||
330 | |||
331 | ALL ABOARD | ||
332 | choo choo | ||
333 | tickets please tickets please choo | ||
334 | chug choo choo | ||
335 | chugga your ticket please choo | ||
336 | choo | ||
337 | chug choo | ||
338 | your ticket please | ||
339 | |||
340 | END OF THE LINE | ||
341 | Special case: move remainder back to divisor and increase quotient | ||
342 | |||
343 | ALL ABOARD | ||
344 | choo choo | ||
345 | choo choo | ||
346 | choo choo | ||
347 | choo choo | ||
348 | choo choo | ||
349 | chugga | ||
350 | END OF THE LINE | ||
351 | Decrement dividend | ||
352 | |||
353 | ALL ABOARD | ||
354 | your ticket please | ||
355 | END OF THE LINE | ||
356 | End division loop | ||
357 | |||
358 | ALL ABOARD | ||
359 | your ticket please choo | ||
360 | choo | ||
361 | choo | ||
362 | tickets please chugga your ticket please chug | ||
363 | END OF THE LINE | ||
364 | End skip loop; zero former divisor and reuse space for a flag | ||
365 | |||
366 | ALL ABOARD | ||
367 | choo | ||
368 | chugga chugga tickets please chugga tickets please choo choo | ||
369 | chugga choo | ||
370 | chug chug chug | ||
371 | tickets please chugga your ticket please your ticket please your ticket please | ||
372 | choo choo | ||
373 | tickets please | ||
374 | END OF THE LINE | ||
375 | Zero that flag unless quotient was 2 or 3; zero quotient; check flag | ||
376 | |||
377 | ALL ABOARD | ||
378 | chug chug chug chug chug chug chug chug chug chug chug chug choo choo | ||
379 | tickets please | ||
380 | |||
381 | END OF THE LINE | ||
382 | If flag then set up divisor (13) for second division loop | ||
383 | (MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero) | ||
384 | |||
385 | ALL ABOARD | ||
386 | choo | ||
387 | chugga tickets please choo | ||
388 | chug choo | ||
389 | choo | ||
390 | your ticket please | ||
391 | END OF THE LINE | ||
392 | Reduce divisor; Normal case: increase remainder | ||
393 | |||
394 | ALL ABOARD | ||
395 | choo | ||
396 | tickets please chug tickets please choo choo | ||
397 | chug choo | ||
398 | chugga your ticket please choo | ||
399 | chug | ||
400 | choo | ||
401 | choo | ||
402 | your ticket please | ||
403 | END OF THE LINE | ||
404 | Special case: increase remainder / move it back to divisor / increase quotient | ||
405 | |||
406 | ALL ABOARD | ||
407 | choo choo | ||
408 | choo choo | ||
409 | choo choo | ||
410 | choo choo | ||
411 | choo choo | ||
412 | chugga | ||
413 | END OF THE LINE | ||
414 | Decrease dividend | ||
415 | |||
416 | ALL ABOARD | ||
417 | your ticket please | ||
418 | END OF THE LINE | ||
419 | End division loop | ||
420 | |||
421 | ALL ABOARD | ||
422 | choo | ||
423 | choo | ||
424 | tickets please choo choo | ||
425 | chug choo | ||
426 | chugga your ticket please | ||
427 | END OF THE LINE | ||
428 | Add remainder back to divisor to get a useful 13 | ||
429 | |||
430 | ALL ABOARD | ||
431 | choo | ||
432 | tickets please | ||
433 | END OF THE LINE | ||
434 | Skip forward if quotient was 0 | ||
435 | |||
436 | ALL ABOARD | ||
437 | chugga tickets please | ||
438 | END OF THE LINE | ||
439 | Decrement quotient and skip forward if quotient was 1 | ||
440 | |||
441 | ALL ABOARD | ||
442 | chugga choo choo | ||
443 | choo choo | ||
444 | tickets please chugga your ticket please choo | ||
445 | choo | ||
446 | |||
447 | END OF THE LINE | ||
448 | Zero quotient and divisor if quotient was 2 | ||
449 | |||
450 | ALL ABOARD | ||
451 | your ticket please choo choo | ||
452 | choo choo | ||
453 | tickets please choo choo | ||
454 | choo choo | ||
455 | chugga choo | ||
456 | choo | ||
457 | chugga your ticket please choo | ||
458 | choo | ||
459 | |||
460 | END OF THE LINE | ||
461 | Zero divisor and subtract 13 from copy if quotient was 1 | ||
462 | |||
463 | ALL ABOARD | ||
464 | your ticket please choo choo | ||
465 | choo choo | ||
466 | tickets please choo choo | ||
467 | choo choo | ||
468 | chug choo | ||
469 | choo | ||
470 | chugga your ticket please | ||
471 | END OF THE LINE | ||
472 | Zero divisor and add 13 to copy if quotient was 0 | ||
473 | |||
474 | ALL ABOARD | ||
475 | your ticket please | ||
476 | END OF THE LINE | ||
477 | End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) | ||
478 | |||
479 | ALL ABOARD | ||
480 | choo choo | ||
481 | tickets please chugga your ticket please | ||
482 | END OF THE LINE | ||
483 | Clear remainder from first division if second division was skipped | ||
484 | |||
485 | ALL ABOARD | ||
486 | choo choo | ||
487 | click tickets please chugga your ticket please | ||
488 | END OF THE LINE | ||
489 | Output ROT13ed character from copy and clear it | ||
490 | |||
491 | ALL ABOARD | ||
492 | choo choo | ||
493 | chugga clack chug | ||
494 | END OF THE LINE | ||
495 | Read next character | ||
496 | |||
497 | ALL ABOARD | ||
498 | your ticket please | ||
499 | END OF THE LINE | ||
500 | End character reading loop | ||
diff --git a/examples/hello-world.bf b/examples/hello-world.bf index dce24e2..eab99ed 100644 --- a/examples/hello-world.bf +++ b/examples/hello-world.bf | |||
@@ -8,38 +8,37 @@ ignored, the "[" and "]" characters just have to be balanced. This | |||
8 | loop and the commands it contains are ignored because the current cell | 8 | loop and the commands it contains are ignored because the current cell |
9 | defaults to a value of 0; the 0 value causes this loop to be skipped. | 9 | defaults to a value of 0; the 0 value causes this loop to be skipped. |
10 | 10 | ||
11 | from https://en.wikipedia.org/wiki/Brainfuck#Hello_World! | 11 | from https://en.wikipedia.org/wiki/Brainfuck#Hello_World! ] |
12 | ] | 12 | ++++++++ Set Cell #0 to 8 |
13 | ++++++++ Set Cell #0 to 8 | ||
14 | [ | 13 | [ |
15 | >++++ Add 4 to Cell #1; this will always set Cell #1 to 4 | 14 | >++++ Add 4 to Cell #1; this will always set Cell #1 to 4 |
16 | [ as the cell will be cleared by the loop | 15 | [ as the cell will be cleared by the loop |
17 | >++ Add 2 to Cell #2 | 16 | >++ Add 2 to Cell #2 |
18 | >+++ Add 3 to Cell #3 | 17 | >+++ Add 3 to Cell #3 |
19 | >+++ Add 3 to Cell #4 | 18 | >+++ Add 3 to Cell #4 |
20 | >+ Add 1 to Cell #5 | 19 | >+ Add 1 to Cell #5 |
21 | <<<<- Decrement the loop counter in Cell #1 | 20 | <<<<- Decrement the loop counter in Cell #1 |
22 | ] Loop until Cell #1 is zero; number of iterations is 4 | 21 | ] Loop until Cell #1 is zero; number of iterations is 4 |
23 | >+ Add 1 to Cell #2 | 22 | >+ Add 1 to Cell #2 |
24 | >+ Add 1 to Cell #3 | 23 | >+ Add 1 to Cell #3 |
25 | >- Subtract 1 from Cell #4 | 24 | >- Subtract 1 from Cell #4 |
26 | >>+ Add 1 to Cell #6 | 25 | >>+ Add 1 to Cell #6 |
27 | [<] Move back to the first zero cell you find; this will | 26 | [<] Move back to the first zero cell you find; this will |
28 | be Cell #1 which was cleared by the previous loop | 27 | be Cell #1 which was cleared by the previous loop |
29 | <- Decrement the loop Counter in Cell #0 | 28 | <- Decrement the loop Counter in Cell #0 |
30 | ] Loop until Cell #0 is zero; number of iterations is 8 | 29 | ] Loop until Cell #0 is zero; number of iterations is 8 |
31 | 30 | ||
32 | The result of this is: | 31 | The result of this is: |
33 | Cell no : 0 1 2 3 4 5 6 | 32 | Cell no : 0 1 2 3 4 5 6 |
34 | Contents: 0 0 72 104 88 32 8 | 33 | Contents: 0 0 72 104 88 32 8 |
35 | Pointer : ^ | 34 | Pointer : ^ |
36 | 35 | ||
37 | >>. Cell #2 has value 72 which is 'H' | 36 | >>. Cell #2 has value 72 which is 'H' |
38 | >---. Subtract 3 from Cell #3 to get 101 which is 'e' | 37 | >---. Subtract 3 from Cell #3 to get 101 which is 'e' |
39 | +++++++..+++. Likewise for 'llo' from Cell #3 | 38 | +++++++..+++. Likewise for 'llo' from Cell #3 |
40 | >>. Cell #5 is 32 for the space | 39 | >>. Cell #5 is 32 for the space |
41 | <-. Subtract 1 from Cell #4 for 87 to give a 'W' | 40 | <-. Subtract 1 from Cell #4 for 87 to give a 'W' |
42 | <. Cell #3 was set to 'o' from the end of 'Hello' | 41 | <. Cell #3 was set to 'o' from the end of 'Hello' |
43 | +++.------.--------. Cell #3 for 'rl' and 'd' | 42 | +++.------.--------. Cell #3 for 'rl' and 'd' |
44 | >>+. Add 1 to Cell #5 gives us an exclamation point | 43 | >>+. Add 1 to Cell #5 gives us an exclamation point |
45 | >++. And finally a newline from Cell #6 | 44 | >++. And finally a newline from Cell #6 |
diff --git a/examples/hello-world.tf b/examples/hello-world.tf new file mode 100644 index 0000000..397bc43 --- /dev/null +++ b/examples/hello-world.tf | |||
@@ -0,0 +1,388 @@ | |||
1 | This program prints "Hello World!" and a newline to the screen, its | ||
2 | length is 106 active command characters. [It is not the shortest.] | ||
3 | |||
4 | This loop is an "initial comment loop", a simple way of adding a comment | ||
5 | to a BF program such that you don't have to worry about any command | ||
6 | characters. Any ".", ",", "+", "-", "<" and ">" characters are simply | ||
7 | ignored, the "[" and "]" characters just have to be balanced. This | ||
8 | loop and the commands it contains are ignored because the current cell | ||
9 | defaults to a value of 0; the 0 value causes this loop to be skipped. | ||
10 | |||
11 | from https://en.wikipedia.org/wiki/Brainfuck#Hello_World! | ||
12 | |||
13 | |||
14 | ALL ABOARD | ||
15 | chug chug chug chug chug chug chug chug | ||
16 | END OF THE LINE | ||
17 | Set Cell #0 to 8 | ||
18 | |||
19 | ALL ABOARD | ||
20 | tickets please | ||
21 | choo | ||
22 | chug chug chug chug | ||
23 | END OF THE LINE | ||
24 | Add 4 to Cell #1; this will always set Cell #1 to 4 | ||
25 | |||
26 | ALL ABOARD | ||
27 | tickets please | ||
28 | END OF THE LINE | ||
29 | as the cell will be cleared by the loop | ||
30 | |||
31 | ALL ABOARD | ||
32 | choo | ||
33 | chug chug | ||
34 | END OF THE LINE | ||
35 | Add 2 to Cell #2 | ||
36 | |||
37 | ALL ABOARD | ||
38 | choo | ||
39 | chug chug chug | ||
40 | END OF THE LINE | ||
41 | Add 3 to Cell #3 | ||
42 | |||
43 | ALL ABOARD | ||
44 | choo | ||
45 | chug chug chug | ||
46 | END OF THE LINE | ||
47 | Add 3 to Cell #4 | ||
48 | |||
49 | ALL ABOARD | ||
50 | choo | ||
51 | chug | ||
52 | END OF THE LINE | ||
53 | Add 1 to Cell #5 | ||
54 | |||
55 | ALL ABOARD | ||
56 | choo choo | ||
57 | choo choo | ||
58 | choo choo | ||
59 | choo choo | ||
60 | chugga | ||
61 | END OF THE LINE | ||
62 | Decrement the loop counter in Cell #1 | ||
63 | |||
64 | ALL ABOARD | ||
65 | your ticket please | ||
66 | END OF THE LINE | ||
67 | Loop until Cell #1 is zero; number of iterations is 4 | ||
68 | |||
69 | ALL ABOARD | ||
70 | choo | ||
71 | chug | ||
72 | END OF THE LINE | ||
73 | Add 1 to Cell #2 | ||
74 | |||
75 | ALL ABOARD | ||
76 | choo | ||
77 | chug | ||
78 | END OF THE LINE | ||
79 | Add 1 to Cell #3 | ||
80 | |||
81 | ALL ABOARD | ||
82 | choo | ||
83 | chugga | ||
84 | END OF THE LINE | ||
85 | Subtract 1 from Cell #4 | ||
86 | |||
87 | ALL ABOARD | ||
88 | choo | ||
89 | choo | ||
90 | chug | ||
91 | END OF THE LINE | ||
92 | Add 1 to Cell #6 | ||
93 | |||
94 | ALL ABOARD | ||
95 | tickets please choo choo | ||
96 | your ticket please | ||
97 | END OF THE LINE | ||
98 | Move back to the first zero cell you find; this will | ||
99 | be Cell #1 which was cleared by the previous loop | ||
100 | |||
101 | ALL ABOARD | ||
102 | choo choo | ||
103 | chugga | ||
104 | END OF THE LINE | ||
105 | Decrement the loop Counter in Cell #0 | ||
106 | |||
107 | ALL ABOARD | ||
108 | your ticket please | ||
109 | END OF THE LINE | ||
110 | Loop until Cell #0 is zero; number of iterations is 8 | ||
111 | |||
112 | The result of this is: | ||
113 | Cell no : 0 1 2 3 4 5 6 | ||
114 | Contents: 0 0 72 104 88 32 8 | ||
115 | Pointer : ^ | ||
116 | |||
117 | |||
118 | ALL ABOARD | ||
119 | choo | ||
120 | choo | ||
121 | click | ||
122 | END OF THE LINE | ||
123 | Cell #2 has value 72 which is 'H' | ||
124 | |||
125 | ALL ABOARD | ||
126 | choo | ||
127 | chugga chugga chugga click | ||
128 | END OF THE LINE | ||
129 | Subtract 3 from Cell #3 to get 101 which is 'e' | ||
130 | |||
131 | ALL ABOARD | ||
132 | chug chug chug chug chug chug chug clickety click chug chug chug click | ||
133 | |||
134 | END OF THE LINE | ||
135 | Likewise for 'llo' from Cell #3 | ||
136 | |||
137 | ALL ABOARD | ||
138 | choo | ||
139 | choo | ||
140 | click | ||
141 | END OF THE LINE | ||
142 | Cell #5 is 32 for the space | ||
143 | |||
144 | ALL ABOARD | ||
145 | choo choo | ||
146 | chugga clickety | ||
147 | END OF THE LINE | ||
148 | Subtract 1 from Cell #4 for 87 to give a 'W' | ||
149 | |||
150 | ALL ABOARD | ||
151 | choo choo | ||
152 | clickety | ||
153 | END OF THE LINE | ||
154 | Cell #3 was set to 'o' from the end of 'Hello' | ||
155 | |||
156 | ALL ABOARD | ||
157 | chug chug chug click chugga chugga chugga chugga chugga chugga clickety | ||
158 | chugga chugga chugga chugga chugga chugga chugga chugga click | ||
159 | END OF THE LINE | ||
160 | Cell #3 for 'rl' and 'd' | ||
161 | |||
162 | ALL ABOARD | ||
163 | choo | ||
164 | choo | ||
165 | chug click | ||
166 | END OF THE LINE | ||
167 | Add 1 to Cell #5 gives us an exclamation point | ||
168 | |||
169 | ALL ABOARD | ||
170 | choo | ||
171 | chug chug click | ||
172 | END OF THE LINE | ||
173 | And finally a newline from Cell #6 | ||
174 | ROT13 in Brainfuck | ||
175 | from https://en.wikipedia.org/wiki/Brainfuck#ROT13 | ||
176 | |||
177 | |||
178 | |||
179 | |||
180 | ALL ABOARD | ||
181 | chugga clack chug tickets please | ||
182 | END OF THE LINE | ||
183 | Read first character and start outer character reading loop | ||
184 | |||
185 | ALL ABOARD | ||
186 | chugga tickets please | ||
187 | END OF THE LINE | ||
188 | Skip forward if character is 0 | ||
189 | |||
190 | ALL ABOARD | ||
191 | choo | ||
192 | choo | ||
193 | chug chug chug chug tickets please choo | ||
194 | chug chug chug chug chug chug chug chug | ||
195 | choo choo | ||
196 | chugga your ticket please | ||
197 | END OF THE LINE | ||
198 | Set up divisor (32) for division loop | ||
199 | (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) | ||
200 | |||
201 | ALL ABOARD | ||
202 | choo choo | ||
203 | chug choo choo | ||
204 | chugga tickets please | ||
205 | END OF THE LINE | ||
206 | Set up dividend (x minus 1) and enter division loop | ||
207 | |||
208 | ALL ABOARD | ||
209 | choo | ||
210 | chug choo | ||
211 | chug choo | ||
212 | chugga tickets please choo | ||
213 | choo | ||
214 | choo | ||
215 | your ticket please | ||
216 | END OF THE LINE | ||
217 | Increase copy and remainder / reduce divisor / Normal case: skip forward | ||
218 | |||
219 | ALL ABOARD | ||
220 | choo choo | ||
221 | tickets please tickets please choo | ||
222 | chug choo choo | ||
223 | chugga your ticket please choo | ||
224 | choo | ||
225 | chug choo | ||
226 | your ticket please | ||
227 | |||
228 | END OF THE LINE | ||
229 | Special case: move remainder back to divisor and increase quotient | ||
230 | |||
231 | ALL ABOARD | ||
232 | choo choo | ||
233 | choo choo | ||
234 | choo choo | ||
235 | choo choo | ||
236 | choo choo | ||
237 | chugga | ||
238 | END OF THE LINE | ||
239 | Decrement dividend | ||
240 | |||
241 | ALL ABOARD | ||
242 | your ticket please | ||
243 | END OF THE LINE | ||
244 | End division loop | ||
245 | |||
246 | ALL ABOARD | ||
247 | your ticket please choo | ||
248 | choo | ||
249 | choo | ||
250 | tickets please chugga your ticket please chug | ||
251 | END OF THE LINE | ||
252 | End skip loop; zero former divisor and reuse space for a flag | ||
253 | |||
254 | ALL ABOARD | ||
255 | choo | ||
256 | chugga chugga tickets please chugga tickets please choo choo | ||
257 | chugga choo | ||
258 | chug chug chug | ||
259 | tickets please chugga your ticket please your ticket please your ticket please | ||
260 | choo choo | ||
261 | tickets please | ||
262 | END OF THE LINE | ||
263 | Zero that flag unless quotient was 2 or 3; zero quotient; check flag | ||
264 | |||
265 | ALL ABOARD | ||
266 | chug chug chug chug chug chug chug chug chug chug chug chug choo choo | ||
267 | tickets please | ||
268 | |||
269 | END OF THE LINE | ||
270 | If flag then set up divisor (13) for second division loop | ||
271 | (MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero) | ||
272 | |||
273 | ALL ABOARD | ||
274 | choo | ||
275 | chugga tickets please choo | ||
276 | chug choo | ||
277 | choo | ||
278 | your ticket please | ||
279 | END OF THE LINE | ||
280 | Reduce divisor; Normal case: increase remainder | ||
281 | |||
282 | ALL ABOARD | ||
283 | choo | ||
284 | tickets please chug tickets please choo choo | ||
285 | chug choo | ||
286 | chugga your ticket please choo | ||
287 | chug | ||
288 | choo | ||
289 | choo | ||
290 | your ticket please | ||
291 | END OF THE LINE | ||
292 | Special case: increase remainder / move it back to divisor / increase quotient | ||
293 | |||
294 | ALL ABOARD | ||
295 | choo choo | ||
296 | choo choo | ||
297 | choo choo | ||
298 | choo choo | ||
299 | choo choo | ||
300 | chugga | ||
301 | END OF THE LINE | ||
302 | Decrease dividend | ||
303 | |||
304 | ALL ABOARD | ||
305 | your ticket please | ||
306 | END OF THE LINE | ||
307 | End division loop | ||
308 | |||
309 | ALL ABOARD | ||
310 | choo | ||
311 | choo | ||
312 | tickets please choo choo | ||
313 | chug choo | ||
314 | chugga your ticket please | ||
315 | END OF THE LINE | ||
316 | Add remainder back to divisor to get a useful 13 | ||
317 | |||
318 | ALL ABOARD | ||
319 | choo | ||
320 | tickets please | ||
321 | END OF THE LINE | ||
322 | Skip forward if quotient was 0 | ||
323 | |||
324 | ALL ABOARD | ||
325 | chugga tickets please | ||
326 | END OF THE LINE | ||
327 | Decrement quotient and skip forward if quotient was 1 | ||
328 | |||
329 | ALL ABOARD | ||
330 | chugga choo choo | ||
331 | choo choo | ||
332 | tickets please chugga your ticket please choo | ||
333 | choo | ||
334 | |||
335 | END OF THE LINE | ||
336 | Zero quotient and divisor if quotient was 2 | ||
337 | |||
338 | ALL ABOARD | ||
339 | your ticket please choo choo | ||
340 | choo choo | ||
341 | tickets please choo choo | ||
342 | choo choo | ||
343 | chugga choo | ||
344 | choo | ||
345 | chugga your ticket please choo | ||
346 | choo | ||
347 | |||
348 | END OF THE LINE | ||
349 | Zero divisor and subtract 13 from copy if quotient was 1 | ||
350 | |||
351 | ALL ABOARD | ||
352 | your ticket please choo choo | ||
353 | choo choo | ||
354 | tickets please choo choo | ||
355 | choo choo | ||
356 | chug choo | ||
357 | choo | ||
358 | chugga your ticket please | ||
359 | END OF THE LINE | ||
360 | Zero divisor and add 13 to copy if quotient was 0 | ||
361 | |||
362 | ALL ABOARD | ||
363 | your ticket please | ||
364 | END OF THE LINE | ||
365 | End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) | ||
366 | |||
367 | ALL ABOARD | ||
368 | choo choo | ||
369 | tickets please chugga your ticket please | ||
370 | END OF THE LINE | ||
371 | Clear remainder from first division if second division was skipped | ||
372 | |||
373 | ALL ABOARD | ||
374 | choo choo | ||
375 | click tickets please chugga your ticket please | ||
376 | END OF THE LINE | ||
377 | Output ROT13ed character from copy and clear it | ||
378 | |||
379 | ALL ABOARD | ||
380 | choo choo | ||
381 | chugga clack chug | ||
382 | END OF THE LINE | ||
383 | Read next character | ||
384 | |||
385 | ALL ABOARD | ||
386 | your ticket please | ||
387 | END OF THE LINE | ||
388 | End character reading loop | ||
diff --git a/examples/printchar.bf b/examples/printchar.bf new file mode 100644 index 0000000..e0d73ad --- /dev/null +++ b/examples/printchar.bf | |||
@@ -0,0 +1,5 @@ | |||
1 | [ printchar is a small example input/output trainfuck program. | ||
2 | it waits for the user to press a key, then prints that key | ||
3 | and a newline to the screen. | ||
4 | ] | ||
5 | ,.>++++++++++. | ||
diff --git a/examples/printchar.tf b/examples/printchar.tf new file mode 100644 index 0000000..c9092be --- /dev/null +++ b/examples/printchar.tf | |||
@@ -0,0 +1,10 @@ | |||
1 | printchar is a small example input/output trainfuck program. | ||
2 | it waits for the user to press a key, then prints that key | ||
3 | and a newline to the screen. | ||
4 | ALL ABOARD | ||
5 | clack clickety | ||
6 | choo | ||
7 | chug chug chug chug chug | ||
8 | chug chug chug chug chug | ||
9 | click | ||
10 | END OF THE LINE | ||
diff --git a/examples/rot13.tf b/examples/rot13.tf new file mode 100644 index 0000000..f7c24df --- /dev/null +++ b/examples/rot13.tf | |||
@@ -0,0 +1,215 @@ | |||
1 | ROT13 in Brainfuck | ||
2 | from https://en.wikipedia.org/wiki/Brainfuck#ROT13 | ||
3 | |||
4 | |||
5 | |||
6 | |||
7 | ALL ABOARD | ||
8 | chugga clack chug tickets please | ||
9 | END OF THE LINE | ||
10 | Read first character and start outer character reading loop | ||
11 | |||
12 | ALL ABOARD | ||
13 | chugga tickets please | ||
14 | END OF THE LINE | ||
15 | Skip forward if character is 0 | ||
16 | |||
17 | ALL ABOARD | ||
18 | choo | ||
19 | choo | ||
20 | chug chug chug chug tickets please choo | ||
21 | chug chug chug chug chug chug chug chug | ||
22 | choo choo | ||
23 | chugga your ticket please | ||
24 | END OF THE LINE | ||
25 | Set up divisor (32) for division loop | ||
26 | (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) | ||
27 | |||
28 | ALL ABOARD | ||
29 | choo choo | ||
30 | chug choo choo | ||
31 | chugga tickets please | ||
32 | END OF THE LINE | ||
33 | Set up dividend (x minus 1) and enter division loop | ||
34 | |||
35 | ALL ABOARD | ||
36 | choo | ||
37 | chug choo | ||
38 | chug choo | ||
39 | chugga tickets please choo | ||
40 | choo | ||
41 | choo | ||
42 | your ticket please | ||
43 | END OF THE LINE | ||
44 | Increase copy and remainder / reduce divisor / Normal case: skip forward | ||
45 | |||
46 | ALL ABOARD | ||
47 | choo choo | ||
48 | tickets please tickets please choo | ||
49 | chug choo choo | ||
50 | chugga your ticket please choo | ||
51 | choo | ||
52 | chug choo | ||
53 | your ticket please | ||
54 | |||
55 | END OF THE LINE | ||
56 | Special case: move remainder back to divisor and increase quotient | ||
57 | |||
58 | ALL ABOARD | ||
59 | choo choo | ||
60 | choo choo | ||
61 | choo choo | ||
62 | choo choo | ||
63 | choo choo | ||
64 | chugga | ||
65 | END OF THE LINE | ||
66 | Decrement dividend | ||
67 | |||
68 | ALL ABOARD | ||
69 | your ticket please | ||
70 | END OF THE LINE | ||
71 | End division loop | ||
72 | |||
73 | ALL ABOARD | ||
74 | your ticket please choo | ||
75 | choo | ||
76 | choo | ||
77 | tickets please chugga your ticket please chug | ||
78 | END OF THE LINE | ||
79 | End skip loop; zero former divisor and reuse space for a flag | ||
80 | |||
81 | ALL ABOARD | ||
82 | choo | ||
83 | chugga chugga tickets please chugga tickets please choo choo | ||
84 | chugga choo | ||
85 | chug chug chug | ||
86 | tickets please chugga your ticket please your ticket please your ticket please | ||
87 | choo choo | ||
88 | tickets please | ||
89 | END OF THE LINE | ||
90 | Zero that flag unless quotient was 2 or 3; zero quotient; check flag | ||
91 | |||
92 | ALL ABOARD | ||
93 | chug chug chug chug chug chug chug chug chug chug chug chug choo choo | ||
94 | tickets please | ||
95 | |||
96 | END OF THE LINE | ||
97 | If flag then set up divisor (13) for second division loop | ||
98 | (MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero) | ||
99 | |||
100 | ALL ABOARD | ||
101 | choo | ||
102 | chugga tickets please choo | ||
103 | chug choo | ||
104 | choo | ||
105 | your ticket please | ||
106 | END OF THE LINE | ||
107 | Reduce divisor; Normal case: increase remainder | ||
108 | |||
109 | ALL ABOARD | ||
110 | choo | ||
111 | tickets please chug tickets please choo choo | ||
112 | chug choo | ||
113 | chugga your ticket please choo | ||
114 | chug | ||
115 | choo | ||
116 | choo | ||
117 | your ticket please | ||
118 | END OF THE LINE | ||
119 | Special case: increase remainder / move it back to divisor / increase quotient | ||
120 | |||
121 | ALL ABOARD | ||
122 | choo choo | ||
123 | choo choo | ||
124 | choo choo | ||
125 | choo choo | ||
126 | choo choo | ||
127 | chugga | ||
128 | END OF THE LINE | ||
129 | Decrease dividend | ||
130 | |||
131 | ALL ABOARD | ||
132 | your ticket please | ||
133 | END OF THE LINE | ||
134 | End division loop | ||
135 | |||
136 | ALL ABOARD | ||
137 | choo | ||
138 | choo | ||
139 | tickets please choo choo | ||
140 | chug choo | ||
141 | chugga your ticket please | ||
142 | END OF THE LINE | ||
143 | Add remainder back to divisor to get a useful 13 | ||
144 | |||
145 | ALL ABOARD | ||
146 | choo | ||
147 | tickets please | ||
148 | END OF THE LINE | ||
149 | Skip forward if quotient was 0 | ||
150 | |||
151 | ALL ABOARD | ||
152 | chugga tickets please | ||
153 | END OF THE LINE | ||
154 | Decrement quotient and skip forward if quotient was 1 | ||
155 | |||
156 | ALL ABOARD | ||
157 | chugga choo choo | ||
158 | choo choo | ||
159 | tickets please chugga your ticket please choo | ||
160 | choo | ||
161 | |||
162 | END OF THE LINE | ||
163 | Zero quotient and divisor if quotient was 2 | ||
164 | |||
165 | ALL ABOARD | ||
166 | your ticket please choo choo | ||
167 | choo choo | ||
168 | tickets please choo choo | ||
169 | choo choo | ||
170 | chugga choo | ||
171 | choo | ||
172 | chugga your ticket please choo | ||
173 | choo | ||
174 | |||
175 | END OF THE LINE | ||
176 | Zero divisor and subtract 13 from copy if quotient was 1 | ||
177 | |||
178 | ALL ABOARD | ||
179 | your ticket please choo choo | ||
180 | choo choo | ||
181 | tickets please choo choo | ||
182 | choo choo | ||
183 | chug choo | ||
184 | choo | ||
185 | chugga your ticket please | ||
186 | END OF THE LINE | ||
187 | Zero divisor and add 13 to copy if quotient was 0 | ||
188 | |||
189 | ALL ABOARD | ||
190 | your ticket please | ||
191 | END OF THE LINE | ||
192 | End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) | ||
193 | |||
194 | ALL ABOARD | ||
195 | choo choo | ||
196 | tickets please chugga your ticket please | ||
197 | END OF THE LINE | ||
198 | Clear remainder from first division if second division was skipped | ||
199 | |||
200 | ALL ABOARD | ||
201 | choo choo | ||
202 | click tickets please chugga your ticket please | ||
203 | END OF THE LINE | ||
204 | Output ROT13ed character from copy and clear it | ||
205 | |||
206 | ALL ABOARD | ||
207 | choo choo | ||
208 | chugga clack chug | ||
209 | END OF THE LINE | ||
210 | Read next character | ||
211 | |||
212 | ALL ABOARD | ||
213 | your ticket please | ||
214 | END OF THE LINE | ||
215 | End character reading loop | ||