-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.ebnf
55 lines (37 loc) · 1.57 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
(* A grammar used as reference when building the parser. *)
(* It's probably out of date. *)
root = scope ;
scope = { cmp, ";" | definition | term-selection | term-iteration },
[ cmp | definition | selection | iteration ] ;
definition = "def", [ name ], term-abstraction ;
term-abstraction = [ jux ], term-thunk ;
abstraction = [ jux ], thunk ;
term-thunk = thunk-arrow, ";" | thunk-block ;
thunk = thunk-arrow | thunk-block ;
thunk-arrow = [ "->", jux ], "=>", bitwise ;
thunk-block = [ "->", jux ], "{", scope, "}"
| [ "impl", jux ], ".{", scope, "}" ;
term-selection = "case", logical, term-thunk,
{ "else", logical, term-thunk },
[ "else", term-thunk ] ;
term-iteration = "loop", expr, term-thunk ;
selection = "case", logical, thunk,
{ "else", logical, thunk },
[ "else", thunk ] ;
iteration = "loop", logical, thunk ;
logical = logic-or ;
logic-or = [ logic-or, "or" ], logic-and ;
logic-and = [ logic-and, "and" ], cmp ;
cmp = [ unknown, ( "=" | "!=" | "<" | "<=" | ">" | ">=" | "<-" ) ], unknown ;
unknown = bitwise | ( "val" | "var" | "set" ), name, [ ":", bitwise ] | abstraction ;
bitwise = bit-or;
bit-or = [ bit-or, "|" ], bit-xor ;
bit-xor = [ bit-xor, "~" ], bit-and ;
bit-and = [ bit-and, "&" ], shift ;
shift = [ shift, ( "<<" | ">>" ) ], arith ;
arith = [ arith, ( "+" | "-" ) ], term ;
term = [ term, ( "*" | "/" | "%" ) ], prefix ;
prefix = [ "!" | "-" | "^" ], jux ;
jux = atom, { atom } ;
atom = name | number | string | ".", name | "(", tuple, ")" ;
tuple = { scope, ",", }, scope, [ "," ] ;