-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsyntax.lean
125 lines (110 loc) · 4.12 KB
/
syntax.lean
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
-- syntax for values. expressions, terms, propositions, etc.
-- x ∈ VariableNames
@[reducible]
def var := ℕ
-- ⊗ ∈ UnaryOperators
inductive unop
| not : unop
| isInt : unop
| isBool : unop
| isFunc : unop
-- ⊕ ∈ BinaryOperators
inductive binop
| plus : binop
| minus : binop
| times : binop
| div : binop
| and : binop
| or : binop
| eq : binop
| lt : binop
mutual inductive value, exp, term, spec, env
-- v ∈ Values := true | false | n | <func f(x) R S {e}, σ>
with value: Type
| true : value
| false : value
| num : ℤ → value
| func : var → var → spec → spec → exp → env → value
-- e ∈ Expressions := ...
with exp: Type
| true : var → exp → exp -- let x = true in e
| false : var → exp → exp -- let x = false in e
| num : var → ℤ → exp → exp -- let x = n in e
| func : var → var → spec → spec → exp → exp → exp -- let f(x) R S = e in e
| unop : var → unop → var → exp → exp -- let y = op x in e
| binop : var → binop → var → var → exp → exp -- let z = x op y in e
| app : var → var → var → exp → exp -- let z = x(y) in e
| ite : var → exp → exp → exp -- if x then e else e
| return : var → exp -- return x
-- A ∈ LogicalTerms := v | x | ⊗A | A⊕A | A(A)
with term: Type
| value : value → term
| var : var → term
| unop : unop → term → term
| binop : binop → term → term → term
| app : term → term → term
-- R,S ∈ Specs := A | ¬ R | R ∧ S | R ∨ S | spec A(x) req R ens S
with spec: Type
| term : term → spec
| not : spec → spec
| and : spec → spec → spec
| or : spec → spec → spec
| func : term → var → spec → spec → spec
-- σ ∈ Environments := • | σ[x↦v]
with env: Type
| empty : env
| cons : env → var → value → env
-- s ∈ Stacks := (σ, e) | s · (σ, let y = f(x) in e)
inductive stack
| top : env → exp → stack
| cons : stack → env → var → var → var → exp → stack
-- P,Q ∈ Propositions := A | ¬ P | P ∧ Q | P ∨ Q | pre(A, A) | pre(⊗, A) | pre(⊕, A, A) |
-- post(A, A) | call(A) | ∀x. {call(x)} ⇒ P | ∃x. P
inductive prop
| term : term → prop
| not : prop → prop
| and : prop → prop → prop
| or : prop → prop → prop
| pre : term → term → prop
| pre₁ : unop → term → prop
| pre₂ : binop → term → term → prop
| post : term → term → prop
| call : term → prop
| forallc : var → prop → prop
| exis : var → prop → prop
-- A[•] ∈ TermContexts := • | v | x | ⊗ A[•] | A[•] ⊕ A[•] | A[•] ( A[•] )
inductive termctx
| hole : termctx
| value : value → termctx
| var : var → termctx
| unop : unop → termctx → termctx
| binop : binop → termctx → termctx → termctx
| app : termctx → termctx → termctx
-- P[•], Q[•] ∈ PropositionsContexts := A[•] | ¬ P[•] | P[•] ∧ Q[•] | P[•] ∨ Q[•] |
-- pre(A[•], A[•]) | pre(⊗, A[•]) | pre(⊕, A[•], A[•]) | post(A[•], A[•]) |
-- call(A[•]) | ∀x. {call(x)} ⇒ P[•] | ∃x. P[•]
inductive propctx
| term : termctx → propctx
| not : propctx → propctx
| and : propctx → propctx → propctx
| or : propctx → propctx → propctx
| pre : termctx → termctx → propctx
| pre₁ : unop → termctx → propctx
| pre₂ : binop → termctx → termctx → propctx
| post : termctx → termctx → propctx
| call : termctx → propctx
| forallc : var → propctx → propctx
| exis : var → propctx → propctx
-- call(x) ∈ CallTriggers
structure calltrigger := (x: term)
-- P,Q ∈ VerificationCondition := ...
inductive vc: Type
| term : term → vc
| not : vc → vc
| and : vc → vc → vc
| or : vc → vc → vc
| pre : term → term → vc
| pre₁ : unop → term → vc
| pre₂ : binop → term → term → vc
| post : term → term → vc
| univ : var → vc → vc