diff options
author | Case Duckworth | 2022-07-06 22:19:46 -0500 |
---|---|---|
committer | Case Duckworth | 2022-07-06 22:19:46 -0500 |
commit | cdfe94135fe8ab1f407bb5e09c3cea93ec300469 (patch) | |
tree | 899b4aa91fd88bbaf3b1008950dcf5b6bff1b1f5 | |
parent | Fix other help (diff) | |
download | trainfuck-cdfe94135fe8ab1f407bb5e09c3cea93ec300469.tar.gz trainfuck-cdfe94135fe8ab1f407bb5e09c3cea93ec300469.zip |
Fix examples
-rw-r--r-- | examples/add2.tf | 441 | ||||
-rw-r--r-- | examples/hello-world.tf | 271 | ||||
-rw-r--r-- | examples/rot13.tf | 56 | ||||
-rwxr-xr-x | fucktrain.awk | 3 |
4 files changed, 86 insertions, 685 deletions
diff --git a/examples/add2.tf b/examples/add2.tf index 3c1529b..bdb0ddf 100644 --- a/examples/add2.tf +++ b/examples/add2.tf | |||
@@ -5,7 +5,7 @@ from https://en.wikipedia.org/wiki/Brainfuck#Adding_two_values | |||
5 | 5 | ||
6 | 6 | ||
7 | ALL ABOARD | 7 | ALL ABOARD |
8 | chug chug | 8 | chug chug |
9 | END OF THE LINE | 9 | END OF THE LINE |
10 | Cell c0 = 2 | 10 | Cell c0 = 2 |
11 | 11 | ||
@@ -13,15 +13,15 @@ ALL ABOARD | |||
13 | choo | 13 | choo |
14 | 14 | ||
15 | END OF THE LINE | 15 | END OF THE LINE |
16 | 16 | ||
17 | ALL ABOARD | 17 | ALL ABOARD |
18 | chug chug chug chug chug | 18 | chug chug chug chug chug |
19 | END OF THE LINE | 19 | END OF THE LINE |
20 | Cell c1 = 5 | 20 | Cell c1 = 5 |
21 | 21 | ||
22 | 22 | ||
23 | ALL ABOARD | 23 | ALL ABOARD |
24 | tickets please | 24 | tickets please |
25 | END OF THE LINE | 25 | END OF THE LINE |
26 | Start your loops with your cell pointer on the loop counter (c1 in our case) | 26 | Start your loops with your cell pointer on the loop counter (c1 in our case) |
27 | 27 | ||
@@ -29,9 +29,9 @@ ALL ABOARD | |||
29 | choo choo | 29 | choo choo |
30 | 30 | ||
31 | END OF THE LINE | 31 | END OF THE LINE |
32 | 32 | ||
33 | ALL ABOARD | 33 | ALL ABOARD |
34 | chug | 34 | chug |
35 | END OF THE LINE | 35 | END OF THE LINE |
36 | Add 1 to c0 | 36 | Add 1 to c0 |
37 | 37 | ||
@@ -39,14 +39,14 @@ ALL ABOARD | |||
39 | choo | 39 | choo |
40 | 40 | ||
41 | END OF THE LINE | 41 | END OF THE LINE |
42 | 42 | ||
43 | ALL ABOARD | 43 | ALL ABOARD |
44 | chugga | 44 | chugga |
45 | END OF THE LINE | 45 | END OF THE LINE |
46 | Subtract 1 from c1 | 46 | Subtract 1 from c1 |
47 | 47 | ||
48 | ALL ABOARD | 48 | ALL ABOARD |
49 | your ticket please | 49 | your ticket please |
50 | END OF THE LINE | 50 | END OF THE LINE |
51 | End your loops with the cell pointer on the loop counter | 51 | End your loops with the cell pointer on the loop counter |
52 | 52 | ||
@@ -58,26 +58,26 @@ We use a loop to compute 48 = 6 * 8 | |||
58 | 58 | ||
59 | 59 | ||
60 | ALL ABOARD | 60 | ALL ABOARD |
61 | chug chug chug chug | 61 | chug chug chug chug |
62 | END OF THE LINE | 62 | END OF THE LINE |
63 | 63 | ||
64 | ALL ABOARD | 64 | ALL ABOARD |
65 | chug chug chug chug | 65 | chug chug chug chug |
66 | END OF THE LINE | 66 | END OF THE LINE |
67 | c1 = 8 and this will be our loop counter again | 67 | c1 = 8 and this will be our loop counter again |
68 | 68 | ||
69 | ALL ABOARD | 69 | ALL ABOARD |
70 | tickets please | 70 | tickets please |
71 | choo choo | 71 | choo choo |
72 | 72 | ||
73 | END OF THE LINE | 73 | END OF THE LINE |
74 | 74 | ||
75 | ALL ABOARD | 75 | ALL ABOARD |
76 | chug chug chug | 76 | chug chug chug |
77 | END OF THE LINE | 77 | END OF THE LINE |
78 | 78 | ||
79 | ALL ABOARD | 79 | ALL ABOARD |
80 | chug chug chug | 80 | chug chug chug |
81 | END OF THE LINE | 81 | END OF THE LINE |
82 | Add 6 to c0 | 82 | Add 6 to c0 |
83 | 83 | ||
@@ -85,416 +85,29 @@ ALL ABOARD | |||
85 | choo | 85 | choo |
86 | 86 | ||
87 | END OF THE LINE | 87 | END OF THE LINE |
88 | 88 | ||
89 | ALL ABOARD | 89 | ALL ABOARD |
90 | chugga | 90 | chugga |
91 | END OF THE LINE | 91 | END OF THE LINE |
92 | Subtract 1 from c1 | 92 | Subtract 1 from c1 |
93 | 93 | ||
94 | ALL ABOARD | 94 | ALL ABOARD |
95 | your ticket please | 95 | your ticket please |
96 | choo choo | 96 | choo choo |
97 | 97 | ||
98 | END OF THE LINE | 98 | END OF THE LINE |
99 | 99 | ||
100 | ALL ABOARD | 100 | ALL ABOARD |
101 | click | 101 | click |
102 | END OF THE LINE | 102 | END OF THE LINE |
103 | Print out c0 which has the value 55 which translates to "7"! | 103 | Print out c0 which has the value 55 which translates to "7"! |
104 | 104 | ||
105 | Finally print a newline: | 105 | Finally print a newline: |
106 | 106 | ||
107 | ALL ABOARD | 107 | ALL ABOARD |
108 | chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga | 108 | chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga |
109 | 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 | 110 | chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga chugga |
111 | 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 | 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 | 113 | END OF THE LINE |
500 | End character reading loop | ||
diff --git a/examples/hello-world.tf b/examples/hello-world.tf index 397bc43..227faf6 100644 --- a/examples/hello-world.tf +++ b/examples/hello-world.tf | |||
@@ -8,47 +8,47 @@ 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 | ||
13 | 13 | ||
14 | ALL ABOARD | 14 | ALL ABOARD |
15 | chug chug chug chug chug chug chug chug | 15 | chug chug chug chug chug chug chug chug |
16 | END OF THE LINE | 16 | END OF THE LINE |
17 | Set Cell #0 to 8 | 17 | Set Cell #0 to 8 |
18 | 18 | ||
19 | ALL ABOARD | 19 | ALL ABOARD |
20 | tickets please | 20 | tickets please |
21 | choo | 21 | choo |
22 | chug chug chug chug | 22 | chug chug chug chug |
23 | END OF THE LINE | 23 | END OF THE LINE |
24 | Add 4 to Cell #1; this will always set Cell #1 to 4 | 24 | Add 4 to Cell #1; this will always set Cell #1 to 4 |
25 | 25 | ||
26 | ALL ABOARD | 26 | ALL ABOARD |
27 | tickets please | 27 | tickets please |
28 | END OF THE LINE | 28 | END OF THE LINE |
29 | as the cell will be cleared by the loop | 29 | as the cell will be cleared by the loop |
30 | 30 | ||
31 | ALL ABOARD | 31 | ALL ABOARD |
32 | choo | 32 | choo |
33 | chug chug | 33 | chug chug |
34 | END OF THE LINE | 34 | END OF THE LINE |
35 | Add 2 to Cell #2 | 35 | Add 2 to Cell #2 |
36 | 36 | ||
37 | ALL ABOARD | 37 | ALL ABOARD |
38 | choo | 38 | choo |
39 | chug chug chug | 39 | chug chug chug |
40 | END OF THE LINE | 40 | END OF THE LINE |
41 | Add 3 to Cell #3 | 41 | Add 3 to Cell #3 |
42 | 42 | ||
43 | ALL ABOARD | 43 | ALL ABOARD |
44 | choo | 44 | choo |
45 | chug chug chug | 45 | chug chug chug |
46 | END OF THE LINE | 46 | END OF THE LINE |
47 | Add 3 to Cell #4 | 47 | Add 3 to Cell #4 |
48 | 48 | ||
49 | ALL ABOARD | 49 | ALL ABOARD |
50 | choo | 50 | choo |
51 | chug | 51 | chug |
52 | END OF THE LINE | 52 | END OF THE LINE |
53 | Add 1 to Cell #5 | 53 | Add 1 to Cell #5 |
54 | 54 | ||
@@ -57,55 +57,55 @@ choo choo | |||
57 | choo choo | 57 | choo choo |
58 | choo choo | 58 | choo choo |
59 | choo choo | 59 | choo choo |
60 | chugga | 60 | chugga |
61 | END OF THE LINE | 61 | END OF THE LINE |
62 | Decrement the loop counter in Cell #1 | 62 | Decrement the loop counter in Cell #1 |
63 | 63 | ||
64 | ALL ABOARD | 64 | ALL ABOARD |
65 | your ticket please | 65 | your ticket please |
66 | END OF THE LINE | 66 | END OF THE LINE |
67 | Loop until Cell #1 is zero; number of iterations is 4 | 67 | Loop until Cell #1 is zero; number of iterations is 4 |
68 | 68 | ||
69 | ALL ABOARD | 69 | ALL ABOARD |
70 | choo | 70 | choo |
71 | chug | 71 | chug |
72 | END OF THE LINE | 72 | END OF THE LINE |
73 | Add 1 to Cell #2 | 73 | Add 1 to Cell #2 |
74 | 74 | ||
75 | ALL ABOARD | 75 | ALL ABOARD |
76 | choo | 76 | choo |
77 | chug | 77 | chug |
78 | END OF THE LINE | 78 | END OF THE LINE |
79 | Add 1 to Cell #3 | 79 | Add 1 to Cell #3 |
80 | 80 | ||
81 | ALL ABOARD | 81 | ALL ABOARD |
82 | choo | 82 | choo |
83 | chugga | 83 | chugga |
84 | END OF THE LINE | 84 | END OF THE LINE |
85 | Subtract 1 from Cell #4 | 85 | Subtract 1 from Cell #4 |
86 | 86 | ||
87 | ALL ABOARD | 87 | ALL ABOARD |
88 | choo | 88 | choo |
89 | choo | 89 | choo |
90 | chug | 90 | chug |
91 | END OF THE LINE | 91 | END OF THE LINE |
92 | Add 1 to Cell #6 | 92 | Add 1 to Cell #6 |
93 | 93 | ||
94 | ALL ABOARD | 94 | ALL ABOARD |
95 | tickets please choo choo | 95 | tickets please choo choo |
96 | your ticket please | 96 | your ticket please |
97 | END OF THE LINE | 97 | END OF THE LINE |
98 | Move back to the first zero cell you find; this will | 98 | Move back to the first zero cell you find; this will |
99 | be Cell #1 which was cleared by the previous loop | 99 | be Cell #1 which was cleared by the previous loop |
100 | 100 | ||
101 | ALL ABOARD | 101 | ALL ABOARD |
102 | choo choo | 102 | choo choo |
103 | chugga | 103 | chugga |
104 | END OF THE LINE | 104 | END OF THE LINE |
105 | Decrement the loop Counter in Cell #0 | 105 | Decrement the loop Counter in Cell #0 |
106 | 106 | ||
107 | ALL ABOARD | 107 | ALL ABOARD |
108 | your ticket please | 108 | your ticket please |
109 | END OF THE LINE | 109 | END OF THE LINE |
110 | Loop until Cell #0 is zero; number of iterations is 8 | 110 | Loop until Cell #0 is zero; number of iterations is 8 |
111 | 111 | ||
@@ -118,18 +118,18 @@ Pointer : ^ | |||
118 | ALL ABOARD | 118 | ALL ABOARD |
119 | choo | 119 | choo |
120 | choo | 120 | choo |
121 | click | 121 | click |
122 | END OF THE LINE | 122 | END OF THE LINE |
123 | Cell #2 has value 72 which is 'H' | 123 | Cell #2 has value 72 which is 'H' |
124 | 124 | ||
125 | ALL ABOARD | 125 | ALL ABOARD |
126 | choo | 126 | choo |
127 | chugga chugga chugga click | 127 | chugga chugga chugga click |
128 | END OF THE LINE | 128 | END OF THE LINE |
129 | Subtract 3 from Cell #3 to get 101 which is 'e' | 129 | Subtract 3 from Cell #3 to get 101 which is 'e' |
130 | 130 | ||
131 | ALL ABOARD | 131 | ALL ABOARD |
132 | chug chug chug chug chug chug chug clickety click chug chug chug click | 132 | chug chug chug chug chug chug chug clickety click chug chug chug click |
133 | 133 | ||
134 | END OF THE LINE | 134 | END OF THE LINE |
135 | Likewise for 'llo' from Cell #3 | 135 | Likewise for 'llo' from Cell #3 |
@@ -137,252 +137,37 @@ END OF THE LINE | |||
137 | ALL ABOARD | 137 | ALL ABOARD |
138 | choo | 138 | choo |
139 | choo | 139 | choo |
140 | click | 140 | click |
141 | END OF THE LINE | 141 | END OF THE LINE |
142 | Cell #5 is 32 for the space | 142 | Cell #5 is 32 for the space |
143 | 143 | ||
144 | ALL ABOARD | 144 | ALL ABOARD |
145 | choo choo | 145 | choo choo |
146 | chugga clickety | 146 | chugga clickety |
147 | END OF THE LINE | 147 | END OF THE LINE |
148 | Subtract 1 from Cell #4 for 87 to give a 'W' | 148 | Subtract 1 from Cell #4 for 87 to give a 'W' |
149 | 149 | ||
150 | ALL ABOARD | 150 | ALL ABOARD |
151 | choo choo | 151 | choo choo |
152 | clickety | 152 | clickety |
153 | END OF THE LINE | 153 | END OF THE LINE |
154 | Cell #3 was set to 'o' from the end of 'Hello' | 154 | Cell #3 was set to 'o' from the end of 'Hello' |
155 | 155 | ||
156 | ALL ABOARD | 156 | ALL ABOARD |
157 | chug chug chug click chugga chugga chugga chugga chugga chugga clickety | 157 | chug chug chug click chugga chugga chugga chugga chugga chugga clickety |
158 | chugga chugga chugga chugga chugga chugga chugga chugga click | 158 | chugga chugga chugga chugga chugga chugga chugga chugga click |
159 | END OF THE LINE | 159 | END OF THE LINE |
160 | Cell #3 for 'rl' and 'd' | 160 | Cell #3 for 'rl' and 'd' |
161 | 161 | ||
162 | ALL ABOARD | 162 | ALL ABOARD |
163 | choo | 163 | choo |
164 | choo | 164 | choo |
165 | chug click | 165 | chug click |
166 | END OF THE LINE | 166 | END OF THE LINE |
167 | Add 1 to Cell #5 gives us an exclamation point | 167 | Add 1 to Cell #5 gives us an exclamation point |
168 | 168 | ||
169 | ALL ABOARD | 169 | ALL ABOARD |
170 | choo | 170 | choo |
171 | chug chug click | 171 | chug chug click |
172 | END OF THE LINE | 172 | END OF THE LINE |
173 | And finally a newline from Cell #6 | 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/rot13.tf b/examples/rot13.tf index f7c24df..31a6829 100644 --- a/examples/rot13.tf +++ b/examples/rot13.tf | |||
@@ -5,12 +5,12 @@ from https://en.wikipedia.org/wiki/Brainfuck#ROT13 | |||
5 | 5 | ||
6 | 6 | ||
7 | ALL ABOARD | 7 | ALL ABOARD |
8 | chugga clack chug tickets please | 8 | chugga clack chug tickets please |
9 | END OF THE LINE | 9 | END OF THE LINE |
10 | Read first character and start outer character reading loop | 10 | Read first character and start outer character reading loop |
11 | 11 | ||
12 | ALL ABOARD | 12 | ALL ABOARD |
13 | chugga tickets please | 13 | chugga tickets please |
14 | END OF THE LINE | 14 | END OF THE LINE |
15 | Skip forward if character is 0 | 15 | Skip forward if character is 0 |
16 | 16 | ||
@@ -18,9 +18,9 @@ ALL ABOARD | |||
18 | choo | 18 | choo |
19 | choo | 19 | choo |
20 | chug chug chug chug tickets please choo | 20 | chug chug chug chug tickets please choo |
21 | chug chug chug chug chug chug chug chug | 21 | chug chug chug chug chug chug chug chug |
22 | choo choo | 22 | choo choo |
23 | chugga your ticket please | 23 | chugga your ticket please |
24 | END OF THE LINE | 24 | END OF THE LINE |
25 | Set up divisor (32) for division loop | 25 | Set up divisor (32) for division loop |
26 | (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) | 26 | (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) |
@@ -28,7 +28,7 @@ END OF THE LINE | |||
28 | ALL ABOARD | 28 | ALL ABOARD |
29 | choo choo | 29 | choo choo |
30 | chug choo choo | 30 | chug choo choo |
31 | chugga tickets please | 31 | chugga tickets please |
32 | END OF THE LINE | 32 | END OF THE LINE |
33 | Set up dividend (x minus 1) and enter division loop | 33 | Set up dividend (x minus 1) and enter division loop |
34 | 34 | ||
@@ -39,7 +39,7 @@ chug choo | |||
39 | chugga tickets please choo | 39 | chugga tickets please choo |
40 | choo | 40 | choo |
41 | choo | 41 | choo |
42 | your ticket please | 42 | your ticket please |
43 | END OF THE LINE | 43 | END OF THE LINE |
44 | Increase copy and remainder / reduce divisor / Normal case: skip forward | 44 | Increase copy and remainder / reduce divisor / Normal case: skip forward |
45 | 45 | ||
@@ -50,7 +50,7 @@ chug choo choo | |||
50 | chugga your ticket please choo | 50 | chugga your ticket please choo |
51 | choo | 51 | choo |
52 | chug choo | 52 | chug choo |
53 | your ticket please | 53 | your ticket please |
54 | 54 | ||
55 | END OF THE LINE | 55 | END OF THE LINE |
56 | Special case: move remainder back to divisor and increase quotient | 56 | Special case: move remainder back to divisor and increase quotient |
@@ -61,12 +61,12 @@ choo choo | |||
61 | choo choo | 61 | choo choo |
62 | choo choo | 62 | choo choo |
63 | choo choo | 63 | choo choo |
64 | chugga | 64 | chugga |
65 | END OF THE LINE | 65 | END OF THE LINE |
66 | Decrement dividend | 66 | Decrement dividend |
67 | 67 | ||
68 | ALL ABOARD | 68 | ALL ABOARD |
69 | your ticket please | 69 | your ticket please |
70 | END OF THE LINE | 70 | END OF THE LINE |
71 | End division loop | 71 | End division loop |
72 | 72 | ||
@@ -74,7 +74,7 @@ ALL ABOARD | |||
74 | your ticket please choo | 74 | your ticket please choo |
75 | choo | 75 | choo |
76 | choo | 76 | choo |
77 | tickets please chugga your ticket please chug | 77 | tickets please chugga your ticket please chug |
78 | END OF THE LINE | 78 | END OF THE LINE |
79 | End skip loop; zero former divisor and reuse space for a flag | 79 | End skip loop; zero former divisor and reuse space for a flag |
80 | 80 | ||
@@ -82,16 +82,16 @@ ALL ABOARD | |||
82 | choo | 82 | choo |
83 | chugga chugga tickets please chugga tickets please choo choo | 83 | chugga chugga tickets please chugga tickets please choo choo |
84 | chugga choo | 84 | chugga choo |
85 | chug chug chug | 85 | chug chug chug |
86 | tickets please chugga your ticket please your ticket please your ticket please | 86 | tickets please chugga your ticket please your ticket please your ticket please |
87 | choo choo | 87 | choo choo |
88 | tickets please | 88 | tickets please |
89 | END OF THE LINE | 89 | END OF THE LINE |
90 | Zero that flag unless quotient was 2 or 3; zero quotient; check flag | 90 | Zero that flag unless quotient was 2 or 3; zero quotient; check flag |
91 | 91 | ||
92 | ALL ABOARD | 92 | ALL ABOARD |
93 | chug chug chug chug chug chug chug chug chug chug chug chug choo choo | 93 | chug chug chug chug chug chug chug chug chug chug chug chug choo choo |
94 | tickets please | 94 | tickets please |
95 | 95 | ||
96 | END OF THE LINE | 96 | END OF THE LINE |
97 | If flag then set up divisor (13) for second division loop | 97 | If flag then set up divisor (13) for second division loop |
@@ -102,7 +102,7 @@ choo | |||
102 | chugga tickets please choo | 102 | chugga tickets please choo |
103 | chug choo | 103 | chug choo |
104 | choo | 104 | choo |
105 | your ticket please | 105 | your ticket please |
106 | END OF THE LINE | 106 | END OF THE LINE |
107 | Reduce divisor; Normal case: increase remainder | 107 | Reduce divisor; Normal case: increase remainder |
108 | 108 | ||
@@ -111,10 +111,10 @@ choo | |||
111 | tickets please chug tickets please choo choo | 111 | tickets please chug tickets please choo choo |
112 | chug choo | 112 | chug choo |
113 | chugga your ticket please choo | 113 | chugga your ticket please choo |
114 | chug | 114 | chug |
115 | choo | 115 | choo |
116 | choo | 116 | choo |
117 | your ticket please | 117 | your ticket please |
118 | END OF THE LINE | 118 | END OF THE LINE |
119 | Special case: increase remainder / move it back to divisor / increase quotient | 119 | Special case: increase remainder / move it back to divisor / increase quotient |
120 | 120 | ||
@@ -124,12 +124,12 @@ choo choo | |||
124 | choo choo | 124 | choo choo |
125 | choo choo | 125 | choo choo |
126 | choo choo | 126 | choo choo |
127 | chugga | 127 | chugga |
128 | END OF THE LINE | 128 | END OF THE LINE |
129 | Decrease dividend | 129 | Decrease dividend |
130 | 130 | ||
131 | ALL ABOARD | 131 | ALL ABOARD |
132 | your ticket please | 132 | your ticket please |
133 | END OF THE LINE | 133 | END OF THE LINE |
134 | End division loop | 134 | End division loop |
135 | 135 | ||
@@ -138,18 +138,18 @@ choo | |||
138 | choo | 138 | choo |
139 | tickets please choo choo | 139 | tickets please choo choo |
140 | chug choo | 140 | chug choo |
141 | chugga your ticket please | 141 | chugga your ticket please |
142 | END OF THE LINE | 142 | END OF THE LINE |
143 | Add remainder back to divisor to get a useful 13 | 143 | Add remainder back to divisor to get a useful 13 |
144 | 144 | ||
145 | ALL ABOARD | 145 | ALL ABOARD |
146 | choo | 146 | choo |
147 | tickets please | 147 | tickets please |
148 | END OF THE LINE | 148 | END OF THE LINE |
149 | Skip forward if quotient was 0 | 149 | Skip forward if quotient was 0 |
150 | 150 | ||
151 | ALL ABOARD | 151 | ALL ABOARD |
152 | chugga tickets please | 152 | chugga tickets please |
153 | END OF THE LINE | 153 | END OF THE LINE |
154 | Decrement quotient and skip forward if quotient was 1 | 154 | Decrement quotient and skip forward if quotient was 1 |
155 | 155 | ||
@@ -182,34 +182,34 @@ tickets please choo choo | |||
182 | choo choo | 182 | choo choo |
183 | chug choo | 183 | chug choo |
184 | choo | 184 | choo |
185 | chugga your ticket please | 185 | chugga your ticket please |
186 | END OF THE LINE | 186 | END OF THE LINE |
187 | Zero divisor and add 13 to copy if quotient was 0 | 187 | Zero divisor and add 13 to copy if quotient was 0 |
188 | 188 | ||
189 | ALL ABOARD | 189 | ALL ABOARD |
190 | your ticket please | 190 | your ticket please |
191 | END OF THE LINE | 191 | END OF THE LINE |
192 | End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) | 192 | End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) |
193 | 193 | ||
194 | ALL ABOARD | 194 | ALL ABOARD |
195 | choo choo | 195 | choo choo |
196 | tickets please chugga your ticket please | 196 | tickets please chugga your ticket please |
197 | END OF THE LINE | 197 | END OF THE LINE |
198 | Clear remainder from first division if second division was skipped | 198 | Clear remainder from first division if second division was skipped |
199 | 199 | ||
200 | ALL ABOARD | 200 | ALL ABOARD |
201 | choo choo | 201 | choo choo |
202 | click tickets please chugga your ticket please | 202 | click tickets please chugga your ticket please |
203 | END OF THE LINE | 203 | END OF THE LINE |
204 | Output ROT13ed character from copy and clear it | 204 | Output ROT13ed character from copy and clear it |
205 | 205 | ||
206 | ALL ABOARD | 206 | ALL ABOARD |
207 | choo choo | 207 | choo choo |
208 | chugga clack chug | 208 | chugga clack chug |
209 | END OF THE LINE | 209 | END OF THE LINE |
210 | Read next character | 210 | Read next character |
211 | 211 | ||
212 | ALL ABOARD | 212 | ALL ABOARD |
213 | your ticket please | 213 | your ticket please |
214 | END OF THE LINE | 214 | END OF THE LINE |
215 | End character reading loop | 215 | End character reading loop |
diff --git a/fucktrain.awk b/fucktrain.awk index 4ab5f5b..eda68ad 100755 --- a/fucktrain.awk +++ b/fucktrain.awk | |||
@@ -84,6 +84,9 @@ END { | |||
84 | } | 84 | } |
85 | } | 85 | } |
86 | print "" | 86 | print "" |
87 | if (boarded) { | ||
88 | print "END OF THE LINE" | ||
89 | } | ||
87 | } | 90 | } |
88 | 91 | ||
89 | 92 | ||