Code Monkey home page Code Monkey logo

brainfuck-interpreter's People

Contributors

cboin avatar irevoire avatar

Watchers

 avatar  avatar  avatar

Forkers

irevoire

brainfuck-interpreter's Issues

Hello world fails

This should print "Hello World!" and a newline.

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

You are not a fascist aren’t you?

If you want to be able to run program like that:

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

You need to handle negative cells which you don’t currently:

t = (unsigned char *) malloc(buflen * sizeof(unsigned char));
if (t == NULL)
handle_error("malloc");
bzero(t, buflen);
ptr = t;

I guess an easy fix would be to move the starting pointer to the middle of the allocated memory so the brainfuck program would be able to go either to the left or to the right:

// ptr = t;
ptr = t + (buflen / 2);

Also the fascist appellation for this kind of interpreter come from here: http://www.hevanet.com/cristofd/brainfuck/

Jumps are broken

case '[':
if (!*ptr)
while (buffer[i++] != ']');
break;
case ']':
if (*ptr)
while (buffer[i--] != '[');
break;

Theses two instructions should jump to the matching brackets, not just to the closest brackets.

On esolangs you can read this about theses two instructions:

Command Description
[ Jump past the matching ] if the cell under the pointer is 0
] Jump back to the matching [ if the cell under the pointer is nonzero

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.