remove variable out of context
This commit is contained in:
parent
de80ed0dba
commit
d8f9ddcc4c
7
spf.py
7
spf.py
@ -15,19 +15,22 @@ class SPFInterpreter(lark.visitors.Interpreter):
|
|||||||
self.variables = Variables(trace)
|
self.variables = Variables(trace)
|
||||||
|
|
||||||
def while_loop(self, el):
|
def while_loop(self, el):
|
||||||
|
old = self.variables.variables.copy()
|
||||||
while self.visit_children(el.children[0])[0]:
|
while self.visit_children(el.children[0])[0]:
|
||||||
self.visit_children(el.children[1])
|
self.visit_children(el.children[1])
|
||||||
|
self.variables.variables = old.copy()
|
||||||
|
|
||||||
def for_loop(self, el):
|
def for_loop(self, el):
|
||||||
type = el.children[0].value
|
type = el.children[0].value
|
||||||
name = el.children[1].value
|
name = el.children[1].value
|
||||||
|
old = self.variables.variables.copy()
|
||||||
self.variables.declare(type, name)
|
self.variables.declare(type, name)
|
||||||
|
|
||||||
target = self.visit_children(el.children[2])[0]
|
target = self.visit_children(el.children[2])[0]
|
||||||
for i in target:
|
for i in target:
|
||||||
self.variables.assign(name, i)
|
self.variables.assign(name, i)
|
||||||
self.visit_children(el.children[3])
|
self.visit_children(el.children[3])
|
||||||
# TODO: delete the variable out of scope
|
self.variables.variables = old.copy()
|
||||||
|
|
||||||
def afficher(self, el):
|
def afficher(self, el):
|
||||||
ligne = ""
|
ligne = ""
|
||||||
@ -126,10 +129,12 @@ class SPFInterpreter(lark.visitors.Interpreter):
|
|||||||
return self.variables.get(el.children[0].value)
|
return self.variables.get(el.children[0].value)
|
||||||
|
|
||||||
def test(self,el):
|
def test(self,el):
|
||||||
|
old = self.variables.variables.copy()
|
||||||
if self.visit_children(el.children[0])[0]:
|
if self.visit_children(el.children[0])[0]:
|
||||||
self.visit_children(el.children[1])
|
self.visit_children(el.children[1])
|
||||||
elif len(el.children) >= 3:
|
elif len(el.children) >= 3:
|
||||||
self.visit_children(el.children[2])
|
self.visit_children(el.children[2])
|
||||||
|
self.variables.variables = old.copy()
|
||||||
|
|
||||||
|
|
||||||
# Literals
|
# Literals
|
||||||
|
Loading…
x
Reference in New Issue
Block a user