-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda.k
49 lines (37 loc) · 1.22 KB
/
lambda.k
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
require "substitution.md"
module LAMBDA-SYNTAX
imports DOMAINS-SYNTAX
imports KVAR-SYNTAX
syntax Val ::= KVar
| "lambda" KVar "." Exp [binder]
syntax Exp ::= Val
| Exp Exp [strict, left]
| "(" Exp ")" [bracket]
syntax Val ::= Int | Bool
syntax Exp ::= "-" Int
> Exp "*" Exp [strict, left]
| Exp "/" Exp [strict]
> Exp "+" Exp [strict, left]
> Exp "<=" Exp [strict]
syntax Exp ::= "if" Exp "then" Exp "else" Exp [strict(1)]
syntax Exp ::= "let" KVar "=" Exp "in" Exp
rule let X = E in E':Exp => (lambda X . E') E [macro]
syntax Exp ::= "func" KVar KVar "=" Exp "in" Exp
| "mu" KVar "." Exp [binder]
rule func F:KVar X = E in E' => let F = mu F . lambda X . E in E' [macro]
endmodule
module LAMBDA
imports LAMBDA-SYNTAX
imports SUBSTITUTION
imports DOMAINS
syntax KResult ::= Val
rule (lambda X:KVar . E:Exp) V:Val => E[V / X]
rule - I => 0 -Int I
rule I1 * I2 => I1 *Int I2
rule I1 / I2 => I1 /Int I2
rule I1 + I2 => I1 +Int I2
rule I1 <= I2 => I1 <=Int I2
rule if true then E else _ => E
rule if false then _ else E => E
rule mu X . E => E[(mu X . E) / X]
endmodule