diff options
-rw-r--r-- | examples/helloworld.trainfuck | 31 | ||||
-rwxr-xr-x | trainfuck | 33 |
2 files changed, 35 insertions, 29 deletions
diff --git a/examples/helloworld.trainfuck b/examples/helloworld.trainfuck index da6baf8..1f68f11 100644 --- a/examples/helloworld.trainfuck +++ b/examples/helloworld.trainfuck | |||
@@ -1,16 +1,16 @@ | |||
1 | TRAINFUCK BABEEE | 1 | TRAINFUCK BABEEE |
2 | CHOO CHOO MUTHERFUCKER | 2 | CHOO CHOO MUTHERFUCKER |
3 | 3 | ||
4 | This example adapted from https://enclick wikipediaclick org/wiki/Brainfuck | 4 | This example adapted from https://en.wikipedia.org/wiki/Brainfuck |
5 | 5 | ||
6 | This program prints "Hello World!" and a newline to the screen, its | 6 | This program prints "Hello World!" and a newline to the screen, its |
7 | length is 106 active command charactersclick [It is not the shortestclick ] | 7 | length is 106 active command characters. |
8 | 8 | ||
9 | The program doesn't start until we have ALL ABOARD on a line by itself, so | 9 | The program doesn't start until we have ALL ABOARD on a line by itself, so |
10 | we've got one better than an initial comment loopclick | 10 | we've got one better than an initial comment loop. |
11 | 11 | ||
12 | This file was handwritten, but soon(TM) we'll have a fucktrain command, | 12 | This file was handwritten, but soon(TM) we'll have a fucktrain command, |
13 | that'll translate to trainfuck from brainfuckclick | 13 | that'll translate to trainfuck from brainfuck. |
14 | 14 | ||
15 | ALL ABOARD | 15 | ALL ABOARD |
16 | chug chug chug chug chug chug chug chug | 16 | chug chug chug chug chug chug chug chug |
@@ -150,26 +150,3 @@ ALL ABOARD | |||
150 | choo | 150 | choo |
151 | chug chug click | 151 | chug chug click |
152 | END OF THE LINE | 152 | END OF THE LINE |
153 | And finally a newline from Cell #6. | ||
154 | Of course, non-commented it's like this: | ||
155 | ALL ABOARD | ||
156 | tickets please chugga your ticket please choo choo | ||
157 | tickets please chugga your ticket please choo choo | ||
158 | tickets please chugga your ticket please choo choo | ||
159 | tickets please chugga your ticket please choo choo | ||
160 | tickets please chugga your ticket please choo choo | ||
161 | tickets please chugga your ticket please choo choo | ||
162 | END OF THE LINE | ||
163 | (first, you gotta zero out those cells) | ||
164 | ALL ABOARD | ||
165 | chug chug chug chug chug chug chug chug tickets please choo chug chug chug chug tickets please choo chug chug choo chug chug chug choo chug chug chug choo chug choo choo | ||
166 | choo choo | ||
167 | choo choo | ||
168 | choo choo | ||
169 | chugga your ticket please choo chug choo chug choo chugga choo | ||
170 | choo chug tickets please choo choo your ticket please choo choo chugga your ticket please choo | ||
171 | choo clickety choo chugga chugga chugga clickety chug chug chug chug chug chug chug clickety clickety chug chug chug clickety choo | ||
172 | choo clickety choo choo | ||
173 | chugga clickety choo choo clickety chug chug chug clickety chugga chugga chugga chugga chugga chugga clickety chugga chugga chugga chugga chugga chugga chugga chugga clickety choo | ||
174 | choo chug clickety choo chug chug clickety | ||
175 | END OF THE LINE | ||
diff --git a/trainfuck b/trainfuck index 6715987..602fc92 100755 --- a/trainfuck +++ b/trainfuck | |||
@@ -3,8 +3,11 @@ | |||
3 | # Author: Case Duckworth <acdw@acdw.net> | 3 | # Author: Case Duckworth <acdw@acdw.net> |
4 | # License: WTFPL | 4 | # License: WTFPL |
5 | # Version: #9 | 5 | # Version: #9 |
6 | # | 6 | |
7 | ### Commentary: | ||
8 | |||
7 | # LANGUAGE | 9 | # LANGUAGE |
10 | |||
8 | # trainfuck is not case-sensitive | 11 | # trainfuck is not case-sensitive |
9 | # -- except for ALL ABOARD and END OF THE LINE | 12 | # -- except for ALL ABOARD and END OF THE LINE |
10 | # ignore everything before ALL ABOARD | 13 | # ignore everything before ALL ABOARD |
@@ -21,11 +24,19 @@ | |||
21 | # ] your ticket please | 24 | # ] your ticket please |
22 | # syntax does NOT WRAP across line breaks | 25 | # syntax does NOT WRAP across line breaks |
23 | # anything else is an error and DERAILS the train | 26 | # anything else is an error and DERAILS the train |
27 | |||
28 | ### Code: | ||
24 | BEGIN { | 29 | BEGIN { |
25 | aboard = 0 | 30 | aboard = 0 |
31 | width = 30 | ||
32 | print "[" | ||
26 | } | 33 | } |
27 | 34 | ||
28 | /^ALL ABOARD$/ { | 35 | /^ALL ABOARD$/ { |
36 | if (! header) { | ||
37 | print "]" | ||
38 | } | ||
39 | header++ | ||
29 | aboard = 1 | 40 | aboard = 1 |
30 | next | 41 | next |
31 | } | 42 | } |
@@ -37,7 +48,16 @@ BEGIN { | |||
37 | 48 | ||
38 | aboard { | 49 | aboard { |
39 | gsub(/[[:space:]]/, "", $0) | 50 | gsub(/[[:space:]]/, "", $0) |
40 | print proc(toupper($0)) | 51 | buf = buf proc(toupper($0)) |
52 | } | ||
53 | |||
54 | ! aboard { | ||
55 | printbuf() | ||
56 | if (header) { | ||
57 | gsub(/[-+<>.,\[\]]/, "", $0) | ||
58 | } | ||
59 | |||
60 | buf = "" | ||
41 | } | 61 | } |
42 | 62 | ||
43 | END { | 63 | END { |
@@ -45,6 +65,8 @@ END { | |||
45 | print DERAIL_ERR | 65 | print DERAIL_ERR |
46 | exit 9 | 66 | exit 9 |
47 | } | 67 | } |
68 | printbuf() | ||
69 | printf "\n" | ||
48 | } | 70 | } |
49 | 71 | ||
50 | 72 | ||
@@ -55,6 +77,13 @@ function derail(err) | |||
55 | exit | 77 | exit |
56 | } | 78 | } |
57 | 79 | ||
80 | function printbuf(newline) | ||
81 | { | ||
82 | for (ss = 1; ss <= length(buf); ss += width) { | ||
83 | printf "%s\n", substr(buf, ss, width) | ||
84 | } | ||
85 | } | ||
86 | |||
58 | function proc(t) | 87 | function proc(t) |
59 | { | 88 | { |
60 | if (! match(t, /CHUGGA|CHUG|CHOO|CLICK|CLICKETY|CLACK|TICKETSPLEASE|YOURTICKETPLEASE|$/)) { | 89 | if (! match(t, /CHUGGA|CHUG|CHOO|CLICK|CLICKETY|CLACK|TICKETSPLEASE|YOURTICKETPLEASE|$/)) { |