From e2508c5efb40973e94e7063cd5de68446b348273 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 6 May 2020 22:35:45 -0500 Subject: CHANGE SYNTAX --- README.md | 11 ++++++----- trainfuck | 51 +++++++++++++++++++++++++++------------------------ 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 ## LANGUAGE - trainfuck is not case-sensitive +- except for ALL ABOARD and END OF THE LINE - ignore everything before ALL ABOARD - ignore everything after END OF THE LINE - (this means you can comment between these) @@ -16,11 +17,11 @@ an esolang that transpiles to everyone's favorite esolange ``` bf tf -> chug -< chugga -+ choo -- choo choo -. click +> choo +< choo choo ++ chug +- chugga +. click OR clickety , clack [ tickets please ] your ticket please diff --git a/trainfuck b/trainfuck index 95adaad..0e35d9c 100755 --- a/trainfuck +++ b/trainfuck @@ -6,36 +6,38 @@ # # LANGUAGE # trainfuck is not case-sensitive +# -- except for ALL ABOARD and END OF THE LINE # ignore everything before ALL ABOARD # ignore everything after END OF THE LINE # (this means you can comment between these) # bf tf -# > chug -# < chugga -# + choo -# - choo choo -# . click +# + chug +# - chugga +# > choo +# < choo choo +# . click OR clickety # , clack # [ tickets please # ] your ticket please # syntax does NOT WRAP across line breaks # anything else is an error and DERAILS the train BEGIN { - aboard = false + aboard = 0 } -/^[Aa][Ll][Ll] [Aa][Bb][Oo][Aa][Rr][Dd]$/ { - aboard = true +/^ALL ABOARD$/ { + aboard = 1 next } -/^[Ee][Nn][Dd] [Oo][Ff] [Tt][Hh][Ee] [Ll][Ii][Nn][Ee]$/ { - aboard = false +/^END OF THE LINE$/ { + aboard = 0 next } aboard { - proc(toupper($0)) + gsub(/[[:space:]]/, "", $0) + print proc(toupper($0)) } END { @@ -55,29 +57,30 @@ function derail(err) function proc(t) { - if (! match(t, /CHUG|CHUGGA|CHOO|CLICK|CLACK|TICKETS PLEASE|YOUR TICKET PLEASE/)) { + if (! match(t, /CHUGGA|CHUG|CHOO|CLICK|CLICKETY|CLACK|TICKETSPLEASE|YOURTICKETPLEASE|$/)) { derail("WTF") } pre = substr(t, 1, RSTART - 1) tok = substr(t, RSTART, RLENGTH) pst = substr(t, RSTART + RLENGTH) - if (tok == "CHUG") { - tok = ">" - return (pre tok proc(pst)) - } - if (tok == "CHUGGA") { - tok = "<" + if (tok == "CHUGGA") { # needs to be first + tok = "-" return (pre tok proc(pst)) } - if (tok == "CHOO CHOO") { # have to do this one first - tok = "-" + if (tok == "CHUG") { + tok = "+" return (pre tok proc(pst)) } if (tok == "CHOO") { - tok = "+" + if (substr(pst, 1, 4) == "CHOO") { + tok = "<" + sub(/CHOO/, "", pst) + } else { + tok = ">" + } return (pre tok proc(pst)) } - if (tok == "CLICK") { + if (tok == "CLICK" || tok == "CLICKETY") { tok = "." return (pre tok proc(pst)) } @@ -85,11 +88,11 @@ function proc(t) tok = "," return (pre tok proc(pst)) } - if (tok == "TICKETS PLEASE") { + if (tok == "TICKETSPLEASE") { tok = "[" return (pre tok proc(pst)) } - if (tok == "YOUR TICKET PLEASE") { + if (tok == "YOURTICKETPLEASE") { tok = "]" return (pre tok proc(pst)) } -- cgit 1.4.1-21-gabe81