Ajout de la gestion des soustractions

This commit is contained in:
Shadow 2020-06-06 16:02:25 +02:00
parent 3758b9ad9c
commit b9f18b2215
1 changed files with 10 additions and 6 deletions

View File

@ -82,12 +82,16 @@ class Parser():
return e
def sum(self):
atome_1 = self.product()
if self.token_ahead.type not in ("PLUS", "MINUS"):
return atome_1
op = self.expect()
sum_1 = self.sum()
return Node("Operation", op.value, atome_1, sum_1)
atomes = [self.product()]
while self.token_ahead.type in ("PLUS", "MINUS"):
operator = self.expect()
atome_after = self.product()
atomes.append((atome_after, Node("Operation", "--", atome_after))[operator.type == "MINUS"])
return Node("Operation", "+", *atomes)
def product(self):
atome_1 = self.exp()