AntimatterReactor / Suff

A brainfuck transpiler to C
The Unlicense
1 stars 0 forks source link

Not a "Fascist" interpreter, this is a newbiefuck interpreter #1

Closed rdebath closed 4 years ago

rdebath commented 4 years ago

See: https://esolangs.org/wiki/Newbiefuck

This program detects a "Newbiefuck" interpreter (it says "Hello World!" for BF)

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

And this is another program that only works with BF

+[>[<-[]>+[>+++>[+++++++++++>][>]-[<]>-]]++++++++++<]>
>>>>>----.<<+++.<-..+++.<-.>>>.<<.+++.------.>-.<<+.<.
rdebath commented 4 years ago

PS: https://gist.github.com/rdebath/c92c79160853f39ab9f72dfab724197d

AntimatterReactor commented 4 years ago

Right, I'll change that. And yes, I thought that jumps was the easiest and this happened

AntimatterReactor commented 4 years ago

Now the problem doesn't exist anymore, does it?

rdebath commented 4 years ago

Heh, yup that's one way round the problem. Of course you're supposed to run the code too :grin:

#!/usr/bin/ruby
eval 'm=Hash.new(p=0);'+ARGF.read.
    gsub(/[^\[\]+,-.<>]/,'').
    gsub(/\[\-\]\+*|\++|-+|>+|<+|./, Hash.new{|_, k|
        (k[0] == '+') ? "m[p]+="+k.length.to_s+";\n" :
        (k[0] == '-') ? "m[p]-="+k.length.to_s+";\n" :
        (k[0] == '>') ? "p+="+k.length.to_s+";\n" :
        (k[0] == '<') ? "p-="+k.length.to_s+";\n" :
        (k[0..3] == '[-]+') ? "m[p]="+(k.length-3).to_s+";\n" : "#{k}\n"
    }.merge({
        '>' => 'p+=1;',
        '<' => 'p-=1;',
        '+' => 'm[p]+=1;',
        '-' => 'm[p]-=1;',
        '[' => '(',
        ']' => ')while((m[p]&=255)!=0);',
        '.' => 'putc m[p];',
        ',' => 'm[p]=STDIN.getbyte if !STDIN.eof;',
        '[-]' => 'm[p]=0;',
        '#' => 'print "(p=",p,",m=",m,")\n";'
    }));