This commit is contained in:
tonitch 2025-03-17 17:53:00 +01:00
parent efa1776155
commit d7f9dac728
Signed by: tonitch
GPG Key ID: A78D6421F083D42E

View File

@ -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