-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar
More file actions
107 lines (76 loc) · 2.06 KB
/
grammar
File metadata and controls
107 lines (76 loc) · 2.06 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// bare minimum ----------------------------------------------------------------
+ = fully realised and tested
- = realised but not tested
// asigments and vars
+type_spec
| KW_I64
+var_spec_no_mut
: IDENTIFIER PUNC_COLON type_spec
+var_spec(#sup)
: (KW_MUT | _) var_spec_no_mut
+assign_op
: OP_ASSIGN
+assign_expr(#sup)
: IDENTIFIER assign_op value_expr PUNC_SEMICOLON
;
+var_init(#sup)
: KW_LET var_spec OP_ASSIGN value_expr PUNC_SEMICOLON
;
// functions -------------
+func_def(#sup)
: KW_FN IDENTIFIER func_def_param PUNC_COLON type_spec statement
+func_def_param(#sup)
| PUNC_LEFT_ROUND_BRACKET (func_def_param_list | _) PUNC_RIGHT_ROUND_BRACKET
+func_def_param_list
: var_spec [PUNC_COMMA func_def_param_list]*
+func_call(#sup)
: IDENTIFIER func_call_param
+func_call_param
| PUNC_LEFT_ROUND_BRACKET (func_call_param_list | _) PUNC_RIGHT_ROUND_BRACKET
+func_call_param_list
: value_expr [PUNC_COMMA value_expr]*
// statements
+statement
: PUNC_LEFT_CURL_BRACKET statement_list PUNC_RIGHT_CURL_BRACKET
;
+statement_list:
| [single_statement]*+
+single_statement
: var_init
| assign_expr
| value_expr
| return_expr
| if_branch
| while_loop
// expression
+value_expr(#sup)
: logical_or_expr
+logical_or_expr
: logical_and_expr [|| logical_and_expr]*
+logical_and_expr
: logical_equal_expr [&& logical_equal_expr]*
+logical_equal_expr
: plus_minus_expr [(== | !=) plus_minus_expr]*
+plus_minus_expr
: mult_expr [(+ | -) mult_expr]*
+mult_expr
: basic_expr [(* | / | %) basic_expr]*
+basic_expr
: func_call
| IDENTIFIER
| CONST
| STR_LIT
| PUNC_LEFT_ROUND_BRACKET logical_or_expr PUNC_RIGHT_ROUND_BRACKET //???
;
// logical_or_expr instead of value_expr
+return_expr(#sup)
: KW_RETURN value_expr PUNC_SEMICOLON
;
// branches
+if_branch(#sup)
: KW_IF PUNC_LEFT_ROUND_BRACKET value_expr PUNC_RIGHT_ROUND_BRACKET statement (else_branch | _)
+else_branch(#sup)
: KW_ELSE if_branch
| KW_ELSE statement
+while_loop(#sup)
: KW_WHILE PUNC_LEFT_ROUND_BRACKET value_expr PUNC_RIGHT_ROUND_BRACKET statement