Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (488)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  brainf*ck to java compiler and a turing complete brainf*ck interpreter. In java!  (Read 3220 times)
0 Members and 1 Guest are viewing this topic.
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Posted 2006-05-13 18:35:55 »

I was feeling a bit bored, so I wrote turing complete a brainf*ck interpreter, and an optimising brainf*ck-to-java compiler. Cheesy
Unfortunately, the compiler doesn't produce a turing complete program, as it limits the cell buffer to 30000 entries.

The compiler turns the following brainf*ck:

1  
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.


into this java code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
/**
 * Compiled by Brainf**kCompiler by Mojang Specifications
 */

public class Foo
{
    public static void main(String[] args) throws java.io.IOException
    {
        StringBuffer sb = new StringBuffer();
        int p = 0;
        byte[] b = new byte[30000];
       
        b[p]+=10;
        while(b[p]!=0)
        {
            b[++p]+=7;
            b[++p]+=10;
            b[++p]+=3;
            ++b[++p];
            --b[p-=4];
        }
        sb.append((char)(b[++p]+=2)).append((char)(++b[++p])).append((char)(b[p]+=7)).append((char)(b[p])).append((char)(b[p]+=3));
        sb.append((char)(b[++p]+=2)).append((char)(b[p-=2]+=15)).append((char)(b[++p])).append((char)(b[p]+=3)).append((char)(b[p]-=6));
        sb.append((char)(b[p]-=8)).append((char)(++b[++p])).append((char)(b[++p]));
        System.out.print(sb.toString());
    }
}


When that java program is run, or when the corresponding brainf*ck code is run through the interpreter, it spits out the following on standard out:

Quote
Hello World!

The compiled version runs about four-five times as fast with the output heavy "hello world" test program.


If the forums didn't censor the word "brainf**k" even in urls, you'd be able to click these two links to get the source code:
brainf**k compiler source code
brainf**k interpreter source code

.. but now you'll have to manually enter the urls into your browser if you want the source code. Undecided

Play Minecraft!
Offline woogley
« Reply #1 - Posted 2006-05-13 18:45:41 »

cool! nice job! Cheesy and I thought *I* had issues with boredom. geez. Tongue

for those too lazy to replace those *'s:

brainf**k compiler source code
brainf**k interpeter source code
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #2 - Posted 2006-05-13 18:47:22 »

saturday + red bull + supposed to be working on wurm = insane tangents. Wink

Thanks for the nicer links. :-)

Play Minecraft!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #3 - Posted 2006-05-13 18:56:58 »

woah, that brainf*k is the nerdiest thing i've ever seen  Grin


i'd use something like jflex lexer to do that job with less effort

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #4 - Posted 2006-05-13 18:58:28 »

Of course it could be done easier! That's pretty much the POINT of brainf**k. ;-)

Play Minecraft!
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #5 - Posted 2006-05-13 20:37:44 »

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>>>+++++.<+++++++.++++.-.+++++.----.---.-------.+++++++++.>>.

(on quakenet) Smiley

A pretty funky js bf interpreter (look at the source) can be found here:
http://www.hevanet.com/cristofd/brainf**k/di.html

弾幕 ☆ @mahonnaiseblog
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #6 - Posted 2006-05-13 20:47:26 »

I prefer Intercal myself (http://www.catb.org/~esr/intercal/)

Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #7 - Posted 2006-05-13 22:21:05 »

Ok, this took far too long, but:

Here's the source code for a java program
Here's the source code for a brainf**k program

The first file was generated by running the second file.
The second file was generated by running the first file.
(of course, I had to start by manually creating and running a variant of the first program)

It was really tricky to make a .java file contain its own source code, since the copy of the code also has to include itself to be a proper copy. But I did it!

Play Minecraft!
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #8 - Posted 2006-05-14 00:55:43 »

Markus you're the most leet haxor I've ever seen.  That is crazy.  Now my question is: have you ever encountered the malebolge language?

Quote
Malbolge was so difficult to understand when it arrived that it took two years for the first Malbolge program to appear. The program was not even written by a human being: it was generated by a beam search algorithm designed by Andrew Cooke and implemented in Lisp.
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #9 - Posted 2006-05-14 01:08:23 »

I'll take that as a compliment. Cheesy

And, whoa.. malebolge looks crazy! CRAAAZZZY!!!
*starts poking*

Play Minecraft!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #10 - Posted 2006-05-14 08:28:48 »

Malbolge: I was nodding away at the assembler type registers, thinking Ok, it's an assembler, that can't be that hard.  Then I read what the instructions did.   Shocked  I'm going to have nightmares about that!  It's not crazy, its 'fcarg', which is a new word I've invented, since none of the ones I can think of adequately express my feelings.  And no, I'm not about to try to code for it.  Life is too short.

Time flies like a bird. Fruit flies like a banana.
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #11 - Posted 2006-05-15 07:51:35 »

I wrote an interpreter, thinking it'd help me understand the language.. and.. well..
I understand the syntax, and what the different commands do, but I HAVE NO IDEA HOW TO WRITE PROGRAMS IN IT!! Argh!!

* Markus_Persson agrees with Alan_W

Play Minecraft!
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #12 - Posted 2006-05-15 12:03:27 »

Markus, this is truly incredible! Have you considered extending this to the Ook! programming language? http://en.wikipedia.org/wiki/Ook%21_programming_language

It's basically just brainf*ck, but offers major improvements in accessibility over other languages. Particularly for orangutans.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (68 views)
2014-08-11 02:49:23

BurntPizza (45 views)
2014-08-09 21:09:32

BurntPizza (36 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!