arthaud / c2bf Goto Github PK
View Code? Open in Web Editor NEWCompiler from C to brainfuck
License: GNU General Public License v2.0
Compiler from C to brainfuck
License: GNU General Public License v2.0
but i think it can be finished at all
I'm trying to compile the following code
int writeNum = 1; // support for boolean?
int fizz[] = "fizz";
int buzz[] = "buzz";
// copied from tests/string.c
void write_string(int[] s) {
int i = 0;
while(s[i] != 0) {
write_char(s[i]);
i = i + 1;
}
}
// written myself
void write_number(int n) {
if (n < 0) {
write_char('-');
n = -1 * n; // support for negative numbers? support for multiplication?
}
while (n != 0) { // until n is 0
int c = n % 10; // get least significant digit, support for modulo?
write_char('0' + c); // write it
n = n - c; // and divide by 10 for the next round
n = n / 10; // support for division?
}
}
// for each number 0 to 100 inclusive:
// If number is divisible by 5 write "buzz"
// If number is divisible by 3 write "fizz"
// If number is divislbe by 3 or 5 write "fizzbuzz"
// otherwise write the number.
//
// for (int i = 0; i <= 100; i++)
// syntax copied from tests/for.c
// WTF, that is not C.
for(int i = 0; , i < 101, i = i + 1;) {
writeNum = 1; // assume number should be printed
if (i % 5 == 0) { // if divisible by 5?
writeNum = 0;
write_string(buzz);
}
if (i % 3 == 0) { // (also) divisibile by 3?
writeNum = 0;
write_string(fizz);
}
// if neither, print the number itself
if (writeNum == 1) {
write_number(i);
}
write_char('\n');
}
This however results in a rather unhelpful error message:
Fatal error: Exception failure("Lexing: empty token")
The documentation of what is and isn't supported is rather lacking.
I plan to use this for a CETI project. In case aliens respond in 20 000 years or so in brainfuck it might be because of you.
I'll make sure to include reference, credits, thanks at .../MatthiasLiszt/cosmicDew but for now I gotta test your compiler.
when I do make build as in the instruction, the top is the output.
I'm running one of the example C files, and it continually returns a Syntax Error. Any help?
I'm trying to convert following code:
#include <stdio.h>
#include <stdlib.h>
static const int SIZE = 15;
static int* board;
static int count = 0;
int main()
{
board = malloc(SIZE * sizeof(*board));
nQueens(0);
printf("%d", count);
free(board);
return 0;
}
void nQueens(int row)
{
for(int i=0; i<SIZE; i++)
{
for(int j=0;j<row;j++)
{
if(board[j] == i || row - j == abs(i - board[j]))
{
goto OUTER;
}
}
board[row] = i;
if(row >= SIZE - 1)
{
++count;
return;
}
nQueens(row + 1);
OUTER:
;
}
}
and getting error Fatal error: exception Failure("lexing: empty token")
without any useful description
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.