-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
59 lines (43 loc) · 1.71 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
statements : NEWLINE* statement (NEWLINE+ statement)* NEWLINE*
statement : KEYWORD:Return expr?
: KEYWORD:Continue
: KEYWORD:Break
: expr
expr : KEYWORD:Set IDENTIFIER EQU expr
: comp-expr ((KEYWORD:And|KEYWORD:Or) comp-expr)*
comp-expr : Not comp-expr
: arith-expr ((DEQ|LSS|GTR|LEQ|GEQ) 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|String|IDENTIFIER
: 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
(statement if-expr-b|if-expr-c?)
| (NEWLINE statements KEYWORD:END|if-expr-b|if-expr-c)
if-expr-b : KEYWORD:Elsif expr KEYWORD:THEN
(statement if-expr-b|if-expr-c?)
| (NEWLINE statements KEYWORD:END|if-expr-b|if-expr-c)
if-expr-c : KEYWORD:Else
statement
| (NEWLINE statements KEYWORD:End)
for-expr : KEYWORD:For IDENTIFIER EQU expr KEYWORD:TO expr
(KEYWORD:STEP expr)? KEYWORD:Then
statement
| (NEWLINE statements KEYWORD:End)
while-expr : KEYWORD:While expr KEYWORD:Then
statement
| (NEWLINE statements KEYWORD:End)
func-def : KEYWORD:Func IDENTIFIER?
LPAREN (IDENTIFIER (COMMA IDENTIFIER)*)? RPAREN
(ARROW expr)
| (NEWLINE statements KEYWORD:End)