Refactor code in directories + add doc strings

This commit is contained in:
Clément Barthélemy 2024-02-20 00:01:55 +01:00
parent 0d9a636da6
commit 77c8973eb7
2 changed files with 23 additions and 3 deletions

View file

@ -0,0 +1,48 @@
from __future__ import annotations
class Symbols:
"""
All maths things (other than number) that will be parsed need to be of "Symbols" class
"""
instances = []
def __init__(self, name):
self.name = name
Symbols.instances.append(self)
def __repr__(self):
return self.name
def __str__(self):
return self.name
def __add__(self, other):
from python_symb.Expressions.expr import Expr
return Expr('+', [self, other])
def __radd__(self, other):
from python_symb.Expressions.expr import Expr
return Expr('+', [other, self])
def __mul__(self, other):
from python_symb.Expressions.expr import Expr
return Expr('*', [self, other])
def __rmul__(self, other):
from python_symb.Expressions.expr import Expr
return Expr('*', [other, self])
class Var(Symbols):
"""
variable, like 'x' in x+2
"""
instances = []
def __init__(self, name):
super().__init__(name)
self.__class__.instances.append(self)