forked from runtimeverification/zero-to-k-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_assignment_withConfig.k.sol
79 lines (61 loc) · 2.27 KB
/
04_assignment_withConfig.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
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 => evalI(IE) ... </k> requires notBool isInt(IE)
rule <k> BE:BExp => evalB(BE) ... </k> requires notBool isBool(BE)
syntax Int ::= evalI ( IExp ) [function]
// ----------------------------------------------
rule evalI(I1 + I2) => evalI(I1) +Int evalI(I2)
rule evalI(I1 - I2) => evalI(I1) -Int evalI(I2)
rule evalI(I1 * I2) => evalI(I1) *Int evalI(I2)
rule evalI(I1 / I2) => evalI(I1) /Int evalI(I2)
rule evalI(I1 ^ I2) => evalI(I1) ^Int evalI(I2)
rule evalI(I:Int) => I
rule [[ evalI(I:Id) => {MEM [ I ]}:>Int ]]
<mem> MEM </mem>
syntax Bool ::= evalB ( BExp ) [function]
// -----------------------------------------------
rule evalB(I1 <= I2) => evalI(I1) <=Int evalI(I2)
rule evalB(I1 < I2) => evalI(I1) <Int evalI(I2)
rule evalB(I1 >= I2) => evalI(I1) >=Int evalI(I2)
rule evalB(I1 > I2) => evalI(I1) >Int evalI(I2)
rule evalB(I1 == I2) => evalI(I1) ==Int evalI(I2)
rule evalB(I1 != I2) => evalI(I1) =/=Int evalI(I2)
rule evalB(B1 && B2) => evalB(B1) andBool evalB(B2)
rule evalB(B1 || B2) => evalB(B1) orBool evalB(B2)
rule evalB(true ) => true
rule evalB(false) => false
rule <k> S1:Stmt S2:Stmt => S1 ~> S2 ... </k>
rule <k> ID = IE ; => . ... </k>
<mem> MEM => MEM [ ID <- evalI(IE) ] </mem>
endmodule