-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.ebnf
66 lines (43 loc) · 1.39 KB
/
grammar.ebnf
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
66
# this is NOT an exact grammar or specification; it's merely a *general* idea
# of the structure and still needs to be semantics checked after parsing
program :: (stmt END)+ EOF
block :: ENTER (stmt END)+ EXIT
stmt :: 'var' decl assn
| 'if' bin_expr block
| 'else' 'if' bin_expr block
| 'else' block
| 'for' decl 'in' il_expr block
| 'while' bin_expr block
| 'loop' block
| 'pass'
| 'break'
| 'continue'
| 'return' ml_expr?
| place (assn | fn_call)
decl :: '[' decl (',' decl)* ']'
| NAME
assn = '=' ml_expr
index :: '.' NAME | '[' bin_expr ']'
place :: '[' place (',' place)* ']'
| simple
ml_expr :: 'fn' '(' fn_params ')' block
| 'catch' block
| il_expr
il_expr :: fn_expr
| array_expr
| dict_expr
| bin_expr
fn_expr :: '|' fn_params '|' il_expr
fn_params :: (NAME (',' NAME)*)?
fn_args :: '(' (il_expr (',' il_expr)*)? ')'
fn_call :: (':' NAME)? fn_args
array_expr :: '[' (il_expr (',' il_expr)*)? ','? ']'
dict_item :: ((NAME | '[' bin_expr ']') '=' il_expr)
dict_expr :: '{' (dict_item (',' dict_item)*)? ','? '}'
bin_op :: '+' | '-' | '*' | '/' | '^'
bin_expr :: un_expr (bin_op un_expr)*
un_op :: '-' | '!' | '~'
un_expr = un_op* simple
simple :: atom (fn_call | index)*
atom :: '(' il_expr ')' | quark
quark :: NAME | INT | FLOAT | BOOL | STRING | NULL | TABLE