From b9f18b2215a6f02d6cdf72ea8497487c926f685f Mon Sep 17 00:00:00 2001 From: Shadow Date: Sat, 6 Jun 2020 16:02:25 +0200 Subject: [PATCH] Ajout de la gestion des soustractions --- Compylateur.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Compylateur.py b/Compylateur.py index 8659c43..27c60af 100644 --- a/Compylateur.py +++ b/Compylateur.py @@ -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()