An interpreter for the esoteric programming language - brainf*ck written in Python. The project includes a CLI, API (with the intention of building an online platform to execute brainfxck code), and a visualiser for the extremely convoluted language (in development).
To do:
- Draw sequence, architecture, and/or use-case diagrams.
- Code the interpreter (lexer, syntax analyser, parser). ✔
- Code the basic API (might still need to add some endpoints). ✔
- Design and code the front-end for the visualiser + online execution platform.
- Optimise the evaluation (Peephole optimisation).
-
token.py
- Token :: serves as a structure to store metadata such as line number, character number, operator data, etc.
-
lexer.py
- Lexer :: generates tokens and populates the brainfxck storage tape with these tokens.
-
parser.py
- Parser :: responsbile for parsing and interpreting the code; generating error messages and other information.
-
rules (refer https://gist.github.com/roachhd/dce54bec8ba55fb17d3a for a more exhaustive study of brainfxck)
- any arbitrary character besides the 8 listed below should be ignored and considered as comments.
- all the blocks on the memory tape are intialised with a zero and the tape pointer starts from the left-most position.
- loops may be nested as many times as one wants but every "[" must have a corresponding "]".
-
inforamation on brainfxck operators
- > :: moves memory pointer to the right of the current position.
- < :: moves memory pointer to the left of the current position.
- + :: increments the memory block value by one.
- - :: decrements the memory block value by one.
- [ :: like c while(cur_block_value != 0) loop.]
- ] :: if block currently pointed to's value is not zero, jump back to "[".
- , :: used to input a character.
- . :: used to output a character.
Follow the steps to run the web-app on your local machine:
-
Clone the repository
git clone https://github.com/chumba-wamba/brainfxck.git
-
Install the Dependencies
cd brainfxck pip install -r requirements.txt
-
Run the test.py file
cd python3 test.py
-
To use the API (Optional)
- Start the server
cd API uvicorn server:app --reload
- Open a browser
- Visit @http://localhost:8000/docs or @http://localhost:8000/redoc
-
Recommened to user the api_client for python (solves JSON parsing issues)
-
To use the CLI (Optional)
- Enter the CLI dircetory and run the following command
cd CLI python3 brainfxck.py location_of_file.bf