Adding range
This commit is contained in:
parent
ca495dfd9e
commit
a22bc69491
9
examples/lists.spf
Normal file
9
examples/lists.spf
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
liste premier = [1, 2, 3];
|
||||||
|
|
||||||
|
ajouter 4 dans premier;
|
||||||
|
|
||||||
|
liste deuxieme = [1:4];
|
||||||
|
|
||||||
|
liste troisième = [deuxieme[0]: 10];
|
||||||
|
|
||||||
|
liste quatrième = [1: troisième[6]];
|
2
spf.lark
2
spf.lark
@ -55,7 +55,7 @@ loop: "tant" "que" expression "faire" "{" instruction_seq "}" -> while_loop
|
|||||||
|
|
||||||
list: "[" expression? ("," expression)* "]"
|
list: "[" expression? ("," expression)* "]"
|
||||||
|
|
||||||
range: "[" expression? ":" expression? "]"
|
range: "[" expression ":" expression "]"
|
||||||
|
|
||||||
controls: test
|
controls: test
|
||||||
| loop
|
| loop
|
||||||
|
4
spf.py
4
spf.py
@ -136,6 +136,10 @@ class SPFInterpreter(lark.visitors.Interpreter):
|
|||||||
true = lambda self, _: True
|
true = lambda self, _: True
|
||||||
false = lambda self, _: False
|
false = lambda self, _: False
|
||||||
|
|
||||||
|
def range(self, el):
|
||||||
|
(left, right) = self.visit_children(el)
|
||||||
|
return list(range(left, right+1))
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
self.variables.dump()
|
self.variables.dump()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user