-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.ebnf
50 lines (41 loc) · 1.62 KB
/
syntax.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
program = { declaration }, ?EOF?;
declaration = class-declaration | function-declaration | variable-declaration | statement;
class-declaration = "class", identifier, "{", { function-declaration }, "}";
function-declaration = "fn", identifier, "(", [ parameters ], ")", block;
parameters = identifier, { ",", identifier };
variable-declaration = "let", identifier, [ "=", expression ];
statement = ( expression | block | if-statement | while-statement | return-statement ), "\n";
return-statement = "return", [ expression ];
while-statement = "while", "(", expression, ")", statement;
if-statement = "if", "(", expression, ")", statement, [ "else", statement ];
block = "{", declaration, "}";
expression = assignment;
assignment = [ call, "." ], identifier, "=", assignment | logic-or;
logic-or = logic-and, { "or", logic-and };
logic-and = equality, { "and", equality };
equality = comparison, { ( "not" | "is" ), comparison };
comparison = term, { ( ">" | ">=" | "<" | "<=" ), term };
term = factor, { ( "-" | "+" ), factor };
factor = unary, { ( "/" | "*" ), unary };
unary = ( "!" | "-" ), unary | call;
call = primary, { ( "(", { arguments }, ")" ) | ( ".", identifier ) };
arguments = expression, { ",", expression };
primary = number | string | "true" | "false" | "none" | "(", expression, ")";
letter = "a".."z" | "A".."Z";
digit = "0".."9";
character = letter | digit;
identifier = ( character | "_" ), { ( character | "_" ) };
number = digit, { digit };
string = '"', letter, { letter }, '"';
operator
= "is"
| "not"
| "<"
| "<="
| ">"
| ">="
| "+"
| "-"
| "*"
| "/";
comment = "?", { character | "_" };