reorder
This commit is contained in:
parent
efa1776155
commit
d7f9dac728
65
spf.lark
65
spf.lark
@ -3,12 +3,10 @@ start: (instruction)*
|
|||||||
instruction: keyword expression TERMINAL
|
instruction: keyword expression TERMINAL
|
||||||
| type declaration TERMINAL
|
| type declaration TERMINAL
|
||||||
| assignation TERMINAL
|
| assignation TERMINAL
|
||||||
| test
|
| controls
|
||||||
| loop
|
|
||||||
|
|
||||||
declaration: VARIABLE (EQUAL_SIGN expression)?
|
keyword: ADD_KW
|
||||||
|
| SHOW_KW
|
||||||
assignation: VARIABLE EQUAL_SIGN expression
|
|
||||||
|
|
||||||
expression: literal
|
expression: literal
|
||||||
| list
|
| list
|
||||||
@ -16,13 +14,20 @@ expression: literal
|
|||||||
//| expression operator expression
|
//| expression operator 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
|
literal: ENTIER
|
||||||
| BOOLEEN
|
| BOOLEEN
|
||||||
| texte
|
| ESCAPED_STRING
|
||||||
|
|
||||||
texte: "\"" STRING "\""
|
|
||||||
|
|
||||||
list: "[" expression? ("," expression)* "]"
|
list: "[" expression? ("," expression)* "]"
|
||||||
|
|
||||||
@ -31,46 +36,46 @@ range: "[" ENTIER? ":" ENTIER? "]"
|
|||||||
controls: test
|
controls: test
|
||||||
| loop
|
| loop
|
||||||
|
|
||||||
|
test: "si" expression "alors" "{" instruction* "}"
|
||||||
|
| "si" expression "alors" "{" instruction* "}" "sinon" "{" instruction* "}"
|
||||||
|
|
||||||
|
|
||||||
operator: PLUS_SIGN
|
operator: PLUS_SIGN
|
||||||
| MINUS_SIGN
|
| MINUS_SIGN
|
||||||
| TIMES_SIGN
|
| TIMES_SIGN
|
||||||
| DIVIDE_SIGN // TODO: not complete
|
| 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: ";"
|
TERMINAL: ";"
|
||||||
|
|
||||||
VAR_CHARS: /[a-zA-Zçâêîôûéàèìòùëïü_]/
|
VAR_CHARS: /[a-zA-Zçâêîôûéàèìòùëïü_]/
|
||||||
VARIABLE: VAR_CHARS (VAR_CHARS | /[0-9]/)*
|
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"
|
ADD_KW: "ajouter"
|
||||||
SHOW_KW: "afficher"
|
SHOW_KW: "afficher"
|
||||||
WHILES_KW: "tant que"
|
WHILES_KW: "tant que"
|
||||||
WHILEE_KW: "faire"
|
WHILEE_KW: "faire"
|
||||||
|
|
||||||
keyword: ADD_KW
|
|
||||||
| SHOW_KW
|
|
||||||
|
|
||||||
%import common.INT -> ENTIER
|
|
||||||
|
|
||||||
TRUE_KW: "vrai"
|
TRUE_KW: "vrai"
|
||||||
FALSE_KW: "faux"
|
FALSE_KW: "faux"
|
||||||
|
|
||||||
BOOLEEN: TRUE_KW
|
%import common.ESCAPED_STRING
|
||||||
| FALSE_KW
|
|
||||||
|
|
||||||
%import common.ESCAPED_STRING -> STRING
|
|
||||||
|
|
||||||
COMMENT: /#[^\n]*/
|
COMMENT: /#[^\n]*/
|
||||||
%ignore COMMENT
|
%ignore COMMENT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user