pyfuck 0.1.0__tar.gz

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-0.1.0/PKG-INFO ADDED
@@ -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
+ ![PyFuck Screenshot](https://cdn.hackclub.com/01a22a07-5500-773d-a9d0-0978d5bca2e1/pyfuckscreenshot.png)
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.
pyfuck-0.1.0/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # PyFuck
2
+
3
+ PyFuck is, obviously, a Brainfuck interpreter written in Python.
4
+
5
+ ![PyFuck Screenshot](https://cdn.hackclub.com/01a22a07-5500-773d-a9d0-0978d5bca2e1/pyfuckscreenshot.png)
6
+
7
+ ## Installation
8
+
9
+ To use PyFuck, install `pip` and then run the command `pip install PyFuck` in your terminal.
10
+
11
+ ## Usage
12
+
13
+ To use PyFuck, navigate to the directory containing your Brainfuck code and then run the command:
14
+
15
+ ` PyFuck --f="YOURFILENAMEGOESHERE" `
16
+
17
+ ## AI Disclosure
18
+
19
+ I did not use AI for a single part of this project.
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "PyFuck"
7
+ version = "0.1.0"
8
+ description = "A brainfuck interpreter for Python"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ 'click>=8.5.1'
13
+ ]
14
+
15
+ [project.scripts]
16
+ PyFuck = "PyFuck.main:main"
@@ -0,0 +1,2 @@
1
+ /.venv
2
+ /_pycache_
File without changes
@@ -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