-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBexp.v
70 lines (61 loc) · 2.42 KB
/
Bexp.v
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
From Rela Require Import Sigma.
From Rela Require Import Loc.
From Rela Require Import Aexp.
Import AexpNotations.
From Coq Require Import Bool.Bool.
From Coq Require Import Init.Nat.
From Coq Require Import Arith.Arith.
From Coq Require Import Arith.EqNat.
(** Definition of boolean expression **)
Inductive bexp : Type :=
| BTrue
| BFalse
| BEq (a1 a2 : aexp)
| BLe (a1 a2 : aexp)
| BNot (b : bexp)
| BAnd (b1 b2 : bexp)
| BOr (b1 b2 : bexp).
(** Evaluation of boolean expression **)
Fixpoint beval (s : sigma) (b : bexp) : bool :=
match b with
| BTrue => true
| BFalse => false
| BEq a1 a2 => (aeval s a1) =? (aeval s a2)
| BLe a1 a2 => (aeval s a1) <=? (aeval s a2)
| BNot b1 => negb (beval s b1)
| BAnd b1 b2 => andb (beval s b1)(beval s b2)
| BOr b1 b2 => orb (beval s b1) (beval s b2)
end.
(** Notations for boolean expression **)
Declare Scope bexp_scope.
Open Scope bexp_scope.
Declare Custom Entry bexp.
Module BexpNotations.
Notation "[! e !]" := (e) (e custom bexp at level 0) : bexp_scope.
Notation "{ x }" := x (in custom bexp at level 0, x constr) : bexp_scope.
Notation "( x )" := x (in custom bexp,
x custom bexp at level 2) : bexp_scope.
Notation "'true'" := true (at level 5).
Notation "'true'" := (BTrue) (in custom bexp at level 4) : bexp_scope.
Notation "'false'" := false (at level 5).
Notation "'false'" := (BFalse) (in custom bexp at level 4) : bexp_scope.
Notation "x '&&' y" := (BAnd x y) (in custom bexp at level 65,
x custom bexp,
y custom bexp,
left associativity) : bexp_scope.
Notation "x '||' y" := (BOr x y) (in custom bexp at level 65,
x custom bexp,
y custom bexp,
left associativity) : bexp_scope.
Notation "'~' b" := (BNot b) (in custom bexp at level 80,
b custom bexp,
right associativity) : bexp_scope.
Notation "x '<=' y" := (BLe x y) (in custom bexp at level 70,
x custom aexp,
y custom aexp,
no associativity) : bexp_scope.
Notation "x = y" := (BEq x y) (in custom bexp at level 70,
x custom aexp,
y custom aexp,
no associativity) : bexp_scope.
End BexpNotations.