~starkingdoms/starkingdoms

ref: fb87d2ae4d216d82afd37a99baec64f034d87f69 starkingdoms/kabel/grammar.ebnf -rw-r--r-- 2.0 KiB
fb87d2ae — ghostly_zsh anonymous functions 1 year, 3 months ago
                                                                                
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
program = { statement } ;

statement = function | return | loop | while | for | break | continue
                | if | block | declaration | expression_statement ;

function = "function" , identifier , "(" , { identifier , "," , } ")" , block ;
return = "return" , expression , ";" ;

loop = "loop" , block ;
while = "while" , "(" , expression , ")" , block ;
for = "for" , "(" , [ expression ] , ";" , [ expression ] , ";" , [ expression ] , ")" , block ;
break = "break" , ";" ;
continue = "continue" , ";" ;

if = "if" , "(" , expression , ")" , block [ , "else" , ( if | block ) ] ;

block = "{" , { statement } , "}" ;

declaration = "var" , identifier , "=" , expression , ";" ;

expression_statement = expression , ";" ;

expression = assignment ;

assignment = ( identifier , ( "=" | "+=" | "-=" | "*="
    | "/=" | "%=" | "&=" | "^=" | "|=" ) , assignment ) | anonymous_function ;

anonymous_function = ( "(" , { identifier , "," , } ")" , "=>" , block ) | ternary ;

ternary = logical_or [ , "?" , expression , ":" , expression ] ;

logical_or = logical_and { , "||" , logical_and } ;

logical_and = bit_and { , "&&" , bit_and } ;

bit_and = bit_xor { , "*" , bit_xor } ;
bit_xor = bit_or { , "^" , bit_or } ;
bit_or = equality { , "|" , equality } ;

equality = comparison { , ( "==" | "!=" ) , comparison } ;

comparison = term { , ( ">" | "<" | ">=" | "<=" ) , term } ;

term = factor { , ( "+" | "-" ) , factor } ;

factor = unary { , ( "*" | "/" ) , unary } ;

unary = ( ( "!" | "-" | "++" | "--" ) , unary ) | subscript ;

subscript = primary , { "[" , expression , "]" , } ;

primary = identifier | array | member | call | number | incdec | string | group ;

array = "[" , { expression , "," ? } , "]" ;

member = identifier , "." ,  { ( identifier | call ) , "." ? } ;

call = identifier , "(" , { expression, "," ? } , ")" ;

incdec = identifier , [ "++" , "--" ] ;

group = "(" , expression , ")" ;

identifier = alphabetic , { alphabetic | digit } ;
string = '"' , { character - '"' } , '"' ;
number = digit , { digit } , [ "." , digit , { digit } ] ;