Directory

Encyclopedia

NodeWorks
                              ENCYCLOPEDIA

Link Checker

Home
Encyclopedia : T : TH : THR :

THRAT

 

THRAT

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.

Technical description


THRAT uses two language instructions to reference and select entries in an op-table. The op-table is basically a list of Brainfuck instructions with two additional instructions, discussed later. The table pointer is controlled by incrementing the pointer's position and then selecting instructions from the table. There is no instruction to traverse backwards in the table so the only way to get to the beginning of the table is to traverse all the way to the end to where it wraps around to the first index. The semi-colon (;) is used to increment the pointer's position and the colon (:) is used the select the instruction being pointed to by the instruction pointer. Each instruction read from file is referenced with the instruction table and then the selected instruction is placed into an execution vector. Once all the instructions have been read in, referenced and pushed, the vector is executed much the same way Brainfuck's instructions are executed. When the program is first executed, the instruction pointer is set the beginning of 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 a 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

Instruction table

  • Increase instruction pointer's position: ;
  • Select instruction: :

    Note: The table wraps around. So when the IP (instruction pointer) reaches the end it will jump back to element zero.

    Sample code


    Here is a sample program that prints "Hi".

    Prints 'Hi' In THRAT --------------------- - :::::::::::::::::: ::::::::::::::::::::: ::::::::::::::::::::: :::::::::::;;;;;;;:;; ;; - ;;;;;;;;::::::::: ::::::::::::::::::::: ::::::::::::::::::::: ::::::::::::::::::::: ::::::::::::::::::::: ::::::::::::;;;;;;;:

    Converting Brainfuck to THRAT


    Here is a simple Perl script to convert Brainfuck files to THRAT:

    #!/usr/bin/perl %c=('+'=>1,'-'=>2,'>'=>3,'<'=>4,'['=>5,']'=>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

    External links

  • Temporary Official THRAT page


  • NodeWorks boosts web surfing!
    Page Returned in 0.071 seconds - HTML Compressed 67.0%

    This article is from Wikipedia. All text is available
    under the terms of the GNU Free Documentation License.
     GNU Free Documentation License
    © 2008 Chamas Enterprises Inc.