arduino BF interpreter that I created!

Hello all!
This is my first post!
My name is Omri, and Im 16 years old.
A month ago I bought the Arduino Duemilanove.
I got a previews interest at BF language ,and saw the BrainDuino,
I decided to write my own interpreter (not based on others interpreters).
This is my first real arduino program(but not the first one…),
the program uses the eeprom the storage the commands,
and the serial monitor as i/o.
Here is the full code:

#include <EEPROM.h>

 int n = ???;                  //how meny memory cells you would like to use?
 unsigned char value[n];       //create n memory cells (you need to change "n" so it will be the same as int n)
 int i = 0;                    //data pointer
 char command;                 //storage the command from the eeprom
 int instruction_pointer = 0;  //instruction pointer
 boolean x = false;
 int y = 0;
 
 void setup()
 {
   do                //put the value zero in all of the memory cells
   {
   value[i] = 0;
   i++;
   }
   while(i < n);
   
   i = 0;
   
   Serial.begin(9600);
   
   Serial.print("hello");
   Serial.print("\n");

//-----------put your BF code into the arduino eeprom memory-------------------   
   EEPROM.write(0, '+');         //write brainfuck code to the arduinos eeprom
   EEPROM.write(1, '[');         //write brainfuck code to the arduinos eeprom
   EEPROM.write(2, ',');         //write brainfuck code to the arduinos eeprom
   EEPROM.write(3, '.');         //write brainfuck code to the arduinos eeprom
   EEPROM.write(4, ']');         //write brainfuck code to the arduinos eeprom
//-----------this is a "cat" example-------------------------------------------  
   
   Serial.print("the code:");
   Serial.print("\n");   
   
   command = EEPROM.read(i);
   while(command == '>' || command == '<' || command == '+' || command == '-' || command == ',' || command == '.' || command == '[' || command == ']')
   {
   command = EEPROM.read(i);
   Serial.print(command);
   i++;
   }
   
   i = 0;
   
   Serial.print("\n");
   Serial.print("start...");
   Serial.print("\n");
   Serial.print("user interface:");
   Serial.print("\n");
   Serial.print(">>");
   Serial.print("\n");
   
 }
 
 
 void loop()
 {
   
   command = EEPROM.read(instruction_pointer);        //read the command
   
    switch (command)                                  //cheack what command is it
    {
      
      case '>' :                     
       ++i;
       break;
       
//-------------------------------------------------------------       
    
      case '<':
       --i;
       break;
       
//-------------------------------------------------------------    
      
      case '+':
       ++value[i];
       break;  
       
//-------------------------------------------------------------      
     
      case '-':
       --value[i];
       break;   
       
//-------------------------------------------------------------            
    
      case '.':
      if(value[i] == 10)
       {
        Serial.println(">>");        //new line (10 at the ascii chart)
       }
      Serial.println(value[i]);
      break;  
      
//-------------------------------------------------------------   
   
      case ',':
      while(x == false)
      {
      if (Serial.available() > 0)   
        {
         value[i] = Serial.read();
         x = true;
         }  
       }
      x = false;
      break;  
      
 //------------------------------------------------------------       
   
      case '[':       if(value[i] == 0)
        {
          y = 1;
           while(y != 0)
           {
             ++instruction_pointer;
             command = EEPROM.read(instruction_pointer);
              if(command == '[')
               {
                y++;
               }
              else if(command == ']')
               {
                y--;
               }
            } 
        }
     
      break;
      
//-------------------------------------------------------------       
    
      case ']':
       if(value[i] != 0)
        {
          y = 1;
           while(y != 0)
           {
             --instruction_pointer;
             command = EEPROM.read(instruction_pointer);
              if(command == ']')
               {
                y++;
               }
              else if(command == '[')
               {
                y--;
               }
            } 
        }
      
      break;
      
//-------------------------------------------------------------        
  
  default:
      Serial.print("error:end of the progrem");    //didnt got a command
      return;

    }
    
   ++instruction_pointer;                         //next command
   
 }

I will be glad to get comments about it,
thanks,
Omri :slight_smile:

P.S.
for these who doesnt know what BF is:

http://www.muppetlabs.com/~breadbox/bf/

Very interesting. Any intended uses or just for fun?

Just for fun,BF is very hard to use.

By the way the Wikipedia value about BF is a great, I cant link it because the Yabb censored the word fuc*(k )

I wanted to do something like this but have the board demonstrate a Turning Machine in sand or something using this language.

Her is a cool Lego turing machine:

http://blog.makezine.com/archive/2009/01/the_lego_turing_machine.html

I believe that you could build something like that,using simple Lego and Arduino instead of the nxt controller.

From the thread title, I read it as a "boyfriend interpreter." It's been a couple years since I'd looked at Brainf*ck as a language, it is cute.

Yes, making a Turing machine with some kind of easy-to-see "tape" would be awesome. Maybe something along the lines of othello-chips on a conveyor-belt.