lookharm / go-brainfuck

Brainfuck interpreter written in Go
MIT License
0 stars 1 forks source link

Input Handling Enhancement - Support Stream Input #2

Open lookharm opened 1 year ago

lookharm commented 1 year ago

Description: The current implementation of the Brainfuck interpreter code includes a TODO comment indicating that input handling should be modified to support a stream input. However, the code does not yet implement this feature.

Code:

// TODO: Input must be stream
var jumpTable [8]ExecuteFunction = [8]ExecuteFunction{
    // ...
}

Expected Behavior: The Brainfuck interpreter should be enhanced to accept a stream input, allowing for continuous or dynamic input rather than a static byte array. This would provide greater flexibility and usability in various scenarios where the input may change or come from a continuous stream source.

Proposed Solution: To implement stream input support in the Brainfuck interpreter, the following steps can be taken:

  1. Modify the Run function to accept a stream input parameter instead of a byte array. The input stream could be an io.Reader or any other suitable input stream interface.
  2. Update the relevant ExecuteFunction to read input from the stream instead of using a static byte array. This can be done by reading bytes from the input stream using appropriate methods provided by the io.Reader interface.
  3. Handle the end of the input stream gracefully, ensuring that the program does not panic or encounter unexpected behavior when reaching the end of the input stream.
alipashamontaseri commented 1 year ago

This issue is now resolved with this PR.