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
|
instruction: KEYWORD TERMINAL
|
||||||
| declaration TERMINAL
|
| declaration TERMINAL
|
||||||
|
|
||||||
declaration: TYPE NOM
|
declaration: TYPE VARIABLE
|
||||||
| TYPE NOM "=" expression
|
| TYPE VARIABLE "=" expression
|
||||||
|
|
||||||
expression: literal
|
expression: literal
|
||||||
| list
|
| list
|
||||||
@ -12,9 +12,29 @@ expression: literal
|
|||||||
| expression operator expression
|
| expression operator expression
|
||||||
| operator expression
|
| operator expression
|
||||||
|
|
||||||
|
literal: ENTIER
|
||||||
|
| BOOLEEN
|
||||||
|
| texte
|
||||||
|
|
||||||
|
texte: "\"" STRING "\""
|
||||||
|
|
||||||
|
list: "[" expression? ("," expression)* "]"
|
||||||
|
|
||||||
|
range: "[" ENTIER? ":" ENTIER? "]"
|
||||||
|
|
||||||
controls: test
|
controls: test
|
||||||
| loop
|
| loop
|
||||||
|
|
||||||
|
operator: PLUS
|
||||||
|
| MINUS
|
||||||
|
| TIMES
|
||||||
|
| DIVIDE // TODO: not complete
|
||||||
|
|
||||||
|
PLUS: "+"
|
||||||
|
MINUS: "-"
|
||||||
|
TIMES: "*"
|
||||||
|
DIVIDE: "/"
|
||||||
|
|
||||||
test: "si" expression "alors" "{" instruction* "}"
|
test: "si" expression "alors" "{" instruction* "}"
|
||||||
|
|
||||||
loop: "si" expression "alors" "{" (instruction)* "}"
|
loop: "si" expression "alors" "{" (instruction)* "}"
|
||||||
@ -24,6 +44,16 @@ COMMENT: "#" /[^\n]/
|
|||||||
|
|
||||||
TERMINAL: ";"
|
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"
|
TYPE: "booléen" | "entier" | "texte" | "liste"
|
||||||
|
|
||||||
|
KEYWORD: "ajouter" | "afficher"
|
||||||
|
|
||||||
|
ENTIER: /[1-9][0-9]*/
|
||||||
|
|
||||||
|
BOOLEEN: "vrai" | "faux"
|
||||||
|
|
||||||
|
STRING: /\w+/
|
||||||
|
|
||||||
|
|
||||||
|
2
spf.py
2
spf.py
@ -32,7 +32,7 @@ def main():
|
|||||||
spf_parser = lark.Lark(grammar, parser="lalr", transformer=SPFTransformer)
|
spf_parser = lark.Lark(grammar, parser="lalr", transformer=SPFTransformer)
|
||||||
|
|
||||||
with open(args.spf_file) as spf_input:
|
with open(args.spf_file) as spf_input:
|
||||||
program = spf_input.readall()
|
program = spf_input.read()
|
||||||
spf_parser.parse(program)
|
spf_parser.parse(program)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user