GithubHelp home page GithubHelp logo

arthaud / c2bf Goto Github PK

View Code? Open in Web Editor NEW
212.0 212.0 12.0 42 KB

Compiler from C to brainfuck

License: GNU General Public License v2.0

C 4.97% OCaml 91.44% Shell 0.99% Makefile 0.18% Standard ML 2.41%

c2bf's People

Contributors

arthaud avatar omerien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

c2bf's Issues

vague error message ''lexing: empty token"

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.

thank you

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.

Erro while converting

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.