Theory Procs_Stat_Vars_Stat

theory Procs_Stat_Vars_Stat
imports Procs
theory Procs_Stat_Vars_Stat imports Procs
begin

subsubsection "Static Scoping of Procedures and Variables"

type_synonym addr = nat
type_synonym venv = "vname => addr"
type_synonym store = "addr => val"
type_synonym penv = "(pname × com × venv) list"

fun venv :: "penv × venv × nat => venv" where
"venv(_,ve,_) = ve"

inductive
  big_step :: "penv × venv × nat => com × store => store => bool"
  ("_ \<turnstile> _ => _" [60,0,60] 55)
where
Skip:    "e \<turnstile> (SKIP,s) => s" |
Assign:  "(pe,ve,f) \<turnstile> (x ::= a,s) => s(ve x := aval a (s o ve))" |
Seq:     "[| e \<turnstile> (c1,s1) => s2;  e \<turnstile> (c2,s2) => s3 |] ==>
          e \<turnstile> (c1;;c2, s1) => s3" |

IfTrue:  "[| bval b (s o venv e);  e \<turnstile> (c1,s) => t |] ==>
         e \<turnstile> (IF b THEN c1 ELSE c2, s) => t" |
IfFalse: "[| ¬bval b (s o venv e);  e \<turnstile> (c2,s) => t |] ==>
         e \<turnstile> (IF b THEN c1 ELSE c2, s) => t" |

WhileFalse: "¬bval b (s o venv e) ==> e \<turnstile> (WHILE b DO c,s) => s" |
WhileTrue:
  "[| bval b (s1 o venv e);  e \<turnstile> (c,s1) => s2;
     e \<turnstile> (WHILE b DO c, s2) => s3 |] ==>
   e \<turnstile> (WHILE b DO c, s1) => s3" |

Var: "(pe,ve(x:=f),f+1) \<turnstile> (c,s) => t  ==>
      (pe,ve,f) \<turnstile> ({VAR x; c}, s) => t" |

Call1: "((p,c,ve)#pe,ve,f) \<turnstile> (c, s) => t  ==>
        ((p,c,ve)#pe,ve',f) \<turnstile> (CALL p, s) => t" |
Call2: "[| p' ≠ p;  (pe,ve,f) \<turnstile> (CALL p, s) => t |] ==>
       ((p',c,ve')#pe,ve,f) \<turnstile> (CALL p, s) => t" |

Proc: "((p,cp,ve)#pe,ve,f) \<turnstile> (c,s) => t
      ==>  (pe,ve,f) \<turnstile> ({PROC p = cp; c}, s) => t"

code_pred big_step .


values "{map t [10,11] |t.
  ([], <''x'' := 10, ''y'' := 11>, 12)
  \<turnstile> (test_com, <>) => t}"

end