-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkpython-semantics-logic.k
More file actions
49 lines (34 loc) · 1.67 KB
/
Copy pathkpython-semantics-logic.k
File metadata and controls
49 lines (34 loc) · 1.67 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
require "kpython-configuration.k"
require "kpython-semantics-arithmetic.k"
module KPYTHON-SEMANTICS-LOGIC
imports KPYTHON-CONFIGURATION
imports KPYTHON-SEMANTICS-ARITHMETIC
syntax KResult ::= Val
syntax KResult ::= Vals
rule if E S => if E S else {} [macro]
rule def X:Id (self) B => def X (.Ids) B [macro]
rule def X:Id (self, Y:Ids) B => def X (Y) B [macro]
rule if true S else _ => S
rule if false _ else S => S
rule E if true else E' => E
rule E if false else E' => E'
rule while E S => if E {S while E S} [structural]
rule _:Val; => .
rule S1::Stmts S2::Stmts => S1 ~> S2 [structural]
rule <k> read() => I ...</k> <input> ListItem(I:Int) => .List ...</input> [read]
rule <k> X:Id => V ...</k>
<env>... X |-> L ...</env>
<store>... L |-> V:Val ...</store> [lookup]
rule if __name__ == '__main__' Block => Block [structural]
rule {} => . [structural]
rule <k> { S } => S ~> setEnv(Env) ...</k> <env> Env </env> [structural]
syntax KItem ::= setEnv(Map)
rule <k> setEnv(Env) => . ...</k> <env> _ => Env </env> [structural]
rule (setEnv(_) => .) ~> setEnv(_) [structural]
syntax Exp ::= lookup(Int)
rule <k> lookup(L) => V ...</k> <store>... L |-> V:Val ...</store> [lookup]
syntax KItem ::= "#freezerFunCall" "(" K ")"
rule V:Val ~> #freezerFunCall(C:Exps) => V(C)
rule (A:Exp(B:Exps))(C:Exps) => A(B) ~> #freezerFunCall(C)
rule (A:Exp[B:Exps])(C:Exps) => A[B] ~> #freezerFunCall(C)
endmodule