-
-
Save Snigelson/8133664 to your computer and use it in GitHub Desktop.
Brainf*ck compiler with example file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Convert brainf*ck to c and compile. Works astonishingly well. | |
# Usage: $0 < file.bf | |
sed '1imain(){char*m=calloc(30000,1); | |
s|[^][+><.,-]||g | |
s|]|}|g | |
s|\[|while(*m){|g | |
s|+|(*m)++;|g | |
s|-|(*m)--;|g | |
s|>|m++;|g | |
s|<|m--;|g | |
s|\.|putchar(*m);|g | |
s|,|*m=getchar();|g | |
$a}'|gcc -xc -O2 - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>>>+>+++>+++>>>>>+++[ | |
>,+>++++[>++++<-]>[<<[-[->]]>[<]>-]<<[ | |
>+>+>>+>+[<<<<]<+>>[+<]<[>]>+[[>>>]>>+[<<<<]>-]+<+>>>-[ | |
<<+[>]>>+<<<+<+<--------[ | |
<<-<<+[>]>+<<-<<-[ | |
<<<+<-[>>]<-<-<<<-<----[ | |
<<<->>>>+<-[ | |
<<<+[>]>+<<+<-<-[ | |
<<+<-<+[>>]<+<<<<+<-[ | |
<<-[>]>>-<<<-<-<-[ | |
<<<+<-[>>]<+<<<+<+<-[ | |
<<<<+[>]<-<<-[ | |
<<+[>]>>-<<<<-<-[ | |
>>>>>+<-<<<+<-[ | |
>>+<<-[ | |
<<-<-[>]>+<<-<-<-[ | |
<<+<+[>]<+<+<-[ | |
>>-<-<-[ | |
<<-[>]<+<++++[<-------->-]++<[ | |
<<+[>]>>-<-<<<<-[ | |
<<-<<->>>>-[ | |
<<<<+[>]>+<<<<-[ | |
<<+<<-[>>]<+<<<<<-[ | |
>>>>-<<<-<- | |
]]]]]]]]]]]]]]]]]]]]]]>[>[[[<<<<]>+>>[>>>>>]<-]<]>>>+>>>>>>>+>]< | |
]<[-]<<<<<<<++<+++<+++[ | |
[>]>>>>>>++++++++[<<++++>++++++>-]<-<<[-[<+>>.<-]]<<<<[ | |
-[-[>+<-]>]>>>>>[.[>]]<<[<+>-]>>>[<<++[<+>--]>>-] | |
<<[->+<[<++>-]]<<<[<+>-]<<<< | |
]>>+>>>--[<+>---]<.>>[[-]<<]< | |
] | |
[Enter a number using ()-./0123456789abcdef and space, and hit return. | |
Daniel B Cristofani (cristofdathevanetdotcom) | |
http://www.hevanet.com/cristofd/brainfuck/] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment