-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
54 lines (41 loc) · 1.57 KB
/
grammar.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
statments : NEWLINE* statment (NEWLINE + statment)* NEWLINE*
statment : KEYWORD:return expr?
: KEYWORD:continue
: KEYWORD:break
: expr
expr:KEYWORD :pik IDENTIFIER EQ expr
:compr-expr ((KEYWORD:AND|KEQWORD:OR) comp-expr)
comp-expr :not comp_expr
:arith-expr ((EE|LT|GT|GTE) arith-expr)
arith-expr : term ((PLUS|MINUS) term)*
term: factor ((MUL|DIV) factor)*
factor :(PLUS|MINUS) factor
:power
power :call (POW factor)*
call :atom (LPAREM (expr (COMMA expr)*)? RPAREM)?
atom: INT|FLOAT|STRING|IDENTIFIER
:LPAREM expr RPAREM
:list_expr
:if-expr
:fun-def
list_expr: LSQUARE (expr (COMMA expr)*)? RSQUARE
if-expr : KEYWORD:IF expr KEYWORD:THEN
(expr if-expr-b|if-expr-c?)
| (NEWLINE statements KEYWORD:END|if-expr-b|if-expr-c)
if-expr-b : KEYWORD:ELIF expr KEYWORD:THEN
(expr if-expr-b|if-expr-c?)
| (NEWLINE statements KEYWORD:END|if-expr-b|if-expr-c)
if-expr-c : KEYWORD:ELSE
expr
| (NEWLINE statements KEYWORD:END)
for-expr : KEYWORD:FOR IDENTIFIER EQ expr KEYWORD:TO expr
(KEYWORD:STEP expr)? KEYWORD:THEN
expr
| (NEWLINE statements KEYWORD:END)
while-expr : KEYWORD:WHILE expr KEYWORD:THEN
expr
| (NEWLINE statements KEYWORD:END)
func-def : KEYWORD:FUN IDENTIFIER?
LPAREN (IDENTIFIER (COMMA IDENTIFIER)*)? RPAREN
(ARROW expr)
| (NEWLINE statements KEYWORD:END)