Skip to content

Commit

Permalink
Merge branch 'release/0.1.0-beta0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Sellig6792 committed Jul 18, 2022
2 parents 39903af + e25b51c commit e049c6d
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea/

env/
**/__pycache__/

test.fbf
87 changes: 87 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#Documentation

Hi, if you are reading this, you want to learn how to use FuckBrainFuck.

First you need to know the classic BrainFuck syntax.
You should read this course:
- [Brainfuck Language (English) (by roachhd)](https://gist.github.com/roachhd/dce54bec8ba55fb17d3a)
- [Brainfuck Language (French) (by Astremy)](https://cdn.discordapp.com/attachments/815331771197030441/824402769397940234/brainfuck.pdf)


Now I'm going to explain how to use the new implementations of FuckBrainFuck.

###FuckBrainFuck already offers:

- "Safe" comments
- Functions


## Comments
Safe comments allow you to use any characters in the comments as opposed to the classic brainfuck comments
where you can't use the characters used by the language

You can write comments between two `#` characters.

Example:
```
,# This is a safe comment. I can use <>+-[],. and
others characters of FuckBrainFuck here like :;
I can also skip lines. This program returns the character of the input #.
```


## Functions
Functions are a way to use the same code multiple times.
Functions are stored in a different array than the classic BrainFuck array.

You can define functions between `:` and `;`. To call it, use `x`.

You can use recursive functions.
You can also define functions inside functions,
but you have to move the pointer to right or left
because you can't have multiple functions in the same cell.


Example:
```
:,++.; # This functions asks the user and adds two to the cell and then prints the result. #
x # Execute the function. #
```

Nested Functions:
```
:
,
>:
<++
; # This function go to left and adds 2 to the value of the cell.#
x. # Execute the function and display the result.
After executing the function, we are one square ahead.
Here, the function is obviously useless since we use it only once.#
;
x
```
_In the example above, I indented the code. It makes it more readable, doesn't it?_

You can see that before declaring the second function, I moved my pointer to the right.
This allows me to avoid unexpected behavior.


Recursive Functions:
```
:
[[->+>[->+>+<<]>>[-<<+>>]<<<<]>>[-]>[-<+>]<<[-<+>]<-x[-]]
; # This function calculates the factorial of a number. #
>>+<<
+++++ # Here is the input for the recursive function. #
x>>. # The output will be "x" because 120 is the ASCII value of "x".
The output is always the remainder of the factorial divided by 255. #
```
_Thanks Astremy for the code!_


I think you now know all about the FuckBrainFuck's syntax.
Thanks for reading the documentation.
Maybe the people in [the BrainFuck channel on Graven's server](https://discord.gg/DTtXYNc3ct)
will help you with FuckBrainFuck (in French).
I hope everything goes well for you, goodbye
183 changes: 183 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<div id="top"></div>

<!-- PROJECT SHIELDS -->
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]



<!-- PROJECT LOGO -->
<br />
<div align="center">
<a href="https://github.com/Sellig6792/FuckBrainFuck">
<img src="assets/logo.png" alt="Logo" width="80" height="auto">
</a>

<h3 align="center">FuckBrainFuck</h3>
<p align="center">
Improved BrainFuck
<br />
<a href="./DOCUMENTATION.md"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/Sellig6792/FuckBrainFuck/issues">Report Bug</a>
·
<a href="https://github.com/Sellig6792/FuckBrainFuck/issues">Request Feature</a>
</p>
</div>



<!-- TABLE OF CONTENTS -->
<details>
<summary>Table of Contents</summary>
<ol>
<li>
<a href="#about-the-project">About The Project</a>
<ul>
<li><a href="#built-with">Built With</a></li>
</ul>
</li>
<li>
<a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li><a href="#usage">Usage</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#license">License</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#acknowledgments">Acknowledgments</a></li>
</ol>
</details>



<!-- ABOUT THE PROJECT -->
## About The Project

It all started on the Discord server of Graven, on 26<sup>th</sup> June 2022.
It was a joke that ended up on this shit...

So FuckBrainFuck was born. It is an improvement of the classic BrainFuck.

We have already implemented:

- Functions
- "Safe" comments

<p align="right">(<a href="#top">back to top</a>)</p>



### Built With

* [![Python][python-shield]][python-url]

<p align="right">(<a href="#top">back to top</a>)</p>



<!-- GETTING STARTED -->
## Getting Started

### Prerequisites

You may need to install Python 3.6 or higher.

### Installation



1. Clone the repo
```sh
git clone https://github.com/Sellig6792/FuckBrainFuck.git
```


<p align="right">(<a href="#top">back to top</a>)</p>



<!-- USAGE EXAMPLES -->
## Usage

Soon...

[//]: # (<p align="right">&#40;<a href="#top">back to top</a>&#41;</p>)


<!-- CONTRIBUTING -->
## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create.
Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request.
You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (`git flow feature start [feature name]`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git flow feature publish [feature name]`)
5. Open a Pull Request on the develop branch

<p align="right">(<a href="#top">back to top</a>)</p>



<!-- LICENSE -->
## License

Distributed under the MIT License. See `LICENSE.txt` for more information.

<p align="right">(<a href="#top">back to top</a>)</p>



<!-- CONTACT -->
## Contact

Your Name - [@Sellig6792](https://twitter.com/Sellig6792) - sellig6792@gmail.com

Project Link: [https://github.com/Sellig6792/FuckBrainFuck](https://github.com/Sellig6792/FuckBrainFuck)

<p align="right">(<a href="#top">back to top</a>)</p>



<!-- ACKNOWLEDGMENTS -->
## Acknowledgments

* [Wikipedia - Brainfuck][wikipedia-brainfuck-url]
* [Astremy - Brainfuck Course (French)][astremy-brainfuck-pdf]
<p align="right">(<a href="#top">back to top</a>)</p>



<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
[contributors-shield]: https://img.shields.io/github/contributors/Sellig6792/FuckBrainFuck.svg?style=for-the-badge
[contributors-url]: https://github.com/Sellig6792/FuckBrainFuck/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/Sellig6792/FuckBrainFuck.svg?style=for-the-badge
[forks-url]: https://github.com/Sellig6792/FuckBrainFuck/network/members
[stars-shield]: https://img.shields.io/github/stars/Sellig6792/FuckBrainFuck.svg?style=for-the-badge
[stars-url]: https://github.com/Sellig6792/FuckBrainFuck/stargazers
[issues-shield]: https://img.shields.io/github/issues/Sellig6792/FuckBrainFuck.svg?style=for-the-badge
[issues-url]: https://github.com/Sellig6792/FuckBrainFuck/issues
[license-shield]: https://img.shields.io/github/license/Sellig6792/FuckBrainFuck.svg?style=for-the-badge
[license-url]: https://github.com/Sellig6792/FuckBrainFuck/blob/master/LICENSE.txt
[Python-url]: https://www.python.org/
[Python-shield]: https://img.shields.io/badge/-Python-black.svg?style=for-the-badge&logo=python&colorB=555
[BrainFuck-url]: https://en.wikipedia.org/wiki/Brainfuck
[BrainFuck-shield]: https://img.shields.io/badge/-BrainFuck-black.svg?style=for-the-badge&logo=brainfuck&colorB=555

[graven-discord-url]: https://discord.gg/graven
[astremy-brainfuck-pdf]: https://cdn.discordapp.com/attachments/815331771197030441/824402769397940234/brainfuck.pdf
[wikipedia-brainfuck-url]: https://en.wikipedia.org/wiki/Brainfuck
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions fbf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
import sys
import argparse

from interpreter import Interpreter


def get_usage() -> str:
return "fbf (path) [-h] [-c COMPILE] [-x EXECUTE]"


def get_args() -> argparse.Namespace:
if not sys.argv[1].startswith('-'):
path = sys.argv[1]
del sys.argv[1]
else:
path = None

parser = argparse.ArgumentParser(prog="FuckBrainFuck", description="The improved version of BrainFuck",
usage=get_usage())

parser.add_argument("-c", "--compile", help="Compile the file")
parser.add_argument("-x", "--execute", help="Execute a string")

_args = parser.parse_args()
setattr(_args, 'path', path)
return _args


if __name__ == '__main__':
args = get_args()

if args.path:
with open(args.path, mode='r+') as file:
code = ''.join(file.readlines())
Interpreter(code)()
if args.execute:
Interpreter(args.execute)()
Loading

0 comments on commit e049c6d

Please sign in to comment.