-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.bnf
85 lines (66 loc) · 2.84 KB
/
grammar.bnf
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<lowercase> ::= "a" | ... | "z"
<uppercase> ::= "A" | ... | "Z"
<letter> ::= <lowercase> | <uppercase>
<digit> ::= "0" | ... | "9"
<program> ::= <fn>
| <method>
| <const>
| <global_var>
| <imports>
| <interface>
<fn> ::= <prototype> <block>
<params> ::= "(" { <param> { , <param> } } ")"
<param> ::= <id>: <type>
<prototype> ::= fn <id> "(" <params> ")" <type>
<method> ::= [pub] [mut] fn "(" <custom_type> ")" <id> "(" <params> ")" <type>
<block>
<block> ::= "{" { <stmt> } [ <expr> ] "}"
<type> ::= i32 | i64 | f32 | f64 | bool | string | <custom_type> | <array>
<custom_type> ::= <uppercase> { ( <lowercase> | <digit> ) }
<array> ::= "[" <type> "]"
<interface> ::= interface <id> "{" { <prototype> ; } "}"
<struct> ::= struct <id> { <implements> } "{"
{ <member_var> }
{ [pub] [static] <prototype> <block> }
"}"
<member_var> ::= <id> : type [ "{" [get [, set]] | [set] "}" ];
<implements> ::= : <id> { , <id> }
<stmt> ::= ( <var_decl>
| <clojure>
| <for>
| <while>
| <for_in>
| <expr_stmt> ) ;
<var_decl> ::= let <id> : <type> = <expr>;
<id> ::= letter { letter | digit | "_" }
<const> ::= const <uppercase> { <uppercase> | <digit> } = <number>
| <string>
| true
| false ;
<global_var> ::= let <uppercase> { <uppercase> | <digit> } = <expr> ;
<imports> ::= { import <id>; }
<expr> ::= <eq>
<eq> ::= <comparison> { ( != | == ) <comparison> }
<comparison> ::= <term> { ( > | >= | < | <= ) <term> }
<term> ::= <factor> { ( - | + ) <factor> }
<factor> ::= <unary> { ( / | * ) <unary> }
<unary> ::= ( ! | - ) <unary> | <primary>
<primary> ::= <number>
| <string>
| true
| false
| "(" <expr> ")"
| <id_expr>
| <if_expr>
| <clojure>
<id_expr> ::= <id> ( <assign> | <fn_call> | <pipe> )
<assign> ::= "=" <expr>
<fn_call> ::= "(" { (<id> | <expr>) { , (<id> | <expr>) } } ")"
<pipe> ::= |> <id> { |> <id> }
<if_expr> ::= if <expr> <block> [ else ( <if_expr> | <block> ) ]
<clojure> ::= | <params> | -> <block>
<for> ::= [<break_tag>] for let <id> = <expr> ; <comparison> ; <expr>
<while> ::= while <expr> <block>
<for_in> ::= [<break_tag>] for <id> in <id> <block>
<expr_stmt> ::= <expr> ;
<break_tag> ::= <id>: