FakeC

From Esolang
Jump to navigation Jump to search

FakeC is an esolang created by User:None1, it is a brainfuck equivalent. It is made to optimize brainfuck.

Commands

FakeC is brainfuck, but every command is replaced with a line of C code.

Commands in FakeC
brainfuck FakeC
(begin) #include<stdio.h>
char tape[1000000];
int p;
int main(){
+ ++tape[p];
- --tape[p];
, tape[p]=getchar();
. putchar(tape[p]);
> ++p;
< --p;
[ while(tape[p])
] }
(end) return 0;
}

Examples

Cat Program

#include<stdio.h>
char tape[1000000];
int p;
int main(){
tape[p]=getchar();
while(tape[p]){
putchar(tape[p]);
tape[p]=getchar();
}
return 0;
}

Hello World

#include<stdio.h>
char tape[1000000];
int p;
int main(){
++tape[p];
++tape[p];
++tape[p];
++tape[p];
++tape[p];
++tape[p];
++tape[p];
++tape[p];
while(tape[p]){
++p;
++tape[p];
++tape[p];
++tape[p];
++tape[p];
while(tape[p]){
++p;
++tape[p];
++tape[p];
++p;
++tape[p];
++tape[p];
++tape[p];
++p;
++tape[p];
++tape[p];
++tape[p];
++p;
++tape[p];
--p;
--p;
--p;
--p;
--tape[p];
}
++p;
++tape[p];
++p;
++tape[p];
++p;
--tape[p];
++p;
++p;
++tape[p];
while(tape[p]){
--p;
}
--p;
--tape[p];
}
++p;
++p;
putchar(tape[p]);
++p;
--tape[p];
--tape[p];
--tape[p];
putchar(tape[p]);
++tape[p];
++tape[p];
++tape[p];
++tape[p];
++tape[p];
++tape[p];
++tape[p];
putchar(tape[p]);
putchar(tape[p]);
++tape[p];
++tape[p];
++tape[p];
putchar(tape[p]);
++p;
++p;
putchar(tape[p]);
--p;
--tape[p];
putchar(tape[p]);
--p;
putchar(tape[p]);
++tape[p];
++tape[p];
++tape[p];
putchar(tape[p]);
--tape[p];
--tape[p];
--tape[p];
--tape[p];
--tape[p];
--tape[p];
putchar(tape[p]);
--tape[p];
--tape[p];
--tape[p];
--tape[p];
--tape[p];
--tape[p];
--tape[p];
--tape[p];
putchar(tape[p]);
++p;
++p;
++tape[p];
putchar(tape[p]);
++p;
++tape[p];
++tape[p];
putchar(tape[p]);
return 0;
}

Implementations

FakeC is unimplemented, but is easy to implement. However, since any FakeC program can also work on C, You can feed a FakeC program to a C compiler, and that will result in an executable equivalent to the original brainfuck program which runs faster than the original brainfuck program. (Note: If you add the -O2 parameter in GCC, it will optimize the code so that a bunch increments and decrements are executed once).

See also