compilation/spf.lark
2025-03-17 17:53:00 +01:00

85 lines
1.4 KiB
Plaintext

start: (instruction)*
instruction: keyword expression TERMINAL
| type declaration TERMINAL
| assignation TERMINAL
| controls
keyword: ADD_KW
| SHOW_KW
expression: literal
| list
| range
//| expression operator expression
//| operator expression
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
| 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"
ADD_KW: "ajouter"
SHOW_KW: "afficher"
WHILES_KW: "tant que"
WHILEE_KW: "faire"
TRUE_KW: "vrai"
FALSE_KW: "faux"
%import common.ESCAPED_STRING
COMMENT: /#[^\n]*/
%ignore COMMENT
%import common.WS
%ignore WS