Brainfuck is an esoteric programming language. Its notation is extremely minimalism. This language use only eight single character as command and a instruction pointer.
Why was this language created?
In 1993, young computer programmer named “Urban Müller”
set out to make the smallest possible compiler, because smaller the compiler lesser time and energy it takes for the
machine to respond.
In the end, he came up with “Brainfuck” a new programming language
whose compiler uses only 240 bytes of memory making it around 11,000 time smaller
than C++ compiler.
However, making such a smaller compiler, Muller has sacrificed
practically.
In Brainfuck, you can only use eight command have single character:
Character
|
Meaning
|
>
|
increment the data pointer (to
point to the next cell to the right). |
<
|
decrement the data pointer (to
point to the next cell to the left). |
+ |
increment (increase by one) the
byte at the data pointer. |
- |
decrement (decrease by one) the
byte at the data pointer. |
. |
output the byte at the data
pointer. |
, |
accept one byte of input,
storing its value in the byte at the data pointer. |
[ |
if the byte at the data pointer
is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command. |
] |
if the byte at the data pointer
is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command. |
That it.
Can you imagine yourself writing codes with this language?
Now you can relate why the name of this language is brainfuck. The language
stick to its name. We should give credit to the founder giving this incredible
name.
So,
basically how it works?
This language work on ASCII code. You have to code in such a
way the you get the ASCII value of the character you want to print.
Example: You want to print “A”
1.
++++++++++++…. +++ [65 time (each “+” add a [0]=i++]
2.
. (“.” to print the “A”)
Its works on shifting operation it has an array who’s
default value is “zero”.
So here what happens is when the array get the value 65 and
print command is executed then the compiler will look for who’s ASCII value is 65
and show the output when it get it.
>: move to next array index in right
Now, let to do a program which all programmer do when they starting
learning a new language print “Hello
world!”
The code for the program is:
++++++++++[>+++++++>++++++++++>+++>+<<<<->++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.
To better understand the step, click on this LINK.
For more understanding the concept.
Related link: Stack-overflow
Comments
Post a Comment