forked from runtimeverification/zero-to-k-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_assignment.k.sol
82 lines (64 loc) · 2.67 KB
/
04_assignment.k.sol
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module ASSIGNMENT-SYNTAX
imports INT-SYNTAX
imports BOOL-SYNTAX
imports ID
syntax Exp ::= IExp | BExp
syntax IExp ::= Id | Int
syntax IExp ::= "(" IExp ")" [bracket]
| IExp "+" IExp
| IExp "-" IExp
> IExp "*" IExp
| IExp "/" IExp
> IExp "^" IExp
syntax BExp ::= Bool
syntax BExp ::= "(" BExp ")" [bracket]
| IExp "<=" IExp
| IExp "<" IExp
| IExp ">=" IExp
| IExp ">" IExp
| IExp "==" IExp
| IExp "!=" IExp
syntax BExp ::= BExp "&&" BExp
| BExp "||" BExp
syntax Stmt ::= Id "=" IExp ";"
| Stmt Stmt [left]
endmodule
module ASSIGNMENT
imports INT
imports BOOL
imports MAP
imports ASSIGNMENT-SYNTAX
configuration
<k> $PGM:Stmt </k>
<mem> .Map </mem>
rule <k> IE:IExp => substI(IE, MEM) ... </k>
<mem> MEM </mem>
requires notBool isInt(IE)
rule <k> BE:BExp => substB(BE, MEM) ... </k>
<mem> MEM </mem>
requires notBool isBool(BE)
syntax Int ::= substI ( IExp , Map ) [function]
// -----------------------------------------------
rule substI(I1 + I2, SUBST) => substI(I1, SUBST) +Int substI(I2, SUBST)
rule substI(I1 - I2, SUBST) => substI(I1, SUBST) -Int substI(I2, SUBST)
rule substI(I1 * I2, SUBST) => substI(I1, SUBST) *Int substI(I2, SUBST)
rule substI(I1 / I2, SUBST) => substI(I1, SUBST) /Int substI(I2, SUBST)
rule substI(I1 ^ I2, SUBST) => substI(I1, SUBST) ^Int substI(I2, SUBST)
rule substI(I:Id, SUBST) => {SUBST [ I ]}:>Int
rule substI(I:Int, _SUBST) => I
syntax Bool ::= substB ( BExp , Map ) [function]
// ------------------------------------------------
rule substB(I1 <= I2, SUBST) => substI(I1, SUBST) <=Int substI(I2, SUBST)
rule substB(I1 < I2, SUBST) => substI(I1, SUBST) <Int substI(I2, SUBST)
rule substB(I1 >= I2, SUBST) => substI(I1, SUBST) >=Int substI(I2, SUBST)
rule substB(I1 > I2, SUBST) => substI(I1, SUBST) >Int substI(I2, SUBST)
rule substB(I1 == I2, SUBST) => substI(I1, SUBST) ==Int substI(I2, SUBST)
rule substB(I1 != I2, SUBST) => substI(I1, SUBST) =/=Int substI(I2, SUBST)
rule substB(B1 && B2, SUBST) => substB(B1, SUBST) andBool substB(B2, SUBST)
rule substB(B1 || B2, SUBST) => substB(B1, SUBST) orBool substB(B2, SUBST)
rule substB(true , _SUBST) => true
rule substB(false, _SUBST) => false
rule <k> S1:Stmt S2:Stmt => S1 ~> S2 ... </k>
rule <k> ID = IE ; => . ... </k>
<mem> MEM => MEM [ ID <- substI(IE, MEM) ] </mem>
endmodule