Syntax of a toy imperative language

Now that we have seen the mathematical basis behind abstract interpretation, let dig into "more concrete stuff".
We want to reason about programs. Thus, we need to formalise in some ways, what kind of program we want to reason about, their syntax and their semantics.
Here, we we will play with a toy imperative programming language.
In this file, we define its syntax.
We will then define concrete and abstract semantics for it, depending on properties we want to prove, but that will be for later files :)
NB : This file is strongly inspired (copy pasted + modified) by the definitions from the Imp chapter in the Logical Foundation book.
From Stdlib Require Import Strings.String.

Module Syntax.

We always restrict ourselves to certain domains.
Parameter D : Type.

Arithmetic expressions

First off all, we should be able to operate on numbers. These operations can be the following :
Inductive aexp : Type :=
  
A numeral (here a natural number)
  | ANum (n : D)
  
A random number between a1 and a2
  | ARandom (a1 : aexp) (a2 : aexp)
  
An identifier, which should have been declared previously
  | AId (x : string)
  
And then the classical operations on numerals.
  | APlus (a1 a2 : aexp)
  | AMinus (a1 a2 : aexp)
  | AMult (a1 a2 : aexp).

Boolean expressions

We should also be able to operate on booleans. We differentiate them from arithmetic expressions in order to have a little bit of typing and to limit ourselves to "very intuitive" semantics.
Inductive bexp : Type :=
  
True or False
  | BTrue
  | BFalse
  
Classical boolean operations
  | BEq (a1 a2 : aexp)
  | BLe (a1 a2 : aexp)
  | BAnd (b1 b2 : bexp)
  | BNot (b : bexp)
.
We can also derive some other classical boolean operations :
Definition BGt (a1 a2 : aexp) :=
  BNot (BLe a1 a2).
Definition BNeq (a1 a2 : aexp) :=
  BNot (BEq a1 a2).

Commands

And finally, it wouldn't be a true programming language without commands, that is, assignment, sequantial, if and while operators.
Inductive com : Type :=
  | CSkip
  | CAsgn (x : string) (a : aexp)
  | CSeq (c1 c2 : com)
  | CIf (b : bexp) (c1 c2 : com)
  | CWhile (b : bexp) (c : com).

Syntactic sugar and notations

To make our lives easier, we will use the following notation, allowing us to write programs in the form :
   <{
      x := 0;
      y := [0, 100];
      while x < y do
        x := x + y
      end
   }>
Coercion AId : string >-> aexp.
Coercion ANum : D >-> aexp.

Declare Scope com_scope.

Notation "<{ e }>" := e
  (e custom com, format "'[hv' <{ '/ ' '[v' e ']' '/' }> ']'") : com_scope.

Notation "( x )" := x (in custom com, x at level 99).
Notation "x" := x (in custom com at level 0, x constr at level 0).

Notation "f x .. y" := (.. (f x) .. y)
                  (in custom com at level 0, only parsing,
                  f constr at level 0, x constr at level 1,
                      y constr at level 1).
Notation "x + y" := (APlus x y) (in custom com at level 50, left associativity).
Notation "[ x , y ]" := (ARandom x y) (in custom com at level 50).
Notation "x - y" := (AMinus x y) (in custom com at level 50, left associativity).
Notation "x * y" := (AMult x y) (in custom com at level 40, left associativity).
Notation "'true'" := true (at level 1).
Notation "'true'" := BTrue (in custom com at level 0).
Notation "'false'" := false (at level 1).
Notation "'false'" := BFalse (in custom com at level 0).
Notation "x <= y" := (BLe x y) (in custom com at level 70, no associativity).
Notation "x > y" := (BGt x y) (in custom com at level 70, no associativity).
Notation "x = y" := (BEq x y) (in custom com at level 70, no associativity).
Notation "x <> y" := (BNeq x y) (in custom com at level 70, no associativity).
Notation "x && y" := (BAnd x y) (in custom com at level 80, left associativity).
Notation "'~' b" := (BNot b) (in custom com at level 75, right associativity).

Open Scope com_scope.

As we did for expressions, we can use a few Notation declarations to make reading and writing Imp programs more convenient.

Notation "'skip'" := CSkip
  (in custom com at level 0) : com_scope.
Notation "x := y" := (CAsgn x y)
  (in custom com at level 0, x constr at level 0, y at level 85, no associativity,
    format "x := y") : com_scope.
Notation "x ; y" := (CSeq x y)
  (in custom com at level 90,
    right associativity,
    format "'[v' x ; '/' y ']'") : com_scope.
Notation "'if' x 'then' y 'else' z 'end'" := (CIf x y z)
  (in custom com at level 89, x at level 99, y at level 99, z at level 99,
    format "'[v' 'if' x 'then' '/ ' y '/' 'else' '/ ' z '/' 'end' ']'") : com_scope.
Notation "'while' x 'do' y 'end'" := (CWhile x y)
  (in custom com at level 89, x at level 99, y at level 99,
    format "'[v' 'while' x 'do' '/ ' y '/' 'end' ']'") : com_scope.

End Syntax.