-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
56 lines (40 loc) · 1.47 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
statements : NEWLINE* expt(NEWLINE+ statement)* NEWLINE*
statement : KEYWORD:return expr?
: expr
expr : KEYWORD IDENTIFIER EQ expr
: comp-expr ((KEYWORD:and|KEYWORD:or) comp-expr)*
comp-expr : not comp-expr
: arith-expr ((EE|NE|LT|LTE|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 (LPAREN (expr (COMMA, expr)*)? RPAREN)?
atom : NUM|IDENTIFIER|STR
: LPAREN expr RPAREN
: list-expr
: if-expr
: for-expr
: while-expr
: func-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 exrp 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:function IDENTIFIER? LPAREN (IDENTIFIER (COMMA, IDENTIFIER)*)? RPAREN
ARROW expr
| (NEWLINE statements KEYWORD:end)