about summary refs log tree commit diff stats
path: root/trainfuck
diff options
context:
space:
mode:
authorCase Duckworth2020-05-06 21:51:15 -0500
committerCase Duckworth2020-05-06 21:51:15 -0500
commite7d9d69741b1b0976a829da4ba841326d855c4ca (patch)
treeec91d2d40ce874b01c602fe16f922d52a4d0deee /trainfuck
downloadtrainfuck-e7d9d69741b1b0976a829da4ba841326d855c4ca.tar.gz
trainfuck-e7d9d69741b1b0976a829da4ba841326d855c4ca.zip
INITIAL COMMIT
Diffstat (limited to 'trainfuck')
-rwxr-xr-xtrainfuck96
1 files changed, 96 insertions, 0 deletions
diff --git a/trainfuck b/trainfuck new file mode 100755 index 0000000..95adaad --- /dev/null +++ b/trainfuck
@@ -0,0 +1,96 @@
1#!/bin/awk -f
2# TRAINFUCK: CHOO CHOO MUTHAFUCKA
3# Author: Case Duckworth <acdw@acdw.net>
4# License: WTFPL
5# Version: #9
6#
7# LANGUAGE
8# trainfuck is not case-sensitive
9# ignore everything before ALL ABOARD
10# ignore everything after END OF THE LINE
11# (this means you can comment between these)
12# bf tf
13# > chug
14# < chugga
15# + choo
16# - choo choo
17# . click
18# , clack
19# [ tickets please
20# ] your ticket please
21# syntax does NOT WRAP across line breaks
22# anything else is an error and DERAILS the train
23BEGIN {
24 aboard = false
25}
26
27/^[Aa][Ll][Ll] [Aa][Bb][Oo][Aa][Rr][Dd]$/ {
28 aboard = true
29 next
30}
31
32/^[Ee][Nn][Dd] [Oo][Ff] [Tt][Hh][Ee] [Ll][Ii][Nn][Ee]$/ {
33 aboard = false
34 next
35}
36
37aboard {
38 proc(toupper($0))
39}
40
41END {
42 if (DERAIL_ERR) {
43 print DERAIL_ERR
44 exit 9
45 }
46}
47
48
49function derail(err)
50{
51 print "TRAIN DERAILED at input line", FNR
52 DERAIL_ERR = err
53 exit
54}
55
56function proc(t)
57{
58 if (! match(t, /CHUG|CHUGGA|CHOO|CLICK|CLACK|TICKETS PLEASE|YOUR TICKET PLEASE/)) {
59 derail("WTF")
60 }
61 pre = substr(t, 1, RSTART - 1)
62 tok = substr(t, RSTART, RLENGTH)
63 pst = substr(t, RSTART + RLENGTH)
64 if (tok == "CHUG") {
65 tok = ">"
66 return (pre tok proc(pst))
67 }
68 if (tok == "CHUGGA") {
69 tok = "<"
70 return (pre tok proc(pst))
71 }
72 if (tok == "CHOO CHOO") { # have to do this one first
73 tok = "-"
74 return (pre tok proc(pst))
75 }
76 if (tok == "CHOO") {
77 tok = "+"
78 return (pre tok proc(pst))
79 }
80 if (tok == "CLICK") {
81 tok = "."
82 return (pre tok proc(pst))
83 }
84 if (tok == "CLACK") {
85 tok = ","
86 return (pre tok proc(pst))
87 }
88 if (tok == "TICKETS PLEASE") {
89 tok = "["
90 return (pre tok proc(pst))
91 }
92 if (tok == "YOUR TICKET PLEASE") {
93 tok = "]"
94 return (pre tok proc(pst))
95 }
96}