-
Notifications
You must be signed in to change notification settings - Fork 8
/
Grammar.txt
61 lines (50 loc) · 1.4 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
55
56
57
58
59
60
61
BLOCK = '{' [STATEMENT]* '}'
STATEMENT = VAR_DECL
| FUNC_DEF
| CONDITIONAL
| FOR
| WHILE
| RETURN
| CONTINUE
| BREAK
| EXPR_COLS
EXPR_COLS = EXPR ';'
EXPR_COLS_OR_RBRACE = EXPR [';' '}']
EXPR = L16
L16 = L15 [',' L15]*
L15 = L14 ['=' L14]*
L14 = L13 [['+=' '-=' '*='
'/=' '%=' '<<=' '>>='
'&=' '|=' '^='] L13]* ['or' BLOCK]*
L13 = L12 ['||' L12]*
L12 = L11 ['&&' L11]*
L11 = L10 ['|' L10]*
L10 = L09 ['^' L09]*
L09 = L08 ['&' L08]*
L08 = L07 ['==' '!=' L07]*
L07 = L06 ['<' '<=' '>' '>=' L06]*
L06 = L05 ['<<' '>>' L05]*
L05 = L04 ['+' '-' L04]*
L04 = L03 ['/' '*' '%' '**' L03]*
L03 = ['++x' '--x' 'u+' 'u-' '!' '~']* L02
L02 = L01 ['x++' 'x--']{0,1}
L01 = '(' EXPR ')'
| TERM ['(' EXPR ')' | '[' EXPR ']' | '.' TERM]*
TERM = iden | str | int | flt | atom
VAR_DECL_BASE = L01 '=' L15
VAR_DECL = 'let' VAR_DECL_BASE [',' VAR_DECL_BASE]* ';'
VA_ARGS = iden '...'
KW_ARGS = atom
KW_ARGS_CALL = iden '=' L15
SIMPLE_DECL_ARGS = iden | iden '=' L15
FUNC_DECL_ARGS = SIMPLE_DECL_ARGS [',' KW_ARGS]{0,1} [',' SIMPLE_DECL_ARGS]* [',' VA_ARGS]{0,1}
FUNC_CALL_ARGS = [KW_ARGS_CALL | L15]*
FUNC_DEF = 'fn' '(' FUNC_DECL_ARGS ')'
BLOCK
CONDITIONAL = 'if' L15 BLOCK ['elif' L15 BLOCK]* ['else' BLOCK]{0,1}
FOR = 'for' iden 'in' L01 BLOCK
| 'for' [VAR_DECL | EXPR]{0,1} ';' [EXPR]{0,1} ';' [EXPR]{0,1} BLOCK
WHILE = 'while' L15 BLOCK
RETURN = 'return' [L15]{0,1} ';'
CONTINUE = 'continue' ';'
BREAK = 'break' ';'