-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.pegjs
More file actions
46 lines (37 loc) · 736 Bytes
/
lambda.pegjs
File metadata and controls
46 lines (37 loc) · 736 Bytes
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
program
= defs:def* _ exp:exp _ {
return {
type: "withdefs",
defs: defs.reduce((all, one) => ({...all, [one.name]: one }), {}),
exp: exp
}
}
/ _ exp:exp _ { return exp }
def
= "def" _ name:name _ "=" _ func:function _ {
return { type: "def", name: name, func: func }
}
exp
= function
/ app
/ var
function
= lambda arg:bound "." body:exp {
return { type: "function", arg: arg, body: body }
}
app
= "(" func:exp _ arg:exp ")" _ {
return { type: "app", func: func, arg: arg }
}
bound
= name
var
= name { return { type: "var", name: text() } }
lambda
= "\\"
/ "λ"
/ _ "lambda" _
name
= [_a-z0-9*/+-]+ { return text() }
_ "whitespace"
= [ \t\n\r]*