mirror of
https://github.com/Open-Argon/Argon.git
synced 2026-10-28 09:43:38 +00:00
add easier to learn operators
This commit is contained in:
1 parent
f932e5dab8
commit
25f64a2eea
3 files changed
+241
-105
No files matched your search
@@ -6,10 +6,13 @@ import math
|
|||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
|
from periodicTable import *
|
||||||
|
|
||||||
version = "ARGON Beta 2.4.2"
|
version = "ARGON Beta 2.4.2"
|
||||||
|
|
||||||
# make a function that takes in 2 params, colour and text and outputs a coloured text
|
# make a function that takes in 2 params, colour and text and outputs a coloured text
|
||||||
|
|
||||||
|
|
||||||
def colourify(colour, text):
|
def colourify(colour, text):
|
||||||
if colour == None:
|
if colour == None:
|
||||||
return text
|
return text
|
||||||
@@ -47,6 +50,8 @@ def colourify(colour, text):
|
|||||||
return "\033[95m" + text + "\033[0m"
|
return "\033[95m" + text + "\033[0m"
|
||||||
|
|
||||||
# make a function that takes in a param of any type and returns it as a number
|
# make a function that takes in a param of any type and returns it as a number
|
||||||
|
|
||||||
|
|
||||||
def number(value: Any):
|
def number(value: Any):
|
||||||
try:
|
try:
|
||||||
inted = int(value)
|
inted = int(value)
|
||||||
@@ -57,6 +62,7 @@ def number(value: Any):
|
|||||||
except:
|
except:
|
||||||
return float(value)
|
return float(value)
|
||||||
|
|
||||||
|
|
||||||
def Atype(value):
|
def Atype(value):
|
||||||
return {
|
return {
|
||||||
int: "number",
|
int: "number",
|
||||||
@@ -68,6 +74,7 @@ def Atype(value):
|
|||||||
dict: "book",
|
dict: "book",
|
||||||
}[type(value)]
|
}[type(value)]
|
||||||
|
|
||||||
|
|
||||||
def code_Aexec(string):
|
def code_Aexec(string):
|
||||||
Aexec(string, False)
|
Aexec(string, False)
|
||||||
|
|
||||||
@@ -75,40 +82,75 @@ def code_Aexec(string):
|
|||||||
def code_Aeval(string):
|
def code_Aeval(string):
|
||||||
return Aexec(string, True)[1]
|
return Aexec(string, True)[1]
|
||||||
|
|
||||||
|
|
||||||
def logSF(*args):
|
def logSF(*args):
|
||||||
newargs = []
|
newargs = []
|
||||||
for i in range(len(args)):
|
for i in range(len(args)):
|
||||||
newargs.append(valToArgonString(args[i], speach=True, colour=False))
|
newargs.append(valToArgonString(args[i], speach=True, colour=False))
|
||||||
print(*newargs, end='')
|
print(*newargs, end='')
|
||||||
|
|
||||||
|
|
||||||
def logSCF(*args):
|
def logSCF(*args):
|
||||||
newargs = []
|
newargs = []
|
||||||
for i in range(len(args)):
|
for i in range(len(args)):
|
||||||
newargs.append(valToArgonString(args[i], speach=True))
|
newargs.append(valToArgonString(args[i], speach=True))
|
||||||
print(*newargs, end='')
|
print(*newargs, end='')
|
||||||
|
|
||||||
|
|
||||||
def logS(*args):
|
def logS(*args):
|
||||||
newargs = []
|
newargs = []
|
||||||
for i in range(len(args)):
|
for i in range(len(args)):
|
||||||
newargs.append(valToArgonString(args[i], speach=True, colour=False))
|
newargs.append(valToArgonString(args[i], speach=True, colour=False))
|
||||||
print(*newargs)
|
print(*newargs)
|
||||||
|
|
||||||
|
|
||||||
def logSC(*args):
|
def logSC(*args):
|
||||||
newargs = []
|
newargs = []
|
||||||
for i in range(len(args)):
|
for i in range(len(args)):
|
||||||
newargs.append(valToArgonString(args[i], speach=True))
|
newargs.append(valToArgonString(args[i], speach=True))
|
||||||
print(*newargs)
|
print(*newargs)
|
||||||
|
|
||||||
|
|
||||||
def logF(*args):
|
def logF(*args):
|
||||||
newargs = []
|
newargs = []
|
||||||
for i in range(len(args)):
|
for i in range(len(args)):
|
||||||
newargs.append(valToArgonString(args[i]))
|
newargs.append(valToArgonString(args[i]))
|
||||||
print(*newargs, end='')
|
print(*newargs, end='')
|
||||||
|
|
||||||
|
|
||||||
def log(*args):
|
def log(*args):
|
||||||
newargs = []
|
newargs = []
|
||||||
for i in range(len(args)):
|
for i in range(len(args)):
|
||||||
newargs.append(valToArgonString(args[i]))
|
newargs.append(valToArgonString(args[i]))
|
||||||
print(*newargs)
|
print(*newargs)
|
||||||
|
|
||||||
|
|
||||||
|
def quadraticFormula(a, b, c):
|
||||||
|
if a == 0:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a), (-b - math.sqrt(b**2 - 4*a*c)) / (2*a)
|
||||||
|
|
||||||
def substring(string, start=None, end=None, step=None):
|
def substring(string, start=None, end=None, step=None):
|
||||||
return string[start:end:step]
|
return string[start:end:step]
|
||||||
|
|
||||||
|
# make a function that takes in a string and an array of strings, and returns the value in the array of string that looks the most similar to the string
|
||||||
|
|
||||||
|
|
||||||
|
def find(string, array):
|
||||||
|
best = None
|
||||||
|
bestscore = 0
|
||||||
|
for i in range(len(array)):
|
||||||
|
score = 0
|
||||||
|
for j in range(len(array[i])):
|
||||||
|
if array[i][j] in string:
|
||||||
|
score += 1
|
||||||
|
else:
|
||||||
|
score -= 1
|
||||||
|
if score > bestscore and score > len(string)/2:
|
||||||
|
best = array[i]
|
||||||
|
bestscore = score
|
||||||
|
return best
|
||||||
|
|
||||||
|
|
||||||
def boxify(text, length=0, align="left"):
|
def boxify(text, length=0, align="left"):
|
||||||
@@ -125,9 +167,9 @@ def boxify(text, length=0, align="left"):
|
|||||||
return ('╔'+((length+2)*'═')+'╗\n'+("\n".join(processed))+'\n╚'+((length+2)*'═')+'╝')
|
return ('╔'+((length+2)*'═')+'╗\n'+("\n".join(processed))+'\n╚'+((length+2)*'═')+'╝')
|
||||||
|
|
||||||
|
|
||||||
def valToArgonString(value, speach = False, colour = True):
|
def valToArgonString(value, speach=False, pretty=1, colour=True):
|
||||||
if type(value) == int or type(value) == float:
|
if type(value) == int or type(value) == float:
|
||||||
return colourify('cyan' if colour else None, str(value))
|
return colourify('cyan' if colour else None, str(number(value)))
|
||||||
elif value == None:
|
elif value == None:
|
||||||
return colourify('grey' if colour else None, "unknown")
|
return colourify('grey' if colour else None, "unknown")
|
||||||
elif value == True:
|
elif value == True:
|
||||||
@@ -135,13 +177,14 @@ def valToArgonString(value, speach = False, colour = True):
|
|||||||
elif value == False:
|
elif value == False:
|
||||||
return colourify('red' if colour else None, "no")
|
return colourify('red' if colour else None, "no")
|
||||||
elif type(value) == dict:
|
elif type(value) == dict:
|
||||||
return "{" + ", ".join(f"{valToArgonString(key, speach=True, colour=colour)}: {valToArgonString(value[key], speach=True, colour=colour)}" for key in value) + "}"
|
return "{"+ ", ".join(("\n"+(' '*pretty) if pretty != None and len(list(value)) > 0 else '')+f"{colourify('lightgreen' if colour else None,key) if noSpaceVarTest.fullmatch(str(key)) else valToArgonString(key, speach=True, colour=colour)}: {valToArgonString(value[key], speach=True, pretty=pretty+1 if pretty != None else None, colour=colour)}" for key in value) + ('\n'+(' '*(pretty-1))if pretty != None and len(list(value)) > 0 else '') + "}"
|
||||||
elif type(value) in [list, tuple]:
|
elif type(value) in [list, tuple]:
|
||||||
return "[" + ", ".join(valToArgonString(i, speach=True, colour=colour) for i in value) + "]"
|
return "[" + ", ".join(('\n'+(' '*(pretty-1))if pretty != None and len(list(value)) > 0 else '')+valToArgonString(i, speach=True, pretty=pretty+1 if pretty != None else None, colour=colour) for i in value) + ('\n'+(' '*(pretty-1))if pretty != None and len(list(value)) > 0 else '') + "]"
|
||||||
elif speach == True and type(value) == str:
|
elif speach == True and type(value) == str:
|
||||||
return colourify('yellow' if colour else None, f'\'{value}\'')
|
return colourify('yellow' if colour else None, f'\'{value}\'')
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
def Arange(start, stop=None, step=1):
|
def Arange(start, stop=None, step=1):
|
||||||
if stop == None:
|
if stop == None:
|
||||||
stop = start
|
stop = start
|
||||||
@@ -153,6 +196,7 @@ def Arange(start, stop=None, step=1):
|
|||||||
else:
|
else:
|
||||||
return list(range(start, stop - 1, step))
|
return list(range(start, stop - 1, step))
|
||||||
|
|
||||||
|
|
||||||
vars = {
|
vars = {
|
||||||
'log': {'type': 'init', 'py': log},
|
'log': {'type': 'init', 'py': log},
|
||||||
'logF': {'type': 'init', 'py': logF},
|
'logF': {'type': 'init', 'py': logF},
|
||||||
@@ -160,6 +204,7 @@ vars = {
|
|||||||
'logSC': {'type': 'init', 'py': logSC},
|
'logSC': {'type': 'init', 'py': logSC},
|
||||||
'logSF': {'type': 'init', 'py': logSF},
|
'logSF': {'type': 'init', 'py': logSF},
|
||||||
'logSCF': {'type': 'init', 'py': logSCF},
|
'logSCF': {'type': 'init', 'py': logSCF},
|
||||||
|
'periodicTable': {'type': 'init', 'value': periodicTable},
|
||||||
'input': {'type': 'init', 'py': input},
|
'input': {'type': 'init', 'py': input},
|
||||||
'PYeval': {'type': 'init', 'py': eval},
|
'PYeval': {'type': 'init', 'py': eval},
|
||||||
'PYexec': {'type': 'init', 'py': exec},
|
'PYexec': {'type': 'init', 'py': exec},
|
||||||
@@ -170,7 +215,7 @@ vars = {
|
|||||||
'upper': {'type': 'init', 'py': lambda x: x.upper()},
|
'upper': {'type': 'init', 'py': lambda x: x.upper()},
|
||||||
'lower': {'type': 'init', 'py': lambda x: x.lower()},
|
'lower': {'type': 'init', 'py': lambda x: x.lower()},
|
||||||
'append': {'type': 'init', 'py': lambda list, value: list.append(value)},
|
'append': {'type': 'init', 'py': lambda list, value: list.append(value)},
|
||||||
'insert': {'type': 'init', 'py': lambda list, to, value: list.insert(to,value)},
|
'insert': {'type': 'init', 'py': lambda list, to, value: list.insert(to, value)},
|
||||||
'extend': {'type': 'init', 'py': lambda list, values: list.extend(values)},
|
'extend': {'type': 'init', 'py': lambda list, values: list.extend(values)},
|
||||||
'pop': {'type': 'init', 'py': lambda list, i=-1: list.pop(i)},
|
'pop': {'type': 'init', 'py': lambda list, i=-1: list.pop(i)},
|
||||||
'number': {'type': 'init', 'py': number},
|
'number': {'type': 'init', 'py': number},
|
||||||
@@ -182,7 +227,7 @@ vars = {
|
|||||||
'binaryToNumber': {'type': 'init', 'py': lambda x: int(x, 2)},
|
'binaryToNumber': {'type': 'init', 'py': lambda x: int(x, 2)},
|
||||||
'hexToNumber': {'type': 'init', 'py': lambda x: int(x, 16)},
|
'hexToNumber': {'type': 'init', 'py': lambda x: int(x, 16)},
|
||||||
'octalToNumber': {'type': 'init', 'py': lambda x: int(x, 8)},
|
'octalToNumber': {'type': 'init', 'py': lambda x: int(x, 8)},
|
||||||
'string': {'type': 'init', 'py': lambda x: valToArgonString(x, colour=False)},
|
'string': {'type': 'init', 'py': lambda x: valToArgonString(x, colour=False)},
|
||||||
'logic': {'type': 'init', 'py': bool},
|
'logic': {'type': 'init', 'py': bool},
|
||||||
'yes': {'type': 'init', 'value': True},
|
'yes': {'type': 'init', 'value': True},
|
||||||
'no': {'type': 'init', 'value': False},
|
'no': {'type': 'init', 'value': False},
|
||||||
@@ -191,9 +236,10 @@ vars = {
|
|||||||
'time': {'type': 'init', 'py': time.time},
|
'time': {'type': 'init', 'py': time.time},
|
||||||
'exit': {'type': 'init', 'py': sys.exit},
|
'exit': {'type': 'init', 'py': sys.exit},
|
||||||
'boxify': {'type': 'init', 'py': boxify},
|
'boxify': {'type': 'init', 'py': boxify},
|
||||||
'whole': {'type':'init', 'py': int},
|
'whole': {'type': 'init', 'py': int},
|
||||||
'book': {'type':'init', 'py': dict},
|
'book': {'type': 'init', 'py': dict},
|
||||||
'items': {'type': 'init', 'py': list},
|
'items': {'type': 'init', 'py': list},
|
||||||
|
'quadraticFormula': {'type': 'init', 'py': quadraticFormula},
|
||||||
'exec': {"type": "init", "py": code_Aexec},
|
'exec': {"type": "init", "py": code_Aexec},
|
||||||
'eval': {"type": "init", "py": code_Aeval},
|
'eval': {"type": "init", "py": code_Aeval},
|
||||||
'range': {'type': 'init', 'py': Arange},
|
'range': {'type': 'init', 'py': Arange},
|
||||||
@@ -203,20 +249,20 @@ vars = {
|
|||||||
'join': {'type': 'init', 'py': lambda by, list: by.join(list)},
|
'join': {'type': 'init', 'py': lambda by, list: by.join(list)},
|
||||||
'split': {'type': 'init', 'py': lambda by, string: string.split(by)},
|
'split': {'type': 'init', 'py': lambda by, string: string.split(by)},
|
||||||
'replace': {'type': 'init', 'py': lambda from_, to, string: string.replace(from_, to)},
|
'replace': {'type': 'init', 'py': lambda from_, to, string: string.replace(from_, to)},
|
||||||
'readFile':{'type': 'init', 'py': lambda filename: open(filename, 'r').read()},
|
'readFile': {'type': 'init', 'py': lambda filename: open(filename, 'r').read()},
|
||||||
'writeFile':{'type': 'init', 'py': lambda filename, text: open(filename, 'w').write(text)},
|
'writeFile': {'type': 'init', 'py': lambda filename, text: open(filename, 'w').write(text)},
|
||||||
'appendFile':{'type': 'init', 'py': lambda filename, text: open(filename, 'a').write(text)},
|
'appendFile': {'type': 'init', 'py': lambda filename, text: open(filename, 'a').write(text)},
|
||||||
'readLines':{'type': 'init', 'py': lambda filename: open(filename, 'r').readlines()},
|
'readLines': {'type': 'init', 'py': lambda filename: open(filename, 'r').readlines()},
|
||||||
'writeLines':{'type': 'init', 'py': lambda filename, lines: open(filename, 'w').writelines(lines)},
|
'writeLines': {'type': 'init', 'py': lambda filename, lines: open(filename, 'w').writelines(lines)},
|
||||||
'appendLines':{'type': 'init', 'py': lambda filename, lines: open(filename, 'a').writelines(lines)},
|
'appendLines': {'type': 'init', 'py': lambda filename, lines: open(filename, 'a').writelines(lines)},
|
||||||
'JSONparse':{'type': 'init', 'py': json.loads},
|
'JSONparse': {'type': 'init', 'py': json.loads},
|
||||||
'JSONstringify':{'type': 'init', 'py': json.dumps},
|
'JSONstringify': {'type': 'init', 'py': json.dumps},
|
||||||
'pi': {'type': 'init', 'value': math.pi},
|
'pi': {'type': 'init', 'value': math.pi},
|
||||||
'e': {'type': 'init', 'value': math.e},
|
'e': {'type': 'init', 'value': math.e},
|
||||||
'sin': {'type': 'init', 'py': lambda x: math.sin(math.radians(x))},
|
'sin': {'type': 'init', 'py': lambda x: math.sin(math.radians(x))},
|
||||||
'cos': {'type': 'init', 'py': lambda x: math.cos(math.radians(x))},
|
'cos': {'type': 'init', 'py': lambda x: math.cos(math.radians(x))},
|
||||||
'tan': {'type': 'init', 'py': lambda x: math.tan(math.radians(x))},
|
'tan': {'type': 'init', 'py': lambda x: math.tan(math.radians(x))},
|
||||||
'rsin':{'type': 'init', 'py': math.sin},
|
'rsin': {'type': 'init', 'py': math.sin},
|
||||||
'rcos': {'type': 'init', 'py': math.cos},
|
'rcos': {'type': 'init', 'py': math.cos},
|
||||||
'rtan': {'type': 'init', 'py': math.tan},
|
'rtan': {'type': 'init', 'py': math.tan},
|
||||||
'asin': {'type': 'init', 'py': math.asin},
|
'asin': {'type': 'init', 'py': math.asin},
|
||||||
@@ -241,8 +287,8 @@ vars = {
|
|||||||
'hypot': {'type': 'init', 'py': math.hypot},
|
'hypot': {'type': 'init', 'py': math.hypot},
|
||||||
'degrees': {'type': 'init', 'py': math.degrees},
|
'degrees': {'type': 'init', 'py': math.degrees},
|
||||||
'radians': {'type': 'init', 'py': math.radians},
|
'radians': {'type': 'init', 'py': math.radians},
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
stringTextREGEX = r"( *)((((\')((\\([a-z\\\"\']))|[^\\\'])*(\'))|((\")((\\([a-z\\\"\']))|[^\\\"])*(\"))))( *)"
|
stringTextREGEX = r"( *)((((\')((\\([a-z\\\"\']))|[^\\\'])*(\'))|((\")((\\([a-z\\\"\']))|[^\\\"])*(\"))))( *)"
|
||||||
numberTextREGEX = r"( *)(\-)?([0-9]*(\.[0-9]*)?(e[0-9]+)?)( *)"
|
numberTextREGEX = r"( *)(\-)?([0-9]*(\.[0-9]*)?(e[0-9]+)?)( *)"
|
||||||
varNoSpace = r'[a-zA-Z_][a-zA-Z0-9_]*(\[([^\[\]]|\[.*\])*\])*'
|
varNoSpace = r'[a-zA-Z_][a-zA-Z0-9_]*(\[([^\[\]]|\[.*\])*\])*'
|
||||||
@@ -258,6 +304,7 @@ remTextREGEX = fr"( *)del( +)({varTextREGEX})( *)"
|
|||||||
cobined = fr"{stringTextREGEX}|{numberTextREGEX}|{varTextREGEX}|{functionTextREGEX}|{switchTextREGEX}|{itemsTextREGEX}|{commentTextREGEX}|{bookTextREGEX}|{varAdd1}|{bracketsTextREGEX}"
|
cobined = fr"{stringTextREGEX}|{numberTextREGEX}|{varTextREGEX}|{functionTextREGEX}|{switchTextREGEX}|{itemsTextREGEX}|{commentTextREGEX}|{bookTextREGEX}|{varAdd1}|{bracketsTextREGEX}"
|
||||||
commentTest = re.compile(commentTextREGEX)
|
commentTest = re.compile(commentTextREGEX)
|
||||||
cobinedcompiled = re.compile(cobined)
|
cobinedcompiled = re.compile(cobined)
|
||||||
|
noSpaceVarTest = re.compile(varNoSpace)
|
||||||
bookcompiled = re.compile(bookTextREGEX)
|
bookcompiled = re.compile(bookTextREGEX)
|
||||||
bracketsTest = re.compile(bracketsTextREGEX)
|
bracketsTest = re.compile(bracketsTextREGEX)
|
||||||
varAdd1compiled = re.compile(varAdd1)
|
varAdd1compiled = re.compile(varAdd1)
|
||||||
@@ -275,6 +322,10 @@ cobinedevalcompiled = re.compile(fr"{cobined}|{setVarREGEX}|{remTextREGEX}")
|
|||||||
evalcompiled = re.compile(r"( *)( *)")
|
evalcompiled = re.compile(r"( *)( *)")
|
||||||
varTest = re.compile(varTextREGEX)
|
varTest = re.compile(varTextREGEX)
|
||||||
|
|
||||||
|
|
||||||
|
def findclosestvarname(varname):
|
||||||
|
return find(varname, list(vars))
|
||||||
|
|
||||||
# make a function that takes an input of a string that represents a string and convert all the \ commands to their actual character
|
# make a function that takes an input of a string that represents a string and convert all the \ commands to their actual character
|
||||||
# make is decode unicode encoding (eg '\u0041' to A)
|
# make is decode unicode encoding (eg '\u0041' to A)
|
||||||
|
|
||||||
@@ -294,6 +345,8 @@ def convert_backslash(string):
|
|||||||
# make a function that takes in variable and outputs 2 things, the variable name and the itterable indexes
|
# make a function that takes in variable and outputs 2 things, the variable name and the itterable indexes
|
||||||
# e.g. variable: 'my2DList[1][4]' will output name: "my2DList" and indexes: [1, 4]
|
# e.g. variable: 'my2DList[1][4]' will output name: "my2DList" and indexes: [1, 4]
|
||||||
# to get the true value of the indexes the Aexec function
|
# to get the true value of the indexes the Aexec function
|
||||||
|
|
||||||
|
|
||||||
def get_var_name_and_indexes(variable):
|
def get_var_name_and_indexes(variable):
|
||||||
bracketSplit = variable.strip().split("[")
|
bracketSplit = variable.strip().split("[")
|
||||||
varName = bracketSplit[0]
|
varName = bracketSplit[0]
|
||||||
@@ -316,44 +369,102 @@ def get_var_name_and_indexes(variable):
|
|||||||
else:
|
else:
|
||||||
process.append(char)
|
process.append(char)
|
||||||
return varName, indexes
|
return varName, indexes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# make a function takes takes in 2 values, a mathermatical operator and 2 values and returns the result
|
# make a function takes takes in 2 values, a mathermatical operator and 2 values and returns the result
|
||||||
# the mathermatical operators are +, -, *, /, %, **, //, and access boolian operators and their nots such as ==, !=, >, <, >=, <=, and in, not in
|
# the mathermatical operators are +, -, *, /, %, **, //, and access boolian operators and their nots such as ==, !=, >, <, >=, <=, and in, not in
|
||||||
|
processes = [
|
||||||
|
"&&",
|
||||||
|
' and ',
|
||||||
|
"||",
|
||||||
|
' or ',
|
||||||
|
"!@",
|
||||||
|
' not in ',
|
||||||
|
' is not in ',
|
||||||
|
"@",
|
||||||
|
' in ',
|
||||||
|
' is in ',
|
||||||
|
"<=",
|
||||||
|
' is less than or equal to ',
|
||||||
|
' is smaller than or equal to ',
|
||||||
|
">=",
|
||||||
|
' is bigger than or equal to ',
|
||||||
|
' is more than or equal to ',
|
||||||
|
"<-",
|
||||||
|
'<',
|
||||||
|
' is less than ',
|
||||||
|
' is smaller than ',
|
||||||
|
">-",
|
||||||
|
'>',
|
||||||
|
' is bigger than ',
|
||||||
|
' is more than ',
|
||||||
|
"!=",
|
||||||
|
' is not ',
|
||||||
|
'!==',
|
||||||
|
"==",
|
||||||
|
' is ',
|
||||||
|
'===',
|
||||||
|
"/",
|
||||||
|
' divided by ',
|
||||||
|
' over ',
|
||||||
|
"%",
|
||||||
|
' modulo ',
|
||||||
|
' mod ',
|
||||||
|
"$",
|
||||||
|
'//',
|
||||||
|
' floor divistion ',
|
||||||
|
' floor division of ',
|
||||||
|
' div ',
|
||||||
|
'**',
|
||||||
|
"*",
|
||||||
|
' multiplied by ',
|
||||||
|
' times ',
|
||||||
|
' x ',
|
||||||
|
"^",
|
||||||
|
' to the power of ',
|
||||||
|
'√',
|
||||||
|
' root ',
|
||||||
|
'!^',
|
||||||
|
'!**',
|
||||||
|
'+',
|
||||||
|
' add ',
|
||||||
|
' plus ',
|
||||||
|
"-",
|
||||||
|
' subtract ',
|
||||||
|
' minus '
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def math_exec(operator, value1, value2):
|
def math_exec(operator, value1, value2):
|
||||||
if operator == "+":
|
if operator in ["+", ' add ', ' plus ']:
|
||||||
if type(value1) == str or type(value2) == str:
|
if type(value1) == str or type(value2) == str:
|
||||||
return valToArgonString(value1, colour=False)+valToArgonString(value2, colour=False)
|
return valToArgonString(value1, colour=False)+valToArgonString(value2, colour=False)
|
||||||
return value1+value2
|
return value1+value2
|
||||||
elif operator == "-":
|
elif operator in ["-", ' subtract ', ' minus ']:
|
||||||
output = value1-value2
|
output = value1-value2
|
||||||
if type(output) == float:
|
|
||||||
output = number(output)
|
|
||||||
return output
|
return output
|
||||||
elif operator == "*":
|
elif operator in ["*", ' multiplied by ', ' times ', ' x ']:
|
||||||
output = value1*value2
|
output = value1*value2
|
||||||
if type(output) == float:
|
|
||||||
output = number(output)
|
|
||||||
return output
|
return output
|
||||||
elif operator == "/":
|
elif operator in ["/", ' divided by ', ' over ']:
|
||||||
output = value1 / value2
|
output = value1 / value2
|
||||||
if type(output) == float:
|
|
||||||
return number(output)
|
|
||||||
return output
|
return output
|
||||||
elif operator == "%":
|
elif operator in ["%", ' modulo ', ' mod ']:
|
||||||
return value1 % value2
|
return value1 % value2
|
||||||
elif operator == "^":
|
elif operator in ["^", '**', ' to the power of ']:
|
||||||
output = value1 ** value2
|
output = value1 ** value2
|
||||||
if type(output) == float:
|
|
||||||
return number(output)
|
|
||||||
return output
|
return output
|
||||||
elif operator == "$":
|
elif operator in [' root ', '!**', '!^']:
|
||||||
|
output = value1 ** (1/value2)
|
||||||
|
return output
|
||||||
|
elif operator == '√':
|
||||||
|
output = value2 ** (1/value1)
|
||||||
|
return output
|
||||||
|
elif operator in ["//", '$', ' floor division ', ' floor division of ', ' div ']:
|
||||||
return value1 // value2
|
return value1 // value2
|
||||||
elif operator == "==":
|
elif operator in ["==", ' is ']:
|
||||||
return value1 == value2
|
return value1 == value2
|
||||||
elif operator == "!=":
|
elif operator in ["!=", ' is not ']:
|
||||||
return value1 != value2
|
return value1 != value2
|
||||||
elif operator == "===":
|
elif operator == "===":
|
||||||
if isinstance(value2, type(value1)):
|
if isinstance(value2, type(value1)):
|
||||||
@@ -363,17 +474,17 @@ def math_exec(operator, value1, value2):
|
|||||||
if isinstance(value2, type(value1)):
|
if isinstance(value2, type(value1)):
|
||||||
return value1 != value2
|
return value1 != value2
|
||||||
return False
|
return False
|
||||||
elif operator == ">-":
|
elif operator in [">", ">", ' is bigger than ', ' is more than ']:
|
||||||
return value1 > value2
|
return value1 > value2
|
||||||
elif operator == "<-":
|
elif operator in ["<-", "<", ' is less than ', ' is smaller than ']:
|
||||||
return value1 < value2
|
return value1 < value2
|
||||||
elif operator == ">=":
|
elif operator in [">=", ' is bigger than or equal to ', ' is more than or equal to ']:
|
||||||
return value1 >= value2
|
return value1 >= value2
|
||||||
elif operator == "<=":
|
elif operator in ["<=", ' is less then or equal to ', ' is smaller than or equal to ']:
|
||||||
return value1 <= value2
|
return value1 <= value2
|
||||||
elif operator == "@":
|
elif operator in ["@", ' in ', ' is in ']:
|
||||||
return value1 in value2
|
return value1 in value2
|
||||||
elif operator == "!@":
|
elif operator in ["!@", ' not in ', 'is not in']:
|
||||||
return value1 not in value2
|
return value1 not in value2
|
||||||
elif operator in ["||", ' or ']:
|
elif operator in ["||", ' or ']:
|
||||||
return value1 or value2
|
return value1 or value2
|
||||||
@@ -397,9 +508,12 @@ def runSub(subname, args):
|
|||||||
return run(vars[subname]['f']['code'], kwargs, True)[1]
|
return run(vars[subname]['f']['code'], kwargs, True)[1]
|
||||||
|
|
||||||
# value Argon executer takes in a string and runs it through the parser
|
# value Argon executer takes in a string and runs it through the parser
|
||||||
def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tuple of a bool and a value
|
|
||||||
didprocess = False # did the string get processed
|
|
||||||
output = None # the output of the string
|
# returns a tuple of a bool and a value
|
||||||
|
def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]:
|
||||||
|
didprocess = False # did the string get processed
|
||||||
|
output = None # the output of the string
|
||||||
if commentTest.fullmatch(string) or string.strip() == "":
|
if commentTest.fullmatch(string) or string.strip() == "":
|
||||||
pass
|
pass
|
||||||
elif not eval and setVar.fullmatch(string):
|
elif not eval and setVar.fullmatch(string):
|
||||||
@@ -407,30 +521,33 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
typeAndVar = re.split(r"( +)", string)
|
typeAndVar = re.split(r"( +)", string)
|
||||||
varname = []
|
varname = []
|
||||||
varnamearray = []
|
varnamearray = []
|
||||||
aftertype = string[5:] if string[0:5] == "const" else string[3:] if string[0:3] == "var" else string
|
aftertype = string[5:] if string[0:5] == "const" else string[3:
|
||||||
|
] if string[0:3] == "var" else string
|
||||||
value = None
|
value = None
|
||||||
type = typeAndVar[0]
|
type = typeAndVar[0]
|
||||||
if type not in ["const", "var"]:
|
if type not in ["const", "var"]:
|
||||||
varname = type
|
varname = type
|
||||||
type = "var"
|
type = "var"
|
||||||
for i in range(len(aftertype)):
|
for i in range(len(aftertype)):
|
||||||
char = aftertype[i]
|
char = aftertype[i]
|
||||||
joined = "".join(varnamearray)
|
|
||||||
if i == len(aftertype)-1 and varTest.fullmatch(joined):
|
|
||||||
varnamearray.append(char)
|
|
||||||
joined = "".join(varnamearray)
|
joined = "".join(varnamearray)
|
||||||
varname = joined.strip()
|
if i == len(aftertype)-1 and varTest.fullmatch(joined):
|
||||||
break
|
varnamearray.append(char)
|
||||||
elif char == "=" and varTest.fullmatch(joined):
|
joined = "".join(varnamearray)
|
||||||
value = Aexec(aftertype[len(joined)+1:], eval=True,vars=vars)[1]
|
varname = joined.strip()
|
||||||
varname = joined.strip()
|
break
|
||||||
break
|
elif char == "=" and varTest.fullmatch(joined):
|
||||||
else:
|
value = Aexec(aftertype[len(joined)+1:],
|
||||||
varnamearray.append(char)
|
eval=True, vars=vars)[1]
|
||||||
|
varname = joined.strip()
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
varnamearray.append(char)
|
||||||
varname, brackets = get_var_name_and_indexes(varname)
|
varname, brackets = get_var_name_and_indexes(varname)
|
||||||
if varname in vars:
|
if varname in vars:
|
||||||
if vars[varname]["type"] == "init":
|
if vars[varname]["type"] == "init":
|
||||||
raise Exception(f'Variable {varname} is an initialized variable')
|
raise Exception(
|
||||||
|
f'Variable {varname} is an initialized variable')
|
||||||
elif vars[varname]["type"] == "const" and len(brackets) == 0:
|
elif vars[varname]["type"] == "const" and len(brackets) == 0:
|
||||||
raise Exception(f"Variable {varname} is already a constant")
|
raise Exception(f"Variable {varname} is already a constant")
|
||||||
if len(brackets) == 0:
|
if len(brackets) == 0:
|
||||||
@@ -440,7 +557,7 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
for i in range(len(brackets)-1):
|
for i in range(len(brackets)-1):
|
||||||
val = val[brackets[i]]
|
val = val[brackets[i]]
|
||||||
val[brackets[-1]] = value
|
val[brackets[-1]] = value
|
||||||
|
|
||||||
elif not eval and remcompiled.fullmatch(string):
|
elif not eval and remcompiled.fullmatch(string):
|
||||||
var = re.split(r"( +)", string)[2]
|
var = re.split(r"( +)", string)[2]
|
||||||
bracketSplit = var.strip().split("[")
|
bracketSplit = var.strip().split("[")
|
||||||
@@ -460,13 +577,14 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
elif inbracket >= 1 and char == "]":
|
elif inbracket >= 1 and char == "]":
|
||||||
inbracket -= 1
|
inbracket -= 1
|
||||||
if inbracket == 0:
|
if inbracket == 0:
|
||||||
bracketslist.append(Aexec("".join(process), True, vars=vars)[1])
|
bracketslist.append(
|
||||||
|
Aexec("".join(process), True, vars=vars)[1])
|
||||||
process = []
|
process = []
|
||||||
else:
|
else:
|
||||||
process.append(char)
|
process.append(char)
|
||||||
else:
|
else:
|
||||||
process.append(char)
|
process.append(char)
|
||||||
|
|
||||||
val = vars[varname]['value']
|
val = vars[varname]['value']
|
||||||
for i in range(len(bracketslist)-1):
|
for i in range(len(bracketslist)-1):
|
||||||
val = val[bracketslist[i]]
|
val = val[bracketslist[i]]
|
||||||
@@ -474,7 +592,12 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
else:
|
else:
|
||||||
del vars[varname]
|
del vars[varname]
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Variable {varname} does not exist")
|
closest = findclosestvarname(varname)
|
||||||
|
if closest == None:
|
||||||
|
raise Exception(f'Variable {varname} does not exist')
|
||||||
|
else:
|
||||||
|
raise Exception(
|
||||||
|
f'Variable {varname} does not exist, did you mean \'{closest}\'?')
|
||||||
elif bracketsTest.fullmatch(string):
|
elif bracketsTest.fullmatch(string):
|
||||||
output = Aexec(string.strip()[1:-1], True, vars=vars)
|
output = Aexec(string.strip()[1:-1], True, vars=vars)
|
||||||
didprocess = True
|
didprocess = True
|
||||||
@@ -504,21 +627,27 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
elif inbracket >= 1 and char == "]":
|
elif inbracket >= 1 and char == "]":
|
||||||
inbracket -= 1
|
inbracket -= 1
|
||||||
if inbracket == 0:
|
if inbracket == 0:
|
||||||
bracketslist.append(Aexec("".join(process), True, vars=vars)[1])
|
bracketslist.append(
|
||||||
|
Aexec("".join(process), True, vars=vars)[1])
|
||||||
process = []
|
process = []
|
||||||
else:
|
else:
|
||||||
process.append(char)
|
process.append(char)
|
||||||
else:
|
else:
|
||||||
process.append(char)
|
process.append(char)
|
||||||
|
|
||||||
output = vars[var]['value']
|
output = vars[var]['value']
|
||||||
for i in range(len(bracketslist)):
|
for i in range(len(bracketslist)):
|
||||||
output = output[bracketslist[i]]
|
output = output[bracketslist[i]]
|
||||||
else:
|
else:
|
||||||
output = vars[var]["value"]
|
output = vars[var]["value"]
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Variable {var} does not exist")
|
closest = findclosestvarname(var)
|
||||||
elif switchcompiled.fullmatch(string):
|
if closest == None:
|
||||||
|
raise Exception(f'Variable {var} does not exist')
|
||||||
|
else:
|
||||||
|
raise Exception(
|
||||||
|
f'Variable {var} does not exist, did you mean \'{closest}\'?')
|
||||||
|
elif False:
|
||||||
process = []
|
process = []
|
||||||
switchlen = 0
|
switchlen = 0
|
||||||
switchval = None
|
switchval = None
|
||||||
@@ -526,6 +655,7 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
for i in range(len(string)):
|
for i in range(len(string)):
|
||||||
switchlen += 1
|
switchlen += 1
|
||||||
if string[i] == "?":
|
if string[i] == "?":
|
||||||
|
print(''.join(process))
|
||||||
try:
|
try:
|
||||||
switchval = Aexec("".join(process), True, vars=vars)[1]
|
switchval = Aexec("".join(process), True, vars=vars)[1]
|
||||||
breaks = True
|
breaks = True
|
||||||
@@ -533,6 +663,7 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
pass
|
pass
|
||||||
process.append(string[i])
|
process.append(string[i])
|
||||||
|
|
||||||
if not breaks:
|
if not breaks:
|
||||||
raise Exception(f"invalid 'checker' value within switch statement")
|
raise Exception(f"invalid 'checker' value within switch statement")
|
||||||
if switchval:
|
if switchval:
|
||||||
@@ -541,7 +672,8 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
char = string[switchlen+1+i]
|
char = string[switchlen+1+i]
|
||||||
if char == ":":
|
if char == ":":
|
||||||
try:
|
try:
|
||||||
didprocess,output = Aexec("".join(process), True, vars=vars)
|
didprocess, output = Aexec(
|
||||||
|
"".join(process), True, vars=vars)
|
||||||
breaks = True
|
breaks = True
|
||||||
break
|
break
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
@@ -555,7 +687,8 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
char = string[len(string)-i-1]
|
char = string[len(string)-i-1]
|
||||||
if char == ":":
|
if char == ":":
|
||||||
try:
|
try:
|
||||||
didprocess,output = Aexec("".join(process), True, vars=vars)
|
didprocess, output = Aexec(
|
||||||
|
"".join(process), True, vars=vars)
|
||||||
break
|
break
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
pass
|
pass
|
||||||
@@ -571,11 +704,12 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
for i in range(len(funcpramsTEXT)):
|
for i in range(len(funcpramsTEXT)):
|
||||||
process.append(funcpramsTEXT[i])
|
process.append(funcpramsTEXT[i])
|
||||||
if funcpramsTEXT[i] == ",":
|
if funcpramsTEXT[i] == ",":
|
||||||
try:
|
try:
|
||||||
funcprams.append(Aexec("".join(process)[:-1], True, vars=vars)[1])
|
funcprams.append(
|
||||||
process = []
|
Aexec("".join(process)[:-1], True, vars=vars)[1])
|
||||||
except SyntaxError:
|
process = []
|
||||||
pass
|
except SyntaxError:
|
||||||
|
pass
|
||||||
if len(process) > 0:
|
if len(process) > 0:
|
||||||
funcprams.append(Aexec("".join(process), True, vars=vars)[1])
|
funcprams.append(Aexec("".join(process), True, vars=vars)[1])
|
||||||
|
|
||||||
@@ -622,7 +756,8 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
if iskey:
|
if iskey:
|
||||||
if char == ",":
|
if char == ",":
|
||||||
try:
|
try:
|
||||||
output[key] = Aexec("".join(process), True, vars=vars)[1]
|
output[key] = Aexec(
|
||||||
|
"".join(process), True, vars=vars)[1]
|
||||||
process = []
|
process = []
|
||||||
iskey = False
|
iskey = False
|
||||||
key = None
|
key = None
|
||||||
@@ -633,7 +768,7 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
else:
|
else:
|
||||||
if char == ":":
|
if char == ":":
|
||||||
try:
|
try:
|
||||||
key = Aexec("".join(process), True, vars=vars)[1]
|
key = convert_backslash("".join(process))
|
||||||
if key in output:
|
if key in output:
|
||||||
raise Exception(f'Key \'{key}\' already exists')
|
raise Exception(f'Key \'{key}\' already exists')
|
||||||
iskey = True
|
iskey = True
|
||||||
@@ -651,11 +786,12 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
for i in range(len(itemsText)):
|
for i in range(len(itemsText)):
|
||||||
process.append(itemsText[i])
|
process.append(itemsText[i])
|
||||||
if itemsText[i] == ",":
|
if itemsText[i] == ",":
|
||||||
try:
|
try:
|
||||||
items.append(Aexec("".join(process)[:-1], True, vars=vars)[1])
|
items.append(
|
||||||
process = []
|
Aexec("".join(process)[:-1], True, vars=vars)[1])
|
||||||
except SyntaxError:
|
process = []
|
||||||
pass
|
except SyntaxError:
|
||||||
|
pass
|
||||||
if len(process) > 0:
|
if len(process) > 0:
|
||||||
items.append(Aexec("".join(process), True, vars=vars)[1])
|
items.append(Aexec("".join(process), True, vars=vars)[1])
|
||||||
didprocess = True
|
didprocess = True
|
||||||
@@ -666,17 +802,19 @@ def val_Aexec(string, eval=False, vars=vars) -> Tuple[bool, Any]: # returns a tu
|
|||||||
|
|
||||||
|
|
||||||
# bodmas stands for brackets, order of operations, division, multiplication, addition, subtraction
|
# bodmas stands for brackets, order of operations, division, multiplication, addition, subtraction
|
||||||
def Aexec(string, eval=False, vars=vars) -> Tuple[bool, str]: # Aexec stands for Argon Execution
|
# Aexec stands for Argon Execution
|
||||||
|
def Aexec(string, eval=False, vars=vars) -> Tuple[bool, str]:
|
||||||
string = string.strip()
|
string = string.strip()
|
||||||
if bracketsTest.fullmatch(string):
|
if bracketsTest.fullmatch(string):
|
||||||
try:
|
try:
|
||||||
return Aexec(string[1:-1], True, vars=vars)
|
return Aexec(string[1:-1], True, vars=vars)
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
pass
|
pass
|
||||||
elif (eval and cobinedcompiled.fullmatch(string)) or (not eval and cobinedevalcompiled.fullmatch(string)):
|
elif (eval and cobinedcompiled.fullmatch(string)) or (not eval and cobinedevalcompiled.fullmatch(string)):
|
||||||
return val_Aexec(string, eval, vars=vars)
|
return val_Aexec(string, eval, vars=vars)
|
||||||
processes = ["&&", ' and ', "||", ' or ', "!@", "@", "<=", ">=", "<-", ">-", "!=", "==", "/", "%", "$","*","^", '+',"-"]
|
|
||||||
didprocess = False
|
didprocess = False
|
||||||
|
output = None
|
||||||
|
breaks = False
|
||||||
for x in range(len(processes)):
|
for x in range(len(processes)):
|
||||||
currentprocesser = processes[x]
|
currentprocesser = processes[x]
|
||||||
currentsplit = string.split(currentprocesser)
|
currentsplit = string.split(currentprocesser)
|
||||||
@@ -689,9 +827,12 @@ def Aexec(string, eval=False, vars=vars) -> Tuple[bool, str]: # Aexec stands for
|
|||||||
val2 = Aexec(after, True, vars=vars)[1]
|
val2 = Aexec(after, True, vars=vars)[1]
|
||||||
didprocess = True
|
didprocess = True
|
||||||
output = math_exec(currentprocesser, val1, val2)
|
output = math_exec(currentprocesser, val1, val2)
|
||||||
|
breaks = True
|
||||||
break
|
break
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
pass
|
pass
|
||||||
|
if breaks:
|
||||||
|
break
|
||||||
if not didprocess:
|
if not didprocess:
|
||||||
raise SyntaxError(f"invalid syntax")
|
raise SyntaxError(f"invalid syntax")
|
||||||
return didprocess, output
|
return didprocess, output
|
||||||
@@ -701,7 +842,7 @@ runnerREGEX = re.compile(
|
|||||||
r"( *)(while( +)\(.*\)|if( +)\(.*\)|(sub)( +)([a-zA-Z]+)\((.*)\)( +))( *)\[( *)")
|
r"( *)(while( +)\(.*\)|if( +)\(.*\)|(sub)( +)([a-zA-Z]+)\((.*)\)( +))( *)\[( *)")
|
||||||
|
|
||||||
|
|
||||||
def run(code: list, vars=vars, isSub = False):
|
def run(code: list, vars=vars, isSub=False):
|
||||||
Runnertype = ""
|
Runnertype = ""
|
||||||
Runnercheck = None
|
Runnercheck = None
|
||||||
inRunner = 0
|
inRunner = 0
|
||||||
@@ -721,8 +862,8 @@ def run(code: list, vars=vars, isSub = False):
|
|||||||
subname = subdata[0]
|
subname = subdata[0]
|
||||||
prams = '('.join(subdata[1:]).split(')')[0].split(',')
|
prams = '('.join(subdata[1:]).split(')')[0].split(',')
|
||||||
for i in range(len(prams)):
|
for i in range(len(prams)):
|
||||||
if prams[i] == '':
|
if prams[i] == '':
|
||||||
prams.pop(i)
|
prams.pop(i)
|
||||||
else:
|
else:
|
||||||
Runnercheck = ''.join(line.strip().split(' ')[1:])[
|
Runnercheck = ''.join(line.strip().split(' ')[1:])[
|
||||||
:-1].strip()[1:-1]
|
:-1].strip()[1:-1]
|
||||||
@@ -767,7 +908,7 @@ def run(code: list, vars=vars, isSub = False):
|
|||||||
Runnercode.append(line)
|
Runnercode.append(line)
|
||||||
elif line != "":
|
elif line != "":
|
||||||
if isSub and line.strip().startswith('return'):
|
if isSub and line.strip().startswith('return'):
|
||||||
return Aexec(line.strip()[6:], vars=vars, eval=True)
|
return Aexec(line.strip()[6:], vars=vars, eval=True)
|
||||||
Aexec(line, vars=vars)
|
Aexec(line, vars=vars)
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
@@ -791,4 +932,4 @@ if __name__ == "__main__":
|
|||||||
if output[0]:
|
if output[0]:
|
||||||
log(output[1])
|
log(output[1])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
Vendored
BIN
Binary file not shown.
+8
-13
@@ -1,14 +1,9 @@
|
|||||||
log('welcome to PI calculator!')
|
const lookFor = 'argon'
|
||||||
|
const mySentence = input('Enter a sentence that contains the word \''+lookFor+'\': ')
|
||||||
|
const doesContainArgon = 'argon' is in split(' ', lower(mySentence))
|
||||||
|
|
||||||
const sides = whole(input('how many sides will the circle have? (more sides = more acurate and longer loading) '))
|
if (doesContainArgon) [
|
||||||
const timing = time()
|
log(doesContainArgon, 'your sentence does contain the word \''+lookFor+'\'!')
|
||||||
const angles = 360 / sides
|
] else [
|
||||||
var diameter = 0
|
log(doesContainArgon, 'your sentence does not contain the word \''+lookFor+'\'!')
|
||||||
|
]
|
||||||
var i = 0
|
|
||||||
while (i <- sides/2) [
|
|
||||||
diameter = diameter + sin(angles*i)
|
|
||||||
i++
|
|
||||||
]
|
|
||||||
log('pi is',sides/diameter)
|
|
||||||
log('completed in', time()-timing, 'seconds')
|
|
||||||
Reference in new issue
Block a user