Science Fair Projects Ideas - THRAT

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

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.

Contents

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

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
,


  • 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

10-26-2009 08:16:03
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice