-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.ebnf
41 lines (26 loc) · 1002 Bytes
/
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
unit = {declaration};
declaration
= letDeclaration
| methodDeclaration
;
letDeclaration = "let" IDENTIFIER [":" ["const"] IDENTIFIER] ["=" (LITERAL | IDENTIFIER | expresion)];
namespaceDeclaration = "space" "{" {declaration} "}";
typeDeclaration = "type" "{" letDeclaration "}";
enumDeclaration = "enum" "{" [enumMember {"," enumMember} ] "}";
enumMember = IDENTIFIER ["(" IDENTIFIER ")"];
methodDeclaration = "fn" IDENTIFIER "(" [parameter {"," parameter}] ")" [IDENTIFIER] "{" [statement] "}";
scope = statement | "{" {statement} "}";
statement
= declaration
| ("if" expresion statement ["else" statement])
| ("match" expresion "{" {(IDENTIFIER | expresion) "->" scope} [(UNDERSCORE) "->" scope] "}")
| scope
;
expresion = binary {operatorLow binary};
binary = [("-" | "!")] value [operatorHight binary];
value = LITERAL | ("(" expresion ")");
operatorLow
= "==" | "!=" | "<" | "<=" | ">" | ">="
| "&" | "|" | "~" | "^" | "<<" | ">>"
| "+" | "-";
operatorHight = "*" | "/";