-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsyntax.ebnf
More file actions
62 lines (61 loc) · 2.66 KB
/
syntax.ebnf
File metadata and controls
62 lines (61 loc) · 2.66 KB
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
expression → assignment;
list → "[" arguments? "]";
dictionary → "{" dict_elements? "}";
dict_elements → keyval ("," keyval)*;
keyval → expression ":" expression;
assignment → (call ".")? IDENTIFIER ("[" slice "]"))* "=" assignment | logic_or;
logic_or → logic_and ("or" logic_and)*;
logic_and → equality ("and" equality)*;
equality → comparison (("!=" | "==") comparison)*;
comparison → addition ((">" | ">=" | "<" | "<=") addition)*;
addition → multiplication (("-" | "+") multiplication)*;
multiplication → power (("/" | "*") power)*;
power → unary ("^" unary)*;
unary → ("not" | "-") unary | call;
call → primary ("(" arguments? ")" | "." IDENTIFIER | ("[" slice "]"))*;
arguments → expression ("," expression)*;
slice → (":" expression)
| (":" expression ":" expression)
| (":" ":" expression)
| expression
| (expression ":")
| (expression ":" expression)
| (expression ":" ":" expression)
| (expression ":" expression ":" expression);
primary → NUMBER
| STRING
| "false"
| "true"
| "nil"
| IDENTIFIER
| "(" expression ")"
| fnAnon
| list
| dictionary;
fnAnon → "fn" "(" parameters? ")" block;
program → declaration* EOF;
declaration → (classDecl | funDecl | varDecl | statement) NEWLINE;
classDecl → "class" IDENTIFIER ( "<" IDENTIFIER )? "{" methodDecl* "}";
methodDecl → "class"? function;
funDecl → "fn" function ;
function → IDENTIFIER "(" parameters? ")" (block | exprStmt) ;
parameters → IDENTIFIER ( "," IDENTIFIER )* ;
varDecl → "let" IDENTIFIER ("=" expression)?;
statement → forStmt
| tryCatchStmt
| ifStmt
| returnStmt
| whileStmt
| exprStmt
| block;
exprStmt → expression;
forStmt → "for" (classicFor | newFor) statement;
tryCatchStmt → "try" block "catch" IDENTIFIER block;
classicFor → (varDecl | exprStmt | ",") expression? "," expression?;
newFor → IDENTIFIER ("," IDENTIFIER)? "in" expression;
ifStmt → "if" expression block ("elif" expression block)* ("else" block)?;
returnStmt → "return" expression?;
breakStmt → "break";
continueStmt → "continue";
whileStmt → "while" expression statement;
block → "{" declaration* "}";