about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2020-05-06 22:35:45 -0500
committerCase Duckworth2020-05-06 22:35:45 -0500
commite2508c5efb40973e94e7063cd5de68446b348273 (patch)
tree4eacf2fba3d79036a4fd8608275d47214676d9f9
parentINITIAL COMMIT (diff)
downloadtrainfuck-e2508c5efb40973e94e7063cd5de68446b348273.tar.gz
trainfuck-e2508c5efb40973e94e7063cd5de68446b348273.zip
CHANGE SYNTAX
-rw-r--r--README.md11
-rwxr-xr-xtrainfuck51
2 files changed, 33 insertions, 29 deletions
diff --git a/README.md b/README.md index 003ea90..957af04 100644 --- a/README.md +++ b/README.md
@@ -6,6 +6,7 @@ an esolang that transpiles to everyone's favorite esolange
6## LANGUAGE 6## LANGUAGE
7 7
8- trainfuck is not case-sensitive 8- trainfuck is not case-sensitive
9- except for ALL ABOARD and END OF THE LINE
9- ignore everything before ALL ABOARD 10- ignore everything before ALL ABOARD
10- ignore everything after END OF THE LINE 11- ignore everything after END OF THE LINE
11- (this means you can comment between these) 12- (this means you can comment between these)
@@ -16,11 +17,11 @@ an esolang that transpiles to everyone's favorite esolange
16 17
17``` 18```
18bf tf 19bf tf
19> chug 20> choo
20< chugga 21< choo choo
21+ choo 22+ chug
22- choo choo 23- chugga
23. click 24. click OR clickety
24, clack 25, clack
25[ tickets please 26[ tickets please
26] your ticket please 27] your ticket please
diff --git a/trainfuck b/trainfuck index 95adaad..0e35d9c 100755 --- a/trainfuck +++ b/trainfuck
@@ -6,36 +6,38 @@
6# 6#
7# LANGUAGE 7# LANGUAGE
8# trainfuck is not case-sensitive 8# trainfuck is not case-sensitive
9# -- except for ALL ABOARD and END OF THE LINE
9# ignore everything before ALL ABOARD 10# ignore everything before ALL ABOARD
10# ignore everything after END OF THE LINE 11# ignore everything after END OF THE LINE
11# (this means you can comment between these) 12# (this means you can comment between these)
12# bf tf 13# bf tf
13# > chug 14# + chug
14# < chugga 15# - chugga
15# + choo 16# > choo
16# - choo choo 17# < choo choo
17# . click 18# . click OR clickety
18# , clack 19# , clack
19# [ tickets please 20# [ tickets please
20# ] your ticket please 21# ] your ticket please
21# syntax does NOT WRAP across line breaks 22# syntax does NOT WRAP across line breaks
22# anything else is an error and DERAILS the train 23# anything else is an error and DERAILS the train
23BEGIN { 24BEGIN {
24 aboard = false 25 aboard = 0
25} 26}
26 27
27/^[Aa][Ll][Ll] [Aa][Bb][Oo][Aa][Rr][Dd]$/ { 28/^ALL ABOARD$/ {
28 aboard = true 29 aboard = 1
29 next 30 next
30} 31}
31 32
32/^[Ee][Nn][Dd] [Oo][Ff] [Tt][Hh][Ee] [Ll][Ii][Nn][Ee]$/ { 33/^END OF THE LINE$/ {
33 aboard = false 34 aboard = 0
34 next 35 next
35} 36}
36 37
37aboard { 38aboard {
38 proc(toupper($0)) 39 gsub(/[[:space:]]/, "", $0)
40 print proc(toupper($0))
39} 41}
40 42
41END { 43END {
@@ -55,29 +57,30 @@ function derail(err)
55 57
56function proc(t) 58function proc(t)
57{ 59{
58 if (! match(t, /CHUG|CHUGGA|CHOO|CLICK|CLACK|TICKETS PLEASE|YOUR TICKET PLEASE/)) { 60 if (! match(t, /CHUGGA|CHUG|CHOO|CLICK|CLICKETY|CLACK|TICKETSPLEASE|YOURTICKETPLEASE|$/)) {
59 derail("WTF") 61 derail("WTF")
60 } 62 }
61 pre = substr(t, 1, RSTART - 1) 63 pre = substr(t, 1, RSTART - 1)
62 tok = substr(t, RSTART, RLENGTH) 64 tok = substr(t, RSTART, RLENGTH)
63 pst = substr(t, RSTART + RLENGTH) 65 pst = substr(t, RSTART + RLENGTH)
64 if (tok == "CHUG") { 66 if (tok == "CHUGGA") { # needs to be first
65 tok = ">" 67 tok = "-"
66 return (pre tok proc(pst))
67 }
68 if (tok == "CHUGGA") {
69 tok = "<"
70 return (pre tok proc(pst)) 68 return (pre tok proc(pst))
71 } 69 }
72 if (tok == "CHOO CHOO") { # have to do this one first 70 if (tok == "CHUG") {
73 tok = "-" 71 tok = "+"
74 return (pre tok proc(pst)) 72 return (pre tok proc(pst))
75 } 73 }
76 if (tok == "CHOO") { 74 if (tok == "CHOO") {
77 tok = "+" 75 if (substr(pst, 1, 4) == "CHOO") {
76 tok = "<"
77 sub(/CHOO/, "", pst)
78 } else {
79 tok = ">"
80 }
78 return (pre tok proc(pst)) 81 return (pre tok proc(pst))
79 } 82 }
80 if (tok == "CLICK") { 83 if (tok == "CLICK" || tok == "CLICKETY") {
81 tok = "." 84 tok = "."
82 return (pre tok proc(pst)) 85 return (pre tok proc(pst))
83 } 86 }
@@ -85,11 +88,11 @@ function proc(t)
85 tok = "," 88 tok = ","
86 return (pre tok proc(pst)) 89 return (pre tok proc(pst))
87 } 90 }
88 if (tok == "TICKETS PLEASE") { 91 if (tok == "TICKETSPLEASE") {
89 tok = "[" 92 tok = "["
90 return (pre tok proc(pst)) 93 return (pre tok proc(pst))
91 } 94 }
92 if (tok == "YOUR TICKET PLEASE") { 95 if (tok == "YOURTICKETPLEASE") {
93 tok = "]" 96 tok = "]"
94 return (pre tok proc(pst)) 97 return (pre tok proc(pst))
95 } 98 }