Library Lang



Require Import Program.

Chapter 4: Extended Language Definition


Inductive OrdOp := EqOP | LeOP.

Inductive BoolOp := AndOP | OrOP.

Inductive NatOp := PlusOP | MinusOP.

Definition SemOrdOp (op : OrdOp) : nat -> nat -> bool :=
  match op with
  | EqOP => Coq.Init.Nat.eqb
  | LeOP => Coq.Init.Nat.leb
  end
.

Definition SemBoolOp (op : BoolOp) : bool -> bool -> bool :=
  match op with
  | AndOP => andb
  | OrOP => orb
  end
.

Definition SemNatOp (op : NatOp) : nat -> nat -> nat :=
  match op with
  | PlusOP => Peano.plus
  | MinusOP => Peano.minus
  end
.

*Language Syntax
Definition Env := nat.

Inductive Var : Env -> Type :=
| ZVAR : forall E, Var (S E)
| SVAR : forall E, Var E -> Var (S E)
.

*Definition 36: Syntax
Inductive V E :=
| VAR : Var E -> V E
| BOOL : bool -> V E
| NAT : nat -> V E
| FUN : Expr E.+2 -> V E
| VPAIR : V E -> V E -> V E
with Expr E :=
| VAL : V E -> Expr E
| APP : V E -> V E -> Expr E
| OOp : OrdOp -> Expr E -> Expr E -> Expr E
| BOp : BoolOp -> Expr E -> Expr E -> Expr E
| NOp : NatOp -> Expr E -> Expr E -> Expr E
| LET : Expr E -> Expr E.+1 -> Expr E
| IFB : Expr E -> Expr E -> Expr E -> Expr E
| EFST : V E -> Expr E
| ESND : V E -> Expr E
.
Arguments BOOL [E] _.
Arguments NAT [E] _.

Scheme V_induction := Induction for V Sort Prop
  with E_induction := Induction for Expr Sort Prop.
Combined Scheme mutual_VE_induction from V_induction, E_induction.

*Definition 37: Frame Stack
*Notation
Notation "⎣ b ⎦" := (VAL (BOOL b)) (at level 1, no associativity).
Notation "⌊ n ⌋" := (VAL (NAT n)) (at level 1, no associativity).
Notation "'v⎨' v ⎬" := (VAR v) (at level 202, no associativity).
Notation "'e⎨' v ⎬" := (VAL (VAR v)) (at level 202, no associativity).
Notation "'λ' e" := (FUN e) (at level 1, no associativity).
Infix "@" := APP (at level 201, left associativity).

Notation "∅" := Empty.
Infix "⊚" := PUSHLet (at level 1, left associativity).
Notation "fs ∘ ( e ⦓ op ⦔ ⊡ )" := (PUSHRNOp op fs e)
                                 (at level 1, left associativity).
Notation "fs ∘ ( ⊡ ⦓ op ⦔ e )" := (PUSHLNOp op fs e)
                                 (at level 1, left associativity).
Notation "fs ∘ ( e ⇆ e' )" := (PUSHCond fs e e')
                                 (at level 1, left associativity).