brittainscript 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.
@@ -0,0 +1,238 @@
1
+ # BrittainScript
2
+
3
+ A custom scripting language built in Python using PLY (Python Lex-Yacc), created as a genius hour project.
4
+
5
+ ## Requirements
6
+
7
+ Python 3 and PLY must be installed:
8
+
9
+ ```
10
+ pip install ply
11
+ ```
12
+
13
+ ---
14
+
15
+ ## Running BrittainScript
16
+
17
+ All commands below are run from the `BrittainScriptInternals/` directory.
18
+
19
+ ### Run a .bs file
20
+
21
+ Pass the path to any `.bs` file as an argument:
22
+
23
+ ```
24
+ python3 main.py path/to/yourfile.bs
25
+ ```
26
+
27
+ For example, to run the included test file:
28
+
29
+ ```
30
+ python3 main.py ../TestFiles/test.bs
31
+ ```
32
+
33
+ Each non-blank line in the file is parsed and executed top to bottom. Lines starting with `#` are treated as comments and skipped.
34
+
35
+ ### Interactive REPL
36
+
37
+ Run without any arguments to get a live prompt where you can type expressions one at a time:
38
+
39
+ ```
40
+ python3 main.py
41
+ ```
42
+
43
+ ```
44
+ BrittainScript — type 'exit' to quit
45
+ bs> 3 + 4
46
+ 7
47
+ bs> push("hello")
48
+ hello
49
+ bs> exit
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Language Syntax
55
+
56
+ ### Basic Math
57
+
58
+ ```
59
+ 3 + 4
60
+ 10 - 3 * 2
61
+ 8 / 2
62
+ ```
63
+
64
+ ### Power and Square Root
65
+
66
+ ```
67
+ 4^2 => 16
68
+ sqrroot(16) => 4.0
69
+ ```
70
+
71
+ ### Pi
72
+
73
+ ```
74
+ 5 * pi => 15.707...
75
+ ```
76
+
77
+ ### Trigonometry (input in degrees)
78
+
79
+ ```
80
+ sin(90) => 1.0
81
+ cos(0) => 1.0
82
+ tan(45) => 1.0
83
+ ```
84
+
85
+ ### Print (`push`)
86
+
87
+ ```
88
+ push(3 + 4) => prints 7
89
+ push("hello") => prints hello
90
+ ```
91
+
92
+ `push()` only prints. It does not return the printed value.
93
+
94
+ ### Variables
95
+
96
+ ```
97
+ name = "BrittainScript"
98
+ count = 3
99
+ ```
100
+
101
+ ### Comments
102
+
103
+ ```
104
+ # Full-line comment
105
+ push("hello") # Inline comment
106
+ ```
107
+
108
+ ### Conditionals
109
+
110
+ ```
111
+ cond (count > 1)
112
+ push("count is greater than one")
113
+ end
114
+ ```
115
+
116
+ ### Loops
117
+
118
+ ```
119
+ x = 0
120
+ while x < 3:
121
+ x = x + 1
122
+ push(x)
123
+ end
124
+
125
+ for i in space(1, 4):
126
+ push(i)
127
+ end
128
+ ```
129
+
130
+ Use `break` to exit a loop and `continue` to skip to the next iteration.
131
+
132
+ ### Functions
133
+
134
+ ```
135
+ func double(x):
136
+ return x * 2
137
+ end
138
+
139
+ push(double(5))
140
+ ```
141
+
142
+ Functions return values with `return`.
143
+
144
+ ### Input
145
+
146
+ ```
147
+ name = input("Enter your name: ")
148
+ push(name)
149
+ ```
150
+
151
+ ### Strings
152
+
153
+ ```
154
+ push("hello" + " world")
155
+ push(len("hello"))
156
+
157
+ name = " BrittainScript "
158
+ push(name[1])
159
+ push(name[1:5])
160
+ push(name.trim().upper())
161
+
162
+ push(tonum("42") + 8)
163
+ push(tostr(42) + "!")
164
+ ```
165
+
166
+ ### Lists
167
+
168
+ ```
169
+ nums = [1, 2, 3, 4]
170
+ push(nums[0])
171
+ nums.add(5)
172
+ push(len(nums))
173
+ ```
174
+
175
+ ### Grouping
176
+
177
+ ```
178
+ (2 + 3) * 4 => 20
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Test Files
184
+
185
+ There are two standalone test suites in `TestFiles/`. These are self-contained and independent from the main interpreter — they were used to prototype the lexer and parser separately.
186
+
187
+ ### Math test (`TestFiles/TestMath/`)
188
+
189
+ Tests a basic arithmetic lexer and parser (addition, subtraction, multiplication, division). Run from inside the `TestMath` folder:
190
+
191
+ ```
192
+ cd TestFiles/TestMath
193
+ python3 testcalc.py
194
+ ```
195
+
196
+ You'll see a `Test:` prompt. Type a math expression and it prints the tokens it found, then the parsed result:
197
+
198
+ ```
199
+ Test: 3 + 4
200
+ LexToken(NUMBER,3,1,0)
201
+ LexToken(PLUS,'+',1,2)
202
+ LexToken(NUMBER,4,1,4)
203
+ Yacc parsed: 7
204
+ ```
205
+
206
+ ### Text test (`TestFiles/TestText/`)
207
+
208
+ Tests a minimal text lexer and parser. Run from inside the `TestText` folder:
209
+
210
+ ```
211
+ cd TestFiles/TestText
212
+ python3 testtext.py
213
+ ```
214
+
215
+ You'll see an `Enter some text:` prompt. Type anything and it prints the token and the parsed result:
216
+
217
+ ```
218
+ Enter some text: hello world
219
+ LexToken(TEXT,'hello world',1,0)
220
+ Parsed: hello world
221
+ ```
222
+
223
+ ---
224
+
225
+ ## Project Structure
226
+
227
+ ```
228
+ BrittainScript/
229
+ ├── BrittainScriptInternals/
230
+ │ ├── main.py — entry point (REPL + file runner)
231
+ │ ├── lexer.py — tokenizer
232
+ │ └── parser.py — grammar and evaluator
233
+ ├── TestFiles/
234
+ │ ├── TestMath/ — standalone arithmetic test
235
+ │ └── TestText/ — standalone text test
236
+ └── Documentation/
237
+ └── mathdocs.txt — language reference for math features
238
+ ```
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 AstraStudios
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,276 @@
1
+ Metadata-Version: 2.4
2
+ Name: brittainscript
3
+ Version: 0.1.0
4
+ Summary: The BrittainScript programming language interpreter
5
+ Author-email: Luke Brittain <luke.brittain@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 AstraStudios
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Keywords: programming-language,interpreter,scripting
29
+ Classifier: Programming Language :: Python :: 3
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Operating System :: OS Independent
32
+ Classifier: Topic :: Software Development :: Interpreters
33
+ Requires-Python: >=3.9
34
+ Description-Content-Type: text/markdown
35
+ License-File: LICENSE
36
+ Requires-Dist: ply>=3.11
37
+ Dynamic: license-file
38
+
39
+ # BrittainScript
40
+
41
+ A custom scripting language built in Python using PLY (Python Lex-Yacc), created as a genius hour project.
42
+
43
+ ## Requirements
44
+
45
+ Python 3 and PLY must be installed:
46
+
47
+ ```
48
+ pip install ply
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Running BrittainScript
54
+
55
+ All commands below are run from the `BrittainScriptInternals/` directory.
56
+
57
+ ### Run a .bs file
58
+
59
+ Pass the path to any `.bs` file as an argument:
60
+
61
+ ```
62
+ python3 main.py path/to/yourfile.bs
63
+ ```
64
+
65
+ For example, to run the included test file:
66
+
67
+ ```
68
+ python3 main.py ../TestFiles/test.bs
69
+ ```
70
+
71
+ Each non-blank line in the file is parsed and executed top to bottom. Lines starting with `#` are treated as comments and skipped.
72
+
73
+ ### Interactive REPL
74
+
75
+ Run without any arguments to get a live prompt where you can type expressions one at a time:
76
+
77
+ ```
78
+ python3 main.py
79
+ ```
80
+
81
+ ```
82
+ BrittainScript — type 'exit' to quit
83
+ bs> 3 + 4
84
+ 7
85
+ bs> push("hello")
86
+ hello
87
+ bs> exit
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Language Syntax
93
+
94
+ ### Basic Math
95
+
96
+ ```
97
+ 3 + 4
98
+ 10 - 3 * 2
99
+ 8 / 2
100
+ ```
101
+
102
+ ### Power and Square Root
103
+
104
+ ```
105
+ 4^2 => 16
106
+ sqrroot(16) => 4.0
107
+ ```
108
+
109
+ ### Pi
110
+
111
+ ```
112
+ 5 * pi => 15.707...
113
+ ```
114
+
115
+ ### Trigonometry (input in degrees)
116
+
117
+ ```
118
+ sin(90) => 1.0
119
+ cos(0) => 1.0
120
+ tan(45) => 1.0
121
+ ```
122
+
123
+ ### Print (`push`)
124
+
125
+ ```
126
+ push(3 + 4) => prints 7
127
+ push("hello") => prints hello
128
+ ```
129
+
130
+ `push()` only prints. It does not return the printed value.
131
+
132
+ ### Variables
133
+
134
+ ```
135
+ name = "BrittainScript"
136
+ count = 3
137
+ ```
138
+
139
+ ### Comments
140
+
141
+ ```
142
+ # Full-line comment
143
+ push("hello") # Inline comment
144
+ ```
145
+
146
+ ### Conditionals
147
+
148
+ ```
149
+ cond (count > 1)
150
+ push("count is greater than one")
151
+ end
152
+ ```
153
+
154
+ ### Loops
155
+
156
+ ```
157
+ x = 0
158
+ while x < 3:
159
+ x = x + 1
160
+ push(x)
161
+ end
162
+
163
+ for i in space(1, 4):
164
+ push(i)
165
+ end
166
+ ```
167
+
168
+ Use `break` to exit a loop and `continue` to skip to the next iteration.
169
+
170
+ ### Functions
171
+
172
+ ```
173
+ func double(x):
174
+ return x * 2
175
+ end
176
+
177
+ push(double(5))
178
+ ```
179
+
180
+ Functions return values with `return`.
181
+
182
+ ### Input
183
+
184
+ ```
185
+ name = input("Enter your name: ")
186
+ push(name)
187
+ ```
188
+
189
+ ### Strings
190
+
191
+ ```
192
+ push("hello" + " world")
193
+ push(len("hello"))
194
+
195
+ name = " BrittainScript "
196
+ push(name[1])
197
+ push(name[1:5])
198
+ push(name.trim().upper())
199
+
200
+ push(tonum("42") + 8)
201
+ push(tostr(42) + "!")
202
+ ```
203
+
204
+ ### Lists
205
+
206
+ ```
207
+ nums = [1, 2, 3, 4]
208
+ push(nums[0])
209
+ nums.add(5)
210
+ push(len(nums))
211
+ ```
212
+
213
+ ### Grouping
214
+
215
+ ```
216
+ (2 + 3) * 4 => 20
217
+ ```
218
+
219
+ ---
220
+
221
+ ## Test Files
222
+
223
+ There are two standalone test suites in `TestFiles/`. These are self-contained and independent from the main interpreter — they were used to prototype the lexer and parser separately.
224
+
225
+ ### Math test (`TestFiles/TestMath/`)
226
+
227
+ Tests a basic arithmetic lexer and parser (addition, subtraction, multiplication, division). Run from inside the `TestMath` folder:
228
+
229
+ ```
230
+ cd TestFiles/TestMath
231
+ python3 testcalc.py
232
+ ```
233
+
234
+ You'll see a `Test:` prompt. Type a math expression and it prints the tokens it found, then the parsed result:
235
+
236
+ ```
237
+ Test: 3 + 4
238
+ LexToken(NUMBER,3,1,0)
239
+ LexToken(PLUS,'+',1,2)
240
+ LexToken(NUMBER,4,1,4)
241
+ Yacc parsed: 7
242
+ ```
243
+
244
+ ### Text test (`TestFiles/TestText/`)
245
+
246
+ Tests a minimal text lexer and parser. Run from inside the `TestText` folder:
247
+
248
+ ```
249
+ cd TestFiles/TestText
250
+ python3 testtext.py
251
+ ```
252
+
253
+ You'll see an `Enter some text:` prompt. Type anything and it prints the token and the parsed result:
254
+
255
+ ```
256
+ Enter some text: hello world
257
+ LexToken(TEXT,'hello world',1,0)
258
+ Parsed: hello world
259
+ ```
260
+
261
+ ---
262
+
263
+ ## Project Structure
264
+
265
+ ```
266
+ BrittainScript/
267
+ ├── BrittainScriptInternals/
268
+ │ ├── main.py — entry point (REPL + file runner)
269
+ │ ├── lexer.py — tokenizer
270
+ │ └── parser.py — grammar and evaluator
271
+ ├── TestFiles/
272
+ │ ├── TestMath/ — standalone arithmetic test
273
+ │ └── TestText/ — standalone text test
274
+ └── Documentation/
275
+ └── mathdocs.txt — language reference for math features
276
+ ```