Coder Profile - Show off your skills, get a coder profile.
 
 
 
thetrojan01's brainfuck tutorial - from the beginning to the interpreter.
Programming
Hello dear readers!
In this tutorial, I'll try to teach you the brainfuck language with simple words. After that, things will go more advanced.
If you are a n00b, all you have to do is sit on your chair and start reading. If you are more advanced or you know brainfuck, check for any mistakes.

1.1 What's brainfuck?

brainfuck -note that 'b' is in lowercase-, also known as brainf*ck, brainfsck or bf (in short), is an esoteric programming language and it's extreeme minimalistic. brainfuck is created by Urban Müller in 1993 with the intention of designing a language which could be implemented with the smallest possible compiler. Urban Müller managed to make his compiler for Amiga OS 240 bytes big! Then, some implemetions (Though he improved upon this later -- he informed me at one point that he had managed to bring it under 200 bytes).

1.2 Do I need it?

You don't really need it... It's good to make very small programs, by using a small compiler. Also, when using interpreter, may your programs be cross-platform


1.3 How strong will my programs be?

* Well, first of all, I must remind you that brainfuck is designed to be small. That means, no functions, no calling API etc.
* However, brainfuck doesn't have variables... How do you hold values? That's for later...

1.4 Ok. I am ready to start learning. What Do I need?

Simply: NOTHING!
Even just paper and pencil is nice... ok ok ok For passing the program to your computer you need an interpreter or a compiler (I'd prefer an interpreter) and a text editor. Even notepad / nano or sth like that is nice!
You also need a keyboard!


OK that was the big theory... now let's move on the practical part!

Well, why is brainfuck so difficult to be used? That's why brainfuck has just 8 commands, and they are all single ascii characters...
well, that's not even assembly!

Also, brainfuck has a pointer, that's called -so simply- 'the pointer', which is free to move arround within an array of 30000 bytes. The pointer is initialized to point to the beginning of the array and the 30000 bytes are all initialized to 0 (zero).

Well, time to see the commands:


____
CODE: commands Copy / Restore  ::  Remove Scroll Bars
  1. ________________________________________________________________________
  2. COMMAND FUNCTION
  3. ===========================================================
  4. > Moves the pointer one step to the right of the array. That means that increases the byte pointer.
  5. < Moves the pointer one step to the left of the array. That means that decreases the byte pointer.
  6. + Increases by one the pointed byte.
  7. - Decrease by one the pointed byte.
  8. . Output the value of the byte at the pointer.
  9. , Waits for one byte (one character) to be input and then stores its value in the pointed byte
  10. [ Jumps foreword to the matching ']' unless the pointed byte is zero (0)
  11. ] Jumps back to the matching '[' Unless the pointed byte is zero (0)
  12. ____________________________________________________________________________
Also, notice that this program:
CODE: addition Copy / Restore  ::  Remove Scroll Bars
  1. + Adds 1
  2. + Adds 1 to 1
  3. + Adds 1 to 2
  4. + Adds 1 to 3
  5. + Adds 1 to 4
  6. + Adds 1 to 5
  7. ++- Adds 1 the 6 and then subtracts 1 from 8; outputs EOF (NOTE THAT I DIDN'T USE COMMMAS IN 'COMMENTS'
  8. THAT'S BECAUSE IF I USE COMMA; THE COMPILER / INTERPRETER WILL CATCH IT! :P
Could be written as well:
CODE: addition2 Copy / Restore  ::  Remove Scroll Bars
  1. ++++++++-.
Remember: the values which are stored in the array, they are single characters. When output, they're shown as explained in ASCII table (scroll down to see it when you finish the tutorial)

Now, you've learned much about brainfuck. Much enough to make programs! You don't need Me to tell You how to do special things, just like division... Find out yourself! (Even if there's in the links
)

Guys who are new in programming can stop reading here

The next part says how to write an interpreter for brainfuck, and may be useless to you!

YOU CAN ALSO SCROLL DOWN TO SEE THE LINKS AND COMMENT THE TUTORIAL!

________________________________________________________________________________
_

3.0

Well, you want to make a brainfuck interpreter and don't know how to start? That's very simple. Read the tutorial!

How did I start? By telling you that there's a byte array with 30000 places and a byte pointer. In C/C++, you can do
CODE: array Copy / Restore  ::  Remove Scroll Bars
  1.  
  2. char array[30000];
  3. char *ptr;
After that, you need file i/o to read the source files. On the continue, you may want to process every readed character. It's

simple. Just read the tutorial. The description each command says exactly what you have to do
. You may want to pass all

the commands in an array and then do you job! (that's more easy for '[' and ']' commands if you don't know good file i/o for

the language in which you are programming the interpreter, but you have limited space of commands).

Well, that's all!
________________________________________________________________________________
_

0xFFFFFFFF

Well, here are some good links:

Wikipedia article for brainfsck
http://www.muppetlabs.com/~breadbox/bf/
Uranium-239 has brainfuck stuff in his site
Search Rohitab Forums for brainfuck stuff

Also, you can't miss the ASCII Table:

ASCII Table (click_here)

another table:

part1
part2
______________________

remember: Think simply.

thetrojan01


Posted By thetrojan01
Please login to rate coding articles.

Click here to register a free account with us.
Attached Image
Comments
Please login to post comments.
Page 1 of 1
More Articles By This Author
thetrojan01's brainfuck tutorial - from the beginning to the interpreter.
Recently Posted "Programming" Articles
thetrojan01's brainfuck tutorial - from the beginning to the interpreter.
My Experiences So Far with Languages
Selecting Your First Programming Language
[PHP] - Lets kill the complex IF
Basic PortScanner in VB6.0
N-Queens-Series Part I (Only the fittest survive)
Currying in JavaScript: Fun for the Whole Family!
[PHP] Create A Unique Page Hits Counter
Actionscript Events
Actionscript API
Recently Rated "Programming" Articles
thetrojan01's brainfuck tutorial - from the beginning to the interpreter.
[PHP] - Lets kill the complex IF
Actionscript API
Actionscript Events
My Experiences So Far with Languages
Selecting Your First Programming Language
Vectors in C++
[C++] Templates
Quick Threading Tutorial - C++
Intorduction to memoization.
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (1)
Hardware (1)
Internet & Web Sites (3)
Life In General (2)
Networking (1)
Operating Systems (4)
Other (2)
Programming (46)
Security (8)
Software Development (5)
Web Development (14)
search Search Inside
Programming
 
 
Latest News About Coder Profile
Coder Profile Poll
Why do you get bored with programming?

Not enough time to do something productive
I run out of ideas
Too hard to show people my creations
Everything i do has too many errors, and it's too hard
I don't get bored!!!


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.20 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved