compilation/spf.lark
2025-03-17 23:19:02 +01:00

91 lines
1.5 KiB
Plaintext

start: (instruction)*
instruction: keyword expression TERMINAL
| type declaration TERMINAL
| assignation TERMINAL
| controls
keyword: ADD_KW
| SHOW_KW
expression: expressionleft
| gen_op
expressionleft: literal
| list
| range
| VARIABLE
gen_op: expressionleft SAME_OP expression
| expressionleft DIFF_OP expression
type: BOOL_TYPE
| INT_TYPE
| STR_TYPE
| LIST_TYPE
declaration: VARIABLE (EQUAL_SIGN expression)?
assignation: VARIABLE EQUAL_SIGN expression
loop: "tant" "que" expression "faire" "{" (instruction)* "}"
literal: ENTIER
| booleen
| ESCAPED_STRING
list: "[" expression? ("," expression)* "]"
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
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"
SAME_OP: "==" | "vaut"
DIFF_OP: "!=" | "ne" "vaut" "pas"
ADD_KW: "ajouter"
SHOW_KW: "afficher"
TRUE_KW: "vrai"
FALSE_KW: "faux"
%import common.ESCAPED_STRING
COMMENT: /#[^\n]*/
%ignore COMMENT
%import common.WS
%ignore WS