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