brittainscript 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.
@@ -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
+ ```
@@ -0,0 +1,14 @@
1
+ brittainscript-0.1.0.dist-info/licenses/LICENSE,sha256=l1YEIDdUaOnj2CbfATge48VA5-9Po7Eqol1xuFJtzTg,1069
2
+ core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ core/lexer.py,sha256=9Wr8rjDubOBfyhS_jFlbuNejM5UrwJ3uFQKuxco7cS8,2110
4
+ core/main.py,sha256=D_UfIwdWwFkBgjSWrFTPn9zRsojCUaOxfG05m-yyvLI,11633
5
+ core/parser.py,sha256=v2j_ePuKs0jckeBmKCFnNoGDCcezGa00f7DsMQRNOSU,10666
6
+ core/parsetab.py,sha256=cQHbA6ggV9byqChUBpFzyAYzHLt_Nqgw5T58M4Pzt7U,16741
7
+ libs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ libs/convert.bs,sha256=V-fS78lKvPp9GFInMMh-0oSADGpY-5PgGqNFZ8bXgcM,736
9
+ libs/math.bs,sha256=UiKyDy9BW4i1ijRwoRd5H1zGGDEPbzsYIGHK_-zhiYo,605
10
+ brittainscript-0.1.0.dist-info/METADATA,sha256=KYX5CXcxMZqDF_l7ZZHOQg0PzTmprLmG2dZFAtPtQCk,5543
11
+ brittainscript-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
12
+ brittainscript-0.1.0.dist-info/entry_points.txt,sha256=yuSEUxEK7wjUmUNNyJuQMJv_ix_pcbPcZ2f8QIYFrVU,43
13
+ brittainscript-0.1.0.dist-info/top_level.txt,sha256=Uho0PL9kAm6KaNujlGM3OewfhOEu_LIj2riui6E3kE4,10
14
+ brittainscript-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ bs = core.main:cli_entry
@@ -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,2 @@
1
+ core
2
+ libs
core/__init__.py ADDED
File without changes
core/lexer.py ADDED
@@ -0,0 +1,132 @@
1
+ import ply.lex as lex
2
+
3
+ tokens = (
4
+ 'NUMBER',
5
+ 'PLUS',
6
+ 'MINUS',
7
+ 'DIVIDE',
8
+ 'MULTIPLY',
9
+ 'POWER',
10
+ 'MODULO',
11
+ 'LPAREN',
12
+ 'RPAREN',
13
+ 'LBRACKET',
14
+ 'RBRACKET',
15
+ 'COMMA',
16
+ 'COLON',
17
+ 'DOT',
18
+ 'STRING',
19
+ # keywords — resolved from ID
20
+ 'SQUAREROOT',
21
+ 'SINE',
22
+ 'COSINE',
23
+ 'TANGENT',
24
+ 'PI',
25
+ 'PRINT',
26
+ # variables
27
+ 'NAME',
28
+ 'EQ',
29
+ # booleans and logic comparsions
30
+ 'AND',
31
+ 'OR',
32
+ 'NOT',
33
+ 'EQUALTO',
34
+ 'NOTEQUALTO',
35
+ 'GREATERTHAN',
36
+ 'LESSTHAN',
37
+ 'GREATERTHANEQUALTO',
38
+ 'LESSTHANEQUALTO',
39
+ 'TRUE',
40
+ 'FALSE',
41
+ # control flow
42
+ 'COND',
43
+ 'RANGE',
44
+ # import
45
+ 'ADD'
46
+ )
47
+
48
+ reserved = {
49
+ 'sqrroot': 'SQUAREROOT',
50
+ 'sin': 'SINE',
51
+ 'cos': 'COSINE',
52
+ 'tan': 'TANGENT',
53
+ 'pi': 'PI',
54
+ 'push': 'PRINT',
55
+ 'and': 'AND',
56
+ 'or': 'OR',
57
+ 'not': 'NOT',
58
+ 'true': 'TRUE',
59
+ 'false': 'FALSE',
60
+ 'cond': 'COND',
61
+ 'space': 'RANGE',
62
+ }
63
+
64
+ t_PLUS = r'\+'
65
+ t_MINUS = r'\-'
66
+ t_DIVIDE = r'\/'
67
+ t_MULTIPLY = r'\*'
68
+ t_POWER = r'\^'
69
+ t_MODULO = r'\%'
70
+ t_LPAREN = r'\('
71
+ t_RPAREN = r'\)'
72
+ t_LBRACKET = r'\['
73
+ t_RBRACKET = r'\]'
74
+ t_COMMA = r','
75
+ t_COLON = r':'
76
+ t_DOT = r'\.'
77
+ t_EQ = r'='
78
+
79
+ def t_EQUALTO(t):
80
+ r'=='
81
+ return t
82
+
83
+ def t_NOTEQUALTO(t):
84
+ r'!='
85
+ return t
86
+
87
+ def t_GREATERTHANEQUALTO(t):
88
+ r'>='
89
+ return t
90
+
91
+ def t_LESSTHANEQUALTO(t):
92
+ r'<='
93
+ return t
94
+
95
+ def t_GREATERTHAN(t):
96
+ r'>'
97
+ return t
98
+
99
+ def t_LESSTHAN(t):
100
+ r'<'
101
+ return t
102
+
103
+ def t_NUMBER(t):
104
+ r'\d+(\.\d+)?'
105
+ t.value = float(t.value) if '.' in t.value else int(t.value)
106
+ return t
107
+
108
+ def t_NAME(t):
109
+ r'[a-zA-Z_][a-zA-Z0-9_]*'
110
+ t.type = reserved.get(t.value, 'NAME')
111
+ return t
112
+
113
+ def t_STRING(t):
114
+ r'"([^"\\]|\\.)*"'
115
+ t.value = bytes(t.value[1:-1], "utf-8").decode("unicode_escape")
116
+ return t
117
+
118
+ def t_COMMENT(t):
119
+ r'\#.*'
120
+ pass
121
+
122
+ def t_newline(t):
123
+ r'\n+'
124
+ t.lexer.lineno += len(t.value)
125
+
126
+ t_ignore = ' \t'
127
+
128
+ def t_error(t):
129
+ print("Illegal character: '%s'" % t.value[0])
130
+ t.lexer.skip(1)
131
+
132
+ lexer = lex.lex()