-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
36 lines (25 loc) · 903 Bytes
/
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
expr : KEYWORD:VAR IDENTIFIER EQ expr
: comp-expr ((KEYWORD:AND|KEYWORD:OR) comp-expr)*
comp-expr : NOT comp-expr
: arith-expr ((EE|LT|GT|LTE|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 : INT|FLOAT|IDENTIFIER
: LPAREN expr RPAREN
: if-expr
: for-expr
: while-expr
: func-def
if-expr : KEYWORD:IF expr KEYWORD:THEN expr
(KEYWORD:ELIF expr KEYWORD:THEN expr)*
(KEYWORD:ELSE expr)?
for-expr : KEYWORD:FOR IDENTIFIER EQ expr KEYWORD:TO expr
(KEYWORD:STEP expr)? KEYWORD:THEN expr
while-expr : KEYWORD:WHILE expr KEYWORD:THEN expr
func-def : KEYWORD:FUN IDENTIFIER?
LPAREN (IDENTIFIER (COMMA IDENTIFIER)*)? RPAREN
ARROW expr