From d8f9ddcc4c0a0151df00f8cf4a17874d04b12b77 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 23 Mar 2025 09:52:05 +0100 Subject: [PATCH] remove variable out of context --- spf.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spf.py b/spf.py index 03418c9..18c8e74 100755 --- a/spf.py +++ b/spf.py @@ -15,19 +15,22 @@ class SPFInterpreter(lark.visitors.Interpreter): self.variables = Variables(trace) def while_loop(self, el): + old = self.variables.variables.copy() while self.visit_children(el.children[0])[0]: self.visit_children(el.children[1]) + self.variables.variables = old.copy() def for_loop(self, el): type = el.children[0].value name = el.children[1].value + old = self.variables.variables.copy() self.variables.declare(type, name) target = self.visit_children(el.children[2])[0] for i in target: self.variables.assign(name, i) self.visit_children(el.children[3]) - # TODO: delete the variable out of scope + self.variables.variables = old.copy() def afficher(self, el): ligne = "" @@ -126,10 +129,12 @@ class SPFInterpreter(lark.visitors.Interpreter): return self.variables.get(el.children[0].value) def test(self,el): + old = self.variables.variables.copy() if self.visit_children(el.children[0])[0]: self.visit_children(el.children[1]) elif len(el.children) >= 3: self.visit_children(el.children[2]) + self.variables.variables = old.copy() # Literals