From d7f9dac728f317748b6238af3f5d01e084378d43 Mon Sep 17 00:00:00 2001 From: tonitch Date: Mon, 17 Mar 2025 17:53:00 +0100 Subject: [PATCH] reorder --- spf.lark | 65 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/spf.lark b/spf.lark index e086cea..5c727ce 100644 --- a/spf.lark +++ b/spf.lark @@ -3,12 +3,10 @@ start: (instruction)* instruction: keyword expression TERMINAL | type declaration TERMINAL | assignation TERMINAL - | test - | loop + | controls -declaration: VARIABLE (EQUAL_SIGN expression)? - -assignation: VARIABLE EQUAL_SIGN expression +keyword: ADD_KW + | SHOW_KW expression: literal | list @@ -16,13 +14,20 @@ expression: literal //| expression operator expression //| operator expression -type: "booléen" | "entier" | "texte" | "liste" +type: BOOL_TYPE + | INT_TYPE + | STR_TYPE + | LIST_TYPE + +declaration: VARIABLE (EQUAL_SIGN expression)? + +assignation: VARIABLE EQUAL_SIGN expression + +loop: WHILES_KW expression WHILEE_KW "{" (instruction)* "}" literal: ENTIER | BOOLEEN - | texte - -texte: "\"" STRING "\"" + | ESCAPED_STRING list: "[" expression? ("," expression)* "]" @@ -31,46 +36,46 @@ range: "[" ENTIER? ":" ENTIER? "]" controls: test | loop +test: "si" expression "alors" "{" instruction* "}" + | "si" expression "alors" "{" instruction* "}" "sinon" "{" instruction* "}" + + operator: PLUS_SIGN | MINUS_SIGN | TIMES_SIGN | DIVIDE_SIGN // TODO: not complete -PLUS_SIGN: "+" -MINUS_SIGN: "-" -TIMES_SIGN: "*" -DIVIDE_SIGN: "/" - -EQUAL_SIGN: "=" - -test: "si" expression "alors" "{" instruction* "}" - | "si" expression "alors" "{" instruction* "}" "sinon" "{" instruction* "}" - -loop: WHILES_KW expression WHILEE_KW "{" (instruction)* "}" - TERMINAL: ";" VAR_CHARS: /[a-zA-Zçâêîôûéàèìòùëïü_]/ VARIABLE: VAR_CHARS (VAR_CHARS | /[0-9]/)* +EQUAL_SIGN: "=" + +ENTIER: /[1-9][0-9]*/ + +BOOLEEN: TRUE_KW + | FALSE_KW + +PLUS_SIGN: "+" +MINUS_SIGN: "-" +TIMES_SIGN: "*" +DIVIDE_SIGN: "/" + +BOOL_TYPE: "booléen" +INT_TYPE: "entier" +STR_TYPE: "texte" +LIST_TYPE: "liste" ADD_KW: "ajouter" SHOW_KW: "afficher" WHILES_KW: "tant que" WHILEE_KW: "faire" -keyword: ADD_KW - | SHOW_KW - -%import common.INT -> ENTIER - TRUE_KW: "vrai" FALSE_KW: "faux" -BOOLEEN: TRUE_KW - | FALSE_KW - -%import common.ESCAPED_STRING -> STRING +%import common.ESCAPED_STRING COMMENT: /#[^\n]*/ %ignore COMMENT