THRAT is an esoteric programming language written by Matthew Varga (2004). THRAT is based on brainfuck's instruction set and uses only two tokens to access entries in a table of 10 opcodes. The programmer can only move the table pointer forward and select entries within the table.
Like brainfuck, you are given a memory block in which you can do whatever you please. The default memory block size in THRAT is 4096 bytes, and the set minimum is 1024 bytes. More memory can be allocated by using an interpreter/compiler flag. You are given a single implicit pointer set the beginning of a memory block which has been initialized to zero. Moving out of the bounds of the block has an undefined effect on the program's execution.
| ID
| Instruction | brainfuck
|
| 0
| Halt Program Execution | Not Defined
|
| 1
| Increase Pointer Value | +
|
| 2
| Decrease Pointer Value | -
|
| 3
| Increase Pointer Position | >
|
| 4
| Decrease Pointer Position | <
|
| 5
| Begin While Loop | [
|
| 6
| End While Loop | ]
|
| 7
| Output pointer's value as integer | Not Defined
|
| 8
| Output pointer's value as ASCII | .
|
| 9
| Input a single byte and store at pointer's position | ,
|
Note: The table wraps around. So when the IP (instruction pointer) reaches the end it will jump back to element zero.
Prints 'Hi' In THRAT
-
#!/usr/bin/perl
%c=('+'=>1,'-'=>2,'>'=>3,'<'=>4,'*'=>6,'.'=>8,','=>9);$n=10;$p=0;
while(<>){for(split '' ){if(exists $c{$_}){$o=$c{$_};$d=$o-$p;if($d<0)
{$d+=$n;}print';'x$d;print':';$p=$o;}}}
Usage is very simple and unixy:
./bf2thrat.pl foo.bf > foo.thr