-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.ebnf
43 lines (35 loc) · 1.25 KB
/
spec.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
program = {functiondef | vardef, ";"};
vardef = "var", id, ":", type, ["=", expr];
funcdef = "func", id, "(", [formal params], ")", [":", type], block;
formalparams = id, ":", type, {",", id, ":", type};
block = "{", {stmt}, "}";
stmt = funccall, ";"
| vardef, ";"
| assignment, ";"
| return, ";"
| break, ";"
| continue, ";"
| if
| while
| for;
funccall = id, "(", [actualparams], ")";
actualparams = expr, {",", expr};
assignment = id, "=", expr | id, "+=", expr | id, "-=", expr
| id, "*=", expr | id, "/=", expr | id, "%=", expr;
if = "if", expr, block, {"else if", block}, ["else", block];
while = "while", expr, block;
for = "for", id, [":", type], "=", expr, ",", expr, [",", expr], block
| "for", id, [":", type], "in", expr, block;
return = "return", expr
| "return";
break = "break";
continue = "continue";
id = (letter | "_"), {letter | digit | "_"};
expr = id | expr, binop, expr | unop, expr | number | string
| "(", expr, ")" | funccall;
type = "integer" | "string";
number = digit, {digit};
binop = "==" | "<" | ">" | "<=" | ">=" | "!=" | "and" | "or" | "xor"
| "+" | "-" | "*" | "/" | "**" | "%" | "&" | "|" | "^" | "~";
unop = "-" | "not" | "!";
string = '"', printablechar - '"', '"';