-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar
53 lines (39 loc) · 1.74 KB
/
grammar
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
/*
* Assert language Grammar
* The notation is a mixture of EBNF and my preferences.
*
* +───────────────────+────────────+
* | Usage | Notation |
* +───────────────────+────────────+
* | definition | -> |
* | concatenation | , |
* | termination | ; |
* | alternation | | |
* | optional | [ ... ] |
* | repetition | { ... } |
* | grouping | ( ... ) |
* | terminal string | " ... " |
* +───────────────────+────────────+
*/
grammar -> { "dump" define | "assert" "(" assign ")" } ;
assign -> ["inv"] ident "=" expression |
["inv"] array "=" expression ;
define -> ident "(" [ident] {"," ident } ")" block ;
block -> statement | "{" statement { statement } "}" ;
statement -> "assert" "(" ( assign | "return" expression ) ")" |
"if" "(" expression ")" block ["else" block] |
"while" "(" expression ")" block |
function ;
function -> (ident | "out" | "in") "(" [expression] {"," expression } ")" ;
array -> ident "[" expression "]" ;
expression -> logical {("||"|"&&") logical} ;
logical -> boolean [(">"|"<"|">="|"<="|"=="|"!=") boolean] ;
boolean -> [+|-] additive {(+|-) additive} ;
additive -> factor {("*"|"/") factor} ;
factor -> exponent ["^" exponent] ;
exponent -> number |
ident |
array |
function |
"!" exponent |
("+"|"-") exponent ;