-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkitty.grammar
65 lines (45 loc) · 1.88 KB
/
kitty.grammar
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
55
56
57
58
59
60
61
62
63
64
65
statements : (NLINE | INLINE_COMMENT)* statement ((NLINE | INLINE_COMMENT)* statement)* (NLINE | INLINE_COMMENT)*
statement : func-def
: var-def
: expr
expr : comp-expr ((KEYWORD:and|KEYWORD:or) comp-expr)*
: KEYWORD:ret expr?
: KEYWORD:continue
: KEYWORD:break
var-def : KEYWORD:var IDENTIFIER
((COLON IDENTIFIER) (ASSIGN expr)?) | ASSIGN expr
comp-expr : KEYWORD:not comp-expr
: arith-expr ((EQ|LT|GT|LTE|GTE) arith-expr)*
arith-expr : term ((ADD|SUB) term)*
term : factor ((MUL|DIV) factor)*
factor : (ADD|SUB) factor
: call
call : atom (L_BRC (expr (COMMA expr)*)? R_BRC)?
atom : INT|FLOAT|STR|CHAR|BOOL|COMMENT|E_BLOCK
: L_BRC expr R_BRC
: if-expr
: for-expr
: while-expr
: list-expr
: var-access
var-access : IDENTIFIER
var-assign : var-access ASSIGN expr
list-expr : L_SQUARE (expr (COMMA expr)*)? R_SQUARE
if-expr-a : KEYWORD:if expr R_ARROW expr (if-expr-d|if-expr-e)?
| (S_BLOCK statements E_BLOCK (if-expr-b|if-expr-c)?)
if-expr-b : KEYWORD:elif expr
S_BLOCK statements E_BLOCK (if-expr-b|if-expr-c)?
if-expr-c : KEYWORD:else S_BLOCK statements E_BLOCK
if-expr-d : KEYWORD:elif R_ARROW expr (if-expr-d|if-expr-e)?
if-expr-e : KEYWORD:else R_ARROW expr
for-expr : KEYWORD:for
(L_BRC var-access KEYWORD:in expr R_BRC)
| (var-access KEYWORD:in expr)
R_ARROW expr
| (S_BLOCK statements E_BLOCK)
while-expr : KEYWORD:while expr
S_BLOCK statements E_BLOCK
func-def : KEYWORD:func IDENTIFIER
L_BRC (IDENTIFIER COLON IDENTIFIER (COMMA IDENTIFIER COLON IDENTIFIER)*)? R_BRC R_ARROW IDENTIFIER
(R_ARROW expr)
| (S_BLOCK statements E_BLOCK)