Skip to content

Commit 16d0f19

Browse files
committed
Version 1.10.0 Release: Added Function Call and Defenition
1 parent 42b9d79 commit 16d0f19

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

NumberScript/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
parser.add_argument("-v", "--version", action="store_true", help="show version")
1414
args = parser.parse_args()
1515

16-
ver = "1.9.2"
16+
ver = "1.9.4"
1717

1818
run = True
1919

@@ -25,6 +25,7 @@
2525
4number[=/!/</>] <- Compare
2626
5 <- pass
2727
6 <- For-loops
28+
7 <- Function Def
2829
% <- comment
2930
^number[+\-\/\*\#]number <- Math-Operation-Start
3031
?conditon:True:False <- If-Else

NumberScript/interpreter.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ def __init__(self):
161161
"""Initialize the interpreter"""
162162
pass
163163

164-
def interpret(self, code: str, variables_dict: dict = {}) -> str:
164+
def interpret(self, code: str, variables_dict: dict = {}, function_dict: dict = {}) -> str:
165165
"""Interprets the code"""
166166
code = code.split(" ")
167167
variables = variables_dict
168+
functions = function_dict
168169
for j in range(0, len(code)):
169170
if code[j].startswith("0"):
170171
variables = {}
@@ -247,4 +248,36 @@ def interpret(self, code: str, variables_dict: dict = {}) -> str:
247248

248249
if code[j].startswith("~"):
249250
recode = code[j].replace("~", "", 1)
250-
input(recode)
251+
input(recode)
252+
253+
if code[j].startswith("7"):
254+
recode = code[j].replace("7", "", 1).split("$", 2)
255+
function_name = recode[0]
256+
function_parameters = recode[1].split(",")
257+
function_code = recode[2].split("|")
258+
functions[function_name] = [function_parameters, function_code]
259+
260+
if any(str(key) in code[j] for key in functions.keys()) and not code[j].startswith("7"):
261+
recode = code[j].split("$", 1)
262+
func_name = functions[recode[0]]
263+
func_params = recode[1].split(",")
264+
for x in range(0, len(func_params)):
265+
if func_params[x] in variables.keys():
266+
variables[func_name[0][x]] = variables[func_params[x]]
267+
elif func_params[x].isdigit():
268+
variables[func_name[0][x]] = int(func_params[x])
269+
elif func_params[x].startswith("^"):
270+
cal = func_params[x].replace("^", "", 1)
271+
variables[func_name[0][x]] = Calculate(cal, variables)
272+
elif func_params[x].startswith("~"):
273+
inp = func_params[x].replace("~", "", 1)
274+
variables[func_name[0][x]] = input(inp)
275+
if variables[func_name[0][x]].isdigit():
276+
variables[func_name[0][x]] = int(variables[func_name[0][x]])
277+
else:
278+
variables[func_name[0][x]] = func_params[x]
279+
func_code = ""
280+
for j in range(0, len(func_name[1])):
281+
func_code += func_name[1][j] + " "
282+
self.interpret(Interpreter, func_code, variables, functions)
283+

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pip install NumberScript
2020

2121
- No spaces (Yup, you read that right)
2222
- Comments
23-
- Only 7 commands
23+
- Only 8 commands
2424
- A shell and a runner
2525

2626
## Docs
@@ -39,6 +39,7 @@ To run a file just use this,
3939

4040
```
4141
commands: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
42+
input: ~
4243
comments: %
4344
arithmetic: ^
4445
Compare: = | ! | < | >
@@ -80,5 +81,5 @@ You can find more examples in the examples folder.
8081
8182
## To-Do
8283

83-
- [ ] Functions
84+
- [ ] Import and library system
8485
- [ ] Possibly OOP

grammar.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
------------------------------
1010
| 6n/7/2n;2hello |
1111
------------------------------
12+
7 <- Function
13+
| = code-split
14+
$ = section-split
15+
, = param-split
16+
------------------------------
17+
| 7add_two$a,b$^a+b |
18+
------------------------------
1219
% <- comment
1320
^ <- Math-Operation-Start
1421
? <- If Else

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
setuptools.setup(
77
name="NumberScript",
8-
version="1.9.3",
8+
version="1.10.0",
99
description="possibly the world's most simplest and restricted language.",
1010
author="Sasen Perera",
1111
long_description=longest_description,
1212
long_description_content_type="text/markdown",
1313
packages=["NumberScript"],
14+
github_url="https://github.com/Sas2k/NumberScript",
15+
license="MIT"
1416
)

0 commit comments

Comments
 (0)