diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 11a620a..0457f06 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,11 @@ + + + - + - + - + - + - - + + - - + + - + + - diff --git a/codepage.py b/codepage.py index b8305e6..4e27ffe 100644 --- a/codepage.py +++ b/codepage.py @@ -1 +1 @@ -codepage = ["+", "-", "×", "÷", "g", "¶"] +codepage = ["+", "-", "×", "÷", "ⁱ", "g", "¶"] diff --git a/elements.py b/elements.py index 7286b88..739788e 100644 --- a/elements.py +++ b/elements.py @@ -5,6 +5,7 @@ "-": [2, Sub], "×": [2, Mul], "÷": [2, TrueDiv], + "ⁱ": [2, Power], "g": [0, lambda *x: g], # g (and other constants) must be a lambda because the interpreter tries to call it "¶": [1, Print] } diff --git a/errors.py b/errors.py new file mode 100644 index 0000000..6f23e13 --- /dev/null +++ b/errors.py @@ -0,0 +1,21 @@ +import sys + + +class NoxanErrorBase: + """ + Base class for all Errorss. + """ + + def __init__(self, mes=None): + self.mes = mes or "" + + def raiserr(self): + errmessage = f"""Noxan {type(self).__name__} {{ + {self.mes} +}}""" + + sys.stderr.write(errmessage) + + +class InvalidSyntaxError(NoxanErrorBase): + pass diff --git a/functions.py b/functions.py index 5d27445..850a7c5 100644 --- a/functions.py +++ b/functions.py @@ -42,6 +42,9 @@ def Mul(a1, a2, ctx=None): def TrueDiv(a1, a2, ctx=None): """Divides two numbers""" + if a2 == 0: + return float(f"{'-' if a1 < 0 else ''}Infinity") + return a1 / a2 @@ -51,3 +54,8 @@ def Print(a1, ctx=None): ctx.printed = True return a1 + + +def Power(a1, a2, ctx=None): + """Calculates a1 to the power of a2""" + return a1 ** a2