Skip to content
/ bfio Public

An interpreter and compiler for the Brainfuck esoteric programming language that also supports file IO.

License

Notifications You must be signed in to change notification settings

yasteen/bfio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brainfuck In and Out

This repository contains an interpreter and a compiler for an extended brainfuck interpreter that also supports file I/O.

The interpreter can be found in the interpreter directory, and the compiler can be found in the ccompiler directory.

As a recap, the standard brainfuck language follows this model (as referenced by Wikipedia): There is a program and an instruction pointer. There is also a 1D array of at least 30000 x 1 byte cells each initialized to the value 0. This array is accessed by a movable data pointer and two streams of bytes for input and output with ASCII character encoding.

the standard 8 language commands are as follows:

  • > Increments the data pointer to point to the next cell to the right
  • < Decrements the data pointer to point to the next cell to the left
  • + Increments the byte at the data pointer by 1
  • - Decrements the byte at the data pointer by 1
  • . Outputs the byte at the data pointer
  • , Accepts one byte of input, storing its value in the byte at the data pointer
  • [ If the byte at the data pointer is 0, then instead of moving the instruction pointer to the next command, it jumps forward to the command right after the matching ] command.
  • ] If the byte at the data pointer is NOT 0, then instead of moving the instruction pointer to the next command, it jumps backward to the command right after the matching [ command.

Now for the new file IO operations:

To open a file, we specify a path, length of path string (the path string must be less than 256 characters), and a byte for read/write info.

  • " Opens a file - only one file open at a time.
  • ' Closes the currently opened file
  • : Writes a byte to the file.
  • ; Reads a byte from the file, storing its value in the byte at the data pointer.

For example, with the following data cells:

  v
| 9 | 48 | 65 | 6C | 6C | 6F | 2E | 74 | 78 | 74 |
  ^

calling " would open a file called Hello.txt - the data pointer points at the length of the string.

About

An interpreter and compiler for the Brainfuck esoteric programming language that also supports file IO.

Resources

License

Stars

Watchers

Forks

Packages