-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrammar
More file actions
66 lines (40 loc) · 1.95 KB
/
grammar
File metadata and controls
66 lines (40 loc) · 1.95 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
63
64
65
66
program -> moduleStatement* EOF
moduleStatement -> importStatement // import
| classStatement // pub/priv class
| topLevelFnStatement // pub/priv fn native
| topLevelVarDecl // pub/priv iden
| expressionStatement
importStatement -> "import" IDENTIFIER ("." IDENTIFIER)*
classStatement -> ("pub" | "priv")? "class" IDENTIFIER "{" classDecl "}"
classDecl -> visDecl // pub/priv :
| constructorDecl // new
| opDecl // op
| staticBlock // static {
| methodStatement // static fn
| memDecl // static iden
visDecl -> ("pub" | "priv") ":"
memDecl -> "static"? IDENTIFIFER ("," IDENTIFIER)* // members can't have default values for now
constructorDecl -> "new" fnBody
opDecl -> "op" OPERATOR fnBody
staticBlock -> "static" blockStatement // static { }
methodStatement -> "static"? fnStatement // static fn native
fnStatement -> "fn" "native"? IDENTIFIER fnBody
fnBody -> "(" (IDENTIFIER ("," IDENTIFIER)*)? ")" blockStatement
topLevelFnStatement -> ("pub" | "priv")? fnStatement // pub native fn
topLevelVarDecl -> ("pub" | "priv")? IDENTIFIER "=" expression
blockStatement -> "{" statement* "}"
statement -> ifStatement
| whileStatement
| printStatement
| doStatement
| throwStatement
| tryCatchBlock
| expressionStatement
ifStatement -> "if" expression blockStatement ("else" (ifStatement | blockStatement))
whileStatement -> "while" expression blockStatement
doStatement -> "do" blockStatement "while" expression
throwStatement -> "throw" expression
tryCatchBlock -> "try" blockStatement catchStatement+
catchStatement -> "catch" "(" IDENTIFIER IDENTIFIER ")" blockStatement
printStatement -> "print" "(" expr ("," expr)* ")"
expressionStatement -> expression ("," expression)*