From cb3e13e353ff6bf5c0233e227b1acd115fa41f94 Mon Sep 17 00:00:00 2001 From: Shadow Date: Thu, 18 Jun 2020 08:16:50 +0200 Subject: [PATCH] Ajout des appels de fonctions --- Compylateur.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Compylateur.py b/Compylateur.py index e2288ac..7cf9405 100644 --- a/Compylateur.py +++ b/Compylateur.py @@ -79,7 +79,10 @@ class Parser(): if atm.type == "MINUS": return self.atome(not minus) elif atm.type == "VAR": - #if self.token_ahead.type == "LPAR" + if self.token_ahead.type == "LPAR": + self.expect() + return Node("Function", atm.value, *self.fct()) + if minus: return Node("Operation", "--", Node("Variable", atm.value)) else: return Node("Variable", atm.value) @@ -91,6 +94,14 @@ class Parser(): if minus: return Node("Operation", "--", e) else: return e + def fct(self): + param = list() + while self.token_ahead.type != "RPAR": + if self.token_ahead.type in ("VAR", "NUM", "MINUS"): + param.append(Node("Parameter", "#{}".format(len(param)+1), self.expr())) + else: self.expect(["COMMA", "RPAR"]) + return param + def sum(self): atomes = [self.product()]