diff --git a/expression.py b/expression.py index 186c43e..9c4361d 100644 --- a/expression.py +++ b/expression.py @@ -1,9 +1,4 @@ -import re - -class Token: - OPERAND_ADDITION = "+" - OPERAND_MULTIPLICATION = "*" - NUMBER = re.compile(r'\d+') #CHANGER +from lexer import Token class Expression: @@ -23,16 +18,6 @@ class Expression: return int(self.val) def __str__(self): - if Token.NUMBER.match(string=self.val) is not None: - return self.val - return "(" + self.gauche.__str__() + self.val + self.droite.__str__() + ")" - - -exp = Expression('*', -Expression(6, None, None), -Expression('+', -Expression(4, None, None), -Expression(3, None, None) -)) -print(exp.evalue()) -print(str(exp)) \ No newline at end of file + if Token.NUMBER.match(str(self.val)) != None: + return str(self.val) + return "(" + str(self.gauche.__str__()) + str(self.val) + str(self.droite.__str__()) + ")" diff --git a/lexer.py b/lexer.py new file mode 100644 index 0000000..34a8e71 --- /dev/null +++ b/lexer.py @@ -0,0 +1,6 @@ +import re + +class Token: + OPERAND_ADDITION = "+" + OPERAND_MULTIPLICATION = "*" + NUMBER = re.compile(r'\d+') #CHANGER