-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.bnf
160 lines (125 loc) · 2.8 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
binary := "0b" ("0" | "1")*
trinary := "0t" ("0" - "2")*
octadecimal := "0c" ("0" - "7")*
hexadecimal := "0x" ("0" - "9" | "a" - "f" | "A" - "F")*
DIGIT :=
("0" - "9")* |
binary |
trinary |
octadecimal |
hexadecimal
global := (statement)*
statement :=
use_stmt |
test_stmt |
break_stmt |
continue_stmt |
ret_stmt |
throw_stmt |
expr_stmt
use_stmt :=
"use" expression
[expression ("," expression)*]
";"
test_stmt :=
"test" "(" expression ")"
expression ";"
break_stmt := "break" ";"
continue_stmt := "continue" ";"
ret_stmt := "ret" expression ";"
throw_stmt := "throw" expression ";"
expr_stmt := expression ";"
expression :=
type_expr |
block_expr |
render_expr |
catch_expr |
do_expr |
while_expr |
if_expr |
random_expr |
loop_expr |
unless_expr |
when_expr |
func_expr |
maybe_expr |
array_expr |
logic_or_expr
type_expr := "type" expression
block_expr := "{" (statement)* "}"
render_expr := "render" expression
catch_expr :=
"catch" block_expr
"handle" <IDENTIFIER> block_expr
"then" block_expr
do_expr :=
"do" expression
"while" "(" expression ")"
while_expr :=
"while" "(" expression ")" expression
if_expr :=
"if" "(" expression ")" expression
["else" expression]
random_expr :=
"random" expression
["else" expression]
loop_expr :=
"loop" "("
expression ";"
expression ";"
expression
")" expression
unless_expr :=
"unless" "(" expression ")" expression
["else" expression]
when_expr :=
"when" "(" expression ")" "{"
[
"if" "(" expression ")" expression
("," "if" "(" expression ")" expression)*
]
["else" expression]
"}"
maybe_expr := "maybe"
func_expr :=
"func" "(" [<IDENTIFIER> ("," <IDENTIFIER>)*] ")"
expression
array_expr :=
"[" [expression ("," expression)*] "]"
logic_or_expr :=
logic_and_expr ["||" logic_and_expr]
logic_and_expr :=
bitwise_or_expr ["&&" bitwise_or_expr]
bitwise_or_expr :=
bitwise_xor_expr ["|" bitwise_xor_expr]
bitwise_xor_expr :=
bitwise_and_expr ["^" bitwise_and_expr]
bitwise_and_expr :=
null_coalesce_expr ["&" null_coalesce_expr]
null_coalesce_expr :=
equality_expr ["?" equality_expr]
equality_expr :=
comparison_expr [("==" | "!=" | "=") comparison_expr]
comparison_expr :=
shift_expr [("<" | "<=" | ">" | ">=") shift_expr]
shift_expr :=
term_expr [("<<" | ">>") term_expr]
term_expr :=
factor_expr [("+" | "-") factor_expr]
factor_expr :=
primary_expr [("*" | "/" | "%) primary_expr]
primary_expr :=
(
("+" | "-" | "~") expression |
"(" expression ")" |
<IDENTIFIER> ("[" expression "]")* |
literal_expr
)
(
"(" [expression ("," expression)*] ")" |
"[" expression"]"
)*
literal_expr :=
"true" | "false" | "nil" |
<STRING> |
<DIGIT>