pyfuck 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- PyFuck/.gitignore +2 -0
- PyFuck/__init__.py +0 -0
- PyFuck/main.py +104 -0
- pyfuck-0.1.0.dist-info/METADATA +27 -0
- pyfuck-0.1.0.dist-info/RECORD +7 -0
- pyfuck-0.1.0.dist-info/WHEEL +4 -0
- pyfuck-0.1.0.dist-info/entry_points.txt +2 -0
PyFuck/.gitignore
ADDED
PyFuck/__init__.py
ADDED
|
File without changes
|
PyFuck/main.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
valid_chars = ["+", "-", "[", "]", ",", ".", "<", ">"]
|
|
4
|
+
memory : list[int] = [0]
|
|
5
|
+
cur_pointer : int = 0
|
|
6
|
+
|
|
7
|
+
for i in range(1000000):
|
|
8
|
+
memory.append(0)
|
|
9
|
+
|
|
10
|
+
@click.command()
|
|
11
|
+
@click.option('--f', help='The file you want to compile.')
|
|
12
|
+
def main(f):
|
|
13
|
+
minimized_file = compile(f)
|
|
14
|
+
i = 0
|
|
15
|
+
while (i < len(minimized_file)):
|
|
16
|
+
if minimized_file[i] == "[":
|
|
17
|
+
if memory[cur_pointer] == 0:
|
|
18
|
+
lbs = 0 # The number of left brackets besides this one
|
|
19
|
+
j = i + 1
|
|
20
|
+
while True:
|
|
21
|
+
if minimized_file[j] == "]":
|
|
22
|
+
if lbs == 0: # Checks if the right bracket found corresponds to this left bracket
|
|
23
|
+
break # If so, we break out of the loop
|
|
24
|
+
else:
|
|
25
|
+
lbs -= 1 # If not, we decrease the amount of left brackets by one
|
|
26
|
+
elif minimized_file[j] == "[":
|
|
27
|
+
lbs += 1
|
|
28
|
+
j += 1
|
|
29
|
+
i = j
|
|
30
|
+
else:
|
|
31
|
+
i += 1
|
|
32
|
+
continue
|
|
33
|
+
elif minimized_file[i] == "]": # Same as above, but inverted
|
|
34
|
+
if memory[cur_pointer] != 0:
|
|
35
|
+
rbs = 0
|
|
36
|
+
j = i - 1
|
|
37
|
+
while True:
|
|
38
|
+
if minimized_file[j] == "[":
|
|
39
|
+
if rbs == 0:
|
|
40
|
+
break
|
|
41
|
+
else:
|
|
42
|
+
rbs -= 1
|
|
43
|
+
elif minimized_file[j] == "]":
|
|
44
|
+
rbs += 1
|
|
45
|
+
j -= 1
|
|
46
|
+
i = j
|
|
47
|
+
else:
|
|
48
|
+
i += 1
|
|
49
|
+
continue
|
|
50
|
+
else:
|
|
51
|
+
parse_character(minimized_file[i])
|
|
52
|
+
i += 1
|
|
53
|
+
|
|
54
|
+
def strip_characters(string : str, characters : list):
|
|
55
|
+
for char in string:
|
|
56
|
+
if char in characters:
|
|
57
|
+
continue
|
|
58
|
+
else:
|
|
59
|
+
string = string.replace(char, '')
|
|
60
|
+
return string
|
|
61
|
+
|
|
62
|
+
def compile(file):
|
|
63
|
+
minimized : str = ''
|
|
64
|
+
with open(file) as file:
|
|
65
|
+
for line in file:
|
|
66
|
+
formatted_line = strip_characters(line, valid_chars)
|
|
67
|
+
minimized = minimized + formatted_line
|
|
68
|
+
return minimized
|
|
69
|
+
|
|
70
|
+
def parse_character(character):
|
|
71
|
+
if character == "+":
|
|
72
|
+
plus()
|
|
73
|
+
elif character == "-":
|
|
74
|
+
minus()
|
|
75
|
+
elif character == "<":
|
|
76
|
+
left_angle()
|
|
77
|
+
elif character == ">":
|
|
78
|
+
right_angle()
|
|
79
|
+
elif character == ".":
|
|
80
|
+
period()
|
|
81
|
+
else:
|
|
82
|
+
comma()
|
|
83
|
+
|
|
84
|
+
def plus():
|
|
85
|
+
if memory[cur_pointer] == None:
|
|
86
|
+
memory[cur_pointer] = 0
|
|
87
|
+
memory[cur_pointer] += 1
|
|
88
|
+
|
|
89
|
+
def minus():
|
|
90
|
+
if memory[cur_pointer] > 0:
|
|
91
|
+
memory[cur_pointer] -= 1
|
|
92
|
+
|
|
93
|
+
def left_angle():
|
|
94
|
+
cur_pointer -= 1
|
|
95
|
+
|
|
96
|
+
def right_angle():
|
|
97
|
+
cur_pointer += 1
|
|
98
|
+
|
|
99
|
+
def period():
|
|
100
|
+
print(chr(memory[cur_pointer]))
|
|
101
|
+
|
|
102
|
+
def comma():
|
|
103
|
+
variable = int(input())
|
|
104
|
+
memory[cur_pointer] = variable
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: PyFuck
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A brainfuck interpreter for Python
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Requires-Dist: click>=8.5.1
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# PyFuck
|
|
10
|
+
|
|
11
|
+
PyFuck is, obviously, a Brainfuck interpreter written in Python.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
To use PyFuck, install `pip` and then run the command `pip install PyFuck` in your terminal.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
To use PyFuck, navigate to the directory containing your Brainfuck code and then run the command:
|
|
22
|
+
|
|
23
|
+
` PyFuck --f="YOURFILENAMEGOESHERE" `
|
|
24
|
+
|
|
25
|
+
## AI Disclosure
|
|
26
|
+
|
|
27
|
+
I did not use AI for a single part of this project.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
PyFuck/.gitignore,sha256=XeO6_hsCOjzZfPxzSKbZOZUnlpNOm8VWiQXA2hs470U,18
|
|
2
|
+
PyFuck/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
PyFuck/main.py,sha256=uTWw6fi4L-XvbpkbDCKwppDRzcoCYC9X-fxNaR1Kx2w,2970
|
|
4
|
+
pyfuck-0.1.0.dist-info/METADATA,sha256=HVdAKPmlig9IrUKbymSzLRb3VFwbTsOIw-mDfrB3GI4,696
|
|
5
|
+
pyfuck-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
6
|
+
pyfuck-0.1.0.dist-info/entry_points.txt,sha256=2rWpICViM8MLycsYXMwbvp5j3frgMR3vP_Mf_TNlmiE,44
|
|
7
|
+
pyfuck-0.1.0.dist-info/RECORD,,
|