Giter Site home page Giter Site logo

bomb's Introduction

BOMB Interpreter

bomb's People

Watchers

Mts avatar

bomb's Issues

Nested loops are causing logical error

So, nested loops are causing some serious problems due to a silly flaw.
Whenever our interpreter reaches an opening bracket, it verifies whether the current index being pointed is false or true (0 or !0 basically) and iterates through its instructions in case of true, which is a good thing, that's exactly what Bomb is supposed to do, the problem is when it has to break or skip a loop. In theory, when reaching an opening bracket with the pointed index being false, Bomb should ignore all instructions after it until its closing bracket is found, but in the current state, Bomb is ignoring all instructions until the next closing bracket in the code is found:

++++++++++[>[[]++++++++++.]]<.
This code is supposed to do the following:

++++++++++[>[[]++++++++++.]]<.
1 - Add 10 to index 0 (which is basically a new line character)

++++++++++[>[[]++++++++++.]]<.
2 - Create a new loop (let's call it Geladeira, cuz why not?)

++++++++++[>[[]++++++++++.]]<.
3 - Point to index 1 (which is storing the number 0)

++++++++++[>[[]++++++++++.]]<.
4 - Ignore all these instructions because the current value is 0

++++++++++[>[[]++++++++++.]]<.
5 - Break the loop because the current value is 0

++++++++++[>[[]++++++++++.]]<.
6 - Point to index #0 and print its content (new line :D)

So, in step number 4 the interpreter ignores all instructions until the Geladeiras closing bracket is found, because Geladeira is the loop being executed at the moment.

Well, when running the same code on Bomb this is what we get:

++++++++++[>[[]++++++++++.]]<.
1 - Add 10 to index 0

++++++++++[>[[]++++++++++.]]<.
2 - Create a new loop (aka Geladeira)

++++++++++[>[[]++++++++++.]]<.
3 - Point to the next index (which is storing the number 0)

++++++++++[>[[]++++++++++.]]<.
4 - Ignore these opening brackets (for the sake of this example we're gonna call the first one Gengibre and the second one Gelatina)

++++++++++[>[[]++++++++++.]]<.
5 - Add 10 to the current index (1) and print its content (new line)

++++++++++[>[[]++++++++++.]]<.
6 - Check if the current value is true (Yeah it is, because it's 10 and not 0) and go back to the beginning of the current loop (aka Geladeira)

And now we have an infinite (K, not exactly infinite since our interpreter has a finite number of indexes, but you got it) loop that repeats steps 3, 4, 5 and 6.

All it had to do is to print one single new line character ;-;

So, in case i haven't made it clear yet, our interpreter was supposed to jump to Geladeira's closing bracket in step 4 instead of jumping to Gelatina's closing bracket.

Anyways, here's a solution to this problem (I don't think it's the best one tho): A var used to count how many opening brackets were found before finding a closing bracket.

TL;DR

// Jump to the next closing bracket
while (currChar != ']') {
currChar = fgetc(fp);
}

I wrote this dumb piece of code and we've gotta change it because Bomb's not supposed to jump to the next closing bracket. ;-;

Repeat loops taken too seriously

Our interpreter ends the Brainfuck code execution when it reachs the EOF, but it only happens while not in a loop and this is not good. D:

A simple Brainfuck code like ,>,< [>.< could be a problem since it ends before closing that bracket, gotta fix this. ๐Ÿ˜›

We have to make it to stop running as soon as it finds the EOF, no matter what.

File verification

BOMB is not verifying if the given Brainfuck code directory exists before trying to read it.

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.