notation.v 3.63 KB
Newer Older
1
From heap_lang Require Export derived.
2

3
(* What about Arguments for hoare triples?. *)
4 5
Arguments wp {_ _} _ _%L _.

6
Coercion LitInt : Z >-> base_lit.
7 8 9 10 11 12 13 14 15
Coercion LitBool : bool >-> base_lit.
(** No coercion from base_lit to expr. This makes is slightly easier to tell
   apart language and Coq expressions. *)
Coercion Var : string >-> expr.
Coercion App : expr >-> Funclass.
Coercion of_val : val >-> expr.

(** Syntax inspired by Coq/Ocaml. Constructions with higher precedence come
    first. *)
16 17
(* We have overlapping notation for values and expressions, with the expressions
   coming first. This way, parsing as a value will be preferred. If an expression
18 19 20 21 22
   was needed, the coercion of_val will be called. The notations for literals
   are not put in any scope so as to avoid lots of annoying %L scopes while
   pretty printing. *)
Notation "' l" := (Lit l%Z) (at level 8, format "' l").
Notation "' l" := (LitV l%Z) (at level 8, format "' l").
23 24
Notation "'()"  := (Lit LitUnit) (at level 0).
Notation "'()"  := (LitV LitUnit) (at level 0).
25 26 27 28 29
Notation "! e" := (Load e%L) (at level 10, right associativity) : lang_scope.
Notation "'ref' e" := (Alloc e%L)
  (at level 30, right associativity) : lang_scope.
Notation "- e" := (UnOp MinusUnOp e%L)
  (at level 35, right associativity) : lang_scope.
30 31 32 33 34 35 36
Notation "e1 + e2" := (BinOp PlusOp e1%L e2%L)
  (at level 50, left associativity) : lang_scope.
Notation "e1 - e2" := (BinOp MinusOp e1%L e2%L)
  (at level 50, left associativity) : lang_scope.
Notation "e1 ≤ e2" := (BinOp LeOp e1%L e2%L) (at level 70) : lang_scope.
Notation "e1 < e2" := (BinOp LtOp e1%L e2%L) (at level 70) : lang_scope.
Notation "e1 = e2" := (BinOp EqOp e1%L e2%L) (at level 70) : lang_scope.
37
Notation "~ e" := (UnOp NegOp e%L) (at level 75, right associativity) : lang_scope.
38 39 40 41
(* The unicode ← is already part of the notation "_ ← _; _" for bind. *)
Notation "e1 <- e2" := (Store e1%L e2%L) (at level 80) : lang_scope.
Notation "'rec:' f x := e" := (Rec f x e%L)
  (at level 102, f at level 1, x at level 1, e at level 200) : lang_scope.
42 43
Notation "'rec:' f x := e" := (RecV f x e%L)
  (at level 102, f at level 1, x at level 1, e at level 200) : lang_scope.
44
Notation "'if:' e1 'then' e2 'else' e3" := (If e1%L e2%L e3%L)
45 46 47 48 49 50 51 52
  (at level 200, e1, e2, e3 at level 200) : lang_scope.

(** Derived notions, in order of declaration. The notations for let and seq
are stated explicitly instead of relying on the Notations Let and Seq as
defined above. This is needed because App is now a coercion, and these
notations are otherwise not pretty printed back accordingly. *)
Notation "λ: x , e" := (Lam x e%L)
  (at level 102, x at level 1, e at level 200) : lang_scope.
53 54
Notation "λ: x , e" := (LamV x e%L)
  (at level 102, x at level 1, e at level 200) : lang_scope.
55 56
Notation "'let:' x := e1 'in' e2" := (Lam x e2%L e1%L)
  (at level 102, x at level 1, e1, e2 at level 200) : lang_scope.
57 58
Notation "'let:' x := e1 'in' e2" := (LamV x e2%L e1%L)
  (at level 102, x at level 1, e1, e2 at level 200) : lang_scope.
59
Notation "e1 ;; e2" := (Lam "" e2%L e1%L)
60
  (at level 100, e2 at level 200) : lang_scope.
61 62
Notation "e1 ;; e2" := (LamV "" e2%L e1%L)
  (at level 100, e2 at level 200) : lang_scope.
Robbert Krebbers's avatar
Robbert Krebbers committed
63 64 65 66 67 68 69 70

Notation "'rec:' f x y := e" := (Rec f x (Lam y e%L))
  (at level 102, f, x, y at level 1, e at level 200) : lang_scope.
Notation "'rec:' f x y := e" := (RecV f x (Lam y e%L))
  (at level 102, f, x, y at level 1, e at level 200) : lang_scope.
Notation "'rec:' f x y z := e" := (Rec f x (Lam y (Lam z e%L)))
  (at level 102, f, x, y, z at level 1, e at level 200) : lang_scope.
Notation "'rec:' f x y z := e" := (RecV f x (Lam y (Lam z e%L)))
71
  (at level 102, f, x, y, z at level 1, e at level 200) : lang_scope.