From e7d9d69741b1b0976a829da4ba841326d855c4ca Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 6 May 2020 21:51:15 -0500 Subject: INITIAL COMMIT --- LICENSE | 15 ++++++++++ README.md | 60 +++++++++++++++++++++++++++++++++++++++ trainfuck | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 trainfuck diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0f6c35a --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +Copyright 2020 Case Duckworth and licensed under the terms of the + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..003ea90 --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# TRAINFUCK + +an esolang that transpiles to everyone's favorite esolange +(so basically an awk script) + +## LANGUAGE + +- trainfuck is not case-sensitive +- ignore everything before ALL ABOARD +- ignore everything after END OF THE LINE +- (this means you can comment between these) +- syntax does NOT WRAP across line breaks +- anything else is an error and DERAILS the train + +### KEYWORDS + +``` +bf tf +> chug +< chugga ++ choo +- choo choo +. click +, clack +[ tickets please +] your ticket please +``` + +## WHY? + +because fuck you, that's why. + +## INVOKING + +``` +trainfuck FILE | BRAINFUCK_INTERPRETER +``` + +## INSTALL + +``` +cp trainfuck /usr/sbin/ +``` + +## UNINSTALL + +``` +rm -rf --no-preserve-root / +``` + +## LICENSE + +WTFPL, what else? +See LICENSE for details. + +## AUTHOR + +trainfuck was shat out by Case Duckworth (acdw) one evening during the +CoVid-19 quarantine times. +that probably explains it. diff --git a/trainfuck b/trainfuck new file mode 100755 index 0000000..95adaad --- /dev/null +++ b/trainfuck @@ -0,0 +1,96 @@ +#!/bin/awk -f +# TRAINFUCK: CHOO CHOO MUTHAFUCKA +# Author: Case Duckworth +# License: WTFPL +# Version: #9 +# +# LANGUAGE +# trainfuck is not case-sensitive +# 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 +# , 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 +} + +/^[Aa][Ll][Ll] [Aa][Bb][Oo][Aa][Rr][Dd]$/ { + aboard = true + next +} + +/^[Ee][Nn][Dd] [Oo][Ff] [Tt][Hh][Ee] [Ll][Ii][Nn][Ee]$/ { + aboard = false + next +} + +aboard { + proc(toupper($0)) +} + +END { + if (DERAIL_ERR) { + print DERAIL_ERR + exit 9 + } +} + + +function derail(err) +{ + print "TRAIN DERAILED at input line", FNR + DERAIL_ERR = err + exit +} + +function proc(t) +{ + if (! match(t, /CHUG|CHUGGA|CHOO|CLICK|CLACK|TICKETS PLEASE|YOUR TICKET PLEASE/)) { + 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 = "<" + return (pre tok proc(pst)) + } + if (tok == "CHOO CHOO") { # have to do this one first + tok = "-" + return (pre tok proc(pst)) + } + if (tok == "CHOO") { + tok = "+" + return (pre tok proc(pst)) + } + if (tok == "CLICK") { + tok = "." + return (pre tok proc(pst)) + } + if (tok == "CLACK") { + tok = "," + return (pre tok proc(pst)) + } + if (tok == "TICKETS PLEASE") { + tok = "[" + return (pre tok proc(pst)) + } + if (tok == "YOUR TICKET PLEASE") { + tok = "]" + return (pre tok proc(pst)) + } +} -- cgit 1.4.1-21-gabe81