adding a bit of lexer
This commit is contained in:
parent
5aaaf574d1
commit
f2a82451ac
36
spf.lark
36
spf.lark
@ -3,8 +3,8 @@ start: (instruction)* TERMINAL
|
||||
instruction: KEYWORD TERMINAL
|
||||
| declaration TERMINAL
|
||||
|
||||
declaration: TYPE NOM
|
||||
| TYPE NOM "=" expression
|
||||
declaration: TYPE VARIABLE
|
||||
| TYPE VARIABLE "=" expression
|
||||
|
||||
expression: literal
|
||||
| list
|
||||
@ -12,9 +12,29 @@ expression: literal
|
||||
| expression operator expression
|
||||
| operator expression
|
||||
|
||||
literal: ENTIER
|
||||
| BOOLEEN
|
||||
| texte
|
||||
|
||||
texte: "\"" STRING "\""
|
||||
|
||||
list: "[" expression? ("," expression)* "]"
|
||||
|
||||
range: "[" ENTIER? ":" ENTIER? "]"
|
||||
|
||||
controls: test
|
||||
| loop
|
||||
|
||||
operator: PLUS
|
||||
| MINUS
|
||||
| TIMES
|
||||
| DIVIDE // TODO: not complete
|
||||
|
||||
PLUS: "+"
|
||||
MINUS: "-"
|
||||
TIMES: "*"
|
||||
DIVIDE: "/"
|
||||
|
||||
test: "si" expression "alors" "{" instruction* "}"
|
||||
|
||||
loop: "si" expression "alors" "{" (instruction)* "}"
|
||||
@ -24,6 +44,16 @@ COMMENT: "#" /[^\n]/
|
||||
|
||||
TERMINAL: ";"
|
||||
|
||||
VARIABLE: /([a-z]|[A-Z]|_)+[a-z]|[A-Z]|[0-9]_)+/ // TODO: ajouter accents
|
||||
VARIABLE: /([a-z]|[A-Z]|_)+([a-z]|[A-Z]|[0-9]|_)+/ // TODO: ajouter accents
|
||||
|
||||
TYPE: "booléen" | "entier" | "texte" | "liste"
|
||||
|
||||
KEYWORD: "ajouter" | "afficher"
|
||||
|
||||
ENTIER: /[1-9][0-9]*/
|
||||
|
||||
BOOLEEN: "vrai" | "faux"
|
||||
|
||||
STRING: /\w+/
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user