src/HOL/Hoare_Parallel/RG_Syntax.thy
author haftmann
Sat Jan 16 17:15:27 2010 +0100 (2010-01-16)
changeset 34940 3e80eab831a1
parent 32621 a073cb249a06
child 35107 bdca9f765ee4
permissions -rw-r--r--
explicit CONST in translations
prensani@13099
     1
header {* \section{Concrete Syntax} *}
prensani@13020
     2
nipkow@15425
     3
theory RG_Syntax
nipkow@15425
     4
imports RG_Hoare Quote_Antiquote
nipkow@15425
     5
begin
prensani@13020
     6
prensani@13020
     7
syntax
prensani@13020
     8
  "_Assign"    :: "idt \<Rightarrow> 'b \<Rightarrow> 'a com"                     ("(\<acute>_ :=/ _)" [70, 65] 61)
prensani@13020
     9
  "_skip"      :: "'a com"                                  ("SKIP")
prensani@13020
    10
  "_Seq"       :: "'a com \<Rightarrow> 'a com \<Rightarrow> 'a com"              ("(_;;/ _)" [60,61] 60)
prensani@13020
    11
  "_Cond"      :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com \<Rightarrow> 'a com"   ("(0IF _/ THEN _/ ELSE _/FI)" [0, 0, 0] 61)
prensani@13020
    12
  "_Cond2"     :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"             ("(0IF _ THEN _ FI)" [0,0] 56)
prensani@13020
    13
  "_While"     :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"             ("(0WHILE _ /DO _ /OD)"  [0, 0] 61)
prensani@13020
    14
  "_Await"     :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"             ("(0AWAIT _ /THEN /_ /END)"  [0,0] 61)
prensani@13020
    15
  "_Atom"      :: "'a com \<Rightarrow> 'a com"                        ("(\<langle>_\<rangle>)" 61)
prensani@13020
    16
  "_Wait"      :: "'a bexp \<Rightarrow> 'a com"                       ("(0WAIT _ END)" 61)
prensani@13020
    17
prensani@13020
    18
translations
schirmer@25706
    19
  "\<acute>\<spacespace>x := a" \<rightharpoonup> "Basic \<guillemotleft>\<acute>\<spacespace>(_update_name x (\<lambda>_. a))\<guillemotright>"
prensani@13020
    20
  "SKIP" \<rightleftharpoons> "Basic id"
prensani@13020
    21
  "c1;; c2" \<rightleftharpoons> "Seq c1 c2"
prensani@13020
    22
  "IF b THEN c1 ELSE c2 FI" \<rightharpoonup> "Cond .{b}. c1 c2"
prensani@13020
    23
  "IF b THEN c FI" \<rightleftharpoons> "IF b THEN c ELSE SKIP FI"
prensani@13020
    24
  "WHILE b DO c OD" \<rightharpoonup> "While .{b}. c"
prensani@13020
    25
  "AWAIT b THEN c END" \<rightleftharpoons> "Await .{b}. c"
prensani@13020
    26
  "\<langle>c\<rangle>" \<rightleftharpoons> "AWAIT True THEN c END"
prensani@13020
    27
  "WAIT b END" \<rightleftharpoons> "AWAIT b THEN SKIP END"
prensani@13020
    28
prensani@13020
    29
nonterminals
prensani@13020
    30
  prgs
prensani@13020
    31
prensani@13020
    32
syntax
prensani@13020
    33
  "_PAR"        :: "prgs \<Rightarrow> 'a"              ("COBEGIN//_//COEND" 60)
prensani@13020
    34
  "_prg"        :: "'a \<Rightarrow> prgs"              ("_" 57)
prensani@13020
    35
  "_prgs"       :: "['a, prgs] \<Rightarrow> prgs"      ("_//\<parallel>//_" [60,57] 57)
prensani@13020
    36
prensani@13020
    37
translations
prensani@13020
    38
  "_prg a" \<rightharpoonup> "[a]"
prensani@13020
    39
  "_prgs a ps" \<rightharpoonup> "a # ps"
prensani@13020
    40
  "_PAR ps" \<rightharpoonup> "ps"
prensani@13020
    41
prensani@13020
    42
syntax
prensani@13020
    43
  "_prg_scheme" :: "['a, 'a, 'a, 'a] \<Rightarrow> prgs"  ("SCHEME [_ \<le> _ < _] _" [0,0,0,60] 57)
prensani@13020
    44
prensani@13020
    45
translations
haftmann@34940
    46
  "_prg_scheme j i k c" \<rightleftharpoons> "(CONST map (\<lambda>i. c) [j..<k])"
prensani@13020
    47
prensani@13020
    48
text {* Translations for variables before and after a transition: *}
prensani@13020
    49
prensani@13020
    50
syntax 
prensani@13020
    51
  "_before" :: "id \<Rightarrow> 'a" ("\<ordmasculine>_")
prensani@13020
    52
  "_after"  :: "id \<Rightarrow> 'a" ("\<ordfeminine>_")
prensani@13020
    53
 
prensani@13020
    54
translations
prensani@13020
    55
  "\<ordmasculine>x" \<rightleftharpoons> "x \<acute>fst"
prensani@13020
    56
  "\<ordfeminine>x" \<rightleftharpoons> "x \<acute>snd"
prensani@13020
    57
prensani@13020
    58
print_translation {*
prensani@13020
    59
  let
prensani@13020
    60
    fun quote_tr' f (t :: ts) =
prensani@13020
    61
          Term.list_comb (f $ Syntax.quote_tr' "_antiquote" t, ts)
prensani@13020
    62
      | quote_tr' _ _ = raise Match;
prensani@13020
    63
prensani@13020
    64
    val assert_tr' = quote_tr' (Syntax.const "_Assert");
prensani@13020
    65
prensani@13020
    66
    fun bexp_tr' name ((Const ("Collect", _) $ t) :: ts) =
prensani@13020
    67
          quote_tr' (Syntax.const name) (t :: ts)
prensani@13020
    68
      | bexp_tr' _ _ = raise Match;
prensani@13020
    69
prensani@13020
    70
    fun upd_tr' (x_upd, T) =
haftmann@31723
    71
      (case try (unsuffix Record.updateN) x_upd of
skalberg@15531
    72
        SOME x => (x, if T = dummyT then T else Term.domain_type T)
skalberg@15531
    73
      | NONE => raise Match);
prensani@13020
    74
prensani@13020
    75
    fun update_name_tr' (Free x) = Free (upd_tr' x)
prensani@13020
    76
      | update_name_tr' ((c as Const ("_free", _)) $ Free x) =
prensani@13020
    77
          c $ Free (upd_tr' x)
prensani@13020
    78
      | update_name_tr' (Const x) = Const (upd_tr' x)
prensani@13020
    79
      | update_name_tr' _ = raise Match;
prensani@13020
    80
schirmer@25706
    81
    fun K_tr' (Abs (_,_,t)) = if null (loose_bnos t) then t else raise Match
schirmer@25706
    82
      | K_tr' (Abs (_,_,Abs (_,_,t)$Bound 0)) = if null (loose_bnos t) then t else raise Match
schirmer@25706
    83
      | K_tr' _ = raise Match;
schirmer@25706
    84
schirmer@25706
    85
    fun assign_tr' (Abs (x, _, f $ k $ Bound 0) :: ts) =
prensani@13020
    86
          quote_tr' (Syntax.const "_Assign" $ update_name_tr' f)
schirmer@25706
    87
            (Abs (x, dummyT, K_tr' k) :: ts)
prensani@13020
    88
      | assign_tr' _ = raise Match;
prensani@13020
    89
  in
prensani@13020
    90
    [("Collect", assert_tr'), ("Basic", assign_tr'),
prensani@13020
    91
      ("Cond", bexp_tr' "_Cond"), ("While", bexp_tr' "_While_inv")]
prensani@13020
    92
  end
prensani@13020
    93
*}
prensani@13020
    94
prensani@13020
    95
end