-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpigeon.ohm
63 lines (54 loc) · 1.77 KB
/
pigeon.ohm
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
Pigeon {
Program = Stmt+
Stmt = PrintStmt
| VarDec
| AssignStmt
| WhileStmt
| FunDec
| ReturnStmt
PrintStmt = print Exp ";"
AssignStmt = Var "=" Exp ";"
VarDec = let id "=" Exp ";"
WhileStmt = while Exp Block
FunDec = function id Params (":" Type)? Block
ReturnStmt = return Exp? ";"
Params = "(" ListOf<Param, ","> ")"
Param = id ":" Type
Block = "{" Stmt* "}"
Type = Type "[]" --array
| id
Exp = Condition relop Condition --binary
| Condition
Condition = Exp ("+"|"-") Term --binary
| Term
Term = Term ("*"|"/"|"%") Factor --binary
| Factor
Factor = Primary "**" Factor --binary
| "-" Primary --negation
| Primary
Primary = Call
| Var
| num
| strlit
| true
| false
| "[" NonemptyListOf<Exp, ","> "]" --array
| "(" Exp ")" --parens
Var = Var "[" Exp "]" --subscript
| id --id
Call = id "(" ListOf<Exp, ","> ")"
print = "print" ~idchar
let = "let" ~idchar
while = "while" ~idchar
function = "function" ~idchar
return = "return" ~idchar
true = "true" ~idchar
false = "false" ~idchar
keyword = print | let | while | function | return | true | false
num = digit+ ("." digit+)? (("E"|"e") ("+"|"-")? digit+)?
strlit = "\"" char* "\""
char = ~"\n" ~"\"" any
id = ~keyword letter idchar*
idchar = letter | digit | "_"
relop = "<=" | "<" | "==" | "!=" | ">=" | ">"
}