Adding range

This commit is contained in:
Anthony Debucquoy 2025-03-20 21:37:08 +01:00
parent ca495dfd9e
commit a22bc69491
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
3 changed files with 14 additions and 1 deletions

9
examples/lists.spf Normal file
View 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]];

View File

@ -55,7 +55,7 @@ loop: "tant" "que" expression "faire" "{" instruction_seq "}" -> while_loop
list: "[" expression? ("," expression)* "]"
range: "[" expression? ":" expression? "]"
range: "[" expression ":" expression "]"
controls: test
| loop

4
spf.py
View File

@ -136,6 +136,10 @@ class SPFInterpreter(lark.visitors.Interpreter):
true = lambda self, _: True
false = lambda self, _: False
def range(self, el):
(left, right) = self.visit_children(el)
return list(range(left, right+1))
def dump(self):
self.variables.dump()