From 197df773f7041703313df3073731f7ed7206c71e Mon Sep 17 00:00:00 2001 From: tonitch Date: Mon, 17 Mar 2025 23:19:02 +0100 Subject: [PATCH] adding control --- examples/simple.spf | 8 ++++++++ spf.lark | 26 ++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 examples/simple.spf diff --git a/examples/simple.spf b/examples/simple.spf new file mode 100644 index 0000000..f605498 --- /dev/null +++ b/examples/simple.spf @@ -0,0 +1,8 @@ +entier pi = 314; +entier pi2 = 3; + +pi = 3; + +tant que pi vaut pi2 faire { + afficher "bonjour"; +} diff --git a/spf.lark b/spf.lark index 5c727ce..0c94809 100644 --- a/spf.lark +++ b/spf.lark @@ -8,11 +8,16 @@ instruction: keyword expression TERMINAL keyword: ADD_KW | SHOW_KW -expression: literal - | list - | range - //| expression operator expression - //| operator expression +expression: expressionleft + | gen_op + +expressionleft: literal + | list + | range + | VARIABLE + +gen_op: expressionleft SAME_OP expression + | expressionleft DIFF_OP expression type: BOOL_TYPE | INT_TYPE @@ -23,10 +28,10 @@ declaration: VARIABLE (EQUAL_SIGN expression)? assignation: VARIABLE EQUAL_SIGN expression -loop: WHILES_KW expression WHILEE_KW "{" (instruction)* "}" +loop: "tant" "que" expression "faire" "{" (instruction)* "}" literal: ENTIER - | BOOLEEN + | booleen | ESCAPED_STRING list: "[" expression? ("," expression)* "]" @@ -54,7 +59,7 @@ EQUAL_SIGN: "=" ENTIER: /[1-9][0-9]*/ -BOOLEEN: TRUE_KW +booleen: TRUE_KW | FALSE_KW PLUS_SIGN: "+" @@ -67,10 +72,11 @@ INT_TYPE: "entier" STR_TYPE: "texte" LIST_TYPE: "liste" +SAME_OP: "==" | "vaut" +DIFF_OP: "!=" | "ne" "vaut" "pas" + ADD_KW: "ajouter" SHOW_KW: "afficher" -WHILES_KW: "tant que" -WHILEE_KW: "faire" TRUE_KW: "vrai" FALSE_KW: "faux"