Skip to content

Commit

Permalink
1.12.0 - Added Import statements and an example Library
Browse files Browse the repository at this point in the history
  • Loading branch information
Sas2k committed Aug 23, 2022
1 parent 7e50cea commit 30011f7
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ cython_debug/

#VS-Code
.vscode/
site/
site/
unix-venv/
10 changes: 10 additions & 0 deletions Libs/extends.ns
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%The-Extends-Library-For-NumberScript
%By-Sasen-Perera-2022
%
%This-library-is-used-to-make-the-normal-single-character-commands-into-more-readable-functions.
0
7print$string$2string
7print_char$string,[email protected]
7input$string$~string
7bool$val1,val2,sign$?sign==|4val1=val2|?sign=!|4val1!val2|?sign=>|4val1>val2|?sign=<|4val1<val2|2Error:Invalid-sign
1
8 changes: 7 additions & 1 deletion NumberScript/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", help="file to interpret")
parser.add_argument("-m", "--module", help="module to interpret", action="store_true")
parser.add_argument("-v", "--version", action="store_true", help="show version")
args = parser.parse_args()

Expand All @@ -29,6 +30,7 @@
% <- comment
^number[+\-\/\*\#]number <- Math-Operation-Start
?condition|True|False <- If-Else
#path/to/file(don't put .ns at the end) <- Import
"""

space = ""
Expand All @@ -42,7 +44,11 @@
with open(args.file, "r") as file:
code = file.read()
code = code.replace("\n", " ")
Interpreter.interpret(Interpreter, code)
if args.module:
print(Interpreter.interpret(Interpreter, code, library=True))
else:
Interpreter.interpret(Interpreter, code)

elif args.version:
print(f"Version: {ver}")
else:
Expand Down
34 changes: 27 additions & 7 deletions NumberScript/interpreter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from functools import reduce
from operator import mod
from random import randint
from os import path, name

import site

Default_Libs_Path = site.getusersitepackages() + "\\NumberScript\\Libs" if name == "nt" else site.getusersitepackages() + "/NumberScript/Libs"

def Calculate(removed_code: str, variables: dict) -> int:
"""Calculator"""
Expand Down Expand Up @@ -162,7 +167,7 @@ def __init__(self):
"""Initialize the interpreter"""
pass

def interpret(self, code: str, variables_dict: dict = {}, function_dict: dict = {}) -> str:
def interpret(self, code: str, variables_dict: dict = {}, function_dict: dict = {}, library: bool = False) -> str:
"""Interprets the code"""
code = code.split(" ")
variables = variables_dict
Expand All @@ -172,8 +177,20 @@ def interpret(self, code: str, variables_dict: dict = {}, function_dict: dict =
variables = {}

if code[j].startswith("1"):
variables = {}
return
break

if code[j].startswith("#"):
recode = code[j].replace("#", "", 1)
file_location = f"{recode}.ns"
module_code = open(f"{file_location}", "r").read()
module_code = module_code.replace("\n", " ")
module_args = self.interpret(Interpreter, module_code, variables, functions, True)
module_varNames = list(module_args[0].keys())
module_funcNames = list(module_args[1].keys())
for x in range(0, len(module_args[0])):
variables[module_varNames[x]] = module_args[0][module_varNames[x]]
for x in range(0, len(module_args[1])):
functions[module_funcNames[x]] = module_args[1][module_funcNames[x]]

if code[j].startswith("2"):
if code[j][1:] in variables.keys():
Expand Down Expand Up @@ -280,10 +297,10 @@ def interpret(self, code: str, variables_dict: dict = {}, function_dict: dict =
repeat_times = int(variables[recode[1]]) if recode[1] in variables.keys() else int(recode[1])
repeat_code = recode[2].replace(";", " ")
variables[repeat_name] = 0
variabless = variables
loop_variables = variables
for x in range(0, repeat_times):
self.interpret(Interpreter, repeat_code, variabless)
variabless[repeat_name] += 1
self.interpret(Interpreter, repeat_code, loop_variables)
loop_variables[repeat_name] += 1

if code[j].startswith("~"):
recode = code[j].replace("~", "", 1)
Expand All @@ -292,7 +309,7 @@ def interpret(self, code: str, variables_dict: dict = {}, function_dict: dict =
if code[j].startswith("7"):
recode = code[j].replace("7", "", 1).split("$", 2)
function_name = recode[0]
function_parameters = recode[1].split(",")
function_parameters = recode[1].split(",") if "," in recode[1] else [recode[1]]
function_code = recode[2].split("|")
functions[function_name] = [function_parameters, function_code]

Expand Down Expand Up @@ -329,4 +346,7 @@ def interpret(self, code: str, variables_dict: dict = {}, function_dict: dict =
for j in range(0, len(func_name[1])):
func_code += func_name[1][j] + " "
self.interpret(Interpreter, func_code, variables, functions)

if library == True:
return [variables, functions]

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ You can find more examples in the `examples` folder.
## To-Do

- [ ] Import and library system
- [ ] Possibly OOP
4 changes: 4 additions & 0 deletions examples/example.ns
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0
3a:Hello
?a=Hello|2bye|2hello
1
10 changes: 8 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@

setuptools.setup(
name="NumberScript",
version="1.11.7",
version="1.12.0",
description="possibly the world's most simplest and restricted language.",
author="Sasen Perera",
long_description=longest_description,
long_description_content_type="text/markdown",
packages=["NumberScript"],
github_url="https://github.com/Sas2k/NumberScript",
license="MIT"
license="MIT",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6'
)

0 comments on commit 30011f7

Please sign in to comment.