~starkingdoms/starkingdoms

ref: 46218c06a96bcafb08cd18349edc8a5b7e451604 starkingdoms/kabel/grammar.ebnf -rw-r--r-- 907 bytes
46218c06 — ghostlyzsh calculator parser kabel 1 year, 4 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
program = { statement } ;

statement = if | while | ( expression , ";" ) ;

while = "while" , expression , block ;

if = "if" , expression , block ;

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

expression = assignment | declaration ;

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

assignment = { identifier , "=" , } logical_or ;

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

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

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

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

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

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

primary = identifier | number | string | group ;

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

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