From Esolang
Jump to: navigation, search

Filth (a recursive acronym meaning Filth is [a] Lame Turing Hack) is a lame Turing hack. It is a concept esoteric programming language created by Brandon Zimmerman (User:Dev squid) in 2010, and is inspired by Befunge and Forth. It is based around a hypothetical stack machine (called a 'Filth Machine'). An interpreter was created by User:Madk in July 2010.


Filth is a language with somewhat of a personality; that is, it hates you, your mother, your future and/or existing posterity, your cat, and your guts. It forces you, the Filth programmer, to construct arithmetic and bitwise logic statements with only NOR logic. A healthy Filth Machine uses a Harvard architecture; that is, code and data are contained in two separate memory spaces. There is an additional stack called the 'command stack' which can be used to store commands for later execution. What makes Filth unique is that both command and data spaces are stack-based, allowing command-space code to be operated upon exactly like normal stack data. The Filth stacks are LIFO stacks. A Filth Machine's native word size is 8-bits wide; however, to simplify its design, the command stack is based on units of commands, not any particular length of data, much in the same way the base unit in Redcode is a line, not a specific unit of data like a byte. It should also be noted here that the actual code space is not a stack, but is a linear array of read-only instructions.


As the result of a syntactical indecision by the author, Filth can have one of two syntaxes: one with a mnemonic-and-operand syntax à la Assembly, and one with single-character operators à la Brainfuck. With the former, code structure is a bit more imposed, whereas with the latter, there are no syntactical rules and foreign characters are ignored, making it easier to write a parser for. For the sake of simplicity, only the latter syntax will be explained here.


_   - (nop) no operation.
XX  - (push) pushes the literal constant 'XX' (in hexadecimal format) or onto the data stack (note: any nonzero value is considered
      a Boolean value true). [push xx]
+   - (dup) duplicates the top byte on the data stack, pushing a copy of the top byte onto the data stack. [pop a, push a, push a]
:X  - (swap) swaps the top two units of size 'X' (numeral 1-9) bytes on the data stack; [pop a, pop b, push a, push b]
;X  - (conditional swap) pops a Boolean value, then swaps the top two units of size 'X' (numeral 1-9) bytes on the data stack if
      the Boolean value is true. [pop a, if a { pop b, pop c, push b, push c }]
$   - (del) discards the top byte from the data stack. [pop a]
@   - (rot) rotates the top three bytes on the data stack, shifting the third-to-last byte to the top of the stack and shifting the
      top two bytes on the data stack down. [pop a, pop b, pop c, push b, push a, push c]
~   - (nor) performs bitwise nor of the top two bytes on the data stack and pushes the result onto the data stack. [pop a, pop b,
      push (a nor b)]
!   - (absolute comp) compares the top two bytes on the data stack; if equal, push Boolean true onto the data stack, otherwise false.
      [pop a, pop b, push (a == b)]
?   - (relative comp) compares the top two bytes on the data stack; if the second-to-last byte is less than the last byte, push Bool-
      ean true onto the data stack, otherwise false. [pop a, pop b, push (b < a)]
/C  - (cmd push) pushes the command 'C' onto the command stack.
\X  - (cmd pop) pops the top X commands from the command stack and executes them. Executing a popped \X will result in strangeness.
-C  - (cmd do) executes the command 'C', but operates on the command stack rather than the data stack; valid operands are '+', ':',
      ';', 'x', '$', and '@'; any control Booleans are still pushed to and popped from the data stack.
*XX - (def label) defines a system variable XXX (three alphanumeric characters), holding the current place in the code stream.
^XX - (jump label) pops a Boolean value, then jumps to the defined label XXX (three alphanumeric characters) if the Boolean
      value is true. Base names are case-insensitive.
.   - (output) pop an ASCII value from the data stack and prints it to standard output. [pop a, stdout a]
,   - (input) waits for an ASCII value from standard input and pushes on onto the stack. [stdin a, push a]
#   - (terminate) terminates the program.
q   - (quine-ify) print 'q#'.

Computational Class

Currently, no tests have been conducted to test whether or not Filth is Turing-complete, and so will be considered non-computable until further research proves otherwise. Since stack machines and NOR logic can be proven to be Turing-complete, it can be hypothesized that Filth may be Turing-complete.




Hello World:




Reflect top three (abc becomes cba):


Reflect top four (abcd becomes dcba):


Swap top with fourth-from-top (abcd becomes dbca):


External resources

Download interpreter