-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgrammar.txt
43 lines (39 loc) · 1.86 KB
/
grammar.txt
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 = {funcDecl | classDecl}
classDecl = "class" ident classBlock
classBlock = "{" {varDecl | funcDecl} "}"
funcDecl = "func" ident paramList returnList block
paramList = "(" {ident ":" varType ","} [ident ":" varType] ")"
returnList = varType | "(" varType {"," varType} ")" // Return void or nothing?
block = "{" {statement} "}"
statement = expr ";"
| varDecl ";"
| varAssignment ";"
| mutliAssignment ";"
| ifStatement
| forStatement
| whileStatement
| jumpStatement ";"
ifStatement = "if" expr block {"else" "if" expr block} ["else" block]
forStatement = "for" ident ":" varType "in" expr block
whileStatement = "while" expr block
jumpStatement = "continue" | "break" | "return" [expr {"," expr}]
varDecl = "var" ident ":" varType {"," ident : varType} "=" expr
varAssignment = expr {"," expr} assignOp expr
varRef = expr {"[" expr "]"} // REMOVE
varType = ident | "[" varType "]" | ident "[" varType {"," varType} "]"
// Tuples? "[" varType {"," varType} "]"
argList = "(" [expr {"," expr}] ")"
expr = logical
logical = equality {("&&" | "||") equality}
equality = comparison {("!=" | "==") comparison}
comparison = addition {(">" | ">=" | "<" | "<=") addition}
addition = multiplication {( "-" | "+" ) multiplication}
multiplication = unary {( "/" | "*" ) unary}
unary = (("!" | "-" | "+") unary) | postfix
postfix = paran {"[" expr "]" | argList | "." ident | "as" ident}
paran = "(" expr ")" | special
special = primary | "new" varType | "typeof" "(" expr ")"
listLiteral = "[" [expr {"," expr}] "]"
primary = ident | int | float | string | "false" | "true" | "nil" | listLiteral
// Consider moving "(" expr ")" into primary from paran.
// Missing... interfaces, switch, contracts, typedef, several literals (byte, hex, rune, char), function pointers, import, module, concurrency