diff --git a/examples/lists.spf b/examples/lists.spf new file mode 100644 index 0000000..9dfb9ef --- /dev/null +++ b/examples/lists.spf @@ -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]]; diff --git a/spf.lark b/spf.lark index 55f6bd1..e41353a 100644 --- a/spf.lark +++ b/spf.lark @@ -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 diff --git a/spf.py b/spf.py index 8c8b907..2a3d98c 100755 --- a/spf.py +++ b/spf.py @@ -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()